diff --git a/src/test/java/com/github/bot/curiosone/core/extraction/QuestionTest.java b/src/test/java/com/github/bot/curiosone/core/extraction/QuestionTest.java new file mode 100644 index 00000000..0887cf5b --- /dev/null +++ b/src/test/java/com/github/bot/curiosone/core/extraction/QuestionTest.java @@ -0,0 +1,42 @@ +package com.github.bot.curiosone.core.extraction; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.bot.curiosone.core.knowledge.SemanticNetwork; +import com.github.bot.curiosone.core.knowledge.SemanticRelationType; +import com.github.bot.curiosone.core.nlp.Phrase; +import com.github.bot.curiosone.core.nlp.Sentence; + +import java.io.IOException; + +import org.junit.Test; + +public class QuestionTest { + + @Test + public void testGetAnswer() throws IOException { + SemanticNetwork sn = SemanticNetwork.getInstance(); + sn.learn("abcdedfgh", SemanticRelationType.IS_A, "alphabet"); + + Sentence s = Sentence.extract(new Phrase("Who is abcdedfgh?")).get(0); + assertThat(Question.getAnswer(s, "")).isPresent(); + + s = Sentence.extract(new Phrase("Where is abcdedfgh?")).get(0); + assertThat(Question.getAnswer(s, "")).isPresent(); + + s = Sentence.extract(new Phrase("Who is Gogol?")).get(0); + assertThat(Question.getAnswer(s, "")).isPresent(); + + s = Sentence.extract(new Phrase("Where is Gogol?")).get(0); + assertThat(Question.getAnswer(s, "")).isPresent(); + + s = Sentence.extract(new Phrase("What is Gogol?")).get(0); + assertThat(Question.getAnswer(s, "")).isPresent(); + + s = Sentence.extract(new Phrase("Why is Gogol?")).get(0); + assertThat(Question.getAnswer(s, "")).isNotPresent(); + + s = Sentence.extract(new Phrase("When is Gogol?")).get(0); + assertThat(Question.getAnswer(s, "")).isNotPresent(); + } +} diff --git a/src/test/java/com/github/bot/curiosone/core/extraction/RandomAnswerTest.java b/src/test/java/com/github/bot/curiosone/core/extraction/RandomAnswerTest.java new file mode 100644 index 00000000..ffd126ed --- /dev/null +++ b/src/test/java/com/github/bot/curiosone/core/extraction/RandomAnswerTest.java @@ -0,0 +1,19 @@ +package com.github.bot.curiosone.core.extraction; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.bot.curiosone.core.nlp.Phrase; + +import org.junit.Test; + +public class RandomAnswerTest { + + @Test + public void testRandomAnswer() { + Phrase p = new Phrase("youdont knowany single token of this very very long sentence"); + assertThat(RandomAnswer.getAnswer(p)).isIn( + new BrainResponse("What a nice day to talk to a chatbot!", ""), + new BrainResponse("Can you reformulate your sentence please?", ""), + new BrainResponse("Tell me something interesting please.", "")); + } +}