edu.washington.cs.knowitall.extractor
Class Extractor<S,T>

java.lang.Object
  extended by edu.washington.cs.knowitall.extractor.Extractor<S,T>
Type Parameters:
S - the source type
T - the target extraction type
Direct Known Subclasses:
ArgLearner, ChunkedArgumentExtractor, ExtractorComposition, ExtractorUnion, RegexExtractor, RegexGroupExtractor, RelationFirstNpChunkExtractor, SentenceExtractor

public abstract class Extractor<S,T>
extends Object

An abstract class that defines the basic behavior of an extractor. An Extractor<S,T> object extracts objects of type T from a source object of type S. Candidate extractions are first obtained by calling the extractCandidates(Object) method, which returns an Iterable object over extractions of type T. These extractions are passed through a list of Mapper<T> objects, each of which can filter or modify the extractions.

Other objects can use an Extractor<S,T> object by calling the extract(Object)extract(S source) object, which returns an Iterable object of extractions after the Mappers have been applied.

Mapper objects can be added to the list of Mappers by calling the addMapper(Mapper) method. This will add a mapper to the end of the list (i.e. it is the last one to be applied to the extractions).

Subclasses extending Extractor<S,T> must implement the abstract extractCandidates(Object) method.

As an example, this class can be used to implement a class for extracting String sentences from a String block of text. Mapper objects can be added to filter the sentences by length, or remove brackets from the sentences.

Author:
afader

Constructor Summary
Extractor()
          Constructs a new extractor with no mappers.
 
Method Summary
 void addMapper(Mapper<T> mapper)
          Adds a mapper to the end of the list of mappers.
static
<R,S,T> Extractor<R,T>
compose(Extractor<R,S> rsExtractor, Extractor<S,T> stExtractor)
          Composes a R->S extractor with a S->T extractor to create a R->T extractor.
 Iterable<T> extract(S source)
           
protected abstract  Iterable<T> extractCandidates(S source)
          Extracts candidate extractions from the given source object.
 MapperList<T> getMappers()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Extractor

public Extractor()
Constructs a new extractor with no mappers.

Method Detail

getMappers

public MapperList<T> getMappers()
Returns:
the list of mappers attached to this extractor.

addMapper

public void addMapper(Mapper<T> mapper)
Adds a mapper to the end of the list of mappers. It will be the new final mapper object applied to the extractions, after the existing mappers have been applied.

Parameters:
mapper - the mapper to add.

extractCandidates

protected abstract Iterable<T> extractCandidates(S source)
                                          throws ExtractorException
Extracts candidate extractions from the given source object. When the user calls extract(Object), the this method is used to generate a set of candidate extractions, which are then passed through each mapper object attached to the extractor.

Parameters:
source - the source to extract from.
Returns:
an iterable object over the candidate extractions.
Throws:
ExtractorException - if unable to extract

extract

public Iterable<T> extract(S source)
                    throws ExtractorException
Parameters:
source - the source object to extract from.
Returns:
an iterable object over the candidate extractions.
Throws:
ExtractorException - if unable to extract

compose

public static <R,S,T> Extractor<R,T> compose(Extractor<R,S> rsExtractor,
                                             Extractor<S,T> stExtractor)
Composes a R->S extractor with a S->T extractor to create a R->T extractor.

Type Parameters:
R -
S -
T -
Parameters:
rsExtractor -
stExtractor -
Returns:
an extractor taking objects of type R and returning objects of type T


Copyright © 2010-2012 University of Washington CSE. All Rights Reserved.