private void dumpMetadata(String group, List<Example> examples) { LispTree tree = LispTree.proto.newList(); tree.addChild("metadata"); tree.addChild(LispTree.proto.newList("group", group)); tree.addChild(LispTree.proto.newList("size", "" + examples.size())); tree.print(out); out.println(); }
private void dumpExample(LispTree tree) { out.println("(example"); for (LispTree subtree : tree.children.subList(1, tree.children.size())) { if (!subtree.isLeaf() && "derivations".equals(subtree.children.get(0).value)) { if (subtree.children.size() == 1) { out.println(" (derivations)"); } else { out.println(" (derivations"); for (LispTree derivation : subtree.children.subList(1, subtree.children.size())) { out.write(" "); derivation.print(Integer.MAX_VALUE, Integer.MAX_VALUE, out); out.write("\n"); } out.println(" )"); } } else { out.write(" "); subtree.print(Integer.MAX_VALUE, Integer.MAX_VALUE, out); out.write("\n"); } } out.println(")"); }
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; }