Class Parse
Data structure for holding parse constituents.
public class Parse : ICloneable, IComparable<Parse>
- Inheritance
-
Parse
- Implements
- Inherited Members
Constructors
Parse(string, Span, string, double, Parse?)
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.
public Parse(string text, Span span, string type, double p, Parse? h)
Parameters
textstringThe text of the sentence for which this node is a part of.
spanSpanThe character offsets for this node within the specified text.
typestringThe constituent label of this node.
pdoubleThe probability of this parse.
hParseThe head token of this parse.
Parse(string, Span, string, double, int)
Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head index.
public Parse(string text, Span span, string type, double p, int index)
Parameters
textstringThe text of the sentence for which this node is a part of.
spanSpanThe character offsets for this node within the specified text.
typestringThe constituent label of this node.
pdoubleThe probability of this parse.
indexintThe token index of the head of this parse.
Fields
BRACKET_LCB
public const string BRACKET_LCB = "{"
Field Value
BRACKET_LRB
public const string BRACKET_LRB = "("
Field Value
BRACKET_LSB
public const string BRACKET_LSB = "["
Field Value
BRACKET_RCB
public const string BRACKET_RCB = "}"
Field Value
BRACKET_RRB
public const string BRACKET_RRB = ")"
Field Value
BRACKET_RSB
public const string BRACKET_RSB = "]"
Field Value
Properties
ChildCount
Returns the number of children for this parse node.
public int ChildCount { get; }
Property Value
CoveredText
public string CoveredText { get; }
Property Value
Derivation
Gets or sets the derivation string for this parse if one has been created.
public StringBuilder? Derivation { get; set; }
Property Value
Head
Returns the head constituent associated with this constituent.
public Parse Head { get; }
Property Value
HeadIndex
Returns the index within a sentence of the head token for this parse.
public int HeadIndex { get; }
Property Value
IsChunk
Gets or sets whether this constituent was built during the chunking phase.
public bool IsChunk { get; set; }
Property Value
IsFlat
Returns true if this constituent contains no sub-constituents.
public bool IsFlat { get; }
Property Value
IsPosTag
Indicates whether this parse node is a pos-tag.
public bool IsPosTag { get; }
Property Value
Label
Gets or sets the label assigned to this parse node during parsing which specifies how this node will be formed into a constituent.
public string? Label { get; set; }
Property Value
NextPunctuationSet
Returns the set of punctuation parses that occur immediately after this parse.
public ICollection<Parse>? NextPunctuationSet { get; }
Property Value
Parent
Gets or sets the parent parse node of this constituent.
public Parse? Parent { get; set; }
Property Value
PreviousPunctuationSet
Returns the set of punctuation parses that occur immediately before this parse.
public ICollection<Parse>? PreviousPunctuationSet { get; }
Property Value
Prob
Returns the log of the product of the probability associated with all the decisions which formed this constituent.
public double Prob { get; }
Property Value
Span
Returns the character offsets for this constituent.
public Span Span { get; }
Property Value
TagSequenceProb
Returns the probability associated with the pos-tag sequence assigned to this parse.
public double TagSequenceProb { get; }
Property Value
Text
Returns the text of the sentence over which this parse was formed.
public string Text { get; }
Property Value
Type
Gets or sets the constituent label for this node of the parse.
public string Type { get; set; }
Property Value
Methods
Add(Parse, IHeadRules)
public void Add(Parse daughter, IHeadRules rules)
Parameters
daughterParserulesIHeadRules
AddNames(string, Span[], Parse[])
Utility method to inserts named entities.
public static void AddNames(string tag, Span[] names, Parse[] tokens)
Parameters
AddNextPunctuation(Parse)
Designates that the specified punctuation follows this parse.
public void AddNextPunctuation(Parse punct)
Parameters
punctParseThe punctuation set.
AddPreviousPunctuation(Parse)
Designates that the specified punctuation should is prior to this parse.
public void AddPreviousPunctuation(Parse punct)
Parameters
punctParseThe punctuation.
AddProb(double)
Adds the specified probability log to this current log for this parse.
public void AddProb(double logProb)
Parameters
logProbdoubleThe probability of an action performed on this parse.
Adjoin(Parse, IHeadRules)
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.
public Parse Adjoin(Parse sister, IHeadRules rules)
Parameters
sisterParseThe node to be adjoined.
rulesIHeadRulesThe head rules for the parser.
Returns
- Parse
The new parent node of this node and the specified sister node.
AdjoinRoot(Parse, IHeadRules, int)
public Parse AdjoinRoot(Parse node, IHeadRules rules, int parseIndex)
Parameters
nodeParserulesIHeadRulesparseIndexint
Returns
Clone()
Creates a new object that is a copy of the current instance.
public object Clone()
Returns
- object
A new object that is a copy of this instance.
Clone(Parse)
Clones the right frontier of parse up to the specified node.
public Parse Clone(Parse node)
Parameters
nodeParseThe last node in the right frontier of the parse tree which should be cloned.
Returns
- Parse
A clone of this parse and its right frontier up to and including the specified node.
CloneRoot(Parse, int)
Clones the right frontier of this root parse up to and including the specified node.
public Parse CloneRoot(Parse node, int parseIndex)
Parameters
nodeParseThe last node in the right frontier of the parse tree which should be cloned.
parseIndexintThe child index of the parse for this root node.
Returns
- Parse
A clone of this root parse and its right frontier up to and including the specified node.
CompareTo(Parse?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(Parse? p)
Parameters
pParse
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Complete()
Returns whether this parse is complete.
public bool Complete()
Returns
- bool
Returns true if the parse contains a single top-most node.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
ExpandTopNode(Parse)
public void ExpandTopNode(Parse root)
Parameters
rootParse
FixPossesives(Parse)
public static void FixPossesives(Parse parse)
Parameters
parseParse
GetChildren()
Returns the child constituents of this constituent.
public Parse[] GetChildren()
Returns
- Parse[]
GetCommonParent(Parse?)
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.
public Parse? GetCommonParent(Parse? node)
Parameters
nodeParseThe node from which parents are compared to this node's parents.
Returns
- Parse
the deepest shared parent of this node and the specified node.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetTagNodes()
Returns the parse nodes which are children of this node and which are pos tags.
public Parse[] GetTagNodes()
Returns
- Parse[]
GetTokenNodes()
public Parse[] GetTokenNodes()
Returns
- Parse[]
IndexOf(Parse)
Returns the index of this specified child.
public int IndexOf(Parse child)
Parameters
childParseA child of this parse.
Returns
- int
the index of this specified child or -1 if the specified child is not a child of this parse.
Insert(Parse)
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.
public void Insert(Parse constituent)
Parameters
constituentParseThe constituent to be inserted.
ParseParse(string)
Parses the specified tree-bank style parse string and return a Parse structure for that string.
public static Parse ParseParse(string parse)
Parameters
parsestringA tree-bank style parse string.
Returns
- Parse
a Parse structure for the specified tree-bank style parse string.
ParseParse(string, IGapLabeler?)
Parses the specified tree-bank style parse string and return a Parse structure for that string.
public static Parse ParseParse(string parse, IGapLabeler? gl)
Parameters
parsestringA tree-bank style parse string.
glIGapLabelerThe gap labeler.
Returns
- Parse
a Parse structure for the specified tree-bank style parse string.
PruneParse(Parse)
Prune the specified sentence parse of vacuous productions.
public static void PruneParse(Parse parse)
Parameters
parseParse
Remove(int)
public void Remove(int index)
Parameters
indexint
SetChild(int, string)
Replaces the child at the specified index with a new child with the specified label.
public void SetChild(int index, string label)
Parameters
indexintThe index of the child to be replaced.
labelstringThe label to be assigned to the new child.
SetNextPunctuation(ICollection<Parse>?)
Sets the set of punctuation tags which follow this parse.
public void SetNextPunctuation(ICollection<Parse>? punctSet)
Parameters
punctSetICollection<Parse>The set of punctuation tags which follow this parse.
SetPrevPunctuation(ICollection<Parse>?)
Sets the set of punctuation tags which preceed this parse.
public void SetPrevPunctuation(ICollection<Parse>? punctSet)
Parameters
punctSetICollection<Parse>The set of punctuation tags which preceed this parse.
Show()
Displays this parse using Penn Treebank-style formatting.
public void Show()
Show(StringBuilder)
Appends the specified string buffer with a string representation of this parse.
public void Show(StringBuilder sb)
Parameters
sbStringBuilderA string buffer into which the parse string can be appended.
ShowCodeTree()
Prints to standard out a representation of the specified parse which contains hash codes so that parent/child relationships can be explicitly seen.
public void ShowCodeTree()
ToString()
Represents this parse in a human readable way.
public override string ToString()
Returns
UpdateHeads(IHeadRules)
Computes the head parses for this parse and its sub-parses and stores this information in the parse data structure.
public void UpdateHeads(IHeadRules rules)
Parameters
rulesIHeadRulesThe head rules which determine how the head of the parse is computed.
UpdateSpan()
public void UpdateSpan()
UseFunctionTags(bool)
Specifies whether function tags should be included as part of the constituent type.
public static void UseFunctionTags(bool uft)
Parameters
uftbooltrue is they should be included; false otherwise.