Skip to content

Commit

Permalink
FIX the bug of Ganswer Handler
Browse files Browse the repository at this point in the history
1. Fix the bug of selecting wrong sparqls and returning wrong answers.
  • Loading branch information
knightmarehs committed Jan 26, 2019
1 parent f0d4b9b commit bfe7cad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/application/GanswerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
JSONObject jsonobj = new JSONObject();
int needAnswer = 0;
int needSparql = 1;
question = "Show me all Czech movies";
question = "Something wrong if you see this.";
jsonobj = new JSONObject(data);
question = jsonobj.getString("question");
if(jsonobj.isNull("maxAnswerNum")){
Expand All @@ -67,7 +67,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
if(qlog == null || qlog.rankedSparqls == null){
try {
baseRequest.setHandled(true);
response.getWriter().println(errorHandle("500","UnvalidQuestionException: the question you input is invalid, please check",question,qlog));
response.getWriter().println(errorHandle("500","InvalidQuestionException: the question you input is invalid, please check",question,qlog));
} catch (Exception e1) {
}
return;
Expand All @@ -94,13 +94,15 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
break;
}
}
curSpq = ga.getUntypedSparql(curSpq);
if(curSpq!=null){
m = ga.getAnswerFromGStore2(curSpq);
}
if(m!=null&&m.answers!=null){
qlog.sparql = curSpq;
qlog.match = m;
if(m==null||m.answers==null){
curSpq = ga.getUntypedSparql(curSpq);
if(curSpq!=null){
m = ga.getAnswerFromGStore2(curSpq);
}
if(m!=null&&m.answers!=null){
qlog.sparql = curSpq;
qlog.match = m;
}
}
if(qlog.match==null)
qlog.match=new Matches();
Expand Down Expand Up @@ -142,8 +144,10 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
if(needSparql>0){
JSONArray spqarr = new JSONArray();
for(idx=0;idx<needSparql&&idx<qlog.rankedSparqls.size();idx+=1){
spqarr.put(qlog.rankedSparqls.get(idx).toStringForGStore2());
spqarr.put(qlog.sparql.toStringForGStore2());
for(idx=0;idx<needSparql-1&&idx<qlog.rankedSparqls.size();idx+=1){
if(qlog.sparql.toStringForGStore2().compareTo(qlog.rankedSparqls.get(idx).toStringForGStore2()) != 0)
spqarr.put(qlog.rankedSparqls.get(idx).toStringForGStore2());
}
resobj.put("sparql", spqarr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/application/GanswerHttpConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String gInfo(){

public static void main(String[] args){
GanswerHttpConnector ghc = new GanswerHttpConnector();
String data = "{\"maxAnswerNum\":\"3\",\"needSparql\":\"2\",\"questions\":\"Who is the wife of Barack Obama?\"}";
String data = "{\"maxAnswerNum\":\"3\",\"needSparql\":\"2\",\"question\":\"Who is the president of China?\"}";
ghc.gInfo();
ghc.gSolve(data);
}
Expand Down

0 comments on commit bfe7cad

Please sign in to comment.