Search in sources :

Example 1 with NLPModule

use of com.graphaware.nlp.module.NLPModule in project neo4j-nlp by graphaware.

the class ConfigurationMigrationTest method testPipelinesCanBeMigrated.

@Test
public void testPipelinesCanBeMigrated() throws Exception {
    PipelineSpecification specification = new PipelineSpecification("custom", StubTextProcessor.class.getName());
    specification.setStopWords("hello,hihi");
    ObjectMapper mapper = new ObjectMapper();
    String spec = mapper.writeValueAsString(specification);
    try (Transaction tx = getDatabase().beginTx()) {
        keyValueStore.set(DynamicConfiguration.STORE_KEY + "PIPELINE_" + specification.getName(), spec);
        assertFalse(spec.contains("\"@class\""));
        tx.success();
    }
    GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    runtime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    runtime.start();
    runtime.waitUntilStarted();
    try (Transaction tx = getDatabase().beginTx()) {
        String s = keyValueStore.get(DynamicConfiguration.STORE_KEY + "PIPELINE_" + specification.getName()).toString();
        assertTrue(s.contains("\"@class\""));
        tx.success();
    }
}
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) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest) Test(org.junit.Test)

Example 2 with NLPModule

use of com.graphaware.nlp.module.NLPModule in project neo4j-nlp by graphaware.

the class DynamicConfigurationTest method testWorfklowItemsInfosShouldBeLoadedFromPreviousState.

@Test
public void testWorfklowItemsInfosShouldBeLoadedFromPreviousState() throws Exception {
    resetSingleton();
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
    keyValueStore = new GraphKeyValueStore(getDatabase());
    QueryBasedWorkflowInput workflowInput = new QueryBasedWorkflowInput("test", getDatabase());
    DynamicConfiguration configuration = new DynamicConfiguration(getDatabase());
    workflowInput.setConfiguration(new WorkflowInputQueryConfiguration(new HashMap<>()));
    try (Transaction tx = getDatabase().beginTx()) {
        configuration.storeWorkflowInstanceItem(workflowInput);
        tx.success();
    }
    GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    runtime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    runtime.start();
    runtime.waitUntilStarted();
}
Also used : WorkflowInputQueryConfiguration(com.graphaware.nlp.workflow.input.WorkflowInputQueryConfiguration) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) GraphAwareRuntime(com.graphaware.runtime.GraphAwareRuntime) NLPModule(com.graphaware.nlp.module.NLPModule) GraphKeyValueStore(com.graphaware.common.kv.GraphKeyValueStore) QueryBasedWorkflowInput(com.graphaware.nlp.workflow.input.QueryBasedWorkflowInput) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest)

Example 3 with NLPModule

use of com.graphaware.nlp.module.NLPModule 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)

Example 4 with NLPModule

use of com.graphaware.nlp.module.NLPModule in project neo4j-nlp by graphaware.

the class NLPIntegrationTest method registerRuntime.

protected void registerRuntime() {
    GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    runtime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    runtime.start();
    runtime.waitUntilStarted();
}
Also used : GraphAwareRuntime(com.graphaware.runtime.GraphAwareRuntime) NLPModule(com.graphaware.nlp.module.NLPModule)

Example 5 with NLPModule

use of com.graphaware.nlp.module.NLPModule in project neo4j-nlp-stanfordnlp by graphaware.

the class ProcedureTest method overallTest.

@Test
public void overallTest() {
    GraphAwareRuntime gaRuntime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    gaRuntime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    gaRuntime.start();
    gaRuntime.waitUntilStarted();
    // testAnnotatedText();
    // clean();
    // testAnnotatedTextWithSentiment();
    // clean();
    // testAnnotatedTextAndSentiment();
    // clean();
    // testAnnotatedTextOnMultiple();
    // clean();
    // testConceptText();
    // clean();
    // testLanguageDetection();
    // clean();
    // testSupportedLanguage();
    // clean();
    // testFilter();
    // clean();
    // testGetProceduresManagement();
    // clean();
    // testStopWords();
    // testTextRank();
    clean();
}
Also used : GraphAwareRuntime(com.graphaware.runtime.GraphAwareRuntime) NLPModule(com.graphaware.nlp.module.NLPModule) Test(org.junit.Test) GraphAwareIntegrationTest(com.graphaware.test.integration.GraphAwareIntegrationTest)

Aggregations

NLPModule (com.graphaware.nlp.module.NLPModule)6 GraphAwareRuntime (com.graphaware.runtime.GraphAwareRuntime)6 Test (org.junit.Test)4 AbstractEmbeddedTest (com.graphaware.nlp.AbstractEmbeddedTest)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Transaction (org.neo4j.graphdb.Transaction)3 GraphKeyValueStore (com.graphaware.common.kv.GraphKeyValueStore)2 PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)2 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)2 QueryBasedWorkflowInput (com.graphaware.nlp.workflow.input.QueryBasedWorkflowInput)1 WorkflowInputQueryConfiguration (com.graphaware.nlp.workflow.input.WorkflowInputQueryConfiguration)1 GraphAwareIntegrationTest (com.graphaware.test.integration.GraphAwareIntegrationTest)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1