Search in sources :

Example 1 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project CoreNLP by stanfordnlp.

the class MorphaAnnotatorITest method testSentencesAnnotation.

public void testSentencesAnnotation() throws Exception {
    List<CoreLabel> words = getTestWords();
    CoreMap sentence = new ArrayCoreMap();
    sentence.set(CoreAnnotations.TokensAnnotation.class, words);
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    sentences.add(sentence);
    Annotation document = new Annotation(text);
    document.set(CoreAnnotations.SentencesAnnotation.class, sentences);
    shortPipeline.annotate(document);
    checkResult(words);
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ArrayList(java.util.ArrayList) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap)

Example 2 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project CoreNLP by stanfordnlp.

the class POSTaggerAnnotatorITest method testMultipleSentencesAnnotation.

/**
   * Test that multiple sentences work for the SentenceAnnotation.
   */
public void testMultipleSentencesAnnotation() {
    List<CoreLabel> firstLabels = makeSentence(testSentences[0]);
    List<CoreLabel> secondLabels = makeSentence(testSentences[1]);
    CoreMap firstSentence = new ArrayCoreMap();
    firstSentence.set(CoreAnnotations.TokensAnnotation.class, firstLabels);
    CoreMap secondSentence = new ArrayCoreMap();
    secondSentence.set(CoreAnnotations.TokensAnnotation.class, secondLabels);
    List<CoreMap> sentences = new ArrayList<>();
    sentences.add(firstSentence);
    sentences.add(secondSentence);
    Annotation annotation = new Annotation(longText);
    annotation.set(CoreAnnotations.SentencesAnnotation.class, sentences);
    tagger.annotate(annotation);
    checkLabels(firstLabels, "PRP$", "NN", "VBZ", "JJ", "CC", "JJ", ".");
    checkLabels(secondLabels, "DT", "VBZ", "DT", "JJ", "NN", ".");
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ArrayList(java.util.ArrayList) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap)

Example 3 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project CoreNLP by stanfordnlp.

the class POSTaggerAnnotatorITest method makeSentenceCoreMap.

private static CoreMap makeSentenceCoreMap(String sentence) {
    List<CoreLabel> tokens = makeSentence(sentence);
    CoreMap map = new ArrayCoreMap(1);
    map.set(CoreAnnotations.TokensAnnotation.class, tokens);
    return map;
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap)

Example 4 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project CoreNLP by stanfordnlp.

the class RegexNERAnnotatorITest method testOverwrite.

/**
   * Neither the LOCATION nor the ORGANIZATION tags should be overridden, since both
   * Ontario (STATE_OR_PROVINCE) and American (NATIONALITY) do not span the entire
   * phrase that is NamedEntityTag-annotated.
   */
public void testOverwrite() {
    String str = "I like Ontario Place , and I like the Native American Church , too .";
    String[] split = str.split(" ");
    List<CoreLabel> tokens = SentenceUtils.toCoreLabelList(split);
    tokens.get(2).set(CoreAnnotations.NamedEntityTagAnnotation.class, "LOCATION");
    tokens.get(3).set(CoreAnnotations.NamedEntityTagAnnotation.class, "LOCATION");
    tokens.get(9).set(CoreAnnotations.NamedEntityTagAnnotation.class, "ORGANIZATION");
    tokens.get(10).set(CoreAnnotations.NamedEntityTagAnnotation.class, "ORGANIZATION");
    tokens.get(11).set(CoreAnnotations.NamedEntityTagAnnotation.class, "ORGANIZATION");
    CoreMap sentence = new ArrayCoreMap();
    sentence.set(CoreAnnotations.TokensAnnotation.class, tokens);
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    sentences.add(sentence);
    Annotation corpus = new Annotation("I like Ontario Place, and I like the Native" + "American Church, too.");
    corpus.set(CoreAnnotations.SentencesAnnotation.class, sentences);
    annotator.annotate(corpus);
    checkTags(tokens, "O", "O", "LOCATION", "LOCATION", "O", "O", "O", "O", "O", "RELIGION", "RELIGION", "RELIGION", "O", "O", "O");
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ArrayList(java.util.ArrayList) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap)

Example 5 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project CoreNLP by stanfordnlp.

the class RegexNERAnnotatorITest method testPriority.

/**
   * In the mapping file, Christianity is assigned a higher priority than Early Christianity,
   * and so Early should not be marked as RELIGION.
   */
public void testPriority() {
    String str = "Christianity is of higher regex priority than Early Christianity . ";
    String[] split = str.split(" ");
    List<CoreLabel> tokens = SentenceUtils.toCoreLabelList(split);
    CoreMap sentence = new ArrayCoreMap();
    sentence.set(CoreAnnotations.TokensAnnotation.class, tokens);
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    sentences.add(sentence);
    Annotation corpus = new Annotation("Christianity is of higher regex priority than Early " + "Christianity. ");
    corpus.set(CoreAnnotations.SentencesAnnotation.class, sentences);
    annotator.annotate(corpus);
    checkTags(tokens, "RELIGION", "O", "O", "O", "O", "O", "O", "O", "RELIGION", "O");
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ArrayList(java.util.ArrayList) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap)

Aggregations

CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)13 CoreLabel (edu.stanford.nlp.ling.CoreLabel)13 ArrayCoreMap (edu.stanford.nlp.util.ArrayCoreMap)13 CoreMap (edu.stanford.nlp.util.CoreMap)13 ArrayList (java.util.ArrayList)7 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)2 StringReader (java.io.StringReader)2 Matcher (java.util.regex.Matcher)2 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 HasWord (edu.stanford.nlp.ling.HasWord)1 DepPattern (edu.stanford.nlp.patterns.dep.DepPattern)1 CreatePatterns (edu.stanford.nlp.patterns.surface.CreatePatterns)1 Annotation (edu.stanford.nlp.pipeline.Annotation)1 DocumentPreprocessor (edu.stanford.nlp.process.DocumentPreprocessor)1 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)1 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)1 Tree (edu.stanford.nlp.trees.Tree)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 Builder (nu.xom.Builder)1