use of com.graphaware.nlp.util.TestNLPGraph in project neo4j-nlp by graphaware.
the class AnnotationPersistenceIntegrationTest method testMultipleSentencesPersistence.
@Test
public void testMultipleSentencesPersistence() {
try (Transaction tx = getDatabase().beginTx()) {
manager.annotateTextAndPersist("hello my name is John. I am working for IBM. I live in Italy", "123", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
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", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
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());
}
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", StubTextProcessor.class.getName(), "tokenizer", false, true);
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 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().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", true, 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 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", StubTextProcessor.class.getName(), TextProcessor.DEFAULT_PIPELINE, false, true);
tx.success();
}
TestNLPGraph test = new TestNLPGraph(getDatabase());
test.assertTagWithIdExist("Barack_en");
test.assertTagWithIdExist("born_en");
}
Aggregations