ABL4J (Alignment Based Learning for Java) - 0.9.7

org.schwiebert.abl4j.data.impl.abl
Class Constituent<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<NonTerminal>
              extended by org.schwiebert.abl4j.data.impl.abl.Constituent<T>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<NonTerminal>, Collection<NonTerminal>, List<NonTerminal>, RandomAccess, IConstituent<T>

public class Constituent<T>
extends ArrayList<NonTerminal>
implements IConstituent<T>

This class is used to store a hypothesis or a nonterminal. A hypothesis is defined by a begin and end index (in a ISentence) and one or more NonTerminals.

Author:
Menno van Zaanen (menno@ics.mq.edu.au) (original C++ Version), Jeroen Geertzen (j.geertzen@uvt.nl) (modifications in C++ Version), Stephan Schwiebert (sschwieb@spinfo.uni-koeln.de) (Java-Implementation)
See Also:
Serialized Form

Field Summary
private  int begin
          The boundaries of the constituent.
private  int end
           
private  ISentence<T> sentence
          The sentence this constituent belongs to.
private  Map<Integer,Double> sentenceToScore
          ABL4J extension: If an alignment or selection algorithm supports local alignments, the probability of the alignment is stored in this map.
private static long serialVersionUID
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Constituent()
          Constructs a new Constituent.
 
Method Summary
 boolean addAllNonTerminals(Collection<NonTerminal> nonTerminals)
          Adds all NonTerminals.
 boolean containsNonTerminal(NonTerminal nonTerminal)
          Returns true if the given NonTerminal is already contained in the List of NonTerminals.
 boolean empty()
          Is the constituent empty (i.e. begin==end)?
 boolean equals(Object o)
          Two IConstituent are equal, if their boundaries are equal (this.boundaries.first == o.boundaries.first && this.boundaries.second == o.boundaries.second).
 double getAverageLocalScore()
          Returns the average local score of this hypothesis.
 int getBeginIndex()
          Returns the begin index
 int getEndIndex()
          Returns the end index
 double getHighestLocalScore()
          Returns the highest local score of this hypothesis.
 Map<Integer,Double> getLocalScoreMap()
          Returns the map of local scores, or Collections.EMPTY_MAP, if no probabilities have been set.
 ISentence<T> getSentence()
          Returns the sentence to which this constituent belongs to.
 List<IWord<T>> getWords()
          Returns the list of words the constituent contains.
 int hashCode()
           
 int indexOf(NonTerminal n)
          Returns the index of NonTerminal n.
 void init(ISentence<T> sentence, int begin, int end)
          Initializes the NonTerminal.
 void mergeNonterminals(NonTerminal n)
          Sets the nonterminal of the hypothesis to n
 void setLocalScore(int sentenceId, double score)
          Sets the local score of a constituent.
 boolean valid()
          Is the constituent valid (i.e. begin<=end)?
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.schwiebert.abl4j.data.IConstituent
add, clear, get, size
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

begin

private int begin
The boundaries of the constituent.


end

private int end

sentenceToScore

private Map<Integer,Double> sentenceToScore
ABL4J extension: If an alignment or selection algorithm supports local alignments, the probability of the alignment is stored in this map.
TODO: Currently, only one probability per sentence can be stored - if a constituent can be aligned twice against a sentence, only the last probability will be stored.


sentence

private ISentence<T> sentence
The sentence this constituent belongs to.

Constructor Detail

Constituent

public Constituent()
Constructs a new Constituent.

Method Detail

init

public void init(ISentence<T> sentence,
                 int begin,
                 int end)
Description copied from interface: IConstituent
Initializes the NonTerminal. Should only be called from DataFactory.

Specified by:
init in interface IConstituent<T>

getBeginIndex

public int getBeginIndex()
Description copied from interface: IConstituent
Returns the begin index

Specified by:
getBeginIndex in interface IConstituent<T>

getEndIndex

public int getEndIndex()
Description copied from interface: IConstituent
Returns the end index

Specified by:
getEndIndex in interface IConstituent<T>

empty

public boolean empty()
Description copied from interface: IConstituent
Is the constituent empty (i.e. begin==end)?

Specified by:
empty in interface IConstituent<T>

equals

public boolean equals(Object o)
Description copied from interface: IConstituent
Two IConstituent are equal, if their boundaries are equal (this.boundaries.first == o.boundaries.first && this.boundaries.second == o.boundaries.second).

Specified by:
equals in interface Collection<NonTerminal>
Specified by:
equals in interface List<NonTerminal>
Specified by:
equals in interface IConstituent<T>
Overrides:
equals in class AbstractList<NonTerminal>

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<NonTerminal>
Specified by:
hashCode in interface List<NonTerminal>
Specified by:
hashCode in interface IConstituent<T>
Overrides:
hashCode in class AbstractList<NonTerminal>

valid

public boolean valid()
Description copied from interface: IConstituent
Is the constituent valid (i.e. begin<=end)?

Specified by:
valid in interface IConstituent<T>

mergeNonterminals

public void mergeNonterminals(NonTerminal n)
Description copied from interface: IConstituent
Sets the nonterminal of the hypothesis to n

Specified by:
mergeNonterminals in interface IConstituent<T>

setLocalScore

public void setLocalScore(int sentenceId,
                          double score)
Description copied from interface: IConstituent
Sets the local score of a constituent. The score is local to the sentence defined by sentenceId, and must be a value between 0 and 1.

Specified by:
setLocalScore in interface IConstituent<T>

getLocalScoreMap

public Map<Integer,Double> getLocalScoreMap()
Description copied from interface: IConstituent
Returns the map of local scores, or Collections.EMPTY_MAP, if no probabilities have been set.
Note:Only a few algorithms support local scores.

Specified by:
getLocalScoreMap in interface IConstituent<T>
Returns:

getAverageLocalScore

public double getAverageLocalScore()
Description copied from interface: IConstituent
Returns the average local score of this hypothesis. Experimental...

Specified by:
getAverageLocalScore in interface IConstituent<T>
Returns:

getHighestLocalScore

public double getHighestLocalScore()
Description copied from interface: IConstituent
Returns the highest local score of this hypothesis. Experimental...

Specified by:
getHighestLocalScore in interface IConstituent<T>
Returns:

getWords

public List<IWord<T>> getWords()
Description copied from interface: IConstituent
Returns the list of words the constituent contains.

Specified by:
getWords in interface IConstituent<T>
Returns:

getSentence

public ISentence<T> getSentence()
Description copied from interface: IConstituent
Returns the sentence to which this constituent belongs to.

Specified by:
getSentence in interface IConstituent<T>
Returns:

indexOf

public int indexOf(NonTerminal n)
Description copied from interface: IConstituent
Returns the index of NonTerminal n.

Specified by:
indexOf in interface IConstituent<T>
Returns:

addAllNonTerminals

public boolean addAllNonTerminals(Collection<NonTerminal> nonTerminals)
Description copied from interface: IConstituent
Adds all NonTerminals.

Specified by:
addAllNonTerminals in interface IConstituent<T>
Returns:

containsNonTerminal

public boolean containsNonTerminal(NonTerminal nonTerminal)
Description copied from interface: IConstituent
Returns true if the given NonTerminal is already contained in the List of NonTerminals.

Specified by:
containsNonTerminal in interface IConstituent<T>
Returns:

ABL4J (Alignment Based Learning for Java) - 0.9.7

© 2007 Stephan Schwiebert