speech_recognition
Classes | Functions
speech_recognition.kaldi_grammar Namespace Reference

Classes

class  Grammar
 
class  SentenceEdge
 
class  SentenceNode
 

Functions

def assign_node (sentence_list, available_nodes, work_list, rules)
 
def expand_sentences (sentence_list, rules)
 
def expand_tree (rules, target='T')
 
def print_graphviz (root_node, outpath)
 
def stringify_suffixes (expanded_list)
 

Function Documentation

◆ assign_node()

def speech_recognition.kaldi_grammar.assign_node (   sentence_list,
  available_nodes,
  work_list,
  rules 
)
For a given list of rule suffixes, find or add a node, and update the work list if necessary.

:param sentence_list: List of rule suffixes to find or add a node for.
:type  sentence_list: List of rule alternatives (a list of conjuncts, partly expanded to words,
        in particular, the first conjuct shou d not be a variable).

:param available_nodes: Known set of rule sufixes and their associated nodes. May be updated.
:type  available_nodes: Dict of str to SentenceNode

:param work_list: List or rule suffixes that need further processing. May be updated.
:type  work_list: List of pairs (node, rule suffixes).

:param rules: Rules of the grammar.

:return: Node associated with the provided sentence_list.

Definition at line 329 of file kaldi_grammar.py.

◆ expand_sentences()

def speech_recognition.kaldi_grammar.expand_sentences (   sentence_list,
  rules 
)
Expands the grammar rules until elimination of all variables at the first position

:param sentence_list: List of grammar rules
:param rules: Rules of the grammar
:return: Expanded list, an whether an end of an sentence was found.

Definition at line 270 of file kaldi_grammar.py.

◆ expand_tree()

def speech_recognition.kaldi_grammar.expand_tree (   rules,
  target = 'T' 
)
Expands the grammar tree based on the words in the grammar rules.

:param rules: Extracted rules from the grammar file.
:param target: Target rule to expand, default is 'T'.
:return: The root of the expanded tree.
:rtype: SentenceNode

Definition at line 228 of file kaldi_grammar.py.

◆ print_graphviz()

def speech_recognition.kaldi_grammar.print_graphviz (   root_node,
  outpath 
)
Prints Graphviz input of the tree.

:param root_node: Root of the tree

Definition at line 367 of file kaldi_grammar.py.

◆ stringify_suffixes()

def speech_recognition.kaldi_grammar.stringify_suffixes (   expanded_list)
Convert the current rule suffixes to string form.

:param expanded_list: List of rule suffixes to convert.
:return: Set of suffixes, after converting each to a string.

Definition at line 315 of file kaldi_grammar.py.