Skip to content

Commit da74857

Browse files
committed
Fixes dbpedia#2 and Added Test for dbpedia#1 and dbpedia#2
1 parent af62129 commit da74857

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/main/java/chatbot/lib/api/qa/QAService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public QAService(WolframRepository wolframRepository) {
3838
// Calls QA Service then returns resulting data as a list of Data Objects. The Data class is defined below as an inner class to be used here locally
3939
public Data search(String question) throws Exception {
4040
return qanary.search(question)
41-
.addData(wolframAlpha.search(question));
41+
.addData(wolframAlpha.search(question), true);
4242
}
4343

4444
public static class Data {
@@ -62,9 +62,17 @@ public Data addLiteral(String literal) {
6262
return this;
6363
}
6464

65-
public Data addData(Data data) {
65+
public Data addData(Data data, boolean fromWolfram) {
6666
uris.addAll(data.getUris());
67-
literals.addAll(data.getLiterals());
67+
// Literal values from WolframAlpha supersede QANARY since they have more detailed information
68+
if (fromWolfram) {
69+
if(data.getLiterals().size() > 0) {
70+
literals = data.getLiterals();
71+
}
72+
}
73+
else {
74+
literals.addAll(data.getLiterals());
75+
}
6876
return this;
6977
}
7078

src/test/java/chatbot/lib/handlers/TestNLHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ private void checkEntity(String userId, String question) throws Exception {
4545
@Test
4646
public void testLiteral() throws Exception {
4747
checkLiteral("user", "What is the population of France?");
48+
checkLiteral("user", "When was Angela Merkel born?");
4849
}
4950

5051
@Test

src/test/java/chatbot/lib/response/TestResponseBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static void checkTextMessage(Response response) {
1616
assertEquals(response.getMessageType(), ResponseType.TEXT_MESSAGE);
1717
assertEquals(messageData.size(), 1);
1818
assertNotNull(messageData.get(0).getText());
19+
assertEquals(messageData.get(0).getText().contains("\n"), false); // Check that we are showing only 1 response and not both responses from both QA Systems
1920
}
2021

2122
public static void checkButtons(List<ResponseData.Button> buttons) {

src/test/java/rivescript/TestBot.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package rivescript;
2+
3+
import org.junit.Test;
4+
5+
import java.util.ArrayList;
6+
7+
/**
8+
* Created by ramgathreya on 7/14/17.
9+
*/
10+
public class TestBot extends RiveScriptBase {
11+
@Test
12+
public void testBotName() {
13+
String[] testCases = new String[]{"Hi what is your name", "Hi, what is your name"};
14+
String[] expectedAnswer = new String[]{"I am the DBpedia Bot"};
15+
checkAnswers(testCases, expectedAnswer, true);
16+
}
17+
}

0 commit comments

Comments
 (0)