@@ -0,0 +1,1977 @@
+package e6893.ocr;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.util.Map;%0A%0Aimport org.neo4j.cypher.javacompat.ExecutionResult;%0Aimport org.neo4j.graphdb.factory.GraphDatabaseFactory;%0A%0Apublic class CreateCorrectionsFile extends BaseOCR %7B%0A%0A%09public static final String FILE_SUFFIX = %22.corrections%22;%0A%0A%09/**%0A%09 * Constructor%0A%09 */%0A%09public CreateCorrectionsFile(String dbPath) throws Exception %7B%0A%09%09this.dbPath = (dbPath == null ? this.getLine(%22Database path%22) : dbPath);%0A%09%09msgn(%22Connecting to database...%22);%0A%09%09db = new GraphDatabaseFactory().newEmbeddedDatabase(this.dbPath);%0A%09%09msg(%22...Database connected.%22);%0A%09%09registerShutdownHook(db);%0A%09%7D%0A%09%0A%09/**%0A%09 * %0A%09 */%0A%09void execute(String csvPath) throws Exception %7B%0A%0A%09%09if (getSystemState(db) != SYSTEM_STATE_COMPLETED) %7B%0A%09%09%09shutDown();%0A%09%09%09throw new Exception(%22System not completed, no corrections file generated.%22);%0A%09%09%7D%0A%0A%09%09loadExecutionEngine(db);%0A%09%09output(csvPath);%0A%09%09shutDown();%0A%09%7D%0A%09%0A%09/*%0A%09 * Create pattern files%0A%09 */%0A%09private void output(String csvPath) throws Exception %7B%0A%0A%0A%09%09/*%0A%09%09 * Create a file%0A%09%09 */%0A%09%09File corrFile = new File(csvPath + FILE_SUFFIX);%0A%09%09if (corrFile.exists()) %7B%0A%09%09%09corrFile.delete();%0A%09%09%7D%0A%0A%09%09int rows = 0;%0A%09%09BufferedWriter bw = new BufferedWriter(new FileWriter(corrFile, true));%0A%09%09try %7B%0A%09%09%09String q = %22MATCH (e:Token) where  ABS(e.truth)%3E13 MATCH (e:Token)-%5Br%5D-%3E(t:Token) %22;%0A%09%09%09q += %22WITH e.literal AS error, t.literal AS truth, t.freq AS freq ORDER BY t.freq DESC %22;%0A%09%09%09q += %22RETURN DISTINCT error, truth, freq  LIMIT %22 + LIMIT_ERROR_FILE;%0A%09%09%09msg(%22Writing from:%22);%0A%09%09%09msg(q);%0A%0A%09%09%09ExecutionResult er = ee.execute(q);%0A%09%09%09for (Map%3CString, Object%3E row : er) %7B%0A%09%09%09%09rows++;%0A%09%09%09%09String error = (String) row.get(%22error%22);%0A%09%09%09%09String truth = (String) row.get(%22truth%22);%0A%09%09%09%09bw.write(error);%0A%09%09%09%09bw.write(%22,%22);%0A%09%09%09%09bw.write(truth);%0A%09%09%09%09bw.newLine();%0A%09%09%09%7D%0A%0A%09%09%7D finally %7B%0A%09%09%09if (bw != null) bw.close();%0A%09%09%7D%0A%0A%09%09msg(%22Wrote %22 + rows + %22 corrections to %22 + corrFile.getAbsolutePath());%0A%09%7D%0A%0A%7D%0A

Create CreateCorrectionsFile.java