You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueryLogger.java 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package log;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.HashMap;
  5. import java.util.HashSet;
  6. import javax.servlet.http.HttpServletRequest;
  7. import qa.Matches;
  8. import qa.Query;
  9. import rdf.EntityMapping;
  10. import rdf.SemanticRelation;
  11. import rdf.Sparql;
  12. import rdf.MergedWord;
  13. import rdf.SemanticUnit;
  14. import qa.Answer;
  15. import nlp.ds.Sentence;
  16. import nlp.ds.Word;
  17. public class QueryLogger {
  18. public Sentence s = null;
  19. public String ipAdress = null;
  20. public Word target = null;
  21. public Sparql sparql = null;
  22. public Matches match = null;
  23. public ArrayList<Answer> answers = null;
  24. public boolean MODE_debug = false;
  25. public boolean MODE_log = true;
  26. public boolean MODE_fragment = true;
  27. public boolean isMaltParserUsed = true; // Notice, we utilize Malt Parser as default parser, which is different from the older version. TODO: some coref rules need changed to fit Malt Parser.
  28. public HashMap<String, Integer> timeTable = null;
  29. public ArrayList<MergedWord> mWordList = null;
  30. public ArrayList<SemanticUnit> semanticUnitList = null;
  31. public HashMap<Integer, SemanticRelation> semanticRelations = null;
  32. public HashMap<Integer, SemanticRelation> potentialSemanticRelations = null;
  33. public HashMap<Word, ArrayList<EntityMapping>> entityDictionary = null;
  34. public ArrayList<Sparql> rankedSparqls = null;
  35. public String NRlog = "";
  36. public String SQGlog = "";
  37. public int gStoreCallTimes = 0;
  38. public QueryLogger (Query query)
  39. {
  40. timeTable = new HashMap<String, Integer>();
  41. rankedSparqls = new ArrayList<Sparql>();
  42. mWordList = query.mWordList;
  43. }
  44. public void reloadSentence(Sentence sentence)
  45. {
  46. this.s = sentence;
  47. if(this.semanticUnitList != null)
  48. this.semanticUnitList.clear();
  49. if(this.semanticRelations != null)
  50. this.semanticRelations.clear();
  51. if(this.rankedSparqls != null)
  52. this.rankedSparqls.clear();
  53. }
  54. // Source code: http://edu.21cn.com/java/g_189_755584-1.htm
  55. public static String getIpAddr(HttpServletRequest request) {
  56. String ip = request.getHeader("x-forwarded-for");
  57. if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  58. ip = request.getHeader("Proxy-Client-IP");
  59. }
  60. if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  61. ip = request.getHeader("WL-Proxy-Client-IP");
  62. }
  63. if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  64. ip = request.getRemoteAddr();
  65. }
  66. int idx;
  67. if((idx = ip.indexOf(',')) != -1) {
  68. ip = ip.substring(0, idx);
  69. }
  70. return ip;
  71. }
  72. public void reviseAnswers()
  73. {
  74. System.out.println("Revise Answers:");
  75. answers = new ArrayList<Answer>();
  76. if (match == null || sparql == null || match.answers == null || sparql.questionFocus == null)
  77. return;
  78. HashSet<Answer> answerSet = new HashSet<Answer>();
  79. String questionFocus = sparql.questionFocus;
  80. String sparqlString = sparql.toStringForGStore();
  81. //System.out.println("mal="+match.answers.length);
  82. for (int i=0;i<match.answers.length;i++)
  83. {
  84. Answer ans = new Answer(questionFocus, match.answers[i]);
  85. if (!sparqlString.contains(ans.questionFocusValue))
  86. answerSet.add(ans);
  87. }
  88. for (Answer ans : answerSet)
  89. answers.add(ans);
  90. Collections.sort(answers);
  91. }
  92. }

GAnswer system is a natural language QA system developed by Institute of Computer Science & Techonology Data Management Lab, Peking University, led by Prof. Zou Lei. GAnswer is able to translate natural language questions to query graphs containing semant