Show / Hide Table of Contents

Class EarleySpan

Represents a collection of ambiguous completed states with the same left-hand side and span.

Inheritance
object
EarleySpan
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

EarleySpan(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 Source

EndColumn

Gets or sets the column where this span ends in the parse chart.

Declaration
public EarleyColumn EndColumn { get; set; }
Property Value
Type Description
EarleyColumn
| Edit this page View Source

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
| Edit this page View Source

Reductors

Gets the list of completed states (reductors) in this span.

Declaration
public List<EarleyState> Reductors { get; }
Property Value
Type Description
List<EarleyState>
| Edit this page View Source

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 Source

Add(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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)
| Edit this page View Source

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.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX