Search in sources :

Example 16 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class TestAnnotatedTesterUnitTest method testSentenceWithText.

@Test
public void testSentenceWithText() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText test = new TestAnnotatedText(annotatedText);
    Sentence sentence = new Sentence("hello it is me");
    sentence.addTag(new Tag("hello", "en"));
    annotatedText.addSentence(sentence);
    test.assertSentenceWithText("hello it is me");
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) TagUtils.newTag(com.graphaware.nlp.util.TagUtils.newTag) Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

Example 17 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText 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 18 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class AnnotatedTextPersister method fromNode.

@Override
public AnnotatedText fromNode(Node node) {
    if (!node.hasLabel(configuration().getLabelFor(Labels.AnnotatedText))) {
        throw new RuntimeException("Expected an " + configuration().getLabelFor(Labels.AnnotatedText) + " node.");
    }
    AnnotatedText annotatedText = mapper().convertValue(node.getAllProperties(), AnnotatedText.class);
    node.getRelationships(configuration().getRelationshipFor(Relationships.CONTAINS_SENTENCE), Direction.OUTGOING).forEach(relationship -> {
        Sentence sentence = (Sentence) getPersister(Sentence.class).fromNode(relationship.getEndNode());
        annotatedText.addSentence(sentence);
    });
    return annotatedText;
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence)

Example 19 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class NLPManager method annotateTextAndPersist.

public Node annotateTextAndPersist(String text, String id, String textProcessor, String pipelineName, boolean force, boolean checkForLanguage) {
    String lang = checkTextLanguage(text, checkForLanguage);
    String pipeline = getPipeline(pipelineName);
    PipelineSpecification pipelineSpecification = getConfiguration().loadPipeline(pipeline);
    if (null == pipelineSpecification) {
        throw new RuntimeException("No pipeline " + pipelineName + " found.");
    }
    TextProcessor processor = textProcessorsManager.getTextProcessor(pipelineSpecification.getTextProcessor());
    AnnotatedText at = processor.annotateText(text, lang, pipelineSpecification);
    return processAnnotationPersist(id, text, at, pipelineSpecification);
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) TextProcessor(com.graphaware.nlp.processor.TextProcessor) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText)

Example 20 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class NLPManager method annotateTextAndPersist.

public Node annotateTextAndPersist(String text, String id, boolean checkForLanguage, PipelineSpecification pipelineSpecification) {
    String lang = checkTextLanguage(text, checkForLanguage);
    TextProcessor processor = textProcessorsManager.getTextProcessor(pipelineSpecification.getTextProcessor());
    AnnotatedText annotatedText = processor.annotateText(text, lang, pipelineSpecification);
    return processAnnotationPersist(id, text, annotatedText, pipelineSpecification);
}
Also used : TextProcessor(com.graphaware.nlp.processor.TextProcessor) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText)

Aggregations

AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)32 Test (org.junit.Test)18 Sentence (com.graphaware.nlp.domain.Sentence)17 Tag (com.graphaware.nlp.domain.Tag)11 TextProcessor (com.graphaware.nlp.processor.TextProcessor)9 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)8 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)5 TagUtils.newTag (com.graphaware.nlp.util.TagUtils.newTag)5 TestNLPGraph (com.graphaware.nlp.util.TestNLPGraph)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Transaction (org.neo4j.graphdb.Transaction)5 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)3 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)3 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 Node (org.neo4j.graphdb.Node)3 PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)2