Parse (Apache OpenNLP Tools 1.9.5 API)
Date: 2026-06-18

opennlp.tools.parser

## Class Parse

- java.lang.Object
- - opennlp.tools.parser.Parse

- All Implemented Interfaces:
    Cloneable, Comparable<Parse>

      public class Parse
      extends Object
      implements Cloneable, Comparable<Parse>

  Data structure for holding parse constituents.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `BRACKET_LCB`
    `static String` | `BRACKET_LRB`
    `static String` | `BRACKET_LSB`
    `static String` | `BRACKET_RCB`
    `static String` | `BRACKET_RRB`
    `static String` | `BRACKET_RSB`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Parse(String text, Span span, String type, double p, int index)` Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head index.
    `Parse(String text, Span span, String type, double p, Parse h)` Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head and head index.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Parse daughter, HeadRules rules)`
    `static void` | `addNames(String tag, Span[] names, Parse[] tokens)` Utility method to inserts named entities.
    `void` | `addNextPunctuation(Parse punct)` Designates that the specified punctuation follows this parse.
    `void` | `addPreviousPunctuation(Parse punct)` Designates that the specified punctuation should is prior to this parse.
    `void` | `addProb(double logProb)` Adds the specified probability log to this current log for this parse.
    `Parse` | `adjoin(Parse sister, HeadRules rules)` Sister adjoins this node's last child and the specified sister node and returns their new parent node.
    `Parse` | `adjoinRoot(Parse node, HeadRules rules, int parseIndex)`
    `Object` | `clone()`
    `Parse` | `clone(Parse node)` Clones the right frontier of parse up to the specified node.
    `Parse` | `cloneRoot(Parse node, int parseIndex)` Clones the right frontier of this root parse up to and including the specified node.
    `int` | `compareTo(Parse p)`
    `boolean` | `complete()` Returns whether this parse is complete.
    `boolean` | `equals(Object obj)`
    `void` | `expandTopNode(Parse root)`
    `static void` | `fixPossesives(Parse parse)`
    `int` | `getChildCount()` Returns the number of children for this parse node.
    `Parse[]` | `getChildren()` Returns the child constituents of this constituent .
    `Parse` | `getCommonParent(Parse node)` Returns the deepest shared parent of this node and the specified node.
    `String` | `getCoveredText()`
    `StringBuffer` | `getDerivation()` Returns the derivation string for this parse if one has been created.
    `Parse` | `getHead()` Returns the head constituent associated with this constituent.
    `int` | `getHeadIndex()` Returns the index within a sentence of the head token for this parse.
    `String` | `getLabel()` Returns the label assigned to this parse node during parsing which specifies how this node will be formed into a constituent.
    `Collection<Parse>` | `getNextPunctuationSet()` Returns the set of punctuation parses that occur immediately after this parse.
    `Parse` | `getParent()` Returns the parent parse node of this constituent.
    `Collection<Parse>` | `getPreviousPunctuationSet()` Returns the set of punctuation parses that occur immediately before this parse.
    `double` | `getProb()` Returns the log of the product of the probability associated with all the decisions which formed this constituent.
    `Span` | `getSpan()` Returns the character offsets for this constituent.
    `Parse[]` | `getTagNodes()` Returns the parse nodes which are children of this node and which are pos tags.
    `double` | `getTagSequenceProb()` Returns the probability associated with the pos-tag sequence assigned to this parse.
    `String` | `getText()` Returns the text of the sentence over which this parse was formed.
    `Parse[]` | `getTokenNodes()`
    `String` | `getType()` Returns the constituent label for this node of the parse.
    `int` | `hashCode()`
    `int` | `indexOf(Parse child)` Returns the index of this specified child.
    `void` | `insert(Parse constituent)` Inserts the specified constituent into this parse based on its text span.This method assumes that the specified constituent can be inserted into this parse.
    `boolean` | `isChunk()`
    `void` | `isChunk(boolean ic)`
    `boolean` | `isFlat()` Returns true if this constituent contains no sub-constituents.
    `boolean` | `isPosTag()` Indicates whether this parse node is a pos-tag.
    `static Parse` | `parseParse(String parse)` Parses the specified tree-bank style parse string and return a Parse structure for that string.
    `static Parse` | `parseParse(String parse, GapLabeler gl)` Parses the specified tree-bank style parse string and return a Parse structure for that string.
    `static void` | `pruneParse(Parse parse)` Prune the specified sentence parse of vacuous productions.
    `void` | `remove(int index)`
    `void` | `setChild(int index, String label)` Replaces the child at the specified index with a new child with the specified label.
    `void` | `setDerivation(StringBuffer derivation)` Specifies the derivation string to be associated with this parse.
    `void` | `setLabel(String label)` Assigns this parse the specified label.
    `void` | `setNextPunctuation(Collection<Parse> punctSet)` Sets the set of punctuation tags which follow this parse.
    `void` | `setParent(Parse parent)` Specifies the parent parse node for this constituent.
    `void` | `setPrevPunctuation(Collection<Parse> punctSet)` Sets the set of punctuation tags which preceed this parse.
    `void` | `setType(String type)` Set the type of this constituent to the specified type.
    `void` | `show()` Displays this parse using Penn Treebank-style formatting.
    `void` | `show(StringBuffer sb)` Appends the specified string buffer with a string representation of this parse.
    `void` | `showCodeTree()` Prints to standard out a representation of the specified parse which contains hash codes so that parent/child relationships can be explicitly seen.
    `String` | `toString()` Represents this parse in a human readable way.
    `void` | `updateHeads(HeadRules rules)` Computes the head parses for this parse and its sub-parses and stores this information in the parse data structure.
    `void` | `updateSpan()`
    `static void` | `useFunctionTags(boolean uft)` Specifies whether function tags should be included as part of the constituent type.

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### BRACKET_LRB

          public static final String BRACKET_LRB

      See Also:
        Constant Field Values

    - #### BRACKET_RRB

          public static final String BRACKET_RRB

      See Also:
        Constant Field Values

    - #### BRACKET_LCB

          public static final String BRACKET_LCB

      See Also:
        Constant Field Values

    - #### BRACKET_RCB

          public static final String BRACKET_RCB

      See Also:
        Constant Field Values

    - #### BRACKET_LSB

          public static final String BRACKET_LSB

      See Also:
        Constant Field Values

    - #### BRACKET_RSB

          public static final String BRACKET_RSB

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Parse

          public Parse(String text,
                       Span span,
                       String type,
                       double p,
                       int index)

      Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head index.
      Parameters:
        `text` - The text of the sentence for which this node is a part of.
        `span` - The character offsets for this node within the specified text.
        `type` - The constituent label of this node.
        `p` - The probability of this parse.
        `index` - The token index of the head of this parse.

    - #### Parse

          public Parse(String text,
                       Span span,
                       String type,
                       double p,
                       Parse h)

      Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head and head index.
      Parameters:
        `text` - The text of the sentence for which this node is a part of.
        `span` - The character offsets for this node within the specified text.
        `type` - The constituent label of this node.
        `p` - The probability of this parse.
        `h` - The head token of this parse.

  - ### Method Detail

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `Object`

    - #### clone

          public Parse clone(Parse node)

      Clones the right frontier of parse up to the specified node.
      Parameters:
        `node` - The last node in the right frontier of the parse tree which should be cloned.
      Returns:
        A clone of this parse and its right frontier up to and including the specified node.

    - #### cloneRoot

          public Parse cloneRoot(Parse node,
                                 int parseIndex)

      Clones the right frontier of this root parse up to and including the specified node.
      Parameters:
        `node` - The last node in the right frontier of the parse tree which should be cloned.
        `parseIndex` - The child index of the parse for this root node.
      Returns:
        A clone of this root parse and its right frontier up to and including the specified node.

    - #### useFunctionTags

          public static void useFunctionTags(boolean uft)

      Specifies whether function tags should be included as part of the constituent type.
      Parameters:
        `uft` - true is they should be included; false otherwise.

    - #### setType

          public void setType(String type)

      Set the type of this constituent to the specified type.
      Parameters:
        `type` - The type of this constituent.

    - #### getType

          public String getType()

      Returns the constituent label for this node of the parse.
      Returns:
        The constituent label for this node of the parse.

    - #### getPreviousPunctuationSet

          public Collection<Parse> getPreviousPunctuationSet()

      Returns the set of punctuation parses that occur immediately before this parse.
      Returns:
        the set of punctuation parses that occur immediately before this parse.

    - #### addPreviousPunctuation

          public void addPreviousPunctuation(Parse punct)

      Designates that the specified punctuation should is prior to this parse.
      Parameters:
        `punct` - The punctuation.

    - #### getNextPunctuationSet

          public Collection<Parse> getNextPunctuationSet()

      Returns the set of punctuation parses that occur immediately after this parse.
      Returns:
        the set of punctuation parses that occur immediately after this parse.

    - #### addNextPunctuation

          public void addNextPunctuation(Parse punct)

      Designates that the specified punctuation follows this parse.
      Parameters:
        `punct` - The punctuation set.

    - #### setNextPunctuation

          public void setNextPunctuation(Collection<Parse> punctSet)

      Sets the set of punctuation tags which follow this parse.
      Parameters:
        `punctSet` - The set of punctuation tags which follow this parse.

    - #### setPrevPunctuation

          public void setPrevPunctuation(Collection<Parse> punctSet)

      Sets the set of punctuation tags which preceed this parse.
      Parameters:
        `punctSet` - The set of punctuation tags which preceed this parse.

    - #### insert

          public void insert(Parse constituent)

      Inserts the specified constituent into this parse based on its text span.This method assumes that the specified constituent can be inserted into this parse.
      Parameters:
        `constituent` - The constituent to be inserted.

    - #### show

          public void show(StringBuffer sb)

      Appends the specified string buffer with a string representation of this parse.
      Parameters:
        `sb` - A string buffer into which the parse string can be appended.

    - #### show

          public void show()

      Displays this parse using Penn Treebank-style formatting.

    - #### getTagSequenceProb

          public double getTagSequenceProb()

      Returns the probability associated with the pos-tag sequence assigned to this parse.
      Returns:
        The probability associated with the pos-tag sequence assigned to this parse.

    - #### complete

          public boolean complete()

      Returns whether this parse is complete.
      Returns:
        Returns true if the parse contains a single top-most node.

    - #### getCoveredText

          public String getCoveredText()

    - #### toString

          public String toString()

      Represents this parse in a human readable way.
      Overrides:
        `toString` in class `Object`

    - #### getText

          public String getText()

      Returns the text of the sentence over which this parse was formed.
      Returns:
        The text of the sentence over which this parse was formed.

    - #### getSpan

          public Span getSpan()

      Returns the character offsets for this constituent.
      Returns:
        The character offsets for this constituent.

    - #### getProb

          public double getProb()

      Returns the log of the product of the probability associated with all the decisions which formed this constituent.
      Returns:
        The log of the product of the probability associated with all the decisions which formed this constituent.

    - #### addProb

          public void addProb(double logProb)

      Adds the specified probability log to this current log for this parse.
      Parameters:
        `logProb` - The probability of an action performed on this parse.

    - #### getChildren

          public Parse[] getChildren()

      Returns the child constituents of this constituent .
      Returns:
        The child constituents of this constituent.

    - #### setChild

          public void setChild(int index,
                               String label)

      Replaces the child at the specified index with a new child with the specified label.
      Parameters:
        `index` - The index of the child to be replaced.
        `label` - The label to be assigned to the new child.

    - #### add

          public void add(Parse daughter,
                          HeadRules rules)

    - #### remove

          public void remove(int index)

    - #### adjoinRoot

          public Parse adjoinRoot(Parse node,
                                  HeadRules rules,
                                  int parseIndex)

    - #### adjoin

          public Parse adjoin(Parse sister,
                              HeadRules rules)

      Sister adjoins this node's last child and the specified sister node and returns their new parent node. The new parent node replace this nodes last child.
      Parameters:
        `sister` - The node to be adjoined.
        `rules` - The head rules for the parser.
      Returns:
        The new parent node of this node and the specified sister node.

    - #### expandTopNode

          public void expandTopNode(Parse root)

    - #### getChildCount

          public int getChildCount()

      Returns the number of children for this parse node.
      Returns:
        the number of children for this parse node.

    - #### indexOf

          public int indexOf(Parse child)

      Returns the index of this specified child.
      Parameters:
        `child` - A child of this parse.
      Returns:
        the index of this specified child or -1 if the specified child is not a child of this parse.

    - #### getHead

          public Parse getHead()

      Returns the head constituent associated with this constituent.
      Returns:
        The head constituent associated with this constituent.

    - #### getHeadIndex

          public int getHeadIndex()

      Returns the index within a sentence of the head token for this parse.
      Returns:
        The index within a sentence of the head token for this parse.

    - #### getLabel

          public String getLabel()

      Returns the label assigned to this parse node during parsing which specifies how this node will be formed into a constituent.
      Returns:
        The outcome label assigned to this node during parsing.

    - #### setLabel

          public void setLabel(String label)

      Assigns this parse the specified label. This is used by parsing schemes to tag parsing nodes while building.
      Parameters:
        `label` - A label indicating something about the stage of building for this parse node.

    - #### updateHeads

          public void updateHeads(HeadRules rules)

      Computes the head parses for this parse and its sub-parses and stores this information in the parse data structure.
      Parameters:
        `rules` - The head rules which determine how the head of the parse is computed.

    - #### updateSpan

          public void updateSpan()

    - #### pruneParse

          public static void pruneParse(Parse parse)

      Prune the specified sentence parse of vacuous productions.
      Parameters:
        `parse` -

    - #### fixPossesives

          public static void fixPossesives(Parse parse)

    - #### parseParse

          public static Parse parseParse(String parse)

      Parses the specified tree-bank style parse string and return a Parse structure for that string.
      Parameters:
        `parse` - A tree-bank style parse string.
      Returns:
        a Parse structure for the specified tree-bank style parse string.

    - #### parseParse

          public static Parse parseParse(String parse,
                                         GapLabeler gl)

      Parses the specified tree-bank style parse string and return a Parse structure for that string.
      Parameters:
        `parse` - A tree-bank style parse string.
        `gl` - The gap labeler.
      Returns:
        a Parse structure for the specified tree-bank style parse string.

    - #### getParent

          public Parse getParent()

      Returns the parent parse node of this constituent.
      Returns:
        The parent parse node of this constituent.

    - #### setParent

          public void setParent(Parse parent)

      Specifies the parent parse node for this constituent.
      Parameters:
        `parent` - The parent parse node for this constituent.

    - #### isPosTag

          public boolean isPosTag()

      Indicates whether this parse node is a pos-tag.
      Returns:
        true if this node is a pos-tag, false otherwise.

    - #### isFlat

          public boolean isFlat()

      Returns true if this constituent contains no sub-constituents.
      Returns:
        true if this constituent contains no sub-constituents; false otherwise.

    - #### isChunk

          public void isChunk(boolean ic)

    - #### isChunk

          public boolean isChunk()

    - #### getTagNodes

          public Parse[] getTagNodes()

      Returns the parse nodes which are children of this node and which are pos tags.
      Returns:
        the parse nodes which are children of this node and which are pos tags.

    - #### getTokenNodes

          public Parse[] getTokenNodes()

    - #### getCommonParent

          public Parse getCommonParent(Parse node)

      Returns the deepest shared parent of this node and the specified node. If the nodes are identical then their parent is returned. If one node is the parent of the other then the parent node is returned.
      Parameters:
        `node` - The node from which parents are compared to this node's parents.
      Returns:
        the deepest shared parent of this node and the specified node.

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### compareTo

          public int compareTo(Parse p)

      Specified by:
        `compareTo` in interface `Comparable<Parse>`

    - #### getDerivation

          public StringBuffer getDerivation()

      Returns the derivation string for this parse if one has been created.
      Returns:
        the derivation string for this parse or null if no derivation string has been created.

    - #### setDerivation

          public void setDerivation(StringBuffer derivation)

      Specifies the derivation string to be associated with this parse.
      Parameters:
        `derivation` - The derivation string to be associated with this parse.

    - #### showCodeTree

          public void showCodeTree()

      Prints to standard out a representation of the specified parse which contains hash codes so that parent/child relationships can be explicitly seen.

    - #### addNames

          public static void addNames(String tag,
                                      Span[] names,
                                      Parse[] tokens)

      Utility method to inserts named entities.
      Parameters:
        `tag` -
        `names` -
        `tokens` -

Copyright © 2026 The Apache Software Foundation. All rights reserved.