use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView in project cogcomp-nlp by CogComp.
the class ParsePhraseTypeOnly method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
TextAnnotation ta = c.getTextAnnotation();
TreeView tree = (TreeView) ta.getView(parseViewname);
Constituent phrase;
try {
phrase = tree.getParsePhrase(c);
} catch (Exception e) {
throw new EdisonException(e);
}
Set<Feature> features = new LinkedHashSet<>();
if (phrase != null)
features.add(DiscreteFeature.create(phrase.getLabel()));
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView in project cogcomp-nlp by CogComp.
the class TestParseViewGenerator method testCharniakParseViewGenerator.
@Test
public final void testCharniakParseViewGenerator() {
String sentence = "This is a test .";
String treeString = "(S1 (S (NP (DT This)) (VP (AUX is) (NP (DT a) (NN test)))(. .)))";
Tree<String> tree = TreeParserFactory.getStringTreeParser().parse(treeString);
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(sentence);
TreeView parseView = new TreeView(ViewNames.PARSE_CHARNIAK, "My_PARSER", ta, 1d);
parseView.setParseTree(0, tree);
ta.addView(ViewNames.PARSE_CHARNIAK, parseView);
TreeView view = (TreeView) ta.getView(ViewNames.PARSE_CHARNIAK);
logger.info(ParseHelper.getParseTree(ViewNames.PARSE_CHARNIAK, ta, 0).toString());
assertEquals(tree, view.getTree(0));
CollinsHeadDependencyParser depParser = new CollinsHeadDependencyParser(true);
Tree<Pair<String, Integer>> depTree = depParser.getLabeledDependencyTree(view.getRootConstituent(0));
TreeView depView = new TreeView(ViewNames.DEPENDENCY, "HeadRuleDependencyTree", ta, 1.0);
logger.info(depTree.toString());
depView.setDependencyTree(0, depTree);
ta.addView(ViewNames.DEPENDENCY, depView);
logger.info(depView.toString());
logger.info(depView.getTree(0).toString());
}
Aggregations