Search in sources :

Example 1 with TestAnnotatedText

use of com.graphaware.nlp.util.TestAnnotatedText in project neo4j-nlp-stanfordnlp by graphaware.

the class TextProcessorTest method testAnnotatedText.

@Test
public void testAnnotatedText() {
    AnnotatedText annotatedText = textProcessor.annotateText("On 8 May 2013, " + "one week before the Pakistani election, the third author, " + "in his keynote address at the Sentiment Analysis Symposium, " + "forecast the winner of the Pakistani election. The chart " + "in Figure 1 shows varying sentiment on the candidates for " + "prime minister of Pakistan in that election. The next day, " + "the BBC’s Owen Bennett Jones, reporting from Islamabad, wrote " + "an article titled “Pakistan Elections: Five Reasons Why the " + "Vote is Unpredictable,”1 in which he claimed that the election " + "was too close to call. It was not, and despite his being in Pakistan, " + "the outcome of the election was exactly as we predicted.", "en", PIPELINE_DEFAULT);
    TestAnnotatedText test = new TestAnnotatedText(annotatedText);
    test.assertSentencesCount(4);
    test.assertTagsCountInSentence(15, 0);
    test.assertTagsCountInSentence(11, 1);
    test.assertTagsCountInSentence(24, 2);
    test.assertTagsCountInSentence(8, 3);
    test.assertTag(newTag("Pakistan", Collections.singletonList("LOCATION"), Collections.emptyList()));
    test.assertTag(newTag("show", Collections.emptyList(), Collections.singletonList("VBZ")));
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) Test(org.junit.Test)

Example 2 with TestAnnotatedText

use of com.graphaware.nlp.util.TestAnnotatedText in project neo4j-nlp by graphaware.

the class TestAnnotatedTesterUnitTest method testSentencesCountIsCorrect.

@Test
public void testSentencesCountIsCorrect() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText test = new TestAnnotatedText(annotatedText);
    Sentence sentence = new Sentence("hello");
    sentence.addTag(new Tag("hello", "en"));
    annotatedText.addSentence(sentence);
    test.assertSentencesCount(1);
}
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 3 with TestAnnotatedText

use of com.graphaware.nlp.util.TestAnnotatedText in project neo4j-nlp by graphaware.

the class TestAnnotatedTesterUnitTest method testSentenceCountThrowsExceptionWhenNotCorrect.

@Test(expected = AssertionError.class)
public void testSentenceCountThrowsExceptionWhenNotCorrect() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText tester = new TestAnnotatedText(annotatedText);
    tester.assertSentencesCount(1);
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) Test(org.junit.Test)

Example 4 with TestAnnotatedText

use of com.graphaware.nlp.util.TestAnnotatedText in project neo4j-nlp by graphaware.

the class TestAnnotatedTesterUnitTest method assertTagEquals.

@Test
public void assertTagEquals() {
    AnnotatedText annotatedText = new AnnotatedText();
    TestAnnotatedText test = new TestAnnotatedText(annotatedText);
    Sentence sentence = new Sentence("John is working in Denver for IBM");
    sentence.addTag(newTag("John", singletonList("PERSON"), emptyList()));
    sentence.addTag(newTag("Denver", singletonList("LOCATION"), emptyList()));
    sentence.addTag(newTag("IBM", singletonList("ORGANIZATION"), emptyList()));
    sentence.addTag(newTag("work"));
    annotatedText.addSentence(sentence);
    test.assertTag(newTag("John", singletonList("PERSON"), emptyList()));
    test.assertTag(newTag("IBM", singletonList("ORGANIZATION"), emptyList()));
    test.assertTag(newTag("work"));
}
Also used : TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) TestAnnotatedText(com.graphaware.nlp.util.TestAnnotatedText) Sentence(com.graphaware.nlp.domain.Sentence) Test(org.junit.Test)

Example 5 with TestAnnotatedText

use of com.graphaware.nlp.util.TestAnnotatedText in project neo4j-nlp by graphaware.

the class TestAnnotatedTesterUnitTest method testTagIsNotFound.

@Test(expected = AssertionError.class)
public void testTagIsNotFound() {
    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.assertTagWithLemma("hella");
}
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)

Aggregations

TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)12 Test (org.junit.Test)12 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)8 Sentence (com.graphaware.nlp.domain.Sentence)7 Tag (com.graphaware.nlp.domain.Tag)5 TagUtils.newTag (com.graphaware.nlp.util.TagUtils.newTag)5 PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)2 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)2