info.ephyra.answerselection.filters
Class AnswerPatternFilter

java.lang.Object
  extended by info.ephyra.answerselection.filters.Filter
      extended by info.ephyra.answerselection.filters.AnswerPatternFilter

public class AnswerPatternFilter
extends Filter

The AnswerPatternFilter uses answer patterns to extract factoid answers from text passages and to rank them. It is only applied if the question could be interpreted, i.e. a QuestionInterpretation is available.

In addition, this Filter provides methods to add, load, save and assess the answer patterns.

This class extends the class Filter.

Version:
2007-04-18
Author:
Nico Schlaefer

Field Summary
private static java.util.ArrayList<AnswerPattern> aps
          For each PROPERTY object the answer pattern used to extract it.
private static java.util.ArrayList<java.lang.String> extr
          PROPERTY objects extracted from a Result.
static java.lang.String ID
          Identifier for the pattern learning and matching approach.
private static java.util.Hashtable<java.lang.String,java.lang.Integer> nOfPassages
          For each PROPERTY the number of text passages used to assess the answer patterns.
private static java.util.Hashtable<java.lang.String,java.util.HashSet<AnswerPattern>> props
          For each PROPERTY the answer patterns that are used to extract it.
private static java.util.Hashtable<java.lang.String,java.lang.String> reverseMap
          Maps tags in PROPERTY objects back to the original strings.
private static java.util.ArrayList<java.lang.String> sents
          For each PROPERTY object the sentence it was extracted from.
private static java.util.ArrayList<java.lang.String[]> types
          For each PROPERTY object the NE types.
 
Constructor Summary
AnswerPatternFilter()
           
 
Method Summary
static boolean addPattern(java.lang.String expr, java.lang.String prop)
          Adds an answer pattern for a specific PROPERTY.
 Result[] apply(Result[] results)
          Applies the answer patterns to the answer strings of the Result objects and creates a new Result for each extracted unique answer.
static void assessPatterns(Result result, java.lang.String regex)
          Assesses the answer patterns by applying them to the answer string of the Result object and comparing the extracted answers to the regular expression regex.
static void dropLowConfidence(float confidenceThresh)
          Drops answer patterns that have a confidence of confidenceThresh or less.
static void dropLowSupport(float supportThresh)
          Drops answer patterns that have a support of supportThresh or less.
private static void extractPos(Result result)
          Applies the answer patterns to the answer string of the Result object to extract PROPERTY objects.
private static java.lang.String[] getNeTypes(java.lang.String pos, AnswerPattern pattern)
          Gets the NE types that a PROPERTY object has in common with the answer pattern used to extract it.
static boolean loadPatterns(java.lang.String dir)
          Loads the answer patterns from a directory of PROPERTY files.
private static java.lang.String prepSentence(java.lang.String sentence, java.lang.String to, java.lang.String[] cos, java.lang.String[][] nes)
          Prepares a sentence for answer extraction.
private static java.lang.String replaceContext(java.lang.String sentence, java.lang.String[] cos, java.lang.String[][] nes)
          Replaces all CONTEXT objects in the sentence.
private static java.lang.String replaceNes(java.lang.String sentence, java.lang.String[][] nes)
          Replaces all NEs in the sentence.
private static java.lang.String replaceTags(java.lang.String po)
          Replaces tags in an extracted PROPERTY object with the original strings stored in reverseMap.
private static java.lang.String replaceTarget(java.lang.String sentence, java.lang.String to, java.lang.String[][] nes)
          Replaces all TARGET objects in the sentence.
static boolean savePatterns(java.lang.String dir)
          Saves the answer patterns to resource files.
 
Methods inherited from class info.ephyra.answerselection.filters.Filter
apply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final java.lang.String ID
Identifier for the pattern learning and matching approach.

See Also:
Constant Field Values

props

private static java.util.Hashtable<java.lang.String,java.util.HashSet<AnswerPattern>> props
For each PROPERTY the answer patterns that are used to extract it.


nOfPassages

private static java.util.Hashtable<java.lang.String,java.lang.Integer> nOfPassages
For each PROPERTY the number of text passages used to assess the answer patterns.


reverseMap

private static java.util.Hashtable<java.lang.String,java.lang.String> reverseMap
Maps tags in PROPERTY objects back to the original strings.


extr

private static java.util.ArrayList<java.lang.String> extr
PROPERTY objects extracted from a Result.


types

private static java.util.ArrayList<java.lang.String[]> types
For each PROPERTY object the NE types.


sents

private static java.util.ArrayList<java.lang.String> sents
For each PROPERTY object the sentence it was extracted from.


aps

private static java.util.ArrayList<AnswerPattern> aps
For each PROPERTY object the answer pattern used to extract it.

Constructor Detail

AnswerPatternFilter

public AnswerPatternFilter()
Method Detail

replaceTarget

private static java.lang.String replaceTarget(java.lang.String sentence,
                                              java.lang.String to,
                                              java.lang.String[][] nes)
Replaces all TARGET objects in the sentence. The reverse mappings are stored in reverseMap.

Parameters:
sentence - input sentence
to - the TARGET object of the question
nes - the NEs in the sentence
Returns:
sentence with TARGET tags or null, if the sentence does not contain the TARGET

replaceContext

private static java.lang.String replaceContext(java.lang.String sentence,
                                               java.lang.String[] cos,
                                               java.lang.String[][] nes)
Replaces all CONTEXT objects in the sentence. The reverse mappings are stored in reverseMap.

Parameters:
sentence - input sentence
cos - the CONTEXT objects of the question
nes - the NEs in the sentence
Returns:
sentence with CONTEXT tags

replaceNes

private static java.lang.String replaceNes(java.lang.String sentence,
                                           java.lang.String[][] nes)
Replaces all NEs in the sentence. The reverse mappings are stored in reverseMap.

Parameters:
sentence - input sentence
nes - the NEs in the sentence
Returns:
sentence with NE tags

prepSentence

private static java.lang.String prepSentence(java.lang.String sentence,
                                             java.lang.String to,
                                             java.lang.String[] cos,
                                             java.lang.String[][] nes)
Prepares a sentence for answer extraction.

Parameters:
sentence - input sentence
to - the TARGET object of the question
cos - the CONTEXT objects of the question
nes - the NEs in the sentence
Returns:
sentence ready for answer extraction or null, if there is no TARGET object in the input sentence

getNeTypes

private static java.lang.String[] getNeTypes(java.lang.String pos,
                                             AnswerPattern pattern)
Gets the NE types that a PROPERTY object has in common with the answer pattern used to extract it.

Parameters:
pos - PROPERTY object
pattern - answer pattern used to extract it
Returns:
NE types or null if the answer pattern does not expect specific types

replaceTags

private static java.lang.String replaceTags(java.lang.String po)
Replaces tags in an extracted PROPERTY object with the original strings stored in reverseMap.

Parameters:
po - PROPERTY object
Returns:
PROPERTY object without tags

extractPos

private static void extractPos(Result result)
Applies the answer patterns to the answer string of the Result object to extract PROPERTY objects.

Parameters:
result - a Result object

addPattern

public static boolean addPattern(java.lang.String expr,
                                 java.lang.String prop)
Adds an answer pattern for a specific PROPERTY.

Parameters:
expr - pattern descriptor
prop - PROPERTY that the pattern extracts
Returns:
true, iff a new pattern was added

loadPatterns

public static boolean loadPatterns(java.lang.String dir)
Loads the answer patterns from a directory of PROPERTY files. The first line of each file is the total number of passages used to assess the patterns. It is followed by a list of pattern descriptors, along with their number of correct and wrong applications. The format of the descriptors is described in the documentation of the class AnswerPattern.

Parameters:
dir - directory of the answer patterns
Returns:
true, iff the answer patterns were loaded successfully

savePatterns

public static boolean savePatterns(java.lang.String dir)
Saves the answer patterns to resource files. A separate file is created for each PROPERTY. The first line is the total number of passages used to assess the answer patterns. It is followed by a list of pattern descriptors along with their number of correct and wrong applications.

Parameters:
dir - directory of the answer patterns
Returns:
true, iff the answer patterns were saved successfully

assessPatterns

public static void assessPatterns(Result result,
                                  java.lang.String regex)
Assesses the answer patterns by applying them to the answer string of the Result object and comparing the extracted answers to the regular expression regex.

Parameters:
result - Result object
regex - regular expression that describes a correct answer

dropLowSupport

public static void dropLowSupport(float supportThresh)
Drops answer patterns that have a support of supportThresh or less.

Parameters:
supportThresh - the support threshold

dropLowConfidence

public static void dropLowConfidence(float confidenceThresh)
Drops answer patterns that have a confidence of confidenceThresh or less.

Parameters:
confidenceThresh - the confidence threshold

apply

public Result[] apply(Result[] results)
Applies the answer patterns to the answer strings of the Result objects and creates a new Result for each extracted unique answer.

Overrides:
apply in class Filter
Parameters:
results - array of Result objects
Returns:
extended array of Result objects