Class EarleySpan
Represents a collection of ambiguous completed states with the same left-hand side and span.
Inherited Members
Namespace: EarleyParser
Assembly: EarleyParser.dll
Syntax
public class EarleySpan
Remarks
This class manages a list of completed Earley states (reductors) that share the same:
- Left-hand side of the grammar rule
- Start and end positions in the input
Constructors
| Edit this page View SourceEarleySpan(EarleyState)
Initializes a new instance of the EarleySpan class.
Declaration
public EarleySpan(EarleyState state)
Parameters
| Type | Name | Description |
|---|---|---|
| EarleyState | state | The initial completed state to add to this span. |
Properties
| Edit this page View SourceEndColumn
Gets or sets the column where this span ends in the parse chart.
Declaration
public EarleyColumn EndColumn { get; set; }
Property Value
| Type | Description |
|---|---|
| EarleyColumn |
LeftHandSide
Gets or sets the left-hand side of the grammar rule shared by all states in this span.
Declaration
public string LeftHandSide { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Reductors
Gets the list of completed states (reductors) in this span.
Declaration
public List<EarleyState> Reductors { get; }
Property Value
| Type | Description |
|---|---|
| List<EarleyState> |
StartColumn
Gets the column where this span begins in the parse chart.
Declaration
public EarleyColumn StartColumn { get; }
Property Value
| Type | Description |
|---|---|
| EarleyColumn |
Methods
| Edit this page View SourceAdd(EarleyState)
Adds a completed state to this span.
Declaration
public void Add(EarleyState state)
Parameters
| Type | Name | Description |
|---|---|---|
| EarleyState | state | The completed state to add. |
CountDerivations(Dictionary<EarleySpan, int>)
Counts the total number of distinct parse trees rooted at this span.
Declaration
public int CountDerivations(Dictionary<EarleySpan, int> visited)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<EarleySpan, int> | visited | Dictionary to track visited spans and their derivation counts. |
Returns
| Type | Description |
|---|---|
| int | The total number of distinct parse trees. |
CountLengthsOfBasicTrees(Dictionary<EarleySpan, List<int>>, HashSet<string>, HashSet<string>, bool)
Counts the lengths of basic trees rooted at this span.
Declaration
public List<int> CountLengthsOfBasicTrees(Dictionary<EarleySpan, List<int>> visited, HashSet<string> encounteredNTs, HashSet<string> recursiveNTs, bool insideRecursion)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<EarleySpan, List<int>> | visited | Dictionary to track visited spans and their tree lengths. |
| HashSet<string> | encounteredNTs | Set of non-terminals encountered in the current path. |
| HashSet<string> | recursiveNTs | Set of non-terminals known to be recursive. |
| bool | insideRecursion | Indicates whether we are already inside a recursive structure. |
Returns
| Type | Description |
|---|---|
| List<int> | List of lengths of basic trees. Returns [-1] for recursive structures. |
GetFormattedString(Grammar, Dictionary<EarleySpan, Color>, bool)
Gets formatted string representations of the parse tree.
Declaration
public List<StringBuilder> GetFormattedString(Grammar g, Dictionary<EarleySpan, Color> visited, bool onlyPartsOfSpeechSequences = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Grammar | g | The grammar used for parsing. |
| Dictionary<EarleySpan, Color> | visited | Dictionary to track visited spans and their colors for cycle detection. |
| bool | onlyPartsOfSpeechSequences | Whether to only include parts of speech in the output. |
Returns
| Type | Description |
|---|---|
| List<StringBuilder> | List of StringBuilder objects containing formatted string representations. |
Remarks
The output can be either:
- Bracketed representation of the subtree, e.g. (START (NP (PN John)) (VP (V0 cried)))
- Parts of speech sequences, e.g. PN V0 (PN = proper noun)
GetPOSRulesInEachDerivation(Grammar, Dictionary<EarleySpan, List<HashSet<Rule>>>, int)
Gets the parts of speech rules used in each derivation.
Declaration
public List<HashSet<Rule>> GetPOSRulesInEachDerivation(Grammar g, Dictionary<EarleySpan, List<HashSet<Rule>>> visited, int i)
Parameters
| Type | Name | Description |
|---|---|---|
| Grammar | g | The grammar used for parsing. |
| Dictionary<EarleySpan, List<HashSet<Rule>>> | visited | Dictionary to track visited spans and their POS rules. |
| int | i | The index of the current derivation. |
Returns
| Type | Description |
|---|---|
| List<HashSet<Rule>> | List of sets of rules containing parts of speech. |