def lattice_to_one_top_string(lattice: pynini.Fst, token_type: Optional[pynini.TokenType] = None ) -> str: """Returns the top string in the lattice, raising an error if there's a tie. Given a pruned DFA of output strings (such as produced by lattice_to_dfa with optimal_only), extracts a single top string, raising an error if there's a tie. Args: lattice: Epsilon-free deterministic finite acceptor. token_type: Optional output token type, or symbol table. Returns: The top string. Raises: Error: Multiple top rewrites found. """ spaths = lattice.paths(output_token_type=token_type) output = spaths.ostring() spaths.next() if not spaths.done(): raise Error("Multiple top rewrites found: " f"{output} and {spaths.ostring()} (weight: {spaths.weight()})") return output
def lattice_to_strings( lattice: pynini.Fst, token_type: Optional[pynini.TokenType] = None) -> List[str]: """Returns tuple of output strings. Args: lattice: Epsilon-free acyclic WFSA. token_type: Optional output token type, or symbol table. Returns: An list of output strings. """ return list(lattice.paths(output_token_type=token_type).ostrings())
def _olabels_iter(f: pynini.Fst) -> Iterator[List[int]]: it = f.paths() while not it.done(): yield it.olabels() it.next()