use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.
the class AnnotationPersistenceIntegrationTest method testAnnotationRunWithPipelineDefaultFromUserConfig.
@Test
public void testAnnotationRunWithPipelineDefaultFromUserConfig() {
manager.getConfiguration().updateInternalSetting(SettingsConstants.DEFAULT_PIPELINE, TextProcessor.DEFAULT_PIPELINE);
try (Transaction tx = getDatabase().beginTx()) {
manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", pipelineSpecification);
tx.success();
}
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
manager.applySentiment(node, StubTextProcessor.class.getName());
});
tx.success();
}
TestNLPGraph tester = new TestNLPGraph(getDatabase());
tester.assertSentenceWithIdHasSentimentLabel("123_0", SentimentLabels.VeryPositive.toString());
assertEquals("tokenizer", ((StubTextProcessor) manager.getTextProcessorsManager().getTextProcessor("com.graphaware.nlp.stub.StubTextProcessor")).getLastPipelineUsed());
}
use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.
the class AnnotationPersistenceIntegrationTest method testLanguageIsCorrectlyDetectedAndStored.
@Test
public void testLanguageIsCorrectlyDetectedAndStored() {
try (Transaction tx = getDatabase().beginTx()) {
Node annotatedText = manager.annotateTextAndPersist("Barack Obama is born in Hawaii. He is our president.", "123", pipelineSpecification);
tx.success();
}
TestNLPGraph test = new TestNLPGraph(getDatabase());
test.assertTagWithIdExist("Barack_en");
test.assertTagWithIdExist("born_en");
}
use of com.graphaware.nlp.util.TestNLPGraph 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.util.TestNLPGraph 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.util.TestNLPGraph in project neo4j-nlp by graphaware.
the class AnnotationPersistenceIntegrationTest method testSentimentLabelCanBeAddedOnExistingSentence.
@Test
public void testSentimentLabelCanBeAddedOnExistingSentence() {
try (Transaction tx = getDatabase().beginTx()) {
manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", pipelineSpecification);
tx.success();
}
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
manager.applySentiment(node, StubTextProcessor.class.getName());
});
tx.success();
}
TestNLPGraph tester = new TestNLPGraph(getDatabase());
tester.assertSentenceWithIdHasSentimentLabel("123_0", SentimentLabels.VeryPositive.toString());
}
Aggregations