Search in sources :

Example 11 with Sentence

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");
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) TagUtils.newTag(com.graphaware.nlp.util.TagUtils.newTag) Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

Example 12 with Sentence

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");
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) TagUtils.newTag(com.graphaware.nlp.util.TagUtils.newTag) Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

Example 13 with Sentence

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;
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence)

Example 14 with Sentence

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;
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence)

Example 15 with Sentence

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;
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence)

Aggregations

Sentence (com.graphaware.nlp.domain.Sentence)18 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)14 Tag (com.graphaware.nlp.domain.Tag)9 Test (org.junit.Test)9 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)7 TagUtils.newTag (com.graphaware.nlp.util.TagUtils.newTag)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Phrase (com.graphaware.nlp.domain.Phrase)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Node (org.neo4j.graphdb.Node)1