From bfe7cad226851cb3afc5d40618aad6f99624b4be Mon Sep 17 00:00:00 2001 From: knightmarehs Date: Sat, 26 Jan 2019 16:27:27 +0800 Subject: [PATCH] FIX the bug of Ganswer Handler 1. Fix the bug of selecting wrong sparqls and returning wrong answers. --- src/application/GanswerHandler.java | 26 +++++++++++++++----------- src/application/GanswerHttpConnector.java | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/application/GanswerHandler.java b/src/application/GanswerHandler.java index cfcc211..d7c62da 100644 --- a/src/application/GanswerHandler.java +++ b/src/application/GanswerHandler.java @@ -44,7 +44,7 @@ public class GanswerHandler extends AbstractHandler{ 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")){ @@ -67,7 +67,7 @@ public class GanswerHandler extends AbstractHandler{ 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; @@ -94,13 +94,15 @@ public class GanswerHandler extends AbstractHandler{ 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(); @@ -142,8 +144,10 @@ public class GanswerHandler extends AbstractHandler{ } if(needSparql>0){ JSONArray spqarr = new JSONArray(); - for(idx=0;idx