Search in sources :

Example 16 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification 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 17 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification 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 18 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class DynamicConfigurationTest method testConfigurationCanStoreAndRetrievePipelines.

@Test
public void testConfigurationCanStoreAndRetrievePipelines() {
    DynamicConfiguration configuration = new DynamicConfiguration(getDatabase());
    PipelineSpecification specification = new PipelineSpecification("custom", StubTextProcessor.class.getName());
    specification.setStopWords("hello,hihi");
    specification.setThreadNumber(4);
    configuration.storeCustomPipeline(specification);
    try (Transaction tx = getDatabase().beginTx()) {
        assertTrue(keyValueStore.hasKey("GA__NLP__PIPELINE_custom"));
        tx.success();
    }
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest)

Example 19 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class DynamicConfigurationTest method testConfigurationCanLoadCustomPipelineAsObject.

@Test
public void testConfigurationCanLoadCustomPipelineAsObject() {
    DynamicConfiguration configuration = new DynamicConfiguration(getDatabase());
    PipelineSpecification specification = new PipelineSpecification("custom", StubTextProcessor.class.getName());
    specification.setStopWords("hello,hihi");
    specification.setThreadNumber(4);
    configuration.storeCustomPipeline(specification);
    PipelineSpecification pipelineSpecification = configuration.loadCustomPipelines().get(0);
    assertEquals(specification.getName(), pipelineSpecification.getName());
    assertEquals(specification.getStopWords(), pipelineSpecification.getStopWords());
    assertEquals(specification.getTextProcessor(), pipelineSpecification.getTextProcessor());
    assertEquals(specification.getThreadNumber(), pipelineSpecification.getThreadNumber());
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest)

Example 20 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class DynamicConfigurationTest method testConfigurationValuesShouldBeLoadedFromPreviousState.

@Test
public void testConfigurationValuesShouldBeLoadedFromPreviousState() throws Exception {
    resetSingleton();
    ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    keyValueStore = new GraphKeyValueStore(getDatabase());
    PipelineSpecification specification = new PipelineSpecification("custom", StubTextProcessor.class.getName());
    specification.setStopWords("hello,hihi");
    specification.setThreadNumber(4);
    try (Transaction tx = getDatabase().beginTx()) {
        String writeValueAsString = mapper.writeValueAsString(specification);
        keyValueStore.set("GA__NLP__PIPELINE_custom", writeValueAsString);
        keyValueStore.set("GA__NLP__SETTING_fallbackLanguage", "en");
        tx.success();
    }
    GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    runtime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    runtime.start();
    runtime.waitUntilStarted();
    assertTrue(getStartedRuntime(getDatabase()).getModule(NLPModule.class).getNlpManager().getTextProcessorsManager().getTextProcessor(StubTextProcessor.class.getName()).getPipelines().contains("custom"));
    assertTrue(getStartedRuntime(getDatabase()).getModule(NLPModule.class).getNlpManager().getConfiguration().hasSettingValue(SettingsConstants.FALLBACK_LANGUAGE));
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) GraphAwareRuntime(com.graphaware.runtime.GraphAwareRuntime) NLPModule(com.graphaware.nlp.module.NLPModule) GraphKeyValueStore(com.graphaware.common.kv.GraphKeyValueStore) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest)

Aggregations

PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)49 Test (org.junit.Test)22 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)13 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)11 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)8 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)8 Transaction (org.neo4j.graphdb.Transaction)8 AbstractEmbeddedTest (com.graphaware.nlp.AbstractEmbeddedTest)5 NLPTextProcessor (com.graphaware.nlp.annotation.NLPTextProcessor)4 TextProcessor (com.graphaware.nlp.processor.TextProcessor)3 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)3 Annotation (edu.stanford.nlp.pipeline.Annotation)3 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)3 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)3 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)3 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)3 CoreMap (edu.stanford.nlp.util.CoreMap)3 Description (org.neo4j.procedure.Description)3 LoggerFactory (com.graphaware.common.log.LoggerFactory)2 NLPManager (com.graphaware.nlp.NLPManager)2