Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.nlp.trees
Class Constituent

    java.lang.Object
      edu.stanford.nlp.trees.Constituent

All Implemented Interfaces:
  Label, Labeled, Scored

Direct Known Subclasses:
  SimpleConstituent

    public abstract class Constituent

extends Object
implements 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`.

Author:
  Christopher Manning

Constructor Summary
`Constituent()`

Method Summary
`boolean` | `contains(Constituent c)` Detects whether this constituent contains a constituent, that is whether they are nested.
`boolean` | `crosses(Collection<Constituent> constColl)` Detects whether this constituent overlaps any of a Collection of Constituents without nesting, that is, whether it "crosses" any of them.
`boolean` | `crosses(Constituent c)` Detects whether this constituent overlaps a constituent without nesting, that is, whether they "cross".
`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<Label>` | `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<Label> 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.ling.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`
  Parameters:
    `label` - The Label value

### labels

    public Collection<Label> 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<Label> labels)

  Description copied from interface: `Labeled`
  Sets the labels associated with this object.

  Specified by:
    `setLabels` in interface `Labeled`
  Parameters:
    `labels` - The set of Label values

### score

    public double score()

  access score

  Specified by:
    `score` in interface `Scored`
  Returns:
    The score of this thing.

### 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 at least one of them has a non-null label, then their labels are equal. 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

### crosses

    public boolean crosses(Constituent c)

  Detects whether this constituent overlaps a constituent without nesting, that is, whether they "cross".

  Parameters:
    `c` - The constituent to check against
  Returns:
    True if the two constituents cross

### crosses

    public boolean crosses(Collection<Constituent> constColl)

  Detects whether this constituent overlaps any of a Collection of Constituents without nesting, that is, whether it "crosses" any of them.

  Parameters:
    `constColl` - The set of constituent to check against
  Returns:
    True if some constituent in the collection is crossed
  Throws:
    `ClassCastException` - If some member of the Collection isn't a Constituent

### contains

    public boolean contains(Constituent c)

  Detects whether this constituent contains a constituent, that is whether they are nested. That is, the other constituent's yield is a sublist of this constituent's yield.

  Parameters:
    `c` - The constituent to check against
  Returns:
    True if the other Constituent is contained in this one

### 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

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Stanford NLP Group