Search in sources :

Example 6 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", pipelineSpecification);
        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) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 7 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", pipelineSpecification);
        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) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 8 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().getTextProcessorsManager().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", 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) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 9 with TestNLPGraph

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

the class AnnotationPersistenceIntegrationTest method testMultipleSentencesPersistence.

@Test
public void testMultipleSentencesPersistence() {
    PipelineSpecification myPipelineSpecification = new PipelineSpecification(TextProcessor.DEFAULT_PIPELINE + "_phrase", StubTextProcessor.class.getName());
    createPipeline(myPipelineSpecification.getTextProcessor(), myPipelineSpecification.getName(), "tokenizer", "phrase");
    try (Transaction tx = getDatabase().beginTx()) {
        manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", myPipelineSpecification.getName());
        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 : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 10 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", pipelineSpecification);
        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) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Aggregations

TestNLPGraph (com.graphaware.nlp.util.TestNLPGraph)23 Test (org.junit.Test)23 Transaction (org.neo4j.graphdb.Transaction)16 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)15 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)11 List (java.util.List)8 Collections (java.util.Collections)7 Before (org.junit.Before)7 StanfordNLPIntegrationTest (com.graphaware.nlp.StanfordNLPIntegrationTest)6 Node (org.neo4j.graphdb.Node)6 Map (java.util.Map)5 TextProcessor (com.graphaware.nlp.processor.TextProcessor)4 Arrays (java.util.Arrays)4 Assert (org.junit.Assert)4 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)3 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 DynamicConfiguration (com.graphaware.nlp.configuration.DynamicConfiguration)2 ConceptRequest (com.graphaware.nlp.dsl.request.ConceptRequest)2