Class QuestionAnswerer

java.lang.Object
  extended by QuestionAnswerer

public class QuestionAnswerer
extends java.lang.Object

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

KEY

private static final java.lang.String KEY
The Google search key to use when accessing Google.

You should initialize this constant with the Google search key provided to you!

See Also:
Constant Field Values

MAX_SNIPPETS_TO_SEARCH

public static final int MAX_SNIPPETS_TO_SEARCH
The maximum number of snippets from the list of Google search results to consider in answering a query.

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.

See Also:
Constant Field Values

MAX_TILES_TO_FORM

public static final int MAX_TILES_TO_FORM
The maximum number of tiles to form from a given search result. For example, if the query is "the tallest mountain in the world" and the search result is "question anyway the tallest mountain in the world is mount everest in the himalayas", the candidate tiles are "mount", "mount everest", "mount everest in", "mount everest in the", and "mount everest in the himalayas". If the maximum number of tiles to form is 3, the QuestionAnswerer would stop considering tiles after "mount everest in".

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.

See Also:
Constant Field Values

myKeyWord

private final java.lang.String myKeyWord
The key word to use when searching for a question answer.


ourCleaner

private static final TextCleaner ourCleaner
A TextCleaner object to put all text manipulated into a simple, canonical form.

Constructor Detail

QuestionAnswerer

public QuestionAnswerer(java.lang.String keyWord)
Construct a QuestionAnswerer that focuses on the given key word.

Parameters:
keyWord - the word to use after search phrases initially and before them in verification (non-null)
Method Detail

answer

public java.lang.String answer(java.lang.String query)
Answer the given query from the user. If no answer can be found, this method returns null to signal the failure.

Parameters:
query - the user's query (non-null)
Returns:
the best answer to the user's query OR null if no answer can be found

buildInitialQuery

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).

Parameters:
query - the user's query (e.g., "the tallest mountain in the world"; non-null)
Returns:
the full phrase search (including the surrounding quotation marks)

buildInitialQueryBody

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).

Parameters:
query - the user's query (e.g., "the tallest mountain in the world"; non-null)
Returns:
the body of the phrase search (without the surrounding quotation marks)

buildVerificationQuery

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. If the answer were "actually mauna kea", the query were "the tallest mountain in the world", and this object's key word were "is", the query would be a phrase search for "actually mauna kea is the tallest mountain in the world".

Parameters:
answer - the candidate answer (non-null)
query - the user's query (non-null)
Returns:
the full phrase search (including the surrounding quotation marks)

getKeyWord

public java.lang.String getKeyWord()
Get the key word associated with this QuestionAnswerer.

Returns:
the key word