Search in sources :

Example 1 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.

the class AnnotationPersistenceIntegrationTest method testMultipleSentencesPersistence.

@Test
public void testMultipleSentencesPersistence() {
    try (Transaction tx = getDatabase().beginTx()) {
        manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
        tx.success();
    }
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertAnnotatedTextNodesCount(1);
    tester.assertSentenceNodesCount(3);
    tester.assertTagNodesCount(14);
    tester.assertTagWithValueExist("hello");
    tester.assertTagWithValueExist("IBM");
    tester.assertTagWithValueHasNERLabel("name", "NER_Test");
    tester.assertPhraseWithTextExist("hello my name is John");
    tester.assertPhraseOccurrenceForTextHasStartAndEndPosition("hello my name is John", 0, "hello my name is John".length());
    tester.assertSentenceWithIdHasPhraseOccurrenceCount("123_0", 1);
    tester.assertSentenceWithIdHasPhraseWithText("123_0", "hello my name is John");
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EmbeddedDatabaseIntegrationTest(com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 2 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.

the class AnnotationPersistenceIntegrationTest method testSentimentLabelCanBeAddedOnExistingSentence.

@Test
public void testSentimentLabelCanBeAddedOnExistingSentence() {
    try (Transaction tx = getDatabase().beginTx()) {
        manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
        tx.success();
    }
    try (Transaction tx = getDatabase().beginTx()) {
        getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
            manager.applySentiment(node, StubTextProcessor.class.getName());
        });
        tx.success();
    }
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertSentenceWithIdHasSentimentLabel("123_0", SentimentLabels.VeryPositive.toString());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EmbeddedDatabaseIntegrationTest(com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 3 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.

the class AnnotationPersistenceIntegrationTest method testAnnotationRunWithPipelineDefaultFromUserConfig.

@Test
public void testAnnotationRunWithPipelineDefaultFromUserConfig() {
    manager.getConfiguration().updateInternalSetting(SettingsConstants.DEFAULT_PIPELINE, TextProcessor.DEFAULT_PIPELINE);
    try (Transaction tx = getDatabase().beginTx()) {
        manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", StubTextProcessor.class.getName(), "tokenizer", false, true);
        tx.success();
    }
    try (Transaction tx = getDatabase().beginTx()) {
        getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
            manager.applySentiment(node, StubTextProcessor.class.getName());
        });
        tx.success();
    }
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertSentenceWithIdHasSentimentLabel("123_0", SentimentLabels.VeryPositive.toString());
    assertEquals("tokenizer", ((StubTextProcessor) manager.getTextProcessorsManager().getTextProcessor("com.graphaware.nlp.stub.StubTextProcessor")).getLastPipelineUsed());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EmbeddedDatabaseIntegrationTest(com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 4 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.

the class AnnotationPersistenceIntegrationTest method testAnnotationWithCustomPipeline.

@Test
public void testAnnotationWithCustomPipeline() {
    Map<String, Object> spec = new HashMap<>();
    spec.put("name", "my-pipeline");
    spec.put("textProcessor", StubTextProcessor.class.getName());
    spec.put("processingSteps", Collections.singletonMap("tokenize", true));
    spec.put("excludedNER", Collections.singletonList("test"));
    PipelineSpecification pipelineSpecification = PipelineSpecification.fromMap(spec);
    getNLPManager().addPipeline(pipelineSpecification);
    try (Transaction tx = getDatabase().beginTx()) {
        manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123-fff", true, pipelineSpecification);
        tx.success();
    }
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertNodesCount("test", 0);
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EmbeddedDatabaseIntegrationTest(com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 5 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.

the class AnnotationPersistenceIntegrationTest method testLanguageIsCorrectlyDetectedAndStored.

@Test
public void testLanguageIsCorrectlyDetectedAndStored() {
    try (Transaction tx = getDatabase().beginTx()) {
        Node annotatedText = manager.annotateTextAndPersist("Barack Obama is born in Hawaii. He is our president.", "123", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
        tx.success();
    }
    TestNLPGraph test = new TestNLPGraph(getDatabase());
    test.assertTagWithIdExist("Barack_en");
    test.assertTagWithIdExist("born_en");
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Node(org.neo4j.graphdb.Node) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EmbeddedDatabaseIntegrationTest(com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Aggregations

TestNLPGraph (com.graphaware.nlp.util.TestNLPGraph)21 Test (org.junit.Test)21 Transaction (org.neo4j.graphdb.Transaction)15 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)13 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)12 EmbeddedDatabaseIntegrationTest (com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest)7 Collections (java.util.Collections)7 List (java.util.List)7 StanfordNLPIntegrationTest (com.graphaware.nlp.StanfordNLPIntegrationTest)6 Before (org.junit.Before)6 Node (org.neo4j.graphdb.Node)5 Arrays (java.util.Arrays)4 Map (java.util.Map)4 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)3 TextProcessor (com.graphaware.nlp.processor.TextProcessor)3 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)3 Assert (org.junit.Assert)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 ConceptRequest (com.graphaware.nlp.dsl.request.ConceptRequest)2