Search in sources :

Example 11 with ArrayCoreMap

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

the class CreatePatternsTest method test.

@Test
public void test() throws IOException {
    Properties props = new Properties();
    props.setProperty("patternType", "DEP");
    ConstantsAndVariables constvars = new ConstantsAndVariables(props, new HashSet<String>(), new HashMap<String, Class<? extends TypesafeMap.Key<String>>>());
    CreatePatterns<DepPattern> createPatterns = new CreatePatterns<>(props, constvars);
    Map<String, DataInstance> sents = new HashMap<String, DataInstance>();
    CoreMap m = new ArrayCoreMap();
    String text = "We present a paper that focuses on semantic graphs applied to language.";
    String graphString = "[present/VBP-2 nsubj>We/PRP-1 dobj>[paper/NN-4 det>a/DT-3] ccomp>[applied/VBN-10 mark>that/IN-5 nsubj>[focuses/NN-6 nmod:on>[graphs/NNS-9 amod>semantic/JJ-8]] nmod:to>language/NN-12]]";
    SemanticGraph graph = SemanticGraph.valueOf(graphString);
    //String phrase = "semantic graphs";
    List<String> tokens = Arrays.asList(new String[] { "We", "present", "a", "paper", "that", "focuses", "on", "semantic", "graphs", "applied", "to", "language" });
    m.set(CoreAnnotations.TokensAnnotation.class, tokens.stream().map(x -> {
        CoreLabel t = new CoreLabel();
        t.setWord(x);
        return t;
    }).collect(Collectors.toList()));
    m.set(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class, graph);
    sents.put("sent1", DataInstance.getNewInstance(PatternFactory.PatternType.DEP, m));
    createPatterns.getAllPatterns(sents, props, ConstantsAndVariables.PatternForEachTokenWay.MEMORY);
    System.out.println("graph is " + graph);
    System.out.println(PatternsForEachTokenInMemory.patternsForEachToken);
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CreatePatterns(edu.stanford.nlp.patterns.surface.CreatePatterns) DepPattern(edu.stanford.nlp.patterns.dep.DepPattern) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) CoreMap(edu.stanford.nlp.util.CoreMap) ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) Test(org.junit.Test)

Example 12 with ArrayCoreMap

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

the class AnnotationTest method testFromList.

/** 
   * Test a bug a user reported where the text would wind up having the list toString used, adding extra []
   */
public void testFromList() {
    List<CoreMap> sentences = Generics.newArrayList();
    CoreMap sentence = new ArrayCoreMap();
    List<CoreLabel> words = SentenceUtils.toCoreLabelList("This", "is", "a", "test", ".");
    sentence.set(CoreAnnotations.TokensAnnotation.class, words);
    sentences.add(sentence);
    Annotation annotation = new Annotation(sentences);
    assertEquals("This is a test .", annotation.toString());
    sentence.set(CoreAnnotations.TextAnnotation.class, "This is a test.");
    annotation = new Annotation(sentences);
    assertEquals("This is a test.", annotation.toString());
}
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 13 with ArrayCoreMap

use of edu.stanford.nlp.util.ArrayCoreMap in project cogcomp-nlp by CogComp.

the class StanfordParseHandler method buildStanfordSentence.

private static CoreMap buildStanfordSentence(Constituent sentence, String rawText, int sentIndex, List<CoreLabel> stanfordTokens) {
    CoreMap stanfordSentence = new ArrayCoreMap();
    CoreLabel firstTok = stanfordTokens.get(0);
    CoreLabel lastTok = stanfordTokens.get(stanfordTokens.size() - 1);
    stanfordSentence.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, sentence.getStartSpan());
    stanfordSentence.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, sentence.getEndSpan());
    stanfordSentence.set(CoreAnnotations.TokenBeginAnnotation.class, firstTok.index());
    // at-the-end
    stanfordSentence.set(CoreAnnotations.TokenEndAnnotation.class, lastTok.index() + 1);
    // indexing?
    stanfordSentence.set(CoreAnnotations.TextAnnotation.class, rawText);
    stanfordSentence.set(CoreAnnotations.SentenceIndexAnnotation.class, sentIndex);
    stanfordSentence.set(CoreAnnotations.TokensAnnotation.class, stanfordTokens);
    return stanfordSentence;
}
Also used : ArrayCoreMap(edu.stanford.nlp.util.ArrayCoreMap) CoreLabel(edu.stanford.nlp.ling.CoreLabel) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) 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