edu.stanford.nlp.trees
Class Constituent

java.lang.Object
  |
  +--edu.stanford.nlp.trees.Constituent
All Implemented Interfaces:
Comparable, Label, Labeled, Scored
Direct Known Subclasses:
SimpleConstituent

public abstract class Constituent
extends Object
implements Comparable, Labeled, Scored, Label

A Constituent object defines a generic edge in a graph. The Constituent class is designed to be extended. It implements the Comparable interface in order to allow graphs to be topologically sorted by the ordinary Collection library in java.util, keying primarily on right-hand node ID number. The Constituent class implements most of the functionality of the the Label interface by passing all requests down to the Label which might be contained in the Constituent. This allows one to put a Constituent anywhere that a Label is required. A Constituent is always Scored.


Constructor Summary
Constituent()
           
 
Method Summary
 int compareTo(Object obj)
          Implementation of comparison for Comparable interface.
abstract  int end()
          access end node.
 boolean equals(Object obj)
          Compare with another Object for equality.
 int hashCode()
          A hashCode for Constituents done by shifting and or'ing for speed.
 Label label()
          access label
 Collection labels()
          Access labels -- actually always a singleton here.
 double score()
          access score
abstract  void setEnd(int end)
          set end node.
 void setFromString(String labelStr)
          Make a new label with this String as the "name", perhaps by doing some appropriate decoding of the string.
 void setLabel(Label label)
          Sets the label associated with the current Constituent, if there is one.
 void setLabels(Collection labels)
          Sets the labels associated with this object.
 void setScore(double score)
          Sets the score associated with the current node, if there is one
abstract  void setStart(int start)
          set start node.
 void setValue(String value)
          Set the value for the label (if one is stored).
 int size()
          Return the length of a Constituent
abstract  int start()
          access start node.
 String toSentenceString(Sentence s)
          Print out as a string the subpart of a sentence covered by this Constituent.
 String toString()
          Return a string representation of a Constituent.
 String value()
          Return the value of the label (or null if none).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.stanford.nlp.trees.Label
labelFactory
 

Constructor Detail

Constituent

public Constituent()
Method Detail

start

public abstract int start()
access start node.


setStart

public abstract void setStart(int start)
set start node.


end

public abstract int end()
access end node.


setEnd

public abstract void setEnd(int end)
set end node.


label

public Label label()
access label

Specified by:
label in interface Labeled
Returns:
One of the labels of the object (if there are multiple labels, preferably the primary label, if it exists). Returns null if there is no label.

setLabel

public void setLabel(Label label)
Sets the label associated with the current Constituent, if there is one.

Specified by:
setLabel in interface Labeled

labels

public Collection labels()
Access labels -- actually always a singleton here.

Specified by:
labels in interface Labeled
Returns:
A Collection of the Object's labels. Returns an empty Collection if there are no labels.

setLabels

public void setLabels(Collection labels)
Description copied from interface: Labeled
Sets the labels associated with this object.

Specified by:
setLabels in interface Labeled

score

public double score()
access score

Specified by:
score in interface Scored

setScore

public void setScore(double score)
Sets the score associated with the current node, if there is one


toString

public String toString()
Return a string representation of a Constituent.

Specified by:
toString in interface Label
Overrides:
toString in class Object
Returns:
The full string representation.

size

public int size()
Return the length of a Constituent


equals

public boolean equals(Object obj)
Compare with another Object for equality. Two Constituent objects are equal if they have the same start and end, and, if they have a non-null label, then their labels are the same. The score of a Constituent is not considered in the equality test. This seems to make sense for most of the applications we have in mind where one wants to assess equality independent of score, and then if necessary to relax a consituent if one with a better score is found. (Note, however, that if you do want to compare Constituent scores for equality, then you have to be careful, because two double NaN values are considered unequal in Java.) The general contract of equals() implies that one can't have a subclass of a concrete [non-abstract] class redefine equals() to use extra aspects, so subclasses shouldn't override this in ways that make use of extra fields.

Overrides:
equals in class Object
Parameters:
obj - The object being compared with
Returns:
true if the objects are equal

hashCode

public int hashCode()
A hashCode for Constituents done by shifting and or'ing for speed. Now includes the label if the constituent has one (otherwise things would work very badly if you were hashing constituents over the same span....).

Overrides:
hashCode in class Object
Returns:
the integer hashCode

compareTo

public int compareTo(Object obj)
Implementation of comparison for Comparable interface. Orders spans by their ends, then by their starts, and finally by their Label. Assume that constituents are assigned times, and if time(node1) < time(node2) then node1 < node2. Thus if node1 < node2 then time(node1) <= time(node2). If two constituents have the same end, then the shorter one is given first by comparing start nodes, and if they are still equal, they are ordered by comparison of their Label, if any. (This natural ordering is now consistent with equals(), unlike in an earlier version. The implementation would break if some starts or ends are large negative numbers, and integer range is exceeded.)

Specified by:
compareTo in interface Comparable
Parameters:
obj - object to compare to
Returns:
result (positive if this is greater than obj)

value

public String value()
Return the value of the label (or null if none).

Specified by:
value in interface Label
Returns:
String the value for the label

setValue

public void setValue(String value)
Set the value for the label (if one is stored).

Specified by:
setValue in interface Label
Parameters:
value - The value for the label

setFromString

public void setFromString(String labelStr)
Make a new label with this String as the "name", perhaps by doing some appropriate decoding of the string.

Specified by:
setFromString in interface Label
Parameters:
labelStr - the String that translates into the content of the label

toSentenceString

public String toSentenceString(Sentence s)
Print out as a string the subpart of a sentence covered by this Constituent.

Returns:
The subpart of the sentence


Stanford NLP Group