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);
}
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");
}
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();
}
}
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());
}
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));
}
Aggregations