예제 #1
0
    def optimal_rewrites(self,
                         string: pynini.FstLike,
                         input_token_type: Optional[pynini.TokenType] = None,
                         output_token_type: Optional[pynini.TokenType] = None,
                         state_multiplier: int = 4) -> List[str]:
        """Returns all optimal rewrites.

    Args:
      string: Input string or FST.
      input_token_type: Optional input token type, or symbol table.
      output_token_type: Optional output token type, or symbol table.
      state_multiplier: Max ratio for the number of states in the DFA lattice to
        the NFA lattice; if exceeded, a warning is logged.

    Returns:
      A tuple of output strings.
    """
        lattice = self._rewrite_lattice(string, input_token_type)
        lattice = rewrite.lattice_to_dfa(lattice, True, state_multiplier)
        return rewrite.lattice_to_strings(lattice, output_token_type)
예제 #2
0
    def top_rewrites(
            self,
            string: pynini.FstLike,
            nshortest: int,
            input_token_type: Optional[pynini.TokenType] = None,
            output_token_type: Optional[pynini.TokenType] = None) -> List[str]:
        """Returns the top n rewrites.

    Args:
      string: Input string or FST.
      nshortest: The maximum number of rewrites to return.
      input_token_type: Optional input token type, or symbol table.
      output_token_type: Optionla output token type, or symbol table.

    Returns:
      A tuple of output strings.
    """
        lattice = self._rewrite_lattice(string, input_token_type)
        lattice = rewrite.lattice_to_nshortest(lattice, nshortest)
        return rewrite.lattice_to_strings(lattice, output_token_type)
예제 #3
0
def optimal_rewrites(
    string: pynini.FstLike,
    rule: pynini.Fst,
    input_token_type: Optional[TokenType] = None,
    output_token_type: Optional[TokenType] = None,
    threshold: float = 1,
) -> List[str]:
    """Returns all optimal rewrites.
    Args:
    string: Input string or FST.
    rule: Input rule WFST.
    input_token_type: Optional input token type, or symbol table.
    output_token_type: Optional output token type, or symbol table.
    threshold: Threshold for weights (1 is optimal only, 0 is for all paths)
    Returns:
    A tuple of output strings.
    """
    lattice = rewrite.rewrite_lattice(string, rule, input_token_type)
    lattice = threshold_lattice_to_dfa(lattice, threshold, 4)
    return rewrite.lattice_to_strings(lattice, output_token_type)
예제 #4
0
 def expand_string(s: str) -> List[str]:
   return rewrite.lattice_to_strings(self.lexicon.expand(s))
예제 #5
0
 def expand_string(s: str) -> List[str]:
   return rewrite.lattice_to_strings(self.deabbreviator.expand(s))