use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.
the class TestAnnotatedTesterUnitTest method testSentenceWithText.
@Test
public void testSentenceWithText() {
AnnotatedText annotatedText = new AnnotatedText();
TestAnnotatedText test = new TestAnnotatedText(annotatedText);
Sentence sentence = new Sentence("hello it is me");
sentence.addTag(new Tag("hello", "en"));
annotatedText.addSentence(sentence);
test.assertSentenceWithText("hello it is me");
}
use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp-stanfordnlp by graphaware.
the class DependencyParserTest method testTagMerging.
@Test
public void testTagMerging() throws Exception {
StanfordCoreNLP pipeline = ((StanfordTextProcessor) textProcessor).getPipeline("default");
String text = "Donald Trump flew yesterday to New York City";
AnnotatedText at = textProcessor.annotateText(text, "en", PIPELINE_DEFAULT);
}
use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.
the class AnnotatedTextPersister method fromNode.
@Override
public AnnotatedText fromNode(Node node) {
if (!node.hasLabel(configuration().getLabelFor(Labels.AnnotatedText))) {
throw new RuntimeException("Expected an " + configuration().getLabelFor(Labels.AnnotatedText) + " node.");
}
AnnotatedText annotatedText = mapper().convertValue(node.getAllProperties(), AnnotatedText.class);
node.getRelationships(configuration().getRelationshipFor(Relationships.CONTAINS_SENTENCE), Direction.OUTGOING).forEach(relationship -> {
Sentence sentence = (Sentence) getPersister(Sentence.class).fromNode(relationship.getEndNode());
annotatedText.addSentence(sentence);
});
return annotatedText;
}
use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.
the class NLPManager method annotateTextAndPersist.
public Node annotateTextAndPersist(String text, String id, String textProcessor, String pipelineName, boolean force, boolean checkForLanguage) {
String lang = checkTextLanguage(text, checkForLanguage);
String pipeline = getPipeline(pipelineName);
PipelineSpecification pipelineSpecification = getConfiguration().loadPipeline(pipeline);
if (null == pipelineSpecification) {
throw new RuntimeException("No pipeline " + pipelineName + " found.");
}
TextProcessor processor = textProcessorsManager.getTextProcessor(pipelineSpecification.getTextProcessor());
AnnotatedText at = processor.annotateText(text, lang, pipelineSpecification);
return processAnnotationPersist(id, text, at, pipelineSpecification);
}
use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.
the class NLPManager method annotateTextAndPersist.
public Node annotateTextAndPersist(String text, String id, boolean checkForLanguage, PipelineSpecification pipelineSpecification) {
String lang = checkTextLanguage(text, checkForLanguage);
TextProcessor processor = textProcessorsManager.getTextProcessor(pipelineSpecification.getTextProcessor());
AnnotatedText annotatedText = processor.annotateText(text, lang, pipelineSpecification);
return processAnnotationPersist(id, text, annotatedText, pipelineSpecification);
}
Aggregations