Search in sources :

Example 1 with CreatePatterns

use of edu.stanford.nlp.patterns.surface.CreatePatterns 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)

Aggregations

CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1 DepPattern (edu.stanford.nlp.patterns.dep.DepPattern)1 CreatePatterns (edu.stanford.nlp.patterns.surface.CreatePatterns)1 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)1 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)1 ArrayCoreMap (edu.stanford.nlp.util.ArrayCoreMap)1 CoreMap (edu.stanford.nlp.util.CoreMap)1 Test (org.junit.Test)1