コード例 #1
0
  def distance(self, iset, oset):
    """Computes minimum distance.

    This method computes, for a pair of input/output strings or acceptors, the
    minimum edit distance according to the underlying edit transducer.

    Args:
      iset: input string or acceptor.
      oset: output string or acceptor.

    Returns:
      Minimum edit distance according to the edit transducer.
    """
    lattice = self._create_lattice(iset, oset)
    # The shortest cost from all final states to the start state is
    # equivalent to the cost of the shortest path.
    return float(shortestdistance(lattice, reverse=True)[0])
コード例 #2
0
    def distance(self, iexpr: pynini.FstLike, oexpr: pynini.FstLike) -> float:
        """Computes minimum distance.

    This method computes, for a pair of input/output strings or acceptors, the
    minimum edit distance according to the underlying edit transducer.

    Args:
      iexpr: input string or acceptor.
      oexpr: output string or acceptor.

    Returns:
      Minimum edit distance according to the edit transducer.
    """
        lattice = self.create_lattice(iexpr, oexpr)
        # The shortest cost from all final states to the start state is
        # equivalent to the cost of the shortest path.
        return float(
            pynini.shortestdistance(lattice, reverse=True)[lattice.start()])
コード例 #3
0
    def disambiguate(self, verbalization):
        normalized = {}
        replacement_dicts = {}
        for verbal_arr in verbalization.paths:
            shortest_path = self._language_model_scoring(verbal_arr)
            normalized_text = shortest_path.stringify(
                token_type=self.word_symbols)
            normalized[normalized_text] = pn.shortestdistance(shortest_path)
            replacement_dicts[normalized_text] = copy.deepcopy(
                self.replacement_dict)

        best_normalized = self._lowest_cost(normalized)
        #print("Best normalized: " + best_normalized)
        if best_normalized in replacement_dicts:
            best_normalized = self._insert_original_words(
                best_normalized, replacement_dicts[best_normalized])

        if self.oov_queue:
            #TODO: is this sufficient for multiple verbalizations?
            best_normalized = self._insert_original_oov(
                best_normalized, self.oov_queue)
            self.oov_queue = None

        return best_normalized
コード例 #4
0
 def best(self):
     return pow(e, -float(shortestdistance(self._best)[-1]))
コード例 #5
0
 def total_weight(self, fst: pynini.Fst) -> float:
     return float(pynini.shortestdistance(fst, reverse=True)[fst.start()])