summaryrefslogtreecommitdiff
path: root/spellchecker/src/ConfusionMatrixReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'spellchecker/src/ConfusionMatrixReader.java')
-rw-r--r--spellchecker/src/ConfusionMatrixReader.java52
1 files changed, 24 insertions, 28 deletions
diff --git a/spellchecker/src/ConfusionMatrixReader.java b/spellchecker/src/ConfusionMatrixReader.java
index b75da47..c9e79ab 100644
--- a/spellchecker/src/ConfusionMatrixReader.java
+++ b/spellchecker/src/ConfusionMatrixReader.java
@@ -1,5 +1,4 @@
-
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -10,58 +9,55 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public class ConfusionMatrixReader {
-
+
final static String DATAFILE_LOC = "confusion_matrix.txt";
- final private HashMap<String,Integer> confusionMatrix = new HashMap<>();
- final private HashMap<String,Integer> countMatrix = new HashMap<>();
- public ConfusionMatrixReader()
- {
+ final private HashMap<String, Integer> confusionMatrix = new HashMap<>();
+ final private HashMap<String, Integer> countMatrix = new HashMap<>();
+
+ public ConfusionMatrixReader() {
try {
readConfusionMatrix();
} catch (Exception ex) {
Logger.getLogger(ConfusionMatrixReader.class.getName()).log(Level.SEVERE, null, ex);
}
}
-
- private void readConfusionMatrix()
- throws FileNotFoundException, IOException
- {
+
+ private void readConfusionMatrix()
+ throws FileNotFoundException, IOException {
FileInputStream fis;
fis = new FileInputStream(DATAFILE_LOC);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
-
- while( in.ready() )
- {
+
+ while (in.ready()) {
String line = in.readLine();
int space = line.lastIndexOf(' ');
- String keys = line.substring(0,space);
+ String keys = line.substring(0, space);
try {
- int count = Integer.parseInt(line.substring(space+1));
+ int count = Integer.parseInt(line.substring(space + 1));
confusionMatrix.put(keys, count);
- String key = keys.substring(0,keys.indexOf('|'));
+ String key = keys.substring(0, keys.indexOf('|'));
Integer value = countMatrix.get(key);
- if (value==null) {
+ if (value == null) {
value = 0;
}
- countMatrix.put(key, value+count);
- } catch(NumberFormatException e) {
- System.err.println("problems with string <"+line+">");
+ countMatrix.put(key, value + count);
+ } catch (NumberFormatException e) {
+ System.err.println("problems with string <" + line + ">");
}
}
}
-
+
/**
- * Returns the count for the pair <error>|<correct> in the confusion
- * matrix, e.g. "c|ct" is 36
- *
+ * Returns the count for the pair <error>|<correct> in the confusion matrix,
+ * e.g. "c|ct" is 36
+ *
* @param error
* @param correct
* @return
*/
- public int getConfusionCount(String error, String correct)
- {
- Integer count = confusionMatrix.get(error+"|"+correct);
- return count==null?0:count;
+ public int getConfusionCount(String error, String correct) {
+ Integer count = confusionMatrix.get(error + "|" + correct);
+ return count == null ? 0 : count;
}
}