Class AbstractBottomUpParser
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 toSetParents 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
taggerIPOSTaggerchunkerIChunkerheadRulesIHeadRulesbeamSizeintadvancePercentagedouble
Fields
COMPLETE
Outcome used when a constituent is complete.
public const string COMPLETE = "c"
Field Value
CONT
Prefix for outcomes continuing a constituent.
public const string CONT = "C-"
Field Value
INCOMPLETE
Outcome used when a constituent is incomplete.
public const string INCOMPLETE = "i"
Field Value
INC_NODE
The label for the top if an incomplete node.
public const string INC_NODE = "INC"
Field Value
K
The maximum number of parses to advance from a single preceding parse.
protected int K
Field Value
M
The maximum number of parses advanced from all preceding parses at each derivation step.
protected int M
Field Value
OTHER
Outcome for token which is not contained in a basal constituent.
public const string OTHER = "O"
Field Value
Q
The minimum total probability mass of advanced outcomes.
protected double Q
Field Value
START
Prefix for outcomes starting a constituent.
public const string START = "S-"
Field Value
TOK_NODE
The label for a token node.
public const string TOK_NODE = "TK"
Field Value
TOP_NODE
The label for the top node.
public const string TOP_NODE = "TOP"
Field Value
ZERO
The integer 0.
public const int ZERO = 0
Field Value
chunker
The chunker that the parser uses to chunk non-recursive structures.
protected IChunker chunker
Field Value
createDerivationString
Specifies whether a derivation string should be created during parsing. This is useful for debugging.
protected bool createDerivationString
Field Value
debugOn
Turns debug print on or off.
protected bool debugOn
Field Value
defaultAdvancePercentage
The default amount of probability mass required of advanced outcomes.
public const double defaultAdvancePercentage = 0.95
Field Value
defaultBeamSize
The default beam size used if no beam size is given.
public const int defaultBeamSize = 20
Field Value
headRules
The head rules for the parser.
protected IHeadRules headRules
Field Value
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
reportFailedParse
Specifies whether failed parses should be reported to standard error.
protected bool reportFailedParse
Field Value
tagger
The pos-tagger that the parser uses.
protected IPOSTagger tagger
Field Value
Methods
AdvanceChunks(Parse, double)
Returns the top chunk sequences for the specified parse.
protected virtual Parse[] AdvanceChunks(Parse p, double minChunkScore)
Parameters
pParseA pos-tag assigned parse.
minChunkScoredoubleA 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
pParseThe parse to advance.
probMassdoubleThe 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
pParseThe 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
pParseThe complete parse.
BuildDictionary(IObjectStream<Parse?>, IHeadRules, TrainingParameters)
public static Dictionary BuildDictionary(IObjectStream<Parse?> data, IHeadRules rules, TrainingParameters parameters)
Parameters
dataIObjectStream<Parse>rulesIHeadRulesparametersTrainingParameters
Returns
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
dataIObjectStream<Parse>rulesIHeadRulescutoffint
Returns
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
chunksParse[]A set of parses.
punctSetISet<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
indexintAn index into the parses without punctuation.
nonPunctParsesParse[]The parses without punctuation.
parsesParse[]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
tokensParseThe 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
tokensParseA parse containing the tokens with a single parent node.
numParsesintThe 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
errorReportingboolIf 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
pParseThe parse whose parent references need to be assigned.