de.fu_berlin.ties.extract
Class ExtractionContainer

java.lang.Object
  extended by de.fu_berlin.ties.extract.ExtractionContainer
All Implemented Interfaces:
RestorableContainer, StorableContainer
Direct Known Subclasses:
EvaluatedExtractionContainer

public class ExtractionContainer
extends Object
implements RestorableContainer

A container of Extractions of different classes. Instances of this class are not thread-safe.

Extraction containers can be serialized (storeEntries(FieldContainer)), but not deserialized.

Instances of this class are not thread-safe and have to be synchronized externally, if required.

Version:
$Revision: 1.35 $, $Date: 2006/10/21 16:04:13 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
ExtractionContainer(TargetStructure targetStruct)
          Creates a new empty instance.
ExtractionContainer(TargetStructure targetStruct, FieldContainer fContainer)
          Creates a new instance from a field container, delegating to restoreEntries(FieldContainer).
 
Method Summary
 void add(Extraction extraction)
          Adds an extraction to this container.
 void addAll(Iterator<Extraction> iterator)
          Adds all extractions from an iterator to this container.
 void filterOverlapping()
          This method filters overlapping extraction.
 TargetStructure getTargetStructure()
          Returns the target structure specifying the classes to recognize.
 Iterator<Extraction> iterator()
          Returns an iterator over all extractions in insertion order.
 Iterator<Extraction> iterator(String className)
          Returns an iterator over the extractions of a specified class, in insertion order.
 Extraction last()
          Returns the last extraction added to this container.
 List lastN(int number)
          Returns a list of the last n extractions added to this container.
 List<Extraction> lastN(String extractionClass, int number)
          Returns a list of the last n extractions of a specified class added to this container.
 boolean remove(Extraction ext)
          Removes an extraction from this container, if it is present.
 int removeAll(Set<Extraction> set)
          Removes all given extractions from this container, if they are present.
 Extraction removeLast()
          Removes the last extraction added to this container.
 void restoreEntries(FieldContainer fContainer)
          Restores extractions stored in a field container and adds them to this instance.
 int size()
          Returns the number of extractions stored in this container.
 void storeEntries(FieldContainer fContainer)
          Adds all extractions stored in this instance to a field container for serialization.
 String toString()
          Returns a string representation of this object.
 void unsetPositions()
          Unsets the positions of all stored extractions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtractionContainer

public ExtractionContainer(TargetStructure targetStruct)
Creates a new empty instance.

Parameters:
targetStruct - the target structure specifying the classes to recognize; a dummy target structure (no classes defined) means that all classes are accepted

ExtractionContainer

public ExtractionContainer(TargetStructure targetStruct,
                           FieldContainer fContainer)
                    throws IllegalArgumentException
Creates a new instance from a field container, delegating to restoreEntries(FieldContainer).

Parameters:
targetStruct - the target structure specifying the classes to recognize
fContainer - the field container to read
Throws:
IllegalArgumentException - if fContainer contains extractions of an unsupported (@link de.fu_berlin.ties.classify.Prediction#getType())
Method Detail

add

public void add(Extraction extraction)
         throws IllegalArgumentException
Adds an extraction to this container.

Parameters:
extraction - the extraction to add
Throws:
IllegalArgumentException - if the type of the extraction (@link de.fu_berlin.ties.classify.Prediction#getType()) is not in the set of class names defined by the target structure

addAll

public void addAll(Iterator<Extraction> iterator)
            throws IllegalArgumentException
Adds all extractions from an iterator to this container.

Parameters:
iterator - an iterator over the extractions to add
Throws:
IllegalArgumentException - if the type of an extraction (@link de.fu_berlin.ties.classify.Prediction#getType()) is not in the set of class names defined by the target structure

iterator

public Iterator<Extraction> iterator()
Returns an iterator over all extractions in insertion order. The iterator is immutable and cannot be used to modify the underlying collection.

Returns:
an iterator over all extractions

iterator

public Iterator<Extraction> iterator(String className)
Returns an iterator over the extractions of a specified class, in insertion order. The iterator is immutable and cannot be used to modify the underlying collection.

Parameters:
className - the name of the class of extractions to iterate
Returns:
an iterator over the extractions of the given class (if any, otherwise an empty iterator will be returned)

filterOverlapping

public void filterOverlapping()
This method filters overlapping extraction. Whenever two extractions overlap, the less probably one of them is removed. This process greedily continues until no overlapping extractions remain.


getTargetStructure

public TargetStructure getTargetStructure()
Returns the target structure specifying the classes to recognize.

Returns:
the used target structure

last

public Extraction last()
Returns the last extraction added to this container.

Returns:
the last extraction added to this container; or null if the container is empty

lastN

public List lastN(int number)
Returns a list of the last n extractions added to this container. Modifications of the returned list will not affect this container and vice versa.

Parameters:
number - the number of extractions to copy
Returns:
a list containing the last Extractions

lastN

public List<Extraction> lastN(String extractionClass,
                              int number)
Returns a list of the last n extractions of a specified class added to this container. Modifications of the returned list will not affect this container and vice versa.

Parameters:
extractionClass - the class of extractions
number - the number of extractions to copy
Returns:
a list containing the last Extractions of the given class; will be empty if there are no extractions of this class

remove

public boolean remove(Extraction ext)
Removes an extraction from this container, if it is present.

Parameters:
ext - the extraction to remove
Returns:
true if the container contained the specified extraction

removeAll

public int removeAll(Set<Extraction> set)
Removes all given extractions from this container, if they are present.

Parameters:
set - the set of extractions to remove
Returns:
the number of extractions removed from this container; will be in the range from 0 (if none of the extractions was found in this container) to set.size() (if all have been found)

removeLast

public Extraction removeLast()
                      throws IllegalStateException
Removes the last extraction added to this container.

Returns:
the removed extraction
Throws:
IllegalStateException - if this method is called while the container is empty

restoreEntries

public void restoreEntries(FieldContainer fContainer)
                    throws IllegalArgumentException
Restores extractions stored in a field container and adds them to this instance. The provided field container must have been filled by calling storeEntries(FieldContainer) on an extraction container with identical target structure, or errors are likely.

Specified by:
restoreEntries in interface RestorableContainer
Parameters:
fContainer - the field container to read
Throws:
IllegalArgumentException - if fContainer contains extractions of an unsupported (@link de.fu_berlin.ties.classify.Prediction#getType())

size

public int size()
Returns the number of extractions stored in this container.

Returns:
the number of extractions stored in this container

storeEntries

public void storeEntries(FieldContainer fContainer)
Adds all extractions stored in this instance to a field container for serialization. Extractions are serialized in insertion order, as required for training.

Specified by:
storeEntries in interface StorableContainer
Parameters:
fContainer - the field container to fill

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation

unsetPositions

public void unsetPositions()
Unsets the positions of all stored extractions. In case of duplicates (extractions that only differed in their position), the most probably one is kept.



Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.