java.lang.Object QuestionAnswerer
public class QuestionAnswerer
A question answerer is capable of answering queries (using the strategy outlined in the ProfessionalMagician class's notes) of a specified type, such as queries using the key word "is" ("who is" or "what is" queries).
Field Summary | |
---|---|
private static java.lang.String |
KEY
The Google search key to use when accessing Google. |
static int |
MAX_SNIPPETS_TO_SEARCH
The maximum number of snippets from the list of Google search results to consider in answering a query. |
static int |
MAX_TILES_TO_FORM
The maximum number of tiles to form from a given search result. |
private java.lang.String |
myKeyWord
The key word to use when searching for a question answer. |
private static TextCleaner |
ourCleaner
A TextCleaner object to put all text manipulated into a simple, canonical form. |
Constructor Summary | |
---|---|
QuestionAnswerer(java.lang.String keyWord)
Construct a QuestionAnswerer that focuses on the given key word. |
Method Summary | |
---|---|
java.lang.String |
answer(java.lang.String query)
Answer the given query from the user. |
private java.lang.String |
buildInitialQuery(java.lang.String query)
Build the full phrase search to use to get initial responses from Google (i.e., the sources of the candidates). |
private java.lang.String |
buildInitialQueryBody(java.lang.String query)
Build just the body of the phrase search to use to get initial responses from Google (i.e., the sources of the candidates). |
private java.lang.String |
buildVerificationQuery(java.lang.String answer,
java.lang.String query)
Build the verification query that tests whether the given answer goes well with the given query. |
java.lang.String |
getKeyWord()
Get the key word associated with this QuestionAnswerer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String KEY
You should initialize this constant with the Google search key provided to you!
public static final int MAX_SNIPPETS_TO_SEARCH
Setting this to a small number can reduce the time your program takes, keep you under the search limit on your search key, and ease debugging.
public static final int MAX_TILES_TO_FORM
Setting this to a small number can reduce the time your program takes, keep you under the search limit on your search key, and ease debugging.
private final java.lang.String myKeyWord
private static final TextCleaner ourCleaner
Constructor Detail |
---|
public QuestionAnswerer(java.lang.String keyWord)
keyWord
- the word to use after search phrases initially and before
them in verification (non-null)Method Detail |
---|
public java.lang.String answer(java.lang.String query)
query
- the user's query (non-null)
private java.lang.String buildInitialQuery(java.lang.String query)
query
- the user's query (e.g., "the tallest mountain in the world";
non-null)
private java.lang.String buildInitialQueryBody(java.lang.String query)
query
- the user's query (e.g., "the tallest mountain in the world";
non-null)
private java.lang.String buildVerificationQuery(java.lang.String answer, java.lang.String query)
answer
- the candidate answer (non-null)query
- the user's query (non-null)
public java.lang.String getKeyWord()