Package 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 SummaryFields Modifier and Type Field Description static StringBRACKET_LCBstatic StringBRACKET_LRBstatic StringBRACKET_LSBstatic StringBRACKET_RCBstatic StringBRACKET_RRBstatic StringBRACKET_RSB
 - 
Constructor SummaryConstructors Constructor Description Parse(String text, Span span, String type, double p, int index)Initializes anodefor this specifiedtextandspanof the specifiedtypewith probabilitypand the headindex.Parse(String text, Span span, String type, double p, Parse h)Initializes anodefor this specifiedtextandspanof the specifiedtypewith probabilitypand the headindex.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Parse daughter, HeadRules rules)static voidaddNames(String tag, Span[] names, Parse[] tokens)Utility method to insert named entities.voidaddNextPunctuation(Parse punct)Designates that the specified punctuation follows this parse.voidaddPreviousPunctuation(Parse punct)Designates that the specified punctuation should is prior to this parse.voidaddProb(double logProb)Adds the specifiedlogProbto this current log for this parse.Parseadjoin(Parse sister, HeadRules rules)Sister adjoins this node's last child and the specified sister node and returns their new parent node.ParseadjoinRoot(Parse node, HeadRules rules, int parseIndex)Objectclone()Parseclone(Parse node)Clones the right frontier ofParseup to the specifiednode.ParsecloneRoot(Parse node, int parseIndex)Clones the right frontier of this rootParseup to and including the specified node.intcompareTo(Parse p)booleancomplete()booleanequals(Object obj)voidexpandTopNode(Parse root)static voidfixPossesives(Parse parse)intgetChildCount()Parse[]getChildren()ParsegetCommonParent(Parse node)Returns the deepest shared parent of this node and the specified node.StringgetCoveredText()StringBuffergetDerivation()ParsegetHead()intgetHeadIndex()StringgetLabel()Retrieves the label assigned to this parse node during parsing which specifies how this node will be formed into a constituent.Collection<Parse>getNextPunctuationSet()ParsegetParent()Collection<Parse>getPreviousPunctuationSet()doublegetProb()SpangetSpan()Parse[]getTagNodes()doublegetTagSequenceProb()StringgetText()Parse[]getTokenNodes()StringgetType()inthashCode()intindexOf(Parse child)voidinsert(Parse constituent)Inserts the specified constituent into this parse based on its text span.booleanisChunk()voidisChunk(boolean ic)booleanisFlat()Indicates whether this parse node contains no sub-constituents.booleanisPosTag()Indicates whether this parse node is a pos-tag.static ParseparseParse(String parse)Parses the specified tree-bank style parse string and return aParsestructure for that string.static ParseparseParse(String parse, GapLabeler gl)static voidpruneParse(Parse parse)Prune the specified sentence parse of vacuous productions.voidremove(int index)voidsetChild(int index, String label)Replaces the child at the specified index with a new child with the specified label.voidsetDerivation(StringBuffer derivation)Specifies the derivation string to be associated with this parse.voidsetLabel(String label)Assigns this parse the specified label.voidsetNextPunctuation(Collection<Parse> punctSet)Sets thepunctuation tagswhich follow this parse.voidsetParent(Parse parent)Specifies the parent parse node for this constituent.voidsetPrevPunctuation(Collection<Parse> punctSet)Sets thepunctuation tagswhich precede this parse.voidsetType(String type)Set the type of this constituent to the specified type.voidshow()Prints this parse using Penn Treebank-style formatting.voidshow(StringBuffer sb)Fills the specifiedStringBufferwith a string representation of this parse.voidshowCodeTree()Prints to standard out a representation of the specified parse which contains hash codes so that parent/child relationships can be explicitly seen.StringtoString()Represents thisParsein a human-readable way.StringtoStringPennTreebank()voidupdateHeads(HeadRules rules)Computes the head parses for this parse and its sub-parses and stores this information in the parse data structure.voidupdateSpan()static voiduseFunctionTags(boolean uft)Specifies whether function tags should be included as part of the constituent type.
 
- 
- 
- 
Field Detail- 
BRACKET_LRBpublic static final String BRACKET_LRB - See Also:
- Constant Field Values
 
 - 
BRACKET_RRBpublic static final String BRACKET_RRB - See Also:
- Constant Field Values
 
 - 
BRACKET_LCBpublic static final String BRACKET_LCB - See Also:
- Constant Field Values
 
 - 
BRACKET_RCBpublic static final String BRACKET_RCB - See Also:
- Constant Field Values
 
 - 
BRACKET_LSBpublic static final String BRACKET_LSB - See Also:
- Constant Field Values
 
 - 
BRACKET_RSBpublic static final String BRACKET_RSB - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Parsepublic Parse(String text, Span span, String type, double p, int index) Initializes anodefor this specifiedtextandspanof the specifiedtypewith probabilitypand the headindex.- Parameters:
- text- The text of the sentence for which this node is a part of.
- span- The- character offsetsfor 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.
 
 - 
Parsepublic Parse(String text, Span span, String type, double p, Parse h) Initializes anodefor this specifiedtextandspanof the specifiedtypewith probabilitypand the headindex.- Parameters:
- text- The text of the sentence for which this node is a part of.
- span- The- character offsetsfor 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- 
clonepublic Object clone() 
 - 
clonepublic Parse clone(Parse node) Clones the right frontier ofParseup to the specifiednode.- Parameters:
- node- The last- nodein the right frontier of the parse tree to be cloned.
- Returns:
- A clone of this parse and its right frontier up to and including the specified node.
 
 - 
cloneRootpublic Parse cloneRoot(Parse node, int parseIndex) Clones the right frontier of this rootParseup to and including the specified node.- Parameters:
- node- The last- nodein the right frontier of the parse tree to 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.
 
 - 
useFunctionTagspublic static void useFunctionTags(boolean uft) Specifies whether function tags should be included as part of the constituent type.- Parameters:
- uft-- trueis they should be included,- falseotherwise.
 
 - 
setTypepublic void setType(String type) Set the type of this constituent to the specified type.- Parameters:
- type- The type of this constituent.
 
 - 
getTypepublic String getType() - Returns:
- Retrieves the constituent label for this node of the parse.
 
 - 
getPreviousPunctuationSetpublic Collection<Parse> getPreviousPunctuationSet() - Returns:
- Retrieves the set of punctuation parsesthat occur immediately before this parse.
 
 - 
addPreviousPunctuationpublic void addPreviousPunctuation(Parse punct) Designates that the specified punctuation should is prior to this parse.- Parameters:
- punct- The- punctuationto be added.
 
 - 
getNextPunctuationSetpublic Collection<Parse> getNextPunctuationSet() - Returns:
- Retrieves the set of punctuation parsesthat occur immediately after this parse.
 
 - 
addNextPunctuationpublic void addNextPunctuation(Parse punct) Designates that the specified punctuation follows this parse.- Parameters:
- punct- The- punctuationset.
 
 - 
setNextPunctuationpublic void setNextPunctuation(Collection<Parse> punctSet) Sets thepunctuation tagswhich follow this parse.- Parameters:
- punctSet- The punctuation tags which follow this parse.
 
 - 
setPrevPunctuationpublic void setPrevPunctuation(Collection<Parse> punctSet) Sets thepunctuation tagswhich precede this parse.- Parameters:
- punctSet- The punctuation tags which precede this parse.
 
 - 
insertpublic 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- constituentto be inserted.
 
 - 
showpublic void show(StringBuffer sb) Fills the specifiedStringBufferwith a string representation of this parse.- Parameters:
- sb- A- StringBufferinto which the parse string can be appended.
 
 - 
showpublic void show() Prints this parse using Penn Treebank-style formatting.
 - 
getTagSequenceProbpublic double getTagSequenceProb() - Returns:
- Retrieves the probability associated with the pos-tag sequence assigned to this parse.
 
 - 
completepublic boolean complete() - Returns:
- trueif the parse contains a single top-most node (=complete),- falseotherwise.
 
 - 
getCoveredTextpublic String getCoveredText() 
 - 
toStringPennTreebankpublic String toStringPennTreebank() - Returns:
- Retrieves a String representation using Penn Treebank-style formatting.
 
 - 
getTextpublic String getText() - Returns:
- Retrieves the text of the sentence over which this parse was formed.
 
 - 
getSpanpublic Span getSpan() - Returns:
- Retrieves the character offsetsfor this constituent.
 
 - 
getProbpublic double getProb() - Returns:
- Retrieves the logof the product of the probability associated with all the decisions which formed this constituent.
 
 - 
addProbpublic void addProb(double logProb) Adds the specifiedlogProbto this current log for this parse.- Parameters:
- logProb- The probability of an action performed on this parse.
 
 - 
getChildrenpublic Parse[] getChildren() - Returns:
- Retrieves the child constituentsof this constituent.
 
 - 
setChildpublic 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.
 
 - 
removepublic void remove(int index) 
 - 
adjoinpublic 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 node's last child.- Parameters:
- sister- The- nodeto be adjoined.
- rules- The- HeadRulesfor the parser.
- Returns:
- The new parent nodeof this node and the specified sister node.
 
 - 
expandTopNodepublic void expandTopNode(Parse root) 
 - 
getChildCountpublic int getChildCount() - Returns:
- Retrieves the number of children for this parse node.
 
 - 
indexOfpublic int indexOf(Parse child) - Parameters:
- child- A child of this parse.
- Returns:
- Retrieves the index of this specified child or -1if the specified child is not a child of this parse.
 
 - 
getHeadpublic Parse getHead() - Returns:
- Retrieves the head constituent associated with this constituent.
 
 - 
getHeadIndexpublic int getHeadIndex() - Returns:
- Retrieves the index within a sentence of the head token for this parse.
 
 - 
getLabelpublic String getLabel() Retrieves 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.
 
 - 
setLabelpublic 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.
 
 - 
updateHeadspublic 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- HeadRuleswhich determine how the head of the parse is computed.
 
 - 
updateSpanpublic void updateSpan() 
 - 
pruneParsepublic static void pruneParse(Parse parse) Prune the specified sentence parse of vacuous productions.- Parameters:
- parse- The sentence- Parse.
 
 - 
fixPossesivespublic static void fixPossesives(Parse parse) 
 - 
parseParsepublic static Parse parseParse(String parse) Parses the specified tree-bank style parse string and return aParsestructure for that string.
 - 
parseParsepublic static Parse parseParse(String parse, GapLabeler gl) - Parameters:
- parse- A tree-bank style- Parsestring.
- gl- The- GapLabelerto be used.
- Returns:
- A Parsestructure for the specified tree-bank style parse string.
 
 - 
getParentpublic Parse getParent() - Returns:
- Retrieves the parent parse node of this constituent.
 
 - 
setParentpublic void setParent(Parse parent) Specifies the parent parse node for this constituent.- Parameters:
- parent- The parent parse node for this constituent.
 
 - 
isPosTagpublic boolean isPosTag() Indicates whether this parse node is a pos-tag.- Returns:
- trueif this node is a pos-tag,- falseotherwise.
 
 - 
isFlatpublic boolean isFlat() Indicates whether this parse node contains no sub-constituents.- Returns:
- trueif this constituent contains no sub-constituents;- falseotherwise.
 
 - 
isChunkpublic void isChunk(boolean ic) 
 - 
isChunkpublic boolean isChunk() 
 - 
getTagNodespublic Parse[] getTagNodes() - Returns:
- Retrieves the parse nodes which are children of this node and which are pos tags.
 
 - 
getTokenNodespublic Parse[] getTokenNodes() 
 - 
getCommonParentpublic 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 than 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.
 
 - 
compareTopublic int compareTo(Parse p) - Specified by:
- compareToin interface- Comparable<Parse>
 
 - 
getDerivationpublic StringBuffer getDerivation() - Returns:
- Retrieves the derivation string for this parse or nullif no derivation string has been created.
 
 - 
setDerivationpublic 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.
 
 - 
showCodeTreepublic 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.
 
- 
 
-