Search in sources :

Example 6 with AnnotatedText

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

the class AnnotatedTextPersistenceTest method testTagOccurrenceGetAPOSProperty.

@Test
public void testTagOccurrenceGetAPOSProperty() {
    clearDb();
    AnnotatedText annotatedText = createAnnotatedTextWithSameTagInSameTextWithDifferentPos();
    try (Transaction tx = getDatabase().beginTx()) {
        getNLPManager().getPersister(AnnotatedText.class).persist(annotatedText, "test", "1");
        tx.success();
    }
    executeInTransaction("MATCH (n:TagOccurrence) WHERE n.value = 'cool' RETURN n", (result -> {
        assertTrue(result.hasNext());
        Node n = (Node) result.next().get("n");
        String[] ners = (String[]) n.getProperty("pos");
        assertTrue(Arrays.asList(ners).contains("cool0"));
    }));
}
Also used : Arrays(java.util.Arrays) TextProcessor(com.graphaware.nlp.processor.TextProcessor) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Node(org.neo4j.graphdb.Node) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Transaction(org.neo4j.graphdb.Transaction) Assert(org.junit.Assert) Collections(java.util.Collections) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest) Tag(com.graphaware.nlp.domain.Tag) Before(org.junit.Before) Transaction(org.neo4j.graphdb.Transaction) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Node(org.neo4j.graphdb.Node) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 7 with AnnotatedText

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

the class AnnotatedTextPersistenceTest method testAnnotatedTextWithSameTagInSameTextGotDifferentPOS.

@Test
public void testAnnotatedTextWithSameTagInSameTextGotDifferentPOS() {
    clearDb();
    TestNLPGraph test = new TestNLPGraph(getDatabase());
    AnnotatedText annotatedText = createAnnotatedTextWithSameTagInSameTextWithDifferentPos();
    try (Transaction tx = getDatabase().beginTx()) {
        getNLPManager().getPersister(AnnotatedText.class).persist(annotatedText, "test", "1");
        tx.success();
    }
    test.assertTagWithValueHasPos("cool", "cool0");
    test.assertTagWithValueHasPos("cool", "cool1");
    test.assertTagWithValueHasNE("cool", "NER_Cool0");
    test.assertTagWithValueHasNE("cool", "NER_Cool1");
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 8 with AnnotatedText

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

the class AnnotatedTextTest method testComplexFilter.

@Test
public void testComplexFilter() {
    AnnotatedText annotatedText = new AnnotatedText();
    Sentence sentence = new Sentence("Owen Bennet Jones is working for the BBC in Pakistan", 0);
    sentence.addTag(getTag("Owen Bennet Jones", "PERSON"));
    sentence.addTag(getTag("work", null));
    sentence.addTag(getTag("the", null));
    sentence.addTag(getTag("BBC", null));
    sentence.addTag(getTag("Pakistan", "LOCATION"));
    annotatedText.addSentence(sentence);
    assertTrue(annotatedText.filter("Owen Bennet Jones/PERSON,BBC,Pakistan/LOCATION"));
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

Example 9 with AnnotatedText

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

the class TestAnnotatedTesterUnitTest method testSentencesCountIsCorrect.

@Test
public void testSentencesCountIsCorrect() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText test = new TestAnnotatedText(annotatedText);
    Sentence sentence = new Sentence("hello");
    sentence.addTag(new Tag("hello", "en"));
    annotatedText.addSentence(sentence);
    test.assertSentencesCount(1);
}
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 10 with AnnotatedText

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

the class TestAnnotatedTesterUnitTest method testSentenceCountThrowsExceptionWhenNotCorrect.

@Test(expected = AssertionError.class)
public void testSentenceCountThrowsExceptionWhenNotCorrect() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText tester = new TestAnnotatedText(annotatedText);
    tester.assertSentencesCount(1);
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) Test(org.junit.Test)

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