polytracker.grammars
grammars classes
Completion
- class polytracker.grammars.Completion(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
Bases:
EarleyState
- __init__(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
- add_predecessor(left_sibling: EarleyState)
- completed_by: Set[EarleyState]
- predecessors: FrozenSet[EarleyState]
- prediction: Prediction
- property production: Production
- to_tree() MutableParseTree[Production | Rule | Terminal]
CorruptedGrammarError
DisconnectedGrammarError
EarleyParser
- class polytracker.grammars.EarleyParser(grammar: Grammar, sentence: str | bytes, start: Production | None = None)
Bases:
object
- property end_states: Iterator[EarleyState]
EarleyQueue
- class polytracker.grammars.EarleyQueue(parser: EarleyParser)
Bases:
object
- __init__(parser: EarleyParser)
- add(state: S, left_sibling: EarleyState | None = None) S
- complete_state(state: EarleyState, completed: EarleyState)
- remove(*states: EarleyState | Iterable) int
EarleyState
- class polytracker.grammars.EarleyState(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
Bases:
object
- __init__(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
- add_predecessor(left_sibling: EarleyState)
- predecessors: FrozenSet[EarleyState]
- prediction: Prediction
- property production: Production
- abstract to_tree() MutableParseTree[Production | Rule | Terminal]
EmptyProduction
- class polytracker.grammars.EmptyProduction(production: Production, prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
Bases:
EarleyState
- __init__(production: Production, prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int)
- add_predecessor(left_sibling: EarleyState)
- predecessors: FrozenSet[EarleyState]
- prediction: Prediction
- property production: Production
- to_tree() MutableParseTree[Production | Rule | Terminal]
Grammar
- class polytracker.grammars.Grammar
Bases:
object
- __init__()
- dependency_graph() DiGraph[Production]
- find_partial_trees(sentence: bytes, start: Production | None = None) Iterator[ParseTree[Production | Rule | Terminal]]
Enumerates all partial parse trees that could result in the given starting sentence fragment.
- remove(production: str | Production) bool
GrammarError
Match
- class polytracker.grammars.Match(parser: EarleyParser)
Bases:
object
- __init__(parser: EarleyParser)
MissingProductionError
PartialMatch
- class polytracker.grammars.PartialMatch(tree: ParseTree[Production | Rule | Terminal], remaining_symbols: Tuple[str | Terminal, ...], remaining_bytes: bytes)
Bases:
object
- __init__(tree: ParseTree[Production | Rule | Terminal], remaining_symbols: Tuple[str | Terminal, ...], remaining_bytes: bytes)
- tree: ParseTree[Production | Rule | Terminal]
Prediction
- class polytracker.grammars.Prediction(production: Production, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int, rule: Rule)
Bases:
EarleyState
- __init__(production: Production, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int, rule: Rule)
- add_predecessor(left_sibling: EarleyState)
- predecessors: FrozenSet[EarleyState]
- prediction: Prediction
- property production: Production
- to_tree() MutableParseTree[Production | Rule | Terminal]
Production
- class polytracker.grammars.Production(grammar: Grammar, name: str, *rules: Rule)
Bases:
object
- _propagate_terminals()
Calculates if this production can produce a terminal. If a rule calls another terminal whose _can_produce_terminal member is None, assume that it is False
- partial_match(sentence: bytes) Iterator[PartialMatch]
Enumerates all partial parse trees and remaining symbols that match the given sentence
- remove_recursive_rules() Set[Rule]
Removes and returns all rules that solely recursively call this same production
- property used_by: Iterable[Production]
Rule
ScannedTerminal
- class polytracker.grammars.ScannedTerminal(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int, terminal: Terminal)
Bases:
EarleyState
- __init__(prediction: Prediction, parsed: Tuple[str | Terminal, ...], expected: Tuple[str | Terminal, ...], index: int, terminal: Terminal)
- add_predecessor(left_sibling: EarleyState)
- predecessors: FrozenSet[EarleyState]
- prediction: Prediction
- property production: Production
- to_tree() MutableParseTree[Production | Rule | Terminal]
grammars functions
extract
- polytracker.grammars.extract(traces: Iterable[ProgramTrace], simplify: bool = False) Grammar
extract a grammar from a set of traces
parse_tree_to_grammar
- polytracker.grammars.parse_tree_to_grammar(tree: NonGeneralizedParseTree) Grammar
production_name
- polytracker.grammars.production_name(event: TraceEvent) str
to_dot
- polytracker.grammars.to_dot(graph: DiGraph, comment: str | None = None) Digraph
- Parameters:
comment – comment for the graph
- Returns:
Graphviz DiGraph
This function creates a dot object which can be saved to disk and converted to PDF its a visualization of the chain fragment, useful for visualizing a reorg.
trace_to_grammar
- polytracker.grammars.trace_to_grammar(trace: ProgramTrace) Grammar