Class AbstractBottomUpParser

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

Abstract class which contains code to tag and chunk parses for bottom up parsing and leaves implementation of advancing parses and completing parses to extend class.

Note: The nodes within the returned parses are shared with other parses and therefore their parent node references will not be consistent with their child node reference. SetParents(Parse) can be used to make the parents consistent with a particular parse, but subsequent calls to SetParents can invalidate the results of earlier calls.
public abstract class AbstractBottomUpParser : IParser
Inheritance
AbstractBottomUpParser
Implements
Derived
Inherited Members

Constructors

AbstractBottomUpParser(IPOSTagger, IChunker, IHeadRules, int, double)

protected AbstractBottomUpParser(IPOSTagger tagger, IChunker chunker, IHeadRules headRules, int beamSize, double advancePercentage)

Parameters

tagger IPOSTagger
chunker IChunker
headRules IHeadRules
beamSize int
advancePercentage double

Fields

COMPLETE

Outcome used when a constituent is complete.

public const string COMPLETE = "c"

Field Value

string

CONT

Prefix for outcomes continuing a constituent.

public const string CONT = "C-"

Field Value

string

INCOMPLETE

Outcome used when a constituent is incomplete.

public const string INCOMPLETE = "i"

Field Value

string

INC_NODE

The label for the top if an incomplete node.

public const string INC_NODE = "INC"

Field Value

string

K

The maximum number of parses to advance from a single preceding parse.

protected int K

Field Value

int

M

The maximum number of parses advanced from all preceding parses at each derivation step.

protected int M

Field Value

int

OTHER

Outcome for token which is not contained in a basal constituent.

public const string OTHER = "O"

Field Value

string

Q

The minimum total probability mass of advanced outcomes.

protected double Q

Field Value

double

START

Prefix for outcomes starting a constituent.

public const string START = "S-"

Field Value

string

TOK_NODE

The label for a token node.

public const string TOK_NODE = "TK"

Field Value

string

TOP_NODE

The label for the top node.

public const string TOP_NODE = "TOP"

Field Value

string

ZERO

The integer 0.

public const int ZERO = 0

Field Value

int

chunker

The chunker that the parser uses to chunk non-recursive structures.

protected IChunker chunker

Field Value

IChunker

createDerivationString

Specifies whether a derivation string should be created during parsing. This is useful for debugging.

protected bool createDerivationString

Field Value

bool

debugOn

Turns debug print on or off.

protected bool debugOn

Field Value

bool

defaultAdvancePercentage

The default amount of probability mass required of advanced outcomes.

public const double defaultAdvancePercentage = 0.95

Field Value

double

defaultBeamSize

The default beam size used if no beam size is given.

public const int defaultBeamSize = 20

Field Value

int

headRules

The head rules for the parser.

protected IHeadRules headRules

Field Value

IHeadRules

punctSet

The set strings which are considered punctuation for the parser. Punctuation is not attached, but floats to the top of the parse as attachment decisions are made about its non-punctuation sister nodes.

protected ISet<string> punctSet

Field Value

ISet<string>

reportFailedParse

Specifies whether failed parses should be reported to standard error.

protected bool reportFailedParse

Field Value

bool

tagger

The pos-tagger that the parser uses.

protected IPOSTagger tagger

Field Value

IPOSTagger

Methods

AdvanceChunks(Parse, double)

Returns the top chunk sequences for the specified parse.

protected virtual Parse[] AdvanceChunks(Parse p, double minChunkScore)

Parameters

p Parse

A pos-tag assigned parse.

minChunkScore double

A minimum score below which chunks should not be advanced.

Returns

Parse[]

The top chunk assignments to the specified parse.

AdvanceParses(Parse, double)

Advances the specified parse and returns the an array advanced parses whose probability accounts for more than the specified amount of probability mass.

protected abstract Parse[]? AdvanceParses(Parse p, double probMass)

Parameters

p Parse

The parse to advance.

probMass double

The amount of probability mass that should be accounted for by the advanced parses.

Returns

Parse[]

AdvanceTags(Parse)

Advances the parse by assigning it POS tags and returns multiple tag sequences.

protected Parse[] AdvanceTags(Parse p)

Parameters

p Parse

The parse to be tagged.

Returns

Parse[]

Parses with different POS-tag sequence assignments.

AdvanceTop(Parse)

Adds the "TOP" node to the specified parse.

protected abstract void AdvanceTop(Parse p)

Parameters

p Parse

The complete parse.

BuildDictionary(IObjectStream<Parse?>, IHeadRules, TrainingParameters)

public static Dictionary BuildDictionary(IObjectStream<Parse?> data, IHeadRules rules, TrainingParameters parameters)

Parameters

data IObjectStream<Parse>
rules IHeadRules
parameters TrainingParameters

Returns

Dictionary

Exceptions

IOException

if there is an error during reading

BuildDictionary(IObjectStream<Parse?>, IHeadRules, int)

public static Dictionary BuildDictionary(IObjectStream<Parse?> data, IHeadRules rules, int cutoff)

Parameters

data IObjectStream<Parse>
rules IHeadRules
cutoff int

Returns

Dictionary

Exceptions

IOException

if there is an error during reading

CollapsePunctuation(Parse[], ISet<string>)

Removes the punctuation from the specified set of chunks, adds it to the parses adjacent to the punctuation is specified, and returns a new array of parses with the punctuation removed.

public static Parse[] CollapsePunctuation(Parse[] chunks, ISet<string> punctSet)

Parameters

chunks Parse[]

A set of parses.

punctSet ISet<string>

The set of punctuation which is to be removed.

Returns

Parse[]

An array of parses which is a subset of chunks with punctuation removed.

MapParseIndex(int, Parse[], Parse[])

Determines the mapping between the specified index into the specified parses without punctuation to the corresponding index into the specified parses.

protected int MapParseIndex(int index, Parse[] nonPunctParses, Parse[] parses)

Parameters

index int

An index into the parses without punctuation.

nonPunctParses Parse[]

The parses without punctuation.

parses Parse[]

The parses wit punctuation.

Returns

int

An index into the specified parses which corresponds to the same node the specified index into the parses with punctuation.

Parse(Parse)

Returns a parse for the specified parse of tokens.

public Parse Parse(Parse tokens)

Parameters

tokens Parse

The root node of a flat parse containing only tokens.

Returns

Parse

A full parse of the specified tokens or the flat chunks of the tokens if a full parse could not be found.

Parse(Parse, int)

Returns the specified number of parses or fewer for the specified tokens.

Note: The nodes within the returned parses are shared with other parses and therefore their parent node references will not be consistent with their child node reference. Parent can be used to make the parents consistent with a particular parse, but subsequent calls to SetParents(Parse) can invalidate the results of earlier calls.
public Parse[] Parse(Parse tokens, int numParses)

Parameters

tokens Parse

A parse containing the tokens with a single parent node.

numParses int

The number of parses desired.

Returns

Parse[]

the specified number of parses for the specified tokens.

SetErrorReporting(bool)

Specifies whether the parser should report when it was unable to find a parse for a particular sentence.

public void SetErrorReporting(bool errorReporting)

Parameters

errorReporting bool

If true then un-parsed sentences are reported, false otherwise.

SetParents(Parse)

Assigns parent references for the specified parse so that they are consistent with the children references.

public static void SetParents(Parse p)

Parameters

p Parse

The parse whose parent references need to be assigned.