private void processExamples(String group, List<Example> examples) { Evaluation evaluation = new Evaluation(); if (examples.isEmpty()) return; final String prefix = "iter=0." + group; Execution.putOutput("group", group); LogInfo.begin_track_printAll("Processing %s: %s examples", prefix, examples.size()); LogInfo.begin_track("Dumping metadata"); dumpMetadata(group, examples); LogInfo.end_track(); LogInfo.begin_track("Examples"); for (int e = 0; e < examples.size(); e++) { Example ex = examples.get(e); LogInfo.begin_track_printAll("%s: example %s/%s: %s", prefix, e, examples.size(), ex.id); ex.log(); Execution.putOutput("example", e); StopWatchSet.begin("Parser.parse"); ParserState state = builder.parser.parse(params, ex, false); StopWatchSet.end(); out.printf("########## Example %s ##########\n", ex.id); dumpExample(exampleToLispTree(state)); LogInfo.logs("Current: %s", ex.evaluation.summary()); evaluation.add(ex.evaluation); LogInfo.logs("Cumulative(%s): %s", prefix, evaluation.summary()); LogInfo.end_track(); ex.predDerivations.clear(); // To save memory } LogInfo.end_track(); LogInfo.logs("Stats for %s: %s", prefix, evaluation.summary()); evaluation.logStats(prefix); evaluation.putOutput(prefix); LogInfo.end_track(); }
private LispTree exampleToLispTree(ParserState state) { LispTree tree = LispTree.proto.newList(); tree.addChild("example"); // Basic information Example ex = state.ex; if (ex.id != null) tree.addChild(LispTree.proto.newList("id", ex.id)); if (ex.utterance != null) tree.addChild(LispTree.proto.newList("utterance", ex.utterance)); if (ex.targetFormula != null) tree.addChild(LispTree.proto.newList("targetFormula", ex.targetFormula.toLispTree())); if (ex.targetValue != null) tree.addChild(LispTree.proto.newList("targetValue", ex.targetValue.toLispTree())); if (ex.context != null) tree.addChild(ex.context.toLispTree()); // Language info if (ex.languageInfo != null) { if (ex.languageInfo.tokens != null) tree.addChild( LispTree.proto.newList("tokens", LispTree.proto.newList(ex.languageInfo.tokens))); if (ex.languageInfo.lemmaTokens != null) tree.addChild( LispTree.proto.newList( "lemmaTokens", LispTree.proto.newList(ex.languageInfo.lemmaTokens))); if (ex.languageInfo.posTags != null) tree.addChild( LispTree.proto.newList("posTags", LispTree.proto.newList(ex.languageInfo.posTags))); if (ex.languageInfo.nerTags != null) tree.addChild( LispTree.proto.newList("nerTags", LispTree.proto.newList(ex.languageInfo.nerTags))); if (ex.languageInfo.nerValues != null) tree.addChild( LispTree.proto.newList("nerValues", LispTree.proto.newList(ex.languageInfo.nerValues))); } // Derivations LispTree derivations = LispTree.proto.newList(); derivations.addChild("derivations"); List<Derivation> preds = state.predDerivations; for (int i = 0; i < preds.size(); i++) { Derivation deriv = preds.get(i); if (!isPruned(deriv)) { derivations.addChild(deriv.toLispTree()); } } tree.addChild(derivations); return tree; }