Search in sources :

Example 1 with StanfordTextProcessor

use of com.graphaware.nlp.processor.stanford.StanfordTextProcessor in project neo4j-nlp-stanfordnlp by graphaware.

the class TextProcessorTest method init.

@BeforeClass
public static void init() {
    textProcessor = new StanfordTextProcessor();
    textProcessor.init();
    Map<String, Object> processingSteps = new HashMap<>();
    processingSteps.put(AbstractTextProcessor.STEP_TOKENIZE, true);
    processingSteps.put(AbstractTextProcessor.STEP_NER, true);
    PipelineSpecification pipelineSpecification = new PipelineSpecification("default", StanfordTextProcessor.class.getName(), processingSteps, null, 1L, Collections.emptyList(), Collections.emptyList());
    PIPELINE_DEFAULT = pipelineSpecification;
    textProcessor.createPipeline(PIPELINE_DEFAULT);
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StanfordTextProcessor(com.graphaware.nlp.processor.stanford.StanfordTextProcessor) BeforeClass(org.junit.BeforeClass)

Example 2 with StanfordTextProcessor

use of com.graphaware.nlp.processor.stanford.StanfordTextProcessor in project neo4j-nlp-stanfordnlp by graphaware.

the class DependencyParserTest method testTagMerging.

@Test
public void testTagMerging() throws Exception {
    StanfordCoreNLP pipeline = ((StanfordTextProcessor) textProcessor).getPipeline("default");
    String text = "Donald Trump flew yesterday to New York City";
    AnnotatedText at = textProcessor.annotateText(text, "en", PIPELINE_DEFAULT);
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) StanfordTextProcessor(com.graphaware.nlp.processor.stanford.StanfordTextProcessor) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Test(org.junit.Test)

Example 3 with StanfordTextProcessor

use of com.graphaware.nlp.processor.stanford.StanfordTextProcessor in project neo4j-nlp-stanfordnlp by graphaware.

the class DependencyParserTest method testStanfordTypedDependenciesParsing.

@Test
public void testStanfordTypedDependenciesParsing() {
    StanfordCoreNLP pipeline = ((StanfordTextProcessor) textProcessor).getPipeline("default");
    String text = "Show me Josh Wedhon latest movies";
    Annotation document = new Annotation(text);
    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    CoreMap sentence = sentences.get(0);
    System.out.println(sentence.toString());
    SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class);
    System.out.println(graph);
    List<SemanticGraphEdge> edges = graph.edgeListSorted();
    for (SemanticGraphEdge edge : edges) {
        System.out.println(edge.getRelation().getSpecific());
        System.out.println(edge.getRelation().getShortName());
        System.out.println(String.format("Source is : %s - Target is : %s - Relation is : %s", edge.getSource(), edge.getTarget(), edge.getRelation()));
    }
}
Also used : CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) StanfordTextProcessor(com.graphaware.nlp.processor.stanford.StanfordTextProcessor) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) Test(org.junit.Test)

Example 4 with StanfordTextProcessor

use of com.graphaware.nlp.processor.stanford.StanfordTextProcessor in project neo4j-nlp-stanfordnlp by graphaware.

the class DependencyParserTest method testStanfordNLPWithPredefinedProcessors.

@Test
public void testStanfordNLPWithPredefinedProcessors() throws Exception {
    StanfordCoreNLP pipeline = ((StanfordTextProcessor) textProcessor).getPipeline("default");
    String text = "Donald Trump flew yesterday to New York City";
    AnnotatedText at = textProcessor.annotateText(text, "en", PIPELINE_DEFAULT);
    Annotation document = new Annotation(text);
    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    CoreMap sentence = sentences.get(0);
    System.out.println(sentence.toString());
    SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
    System.out.println(graph);
    List<SemanticGraphEdge> edges = graph.edgeListSorted();
    for (SemanticGraphEdge edge : edges) {
        System.out.println(edge.getRelation().getShortName());
        System.out.println(String.format("Source is : %s - Target is : %s - Relation is : %s", edge.getSource(), edge.getTarget(), edge.getRelation()));
    }
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) StanfordTextProcessor(com.graphaware.nlp.processor.stanford.StanfordTextProcessor) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) Test(org.junit.Test)

Example 5 with StanfordTextProcessor

use of com.graphaware.nlp.processor.stanford.StanfordTextProcessor in project neo4j-nlp-stanfordnlp by graphaware.

the class DependencyParserTest method testEnhancedDependencyParsingWithQuestion.

@Test
public void testEnhancedDependencyParsingWithQuestion() throws Exception {
    String text = "In what area was Frederic born in";
    StanfordCoreNLP pipeline = ((StanfordTextProcessor) textProcessor).getPipeline("default");
    Map<String, Object> customPipeline = new HashMap<>();
    customPipeline.put("textProcessor", "com.graphaware.nlp.processor.stanford.StanfordTextProcessor");
    customPipeline.put("name", "custom");
    customPipeline.put("stopWords", "start,starts");
    customPipeline.put("processingSteps", Collections.singletonMap("dependency", true));
    PipelineSpecification pipelineSpecification = PipelineSpecification.fromMap(customPipeline);
    ((StanfordTextProcessor) textProcessor).createPipeline(pipelineSpecification);
    textProcessor.annotateText(text, "en", pipelineSpecification);
    Annotation document = new Annotation(text);
    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        System.out.println(sentence.toString());
        SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
        graph.getRoots().forEach(root -> {
            System.out.println(root);
        });
        System.out.println(graph);
        for (SemanticGraphEdge edge : graph.edgeListSorted()) {
            System.out.println(String.format("Source is : %s - Target is : %s - Relation is : %s", edge.getSource(), edge.getTarget(), edge.getRelation()));
        }
    }
}
Also used : SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) StanfordTextProcessor(com.graphaware.nlp.processor.stanford.StanfordTextProcessor) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) CoreMap(edu.stanford.nlp.util.CoreMap) Test(org.junit.Test)

Aggregations

StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)6 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)5 Test (org.junit.Test)5 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)4 Annotation (edu.stanford.nlp.pipeline.Annotation)4 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)4 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)4 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)4 CoreMap (edu.stanford.nlp.util.CoreMap)4 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)3 PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)2 BeforeClass (org.junit.BeforeClass)1