Search in sources :

Example 31 with TreeView

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 32 with TreeView

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());
}
Also used : CollinsHeadDependencyParser(edu.illinois.cs.cogcomp.nlp.utilities.CollinsHeadDependencyParser) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Pair(edu.illinois.cs.cogcomp.core.datastructures.Pair) Test(org.junit.Test)

Aggregations

TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)32 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)27 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)20 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)13 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)12 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)11 LinkedHashSet (java.util.LinkedHashSet)11 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)9 Test (org.junit.Test)7 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)6 ArrayList (java.util.ArrayList)6 Tree (edu.illinois.cs.cogcomp.core.datastructures.trees.Tree)5 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)3 List (java.util.List)3 RealFeature (edu.illinois.cs.cogcomp.edison.features.RealFeature)2 POSFromParse (edu.illinois.cs.cogcomp.nlp.utilities.POSFromParse)2 Annotation (edu.stanford.nlp.pipeline.Annotation)2 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)2 CoreMap (edu.stanford.nlp.util.CoreMap)2 HashSet (java.util.HashSet)2