Class Parse

Namespace
NOpenNLP.Tools.Parser
Assembly
NOpenNLP.Tools.dll

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

text string

The text of the sentence for which this node is a part of.

span Span

The character offsets for this node within the specified text.

type string

The constituent label of this node.

p double

The probability of this parse.

h Parse

The 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

text string

The text of the sentence for which this node is a part of.

span Span

The character offsets for this node within the specified text.

type string

The constituent label of this node.

p double

The probability of this parse.

index int

The token index of the head of this parse.

Fields

BRACKET_LCB

public const string BRACKET_LCB = "{"

Field Value

string

BRACKET_LRB

public const string BRACKET_LRB = "("

Field Value

string

BRACKET_LSB

public const string BRACKET_LSB = "["

Field Value

string

BRACKET_RCB

public const string BRACKET_RCB = "}"

Field Value

string

BRACKET_RRB

public const string BRACKET_RRB = ")"

Field Value

string

BRACKET_RSB

public const string BRACKET_RSB = "]"

Field Value

string

Properties

ChildCount

Returns the number of children for this parse node.

public int ChildCount { get; }

Property Value

int

CoveredText

public string CoveredText { get; }

Property Value

string

Derivation

Gets or sets the derivation string for this parse if one has been created.

public StringBuilder? Derivation { get; set; }

Property Value

StringBuilder

Head

Returns the head constituent associated with this constituent.

public Parse Head { get; }

Property Value

Parse

HeadIndex

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

public int HeadIndex { get; }

Property Value

int

IsChunk

Gets or sets whether this constituent was built during the chunking phase.

public bool IsChunk { get; set; }

Property Value

bool

IsFlat

Returns true if this constituent contains no sub-constituents.

public bool IsFlat { get; }

Property Value

bool

IsPosTag

Indicates whether this parse node is a pos-tag.

public bool IsPosTag { get; }

Property Value

bool

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

string

NextPunctuationSet

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

public ICollection<Parse>? NextPunctuationSet { get; }

Property Value

ICollection<Parse>

Parent

Gets or sets the parent parse node of this constituent.

public Parse? Parent { get; set; }

Property Value

Parse

PreviousPunctuationSet

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

public ICollection<Parse>? PreviousPunctuationSet { get; }

Property Value

ICollection<Parse>

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

double

Span

Returns the character offsets for this constituent.

public Span Span { get; }

Property Value

Span

TagSequenceProb

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

public double TagSequenceProb { get; }

Property Value

double

Text

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

public string Text { get; }

Property Value

string

Type

Gets or sets the constituent label for this node of the parse.

public string Type { get; set; }

Property Value

string

Methods

Add(Parse, IHeadRules)

public void Add(Parse daughter, IHeadRules rules)

Parameters

daughter Parse
rules IHeadRules

AddNames(string, Span[], Parse[])

Utility method to inserts named entities.

public static void AddNames(string tag, Span[] names, Parse[] tokens)

Parameters

tag string
names Span[]
tokens Parse[]

AddNextPunctuation(Parse)

Designates that the specified punctuation follows this parse.

public void AddNextPunctuation(Parse punct)

Parameters

punct Parse

The punctuation set.

AddPreviousPunctuation(Parse)

Designates that the specified punctuation should is prior to this parse.

public void AddPreviousPunctuation(Parse punct)

Parameters

punct Parse

The punctuation.

AddProb(double)

Adds the specified probability log to this current log for this parse.

public void AddProb(double logProb)

Parameters

logProb double

The 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

sister Parse

The node to be adjoined.

rules IHeadRules

The 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

node Parse
rules IHeadRules
parseIndex int

Returns

Parse

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

node Parse

The 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

node Parse

The last node in the right frontier of the parse tree which should be cloned.

parseIndex int

The 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

p Parse

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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

ExpandTopNode(Parse)

public void ExpandTopNode(Parse root)

Parameters

root Parse

FixPossesives(Parse)

public static void FixPossesives(Parse parse)

Parameters

parse Parse

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

node Parse

The 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

child Parse

A 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

constituent Parse

The 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

parse string

A 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

parse string

A tree-bank style parse string.

gl IGapLabeler

The 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

parse Parse

Remove(int)

public void Remove(int index)

Parameters

index int

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

index int

The index of the child to be replaced.

label string

The 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

punctSet ICollection<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

punctSet ICollection<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

sb StringBuilder

A 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

string

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

rules IHeadRules

The 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

uft bool

true is they should be included; false otherwise.