Search in sources :

Example 36 with PipelineSpecification

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

the class DynamicConfigurationTest method testConfigurationCanRemovePipeline.

@Test
public void testConfigurationCanRemovePipeline() {
    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"));
        configuration.removePipeline("custom", StubTextProcessor.class.getName());
        assertFalse(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 37 with PipelineSpecification

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

the class TextProcessorsProcedureTest method testCustomPipelineWithSentimentModelShouldDisplayModelNameInPipelineInfo.

@Test
public void testCustomPipelineWithSentimentModelShouldDisplayModelNameInPipelineInfo() {
    clearDb();
    removeCustomPipelines();
    executeInTransaction("CALL ga.nlp.processor.addPipeline({name:'custom-1', textProcessor:'" + StubTextProcessor.class.getName() + "', processingSteps:{customSentiment:'my-model'}})", emptyConsumer());
    PipelineSpecification pipelineSpecification = getNLPManager().getConfiguration().loadPipeline("custom-1");
    assertEquals("my-model", pipelineSpecification.getProcessingStepAsString("customSentiment"));
    executeInTransaction("CALL ga.nlp.processor.getPipelines('custom-1')", (result -> {
        assertTrue(result.hasNext());
        while (result.hasNext()) {
            Map<String, Object> record = result.next();
            System.out.println(record);
            Map<String, Object> specs = (Map<String, Object>) record.get("processingSteps");
            assertEquals("my-model", specs.get("customSentiment"));
        }
    }));
}
Also used : Date(java.util.Date) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) Assert(org.junit.Assert) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) DateFormat(java.text.DateFormat) PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Map(java.util.Map) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 38 with PipelineSpecification

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

the class TextProcessorsProcedureTest method testAddingPipelineWithCustomSentimentModel.

@Test
public void testAddingPipelineWithCustomSentimentModel() {
    clearDb();
    removeCustomPipelines();
    executeInTransaction("CALL ga.nlp.processor.addPipeline({name:'custom-1', textProcessor:'" + StubTextProcessor.class.getName() + "', processingSteps:{customSentiment:'my-model'}})", emptyConsumer());
    PipelineSpecification pipelineSpecification = getNLPManager().getConfiguration().loadPipeline("custom-1");
    assertEquals("my-model", pipelineSpecification.getProcessingStepAsString("customSentiment"));
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 39 with PipelineSpecification

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

the class TextProcessorsProcedureTest method testAddPipeline.

@Test
public void testAddPipeline() {
    clearDb();
    executeInTransaction("CALL ga.nlp.processor.addPipeline({name:'custom-1', textProcessor:'" + StubTextProcessor.class.getName() + "', processingSteps:{tokenize:true,ner:true,dependency:true},excludedNER:['MONEY','MISC']})", emptyConsumer());
    assertTrue(checkConfigurationContainsKey(STORE_KEY + "PIPELINE_custom-1"));
    PipelineSpecification pipelineSpecification = getNLPManager().getConfiguration().loadPipeline("custom-1");
    assertNotNull(pipelineSpecification);
    assertTrue(pipelineSpecification.hasProcessingStep("tokenize"));
    assertTrue(pipelineSpecification.hasProcessingStep("dependency"));
    assertTrue(pipelineSpecification.getExcludedNER().contains("MONEY"));
    assertTrue(pipelineSpecification.getExcludedNER().contains("MISC"));
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

Example 40 with PipelineSpecification

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

the class TextProcessorsProcedureTest method testAddPipelineWithCustomWhiteList.

@Test
public void testAddPipelineWithCustomWhiteList() {
    clearDb();
    executeInTransaction("CALL ga.nlp.processor.addPipeline({name:'custom-1', textProcessor:'" + StubTextProcessor.class.getName() + "', whitelist:'hello,i,be,work,IBM,ibm', processingSteps:{tokenize:true,ner:true,dependency:true},excludedNER:['MONEY','MISC']})", emptyConsumer());
    assertTrue(checkConfigurationContainsKey(STORE_KEY + "PIPELINE_custom-1"));
    PipelineSpecification pipelineSpecification = getNLPManager().getConfiguration().loadPipeline("custom-1");
    assertEquals("hello,i,be,work,IBM,ibm", pipelineSpecification.getWhitelist());
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) Test(org.junit.Test) NLPIntegrationTest(com.graphaware.nlp.NLPIntegrationTest)

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