@@ -0,0 +1,2004 @@
+package e6893.ocr;%0A%0Aimport org.neo4j.cypher.javacompat.ExecutionEngine;%0Aimport org.neo4j.graphdb.factory.GraphDatabaseFactory;%0A%0Apublic class CreateCouldBeExactlyOne extends BaseOCR %7B%0A%0A%09String q;%0A%09ExecutionEngine engine;%0A%0A%09/**%0A%09 * Main%0A%09 */%0A%09public static void main(final String%5B%5D args) throws Exception %7B%0A%09%09(new CreateCouldBeExactlyOne((args.length %3C 1 ? null : args%5B0%5D))).execute();%0A%09%7D%0A%0A%09/**%0A%09 * Constructor%0A%09 */%0A%09public CreateCouldBeExactlyOne(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%0A%09/**%0A%09 * Mark all ground truth nodes%0A%09 */%0A%09void execute() throws Exception %7B%0A%0A%09%09if (getSystemState(db) %3C SYSTEM_STATE_CREATED_COULD_BE_EXACTLY_ONE - 1) %7B%0A%09%09%09Integer ss = getSystemState(db);%0A%09%09%09shutDown();%0A%09%09%09throw new Exception(%22System in wrong state for this task: %22 + ss);%0A%09%09%7D%0A%0A%09%09if (getSystemState(db) %3E= SYSTEM_STATE_CREATED_COULD_BE_EXACTLY_ONE) %7B%0A%09%09%09shutDown();%0A%09%09%09msg(%22Could Be Exactly One Ground Truth relationships already created.%22);%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09loadExecutionEngine(db);%0A%09%09performUpdate();%0A%09%09shutDown();%0A%09%7D%0A%0A%09/**%0A%09 * Update%0A%09 */%0A%09void performUpdate() throws Exception %7B%0A%09%09Integer iterationNumber = getIterationNumber(db);%0A%09%09int newTruthValue = -10 - iterationNumber; %0A%09%09String couldBeRelation = %22COULDBE%22 + iterationNumber;%0A%09%09%0A%09%09q = %22MATCH (t:Token)-%5Br%5D-%3E(p)%3C-%5Ber%5D-(et) WHERE t.freq%3Cet.freq AND t.truth%3C0 AND et.truth%3E0 AND r.char%3C%3E'$' AND er.char%3C%3E'$' WITH t, count(et) AS cet %22;%0A%09%09q+= %22WHERE cet=1 %22;%0A%09%09q+=%22MATCH (t)-%5Brg%5D-%3E(pg)%3C-%5Berg%5D-(etg) WHERE t.freq%3Cetg.freq AND etg.truth%3E0 AND rg.char%3C%3E'$' AND erg.char%3C%3E'$'  %22;%0A%09%09q+=%22CREATE(t)-%5B:%22;%0A%09%09q+= couldBeRelation + %22 %7Bgiven:erg.char, misreadas:rg.char%7D%5D-%3E(etg) SET t.truth = %22 + newTruthValue;%0A%09%09%0A%09%09msg(%22Executing:%22);%0A%09%09msg(q);%0A%09%09doUpdate(q);%0A%09%09setSystemState(db, SYSTEM_STATE_CREATED_COULD_BE_EXACTLY_ONE);%0A%09%7D%0A%7D%0A

Create CreateCouldBeExactlyOne.java