OpenNLPParser implements Analyzer { @Override public Interpretation analyze(Interpretation interpretation) { String sentence = interpretation.getSentence(); if (sentence != null) { sentence = sentence.trim(); if (!sentence.endsWith(".") && !sentence.endsWith("?") && !sentence.endsWith("!")) { sentence = sentence + " ."; } if (sentence.length() > 0 && Character.isLowerCase(sentence.charAt(0))) { sentence = Character.toUpperCase(sentence.charAt(0)) + sentence.substring(1, sentence.length()); } Parse parse = ParserTool.parseLine(sentence, parser, 1)[0]; interpretation = extractPAS(interpretation, parse); } return interpretation; } OpenNLPParser(); @Override Interpretation analyze(Interpretation interpretation); StringBuilder parseToString(Parse parse, int offset); static void main(String[] args);  }
@SuppressWarnings("unchecked") @Test public void testWhatIs() { Interpretation interpretation = new Interpretation("What is the area code of Germany"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("is", pas.get(SemanticRole.PREDICATE)); assertEquals("the area code of Germany", pas.get(SemanticRole.PATIENT)); assertEquals("What", pas.get(SemanticRole.AGENT)); }
@SuppressWarnings("unchecked") @Test public void testWhenWas() { Interpretation interpretation = new Interpretation("When was Putin born ?"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("born", pas.get(SemanticRole.PREDICATE)); assertEquals("Putin", pas.get(SemanticRole.PATIENT)); assertEquals("When", pas.get(SemanticRole.TIME)); }
@SuppressWarnings("unchecked") @Test public void testWhereWas() { Interpretation interpretation = new Interpretation("Where was Putin born ?"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("born", pas.get(SemanticRole.PREDICATE)); assertEquals("Putin", pas.get(SemanticRole.PATIENT)); assertEquals("Where", pas.get(SemanticRole.LOCATION)); }
@SuppressWarnings("unchecked") @Test public void testWhereDid() { Interpretation interpretation = new Interpretation("Where did Elvis die ?"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("die", pas.get(SemanticRole.PREDICATE)); assertEquals("Elvis",pas.get(SemanticRole.AGENT)); assertEquals("Where", pas.get(SemanticRole.LOCATION)); }
@SuppressWarnings("unchecked") @Test public void testWhenDid() { Interpretation interpretation = new Interpretation("When did Elvis die ?"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("die", pas.get(SemanticRole.PREDICATE)); assertEquals("Elvis", pas.get(SemanticRole.AGENT)); assertEquals("When", pas.get(SemanticRole.TIME)); }
@SuppressWarnings("unchecked") @Test public void testHowAdjective() { Interpretation interpretation = new Interpretation("How high is Mount Everest ?"); interpretation = parser.analyze(interpretation); Map<SemanticRole, String> pas = interpretation.getPas(); assertEquals("is", pas.get(SemanticRole.PREDICATE)); assertEquals("Mount Everest", pas.get(SemanticRole.PATIENT)); assertEquals("How", pas.get(SemanticRole.MANNER)); assertEquals("high", pas.get(SemanticRole.AGENT)); interpretation = new Interpretation("How many people live in Berlin ?"); interpretation = parser.analyze(interpretation); pas = interpretation.getPas(); assertEquals("live", pas.get(SemanticRole.PREDICATE)); assertEquals("in Berlin", pas.get(SemanticRole.LOCATION)); assertEquals("How many people", pas.get(SemanticRole.AGENT)); }