Search in sources :

Example 11 with TestNLPGraph

use of com.graphaware.nlp.util.TestNLPGraph 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 12 with TestNLPGraph

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

the class AnnotateTextProcedureTest method testTextAnnotationViaProcedure.

@Test
public void testTextAnnotationViaProcedure() {
    clearDb();
    executeInTransaction("CALL ga.nlp.annotate({pipeline:'tokenizer', text: 'hello my name is Frank', id: 'test-proc', checkLanguage: false})", emptyConsumer());
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertAnnotatedTextNodesCount(1);
    tester.assertSentenceNodesCount(1);
}
Also used : TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 13 with TestNLPGraph

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

the class SentimentProcedureTest method testSentimentViaProcedure.

@Test
public void testSentimentViaProcedure() {
    clearDb();
    executeInTransaction("CALL ga.nlp.annotate({pipeline:'tokenizer', text: 'hello my name is Frank', id: 'test-proc', checkLanguage: false})", emptyConsumer());
    executeInTransaction("MATCH (n:AnnotatedText) CALL ga.nlp.sentiment(n) YIELD result RETURN result", (result -> {
        assertTrue(result.hasNext());
    }));
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertSentenceWithIdHasSentimentLabel("test-proc_0", Labels.VeryPositive.name());
}
Also used : TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Labels(com.graphaware.nlp.persistence.constants.Labels) TextProcessor(com.graphaware.nlp.processor.TextProcessor) Test(org.junit.Test) Assert(org.junit.Assert) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Before(org.junit.Before) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 14 with TestNLPGraph

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

the class TextRankProcedureTest method testTextRankPostProcessWithCustomInput.

@Test
public void testTextRankPostProcessWithCustomInput() throws Exception {
    clearDb();
    createGraph();
    executeInTransaction("MATCH (n:AnnotatedText) CALL ga.nlp.ml.textRank({annotatedText: n, iterations: 30, damp: 0.85, threshold: 0.0001}) YIELD result RETURN result", (result -> {
        assertTrue("ga.nlp.ml.textRank() procedure failed.", result.hasNext());
    }));
    executeInTransaction("MATCH (a:AnnotatedText)<-[:DESCRIBES]-(k:Keyword) WHERE k.value CONTAINS 'space shuttle' CALL ga.nlp.ml.textRank.postprocess({method:'subgroups', annotatedText: a}) YIELD result RETURN count(*)", emptyConsumer());
    TestNLPGraph testNLPGraph = new TestNLPGraph(getDatabase());
    testNLPGraph.debugKeywords();
    executeInTransaction("MATCH (n:Keyword)-[:HAS_SUBGROUP]->(x) RETURN n.value AS v", (result -> {
        assertTrue(result.hasNext());
        while (result.hasNext()) {
            System.out.println(result.next().get("v"));
        }
    }));
}
Also used : ImportUtils(com.graphaware.nlp.util.ImportUtils) List(java.util.List) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) TextProcessor(com.graphaware.nlp.processor.TextProcessor) Files(java.nio.file.Files) Paths(java.nio.file.Paths) Map(java.util.Map) Test(org.junit.Test) Assert(org.junit.Assert) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Before(org.junit.Before) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 15 with TestNLPGraph

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

the class AnnotationPersistenceIntegrationTest method testLanguageIsDefaultedToNAWhenCheckLanguageIsFalseAndLanguageCouldNotBeDetected.

@Test
public void testLanguageIsDefaultedToNAWhenCheckLanguageIsFalseAndLanguageCouldNotBeDetected() {
    try (Transaction tx = getDatabase().beginTx()) {
        Node annotatedText = manager.annotateTextAndPersist("Barack Obama is born in Hawaii.", "123", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, false);
        tx.success();
    }
    TestNLPGraph test = new TestNLPGraph(getDatabase());
    test.assertTagWithIdExist("Barack_n/a");
    test.assertTagWithIdExist("born_n/a");
}
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)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