info.ephyra.search.searchers
Class KnowledgeAnnotator

java.lang.Object
  extended by java.lang.Thread
      extended by info.ephyra.search.searchers.Searcher
          extended by info.ephyra.search.searchers.KnowledgeAnnotator
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
WikipediaKA, WorldFactbookKA

public abstract class KnowledgeAnnotator
extends Searcher

A KnowledgeAnnotator searches a (semi)structured knowledge source. It provides a specialized solution to certain classes of questions, described by a set of question patterns. Only questions that match at least one of the patterns in the field qPatterns are supported by a KnowledgeAnnotator.

It runs as a separate thread, so several queries can be performed in parallel.

This class extends the class Searcher and is abstract.

Version:
2005-09-28
Author:
Nico Schlaefer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  int index
          Index of the matching pattern.
protected  java.util.regex.Matcher matcher
          The Matcher that matched the pattern with the question.
protected  java.lang.String name
          Name of the knowledge annotator.
protected  java.util.ArrayList<java.lang.String> qContents
          Strings identifying the relevant content of a question by referring to the groups in the corresponding question patterns.
protected  java.util.ArrayList<java.util.regex.Pattern> qPatterns
          A question that matches at least one of these patterns can be handled by the KnowledgeAnnotator.
 
Fields inherited from class info.ephyra.search.searchers.Searcher
query, results
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
  KnowledgeAnnotator(java.lang.String filename)
          Creates a KnowledgeAnnotator and reads the question patterns and descriptors of the relevant content of a question from a file.
protected KnowledgeAnnotator(java.lang.String name, java.util.ArrayList<java.util.regex.Pattern> qPatterns, java.util.ArrayList<java.lang.String> qContents)
          Protected constructor used by the getCopy() method.
 
Method Summary
protected  java.lang.String getContent()
          Extracts the relevant content of a question by resolving the group identifiers of the format [group_no] in the content string that corresponds to the matching pattern.
abstract  KnowledgeAnnotator getCopy()
          Returns a new instance of the KnowledgeAnnotator.
 java.lang.String getKAName()
          Returns the name of the knowledgeAnnotator.
protected  Result[] getResult(java.lang.String answer, java.lang.String docID)
          Creates an array of a single Result object form an answer string and a document ID.
protected  boolean matches(Query query)
          Tests whether the knowledge annotator is appropriate for a question by applying the patterns in the field qPatterns.
 boolean start(Query query)
          Sets the query and starts the thread if the knowledge annotator is appropriate for the user question.
 
Methods inherited from class info.ephyra.search.searchers.Searcher
doSearch, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of the knowledge annotator.


qPatterns

protected java.util.ArrayList<java.util.regex.Pattern> qPatterns
A question that matches at least one of these patterns can be handled by the KnowledgeAnnotator.


qContents

protected java.util.ArrayList<java.lang.String> qContents
Strings identifying the relevant content of a question by referring to the groups in the corresponding question patterns.


index

protected int index
Index of the matching pattern.


matcher

protected java.util.regex.Matcher matcher
The Matcher that matched the pattern with the question.

Constructor Detail

KnowledgeAnnotator

protected KnowledgeAnnotator(java.lang.String name,
                             java.util.ArrayList<java.util.regex.Pattern> qPatterns,
                             java.util.ArrayList<java.lang.String> qContents)
Protected constructor used by the getCopy() method.

Parameters:
name - name of the KnowledgeAnnotator
qPatterns - question patterns
qContents - descriptors of the relevant content of a question

KnowledgeAnnotator

public KnowledgeAnnotator(java.lang.String filename)
                   throws java.io.IOException

Creates a KnowledgeAnnotator and reads the question patterns and descriptors of the relevant content of a question from a file.

The file must have the following format:

KnowledgeAnnotator::
[name of the knowledge annotator]

QuestionPatterns:
[regular expression 1]
[relevant content 1]
...
[regular expression n]
[relevant content n]

The relevant content of a question is described by a string that may contain group identifiers of the format [group_no] that are replaced by the capturing groups that occur in the corresponding question pattern.

Parameters:
filename - file containing the question patterns and descriptors of the relevant content of a question
Throws:
java.io.IOException
Method Detail

matches

protected boolean matches(Query query)
Tests whether the knowledge annotator is appropriate for a question by applying the patterns in the field qPatterns.

Parameters:
query - Query object
Returns:
true, iff the question matches at least one of the patterns in qPatterns

getContent

protected java.lang.String getContent()
Extracts the relevant content of a question by resolving the group identifiers of the format [group_no] in the content string that corresponds to the matching pattern.

Returns:
relevant content of the question

getResult

protected Result[] getResult(java.lang.String answer,
                             java.lang.String docID)
Creates an array of a single Result object form an answer string and a document ID.

Parameters:
answer - answer string
docID - document ID
Returns:
array of a single Result object

getKAName

public java.lang.String getKAName()
Returns the name of the knowledgeAnnotator.

Returns:
name of the knowledge annotator

getCopy

public abstract KnowledgeAnnotator getCopy()

Returns a new instance of the KnowledgeAnnotator. A new instance is created for each query.

It does not necessarily return an exact copy of the current instance.

Returns:
new instance of the KnowledgeAnnotator

start

public boolean start(Query query)

Sets the query and starts the thread if the knowledge annotator is appropriate for the user question.

This method should be used instead of the inherited start() method without arguments.

Parameters:
query - query object
Returns:
true, iff the knowledge annotator is appropriate and the thread was started