AnswerAnalyzer implements Analyzer { @Override public Interpretation analyze(Interpretation interpretation) { Map<SemanticRole, String> pas = interpretation.getPas(); if(pas.containsKey(SemanticRole.PREDICATE) && pas.containsKey(SemanticRole.LOCATION)){ String pp = pas.get(SemanticRole.LOCATION); String pred = pas.get(SemanticRole.PREDICATE); if(Linguistics.tobe.contains(pred)){ pred = ""; } else { pred = pred + " "; } if(pp.contains(" ")){ pp = pp.substring(pp.indexOf(" ") + 1); } interpretation.setObjAnswer(pp.toLowerCase()); interpretation.setPredAnswer(pred + pp.toLowerCase()); return interpretation; } else if(pas.containsKey(SemanticRole.PREDICATE) && pas.containsKey(SemanticRole.PATIENT)){ String pred = pas.get(SemanticRole.PREDICATE).toLowerCase(); if(Linguistics.tobe.contains(pred)){ pred = ""; } else { pred = pred + " "; } String pat = pas.get(SemanticRole.PATIENT).toLowerCase(); interpretation.setObjAnswer(pat); interpretation.setPredAnswer(pred + pat); return interpretation; } int verbIndex = -1; List<String> tokens = interpretation.getTokens(); String[] pos = interpretation.getPosTags(); if (pos != null) { for(int i=0; i < pos.length; i++) { if(pos[i] != null && pos[i].startsWith("V")) { verbIndex = i; } } } else { logger.warn("POSTAGS missing but AnswerAnalyzer is used!"); } if (tokens != null && !tokens.isEmpty()) { if(verbIndex == -1){ if (tokens.size() == 1) { interpretation.setObjAnswer(tokens.get(0)); interpretation.setPredAnswer(tokens.get(0)); return interpretation; } } StringBuilder answer = new StringBuilder(""); StringBuilder answerPred = new StringBuilder(""); for(int i = verbIndex; i < tokens.size(); i++){ if(i != verbIndex){ if(tokens.get(i) != null && !"me".equals(tokens.get(i).toLowerCase())){ if(answer.length() > 0) answer.append(' '); if(Character.isLetterOrDigit(tokens.get(i).charAt(0))) answer.append(tokens.get(i).toLowerCase()); if(answerPred.length()>0) answerPred.append(' '); if(Character.isLetterOrDigit(tokens.get(i).charAt(0))) answerPred.append(tokens.get(i).toLowerCase()); } } else if(verbIndex != -1 && !Linguistics.tobe.contains(tokens.get(i))){ answerPred.append(tokens.get(i).toLowerCase()); } } interpretation.setObjAnswer(answer.toString()); interpretation.setPredAnswer(answerPred.toString()); } else { logger.warn("TOKENS missing but AnswerAnalyzer is used!"); } return interpretation; }  @Override Interpretation analyze(Interpretation interpretation);  }
@Test public void testName() { assertEquals("frank", analyze("Frank")); assertEquals("carl", analyze("I am carl")); assertEquals("horst", analyze("My name is Horst")); assertEquals("bill gates", analyze("I am Bill Gates")); assertEquals("jack", analyze("My friends call me Jack")); assertEquals("bill", analyze("You can call me Bill")); }
@Test public void testOrigin() { assertEquals("netherlands", analyze("Netherlands")); assertEquals("india", analyze("I am from India")); assertEquals("germany", analyze("I live in Germany")); assertEquals("sweden", analyze("My home country is Sweden")); assertEquals("garching", analyze("My home town is Garching")); assertEquals("austria", analyze("I was born in Austria")); }
@Test public void testMovie() { assertEquals("matrix", analyze("I love matrix")); assertEquals("forest gump", analyze("I enjoyed forest gump")); assertEquals("wheel of fortune", analyze("I always watch wheel of fortune")); assertEquals("anything from quentin tarantino", analyze("anything from quentin tarantino")); assertEquals("psycho", analyze("psycho")); }