Class Parse
java.lang.Object
opennlp.tools.parser.Parse
- All Implemented Interfaces:
Cloneable, Comparable<Parse>
Data structure for holding parse constituents.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate StringBufferThe string buffer used to track the derivation of this parse.private static final PatternThe pattern used to find the function tags.private ParseThe head parse of this parse.private intIndex in the sentence of the head of this constituent.private booleanSpecifies whether this constituent was built during the chunking phase.private StringA string used during parse construction to specify which stage of parsing has been performed on this node.private static final org.slf4j.Loggerprivate Collection<Parse> The set of punctuation parses which are between this parse and the subsequent parse.private ParseThe parent parse of this parse.The sub-constituents of this parse.private Collection<Parse> The set of punctuation parses which are between this parse and the previous parse.private doubleThe probability associated with the syntactic type assigned to this parse.private SpanThe character offsets into the text for this constituent.private final StringThe text string on which this parse is based.private static final PatternThe patter used to identify tokens in Penn Treebank labeled constituents.private StringThe syntactic type of this parse.private static final PatternThe pattern used to find the base constituent label of a Penn Treebank labeled constituent.private static booleanSpecifies whether constituent labels should include parts specified after minus character. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic voidUtility 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.Sister adjoins this node's last child and the specified sister node and returns their new parent node.adjoinRoot(Parse node, HeadRules rules, int parseIndex) clone()Clones the right frontier ofParseup to the specifiednode.Clones the right frontier of this rootParseup to and including the specified node.private voidintbooleancomplete()static ParsecreateFromTokens(String[] tokens) Creates aParsestructure from an array of pre-tokenized strings.private static StringdecodeToken(String token) private static StringencodeToken(String token) booleanvoidexpandTopNode(Parse root) static voidfixPossesives(Parse parse) intParse[]getCommonParent(Parse node) Returns the deepest shared parent of this node and the specified node.getHead()intgetLabel()Retrieves the label assigned to this parse node during parsing which specifies how this node will be formed into a constituent.doublegetProb()getSpan()Parse[]doublegetText()private static StringParse[]getType()private static StringinthashCode()intvoidInserts 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) voidReplaces 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.voidAssigns this parse the specified label.voidsetNextPunctuation(Collection<Parse> punctSet) Sets thepunctuation tagswhich follow this parse.voidSpecifies the parent parse node for this constituent.voidsetPrevPunctuation(Collection<Parse> punctSet) Sets thepunctuation tagswhich precede this parse.voidSet 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.voidPrints to standard out a representation of the specified parse which contains hash codes so that parent/child relationships can be explicitly seen.toString()Represents thisParsein a human-readable way.voidupdateHeads(HeadRules rules) Computes the head parses for this parse and its sub-parses and stores this information in the parse data structure.voidstatic voiduseFunctionTags(boolean uft) Specifies whether function tags should be included as part of the constituent type.
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
BRACKET_LRB
- See Also:
-
BRACKET_RRB
- See Also:
-
BRACKET_LCB
- See Also:
-
BRACKET_RCB
- See Also:
-
BRACKET_LSB
- See Also:
-
BRACKET_RSB
- See Also:
-
text
The text string on which this parse is based. This object is shared among all parses for the same sentence. -
span
The character offsets into the text for this constituent. -
type
The syntactic type of this parse. -
parts
-
head
The head parse of this parse. A parse can be its own head. -
label
A string used during parse construction to specify which stage of parsing has been performed on this node. -
headIndex
private int headIndexIndex in the sentence of the head of this constituent. -
parent
The parent parse of this parse. -
prob
private double probThe probability associated with the syntactic type assigned to this parse. -
derivation
The string buffer used to track the derivation of this parse. -
isChunk
private boolean isChunkSpecifies whether this constituent was built during the chunking phase. -
typePattern
The pattern used to find the base constituent label of a Penn Treebank labeled constituent. -
funTypePattern
The pattern used to find the function tags. -
tokenPattern
The patter used to identify tokens in Penn Treebank labeled constituents. -
prevPunctSet
The set of punctuation parses which are between this parse and the previous parse. -
nextPunctSet
The set of punctuation parses which are between this parse and the subsequent parse. -
useFunctionTags
private static boolean useFunctionTagsSpecifies whether constituent labels should include parts specified after minus character.
-
-
Constructor Details
-
Parse
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- Thecharacter offsetsfor this node within the specifiedtext.type- The constituent label of this node.p- The probability of thisParse.index- The token index of the head of this parse.
-
Parse
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- Thecharacter offsetsfor this node within the specifiedtext.type- The constituent label of this node.p- The probability of this parse.h- The head token of this parse.
-
-
Method Details
-
clone
-
clone
-
cloneRoot
Clones the right frontier of this rootParseup to and including the specified node.- Parameters:
node- The lastnodein the right frontier of the parse tree to be cloned.parseIndex- The child index of the parse for this rootnode.- 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-trueis they should be included,falseotherwise.
-
setType
Set the type of this constituent to the specified type.- Parameters:
type- The type of this constituent.
-
getType
- Returns:
- Retrieves the constituent label for this node of the parse.
-
getPreviousPunctuationSet
- Returns:
- Retrieves the set of punctuation
parsesthat occur immediately before this parse.
-
addPreviousPunctuation
Designates that the specified punctuation should is prior to this parse.- Parameters:
punct- Thepunctuationto be added.
-
getNextPunctuationSet
- Returns:
- Retrieves the set of punctuation
parsesthat occur immediately after this parse.
-
addNextPunctuation
Designates that the specified punctuation follows this parse.- Parameters:
punct- Thepunctuationset.
-
setNextPunctuation
Sets thepunctuation tagswhich follow this parse.- Parameters:
punctSet- The punctuation tags which follow this parse.
-
setPrevPunctuation
Sets thepunctuation tagswhich precede this parse.- Parameters:
punctSet- The punctuation tags which precede this parse.
-
insert
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- Theconstituentto be inserted.
-
show
Fills the specifiedStringBufferwith a string representation of this parse.- Parameters:
sb- AStringBufferinto which the parse string can be appended.
-
show
public void show()Prints this parse using Penn Treebank-style formatting. -
getTagSequenceProb
public double getTagSequenceProb()- Returns:
- Retrieves the probability associated with the pos-tag sequence assigned to this parse.
-
complete
public boolean complete()- Returns:
trueif the parse contains a single top-most node (=complete),falseotherwise.
-
getCoveredText
-
toStringPennTreebank
- Returns:
- Retrieves a String representation using Penn Treebank-style formatting.
-
toString
-
getText
- Returns:
- Retrieves the text of the sentence over which this parse was formed.
-
getSpan
- Returns:
- Retrieves the
character offsetsfor this constituent.
-
getProb
public double getProb()- Returns:
- Retrieves the
logof the product of the probability associated with all the decisions which formed this constituent.
-
addProb
public void addProb(double logProb) Adds the specifiedlogProbto this current log for this parse.- Parameters:
logProb- The probability of an action performed on this parse.
-
getChildren
- Returns:
- Retrieves the
child constituentsof this constituent.
-
setChild
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
-
remove
public void remove(int index) -
adjoinRoot
-
adjoin
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- Thenodeto be adjoined.rules- TheHeadRulesfor the parser.- Returns:
- The new
parent nodeof this node and the specified sister node.
-
expandTopNode
-
getChildCount
public int getChildCount()- Returns:
- Retrieves the number of children for this parse node.
-
indexOf
- 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.
-
getHead
- Returns:
- Retrieves the head constituent associated with this constituent.
-
getHeadIndex
public int getHeadIndex()- Returns:
- Retrieves the index within a sentence of the head token for this parse.
-
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.
-
setLabel
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.
-
getType
-
encodeToken
-
decodeToken
-
getToken
-
updateHeads
-
updateSpan
public void updateSpan() -
pruneParse
-
fixPossesives
-
createFromTokens
Creates aParsestructure from an array of pre-tokenized strings.This is a convenience factory method for cases where the input sentence is already tokenized (e.g., as a
String[]). It joins the tokens with whitespace, computes character offsetspansfor each token, and builds the initial flat parse tree expected byParser.parse(Parse).- Parameters:
tokens- The tokens of the sentence.- Returns:
- A flat
Parsestructure with token nodes ready for aParser. - Throws:
IllegalArgumentException- iftokensisnullor empty.
-
parseParse
-
parseParse
- Parameters:
parse- A tree-bank styleParsestring.gl- TheGapLabelerto be used.- Returns:
- A
Parsestructure for the specified tree-bank style parse string.
-
getParent
- Returns:
- Retrieves the parent parse node of this constituent.
-
setParent
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:
trueif this node is a pos-tag,falseotherwise.
-
isFlat
public boolean isFlat()Indicates whether this parse node contains no sub-constituents.- Returns:
trueif this constituent contains no sub-constituents;falseotherwise.
-
isChunk
public void isChunk(boolean ic) -
isChunk
public boolean isChunk() -
getTagNodes
- Returns:
- Retrieves the parse nodes which are children of this node and which are pos tags.
-
getTokenNodes
-
getCommonParent
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.
-
equals
-
hashCode
-
compareTo
- Specified by:
compareToin interfaceComparable<Parse>
-
getDerivation
- Returns:
- Retrieves the derivation string for this parse or
nullif no derivation string has been created.
-
setDerivation
Specifies the derivation string to be associated with this parse.- Parameters:
derivation- The derivation string to be associated with this parse.
-
codeTree
-
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
-