Search in sources :

Example 1 with Sentence

use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.

the class AnnotatedTextPersister method iterateSentencesAndStore.

private void iterateSentencesAndStore(Node annotatedTextNode, AnnotatedText annotatedText, String id, String txId) {
    final AtomicReference<Node> previousSentenceReference = new AtomicReference<>();
    annotatedText.getSentences().sort((Sentence o1, Sentence o2) -> o1.compareTo(o2));
    annotatedText.getSentences().forEach((sentence) -> {
        Node sentenceNode = getPersister(Sentence.class).persist(sentence, id, txId);
        Node previousSentence = previousSentenceReference.get();
        boolean isFirstSentence = previousSentence == null;
        relateSentenceToAnnotatedText(sentenceNode, annotatedTextNode, isFirstSentence);
        if (!isFirstSentence) {
            relatePreviousSentenceToNext(previousSentence, sentenceNode);
        }
        previousSentenceReference.set(sentenceNode);
    });
}
Also used : Node(org.neo4j.graphdb.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) Sentence(com.graphaware.nlp.domain.Sentence)

Example 2 with Sentence

use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.

the class TestAnnotatedText method assertSentenceWithText.

public void assertSentenceWithText(String text) {
    boolean found = false;
    for (Sentence sentence : annotatedText.getSentences()) {
        if (sentence.getSentence().equals(text)) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : Sentence(com.graphaware.nlp.domain.Sentence)

Example 3 with Sentence

use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.

the class TestAnnotatedText method assertTagsCountInSentence.

public void assertTagsCountInSentence(int count, int sentenceNumber) {
    Sentence sentence = annotatedText.getSentencesSorted().get(sentenceNumber);
    assertEquals(count, sentence.getTags().size());
}
Also used : Sentence(com.graphaware.nlp.domain.Sentence)

Example 4 with Sentence

use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.

the class TestAnnotatedText method assertTagWithLemma.

public void assertTagWithLemma(String value) {
    boolean found = false;
    for (Sentence sentence : annotatedText.getSentences()) {
        for (Tag tag : sentence.getTags().values()) {
            if (tag.getLemma().equals(value)) {
                found = true;
                break;
            }
        }
    }
    assertTrue(found);
}
Also used : Tag(com.graphaware.nlp.domain.Tag) Sentence(com.graphaware.nlp.domain.Sentence)

Example 5 with Sentence

use of com.graphaware.nlp.domain.Sentence in project neo4j-nlp by graphaware.

the class AnnotatedTextTest method testComplexFilter.

@Test
public void testComplexFilter() {
    AnnotatedText annotatedText = new AnnotatedText();
    Sentence sentence = new Sentence("Owen Bennet Jones is working for the BBC in Pakistan", 0);
    sentence.addTag(getTag("Owen Bennet Jones", "PERSON"));
    sentence.addTag(getTag("work", null));
    sentence.addTag(getTag("the", null));
    sentence.addTag(getTag("BBC", null));
    sentence.addTag(getTag("Pakistan", "LOCATION"));
    annotatedText.addSentence(sentence);
    assertTrue(annotatedText.filter("Owen Bennet Jones/PERSON,BBC,Pakistan/LOCATION"));
}
Also used : AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

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