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.17 $, $Date: 2004/12/06 17:58:36 $, $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.
 TargetStructure getTargetStructure()
          Returns the target structure specifying the classes to recognize.
 Iterator 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.
 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.
 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

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

iterator

public Iterator 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)

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

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())

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-2004 Christian Siefkes. All Rights Reserved.