Java Reference
In-Depth Information
dependency.gov().originalText())
&& "adjectival modifier".equals(
dependency.reln().getLongName())) {
String positionText =
dependency.dep().originalText();
int position = getOrder(positionText)-1;
System.out.println("The president is "
+ list.get(position).getName());
}
}
}
The getOrder method is as follows and simply takes the first numeric characters and
converts them to an integer. A more sophisticated version would look at other variations
including words such as "first" and "sixteenth":
private static int getOrder(String position) {
String tmp = "";
int i = 0;
while (Character.isDigit(position.charAt(i))) {
tmp += position.charAt(i++);
}
return Integer.parseInt(tmp);
}
When executed, we get the following output:
The president is Franklin D . Roosevelt
This implementation is a simple example of how information can be extracted from a sen-
tence and used to answer questions. The other types of questions can be implemented in a
similar fashion and are left as an exercise for the reader.
Search WWH ::




Custom Search