How to use the pynini.shortestpath function in pynini

To help you get started, we’ve selected a few pynini examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kylebgorman / EditTransducer / edit_transducer / edit_transducer.py View on Github external
in the lexicon according to the underlying edit transducer. In the case of
    a tie (i.e., where there are multiple closest strings), only one will be
    returned; tie breaking is deterministic but difficult to reason about and
    thus should be considered unspecified.) The `closest_matches` method can be
    used to enumerate all the ties.

    Args:
      query: input string or acceptor.

    Returns:
      The closest string in the lexicon.
    """
    lattice = self._create_levenshtein_automaton_lattice(query)
    # For implementation reasons, the shortest path (when k = 1) is in reverse
    # state order, so we perform a topological sort ahead of time.
    return shortestpath(lattice).topsort().stringify()

pynini

Finite-state grammar compilation

MIT
Latest version published 4 months ago

Package Health Score

82 / 100
Full package analysis