S - the source typeT - the target extraction typepublic 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.
| Constructor and Description |
|---|
Extractor()
Constructs a new extractor with no mappers.
|
| Modifier and Type | Method and Description |
|---|---|
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() |
public MapperList<T> getMappers()
public void addMapper(Mapper<T> mapper)
mapper - the mapper to add.protected abstract Iterable<T> extractCandidates(S source) throws ExtractorException
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.source - the source to extract from.ExtractorException - if unable to extractpublic Iterable<T> extract(S source) throws ExtractorException
source - the source object to extract from.ExtractorException - if unable to extractpublic static <R,S,T> Extractor<R,T> compose(Extractor<R,S> rsExtractor, Extractor<S,T> stExtractor)
R->S extractor with a S->T extractor to create
a R->T extractor.R - S - T - rsExtractor - stExtractor - R and returning
objects of type TCopyright © 2010-2013 University of Washington CSE. All Rights Reserved.