use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.
the class TestAnnotatedTesterUnitTest method testSentenceWithNoText.
@Test(expected = AssertionError.class)
public void testSentenceWithNoText() {
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 not me");
}
use of com.graphaware.nlp.domain.Sentence 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.Sentence 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.Sentence in project neo4j-nlp by graphaware.
the class AnnotatedTextPersister method fromNode.
@Override
public AnnotatedText fromNode(Node node, Object... properties) {
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.Sentence in project neo4j-nlp by graphaware.
the class AnnotatedTextPersistenceTest method createAnnotatedTextWithSameTagInSameTextWithDifferentPos.
private AnnotatedText createAnnotatedTextWithSameTagInSameTextWithDifferentPos() {
AnnotatedText annotatedText = new AnnotatedText();
AtomicInteger inc = new AtomicInteger();
for (String s : "Hello my name is cool. And I am cool.".split("\\.")) {
Sentence sentence = new Sentence(s, inc.get());
for (String token : s.split(" ")) {
Tag tag = new Tag(token, "en");
if (token.equals("cool")) {
int v = inc.get();
tag.setPos(Collections.singletonList("cool" + v));
tag.setNe(Collections.singletonList("NER_Cool" + v));
}
sentence.addTagOccurrence(0, 20, token, sentence.addTag(tag));
}
inc.incrementAndGet();
annotatedText.addSentence(sentence);
}
return annotatedText;
}
Aggregations