Search in sources :

Example 16 with CoreLabel

use of edu.stanford.nlp.ling.CoreLabel in project CoreNLP by stanfordnlp.

the class NaturalLogicWeightsITest method mockWord.

private CoreLabel mockWord(String text) {
    CoreLabel word = new CoreLabel();
    word.setOriginalText(text);
    word.setWord(text);
    return word;
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel)

Example 17 with CoreLabel

use of edu.stanford.nlp.ling.CoreLabel in project CoreNLP by stanfordnlp.

the class PolarityITest method annotate.

@SuppressWarnings("unchecked")
private Polarity[] annotate(String text) {
    Annotation ann = new Annotation(text);
    pipeline.annotate(ann);
    List<CoreLabel> tokens = ann.get(CoreAnnotations.SentencesAnnotation.class).get(0).get(CoreAnnotations.TokensAnnotation.class);
    SemanticGraph tree = ann.get(CoreAnnotations.SentencesAnnotation.class).get(0).get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
    Polarity[] polarities = new Polarity[tokens.size()];
    for (int i = 0; i < tokens.size(); ++i) {
        polarities[i] = tokens.get(i).get(NaturalLogicAnnotations.PolarityAnnotation.class);
    }
    return polarities;
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 18 with CoreLabel

use of edu.stanford.nlp.ling.CoreLabel in project CoreNLP by stanfordnlp.

the class DependencyIndexITest method checkTree.

private static void checkTree(Tree tree) {
    List<Tree> leaves = tree.getLeaves();
    for (Tree leaf : leaves) {
        CoreLabel l = null;
        if (leaf.label() instanceof CoreLabel)
            l = (CoreLabel) leaf.label();
        if (l != null) {
            // System.err.println(l + " " + l.get(CoreAnnotations.IndexAnnotation.class));
            int index = l.get(CoreAnnotations.IndexAnnotation.class);
            String text = l.get(CoreAnnotations.TextAnnotation.class);
            if (text.equals("Mary"))
                assertEquals(1, index);
            else if (text.equals("had"))
                assertEquals(2, index);
            else if (text.equals("a"))
                assertEquals(3, index);
            else if (text.equals("little"))
                assertEquals(4, index);
            else if (text.equals("lamb"))
                assertEquals(5, index);
            else if (text.equals("."))
                assertEquals(6, index);
        } else {
        // System.err.println(leaf + " is not a CoreLabel.");
        }
    }
    TreebankLanguagePack tlp = new PennTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
    Collection<TypedDependency> deps = gs.typedDependenciesCCprocessed(GrammaticalStructure.Extras.MAXIMAL);
    // System.out.println(deps);
    // collect all nodes in deps
    Set<IndexedWord> nodes = Generics.newHashSet();
    for (TypedDependency dep : deps) {
        nodes.add(dep.gov());
        nodes.add(dep.dep());
    }
    // check the indices for all nodes
    for (IndexedWord n : nodes) {
        String text = n.value();
        int index = n.get(CoreAnnotations.IndexAnnotation.class);
        if (text.equals("Mary"))
            assertEquals(1, index);
        else if (text.equals("had"))
            assertEquals(2, index);
        else if (text.equals("a"))
            assertEquals(3, index);
        else if (text.equals("little"))
            assertEquals(4, index);
        else if (text.equals("lamb"))
            assertEquals(5, index);
        else if (text.equals("."))
            assertEquals(6, index);
    }
}
Also used : TypedDependency(edu.stanford.nlp.trees.TypedDependency) PennTreebankLanguagePack(edu.stanford.nlp.trees.PennTreebankLanguagePack) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) GrammaticalStructureFactory(edu.stanford.nlp.trees.GrammaticalStructureFactory) GrammaticalStructure(edu.stanford.nlp.trees.GrammaticalStructure) Tree(edu.stanford.nlp.trees.Tree) TreebankLanguagePack(edu.stanford.nlp.trees.TreebankLanguagePack) PennTreebankLanguagePack(edu.stanford.nlp.trees.PennTreebankLanguagePack) IndexedWord(edu.stanford.nlp.ling.IndexedWord)

Example 19 with CoreLabel

use of edu.stanford.nlp.ling.CoreLabel in project CoreNLP by stanfordnlp.

the class LexicalizedParserITest method testCharOffsets.

public void testCharOffsets() {
    String text = "  You can  eat fruits   such as apples and   oranges.";
    String[] tokens = { "You", "can", "eat", "fruits", "such", "as", "apples", "and", "oranges", "." };
    int[] begins = { 2, 6, 11, 15, 24, 29, 32, 39, 45, 52 };
    int[] ends = { 5, 9, 14, 21, 28, 31, 38, 42, 52, 53 };
    Tree tree = englishParser.parse(text);
    List<CoreLabel> yield = tree.yield(new ArrayList<CoreLabel>());
    assertEquals("Wrong number of tokens in parser output", tokens.length, yield.size());
    int i = 0;
    for (CoreLabel cl : yield) {
        assertEquals("Wrong token", tokens[i], cl.word());
        assertEquals("Wrong char begin", begins[i], (int) cl.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class));
        assertEquals("Wrong char end", ends[i], (int) cl.get(CoreAnnotations.CharacterOffsetEndAnnotation.class));
        i++;
    }
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) Tree(edu.stanford.nlp.trees.Tree) TreePrint(edu.stanford.nlp.trees.TreePrint) ParserConstraint(edu.stanford.nlp.parser.common.ParserConstraint)

Example 20 with CoreLabel

use of edu.stanford.nlp.ling.CoreLabel in project CoreNLP by stanfordnlp.

the class LexicalizedParserITest method testParserQuery.

/**
   * Test the query structure that you can use for better control of
   * the parse
   */
public void testParserQuery() {
    List<CoreLabel> sentence = sampleSausage();
    ParserQuery pq = englishParser.parserQuery();
    pq.parse(sentence);
    compareSingleOutput(pq.getBestParse(), false, pennPrint, "(ROOT (S (NP (PRP$ My) (NN dog)) (ADVP (RB also)) (VP (VBZ likes) (S (VP (VBG eating) (NP (NN sausage))))) (. .)))");
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) ParserQuery(edu.stanford.nlp.parser.common.ParserQuery)

Aggregations

CoreLabel (edu.stanford.nlp.ling.CoreLabel)533 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)310 CoreMap (edu.stanford.nlp.util.CoreMap)102 ArrayList (java.util.ArrayList)101 Tree (edu.stanford.nlp.trees.Tree)98 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)96 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)63 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)53 ParserConstraint (edu.stanford.nlp.parser.common.ParserConstraint)41 IndexedWord (edu.stanford.nlp.ling.IndexedWord)38 List (java.util.List)33 Annotation (edu.stanford.nlp.pipeline.Annotation)31 Mention (edu.stanford.nlp.coref.data.Mention)29 Label (edu.stanford.nlp.ling.Label)28 ClassicCounter (edu.stanford.nlp.stats.ClassicCounter)26 Properties (java.util.Properties)24 CorefCoreAnnotations (edu.stanford.nlp.coref.CorefCoreAnnotations)21 CoreAnnotation (edu.stanford.nlp.ling.CoreAnnotation)19 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)18 StringReader (java.io.StringReader)18