Search in sources :

Example 21 with TestNLPGraph

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

the class Word2VecProcedureTest method testAttachVectorsToTagNodes.

@Test
public void testAttachVectorsToTagNodes() {
    executeInTransaction("CALL ga.nlp.annotate({pipeline:'tokenizer', text: 'I met one agriculturist.', id: '123-fff', checkLanguage: false})", emptyConsumer());
    TestNLPGraph tester = new TestNLPGraph(getDatabase());
    tester.assertTagWithValueExist("agriculturist");
    executeInTransaction("CALL ga.nlp.ml.word2vec.attach({query:\"MATCH (t:Tag) return t\", modelName:'numberbatch'}) YIELD result \n" + "return result;", (result -> {
        assertTrue(result.hasNext());
    }));
    executeInTransaction("MATCH (n:Tag {value:'agriculturist'}) RETURN n", (result -> {
        assertTrue(result.hasNext());
        Map<String, Object> record = result.next();
        assertTrue(((Node) record.get("n")).hasProperty("word2vec_type"));
        assertTrue(((Node) record.get("n")).hasProperty("word2vec_array"));
    }));
}
Also used : TextProcessor(com.graphaware.nlp.processor.TextProcessor) Test(org.junit.Test) HashMap(java.util.HashMap) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Node(org.neo4j.graphdb.Node) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Map(java.util.Map) Assert(org.junit.Assert) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest) Before(org.junit.Before) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Node(org.neo4j.graphdb.Node) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 22 with TestNLPGraph

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

the class AnnotationPersistenceIntegrationTest method testLanguageIsDefaultedToENWhenCheckLanguageIsFalseAndLanguageCouldNotBeDetected.

@Test
public void testLanguageIsDefaultedToENWhenCheckLanguageIsFalseAndLanguageCouldNotBeDetected() {
    try (Transaction tx = getDatabase().beginTx()) {
        Node annotatedText = manager.annotateTextAndPersist("Barack Obama is born in Hawaii.", "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 23 with TestNLPGraph

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

the class AnnotationPersistenceIntegrationTest method testAnnotationWillUseExistentFallbackLanguageIfCheckLanguageIsFalseAndNoLanguageIsDetected.

@Test
public void testAnnotationWillUseExistentFallbackLanguageIfCheckLanguageIsFalseAndNoLanguageIsDetected() {
    manager.getConfiguration().updateInternalSetting(SettingsConstants.FALLBACK_LANGUAGE, "en");
    try (Transaction tx = getDatabase().beginTx()) {
        Node annotatedText = manager.annotateTextAndPersist("Barack Obama is born in Hawaii.", "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)

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