示例#1
0
文件: fsa.py 项目: ts0923/k2
    def __str__(self) -> str:
        '''Return a string representation of this object

        For visualization and debug only.
        '''
        if hasattr(self, 'aux_labels'):
            aux_labels = self.aux_labels.to(torch.int32)
        else:
            aux_labels = None
        if self.arcs.num_axes() == 2:
            ans = 'k2.Fsa: ' + _fsa_to_str(self.arcs, False, aux_labels)
        else:
            ans = 'k2.FsaVec: \n'
            for i in range(self.shape[0]):
                # get the i-th Fsa
                ragged_arc, start = self.arcs.index(0, i)
                end = start + ragged_arc.values().shape[0]
                ans += 'FsaVec[' + str(i) + ']: ' + _fsa_to_str(
                    ragged_arc, False,
                    None if aux_labels is None else aux_labels[start:end])
        ans += 'properties_str = ' + _k2.fsa_properties_as_str(
            self._properties) + '.'
        for name, value in self.named_tensor_attr(include_scores=False):
            sep = '\n'
            ans += f'{sep}{name}: {value}'
        for name, value in self.named_non_tensor_attr():
            if name == 'symbols':
                continue
            sep = '\n'
            ans += f'{sep}{name}: {value}'

        return ans
示例#2
0
文件: fsa.py 项目: stormytrail/k2
 def __str__(self) -> str:
     '''Return a string representation of this object (note: does not
        contain all the information in it for now)'''
     if hasattr(self, 'aux_labels'):
         aux_labels = self.aux_labels.to(torch.int32)
     else:
         aux_labels = None
     ans = "k2.Fsa: " + _fsa_to_str(self.arcs, False, aux_labels)
     ans += "properties_str = " + _k2.fsa_properties_as_str(
         self._properties) + "."
     return ans
示例#3
0
 def __str__(self) -> str:
     '''Return a string representation of this object (note: does not
        contain all the information in it for now)'''
     if hasattr(self, 'aux_labels'):
         aux_labels = self.aux_labels.to(torch.int32)
     else:
         aux_labels = None
     if self.arcs.num_axes() == 2:
         ans = "k2.Fsa: " + _fsa_to_str(self.arcs, False, aux_labels)
     else:
         ans = "k2.FsaVec: \n"
         for i in range(self.shape[0]):
             # get the i-th Fsa
             ragged_arc, start = self.arcs.index(0, i)
             end = start + ragged_arc.values().shape[0]
             ans += "FsaVec[" + str(i) + "]: " + _fsa_to_str(
                 ragged_arc, False,
                 None if aux_labels is None else aux_labels[start:end])
     ans += "properties_str = " + _k2.fsa_properties_as_str(
         self._properties) + "."
     return ans
示例#4
0
    def to_str(self, negate_scores: bool = False) -> str:
        '''Convert an Fsa to a string.

        Note:
          The returned string can be used to construct an Fsa.

        Args:
          negate_scores:
            Optional. If true, we negate the score during the conversion,

        Returns:
          A string representation of the Fsa.
        '''
        return _fsa_to_str(self._fsa, negate_scores, self._aux_labels)
示例#5
0
def to_str(fsa: Fsa, openfst: bool = False) -> str:
    '''Convert an Fsa to a string.

    Note:
      The returned string can be used to construct an Fsa.

    Args:
      openfst:
        Optional. If true, we negate the scores during the conversion,

    Returns:
      A string representation of the Fsa.
    '''
    if hasattr(fsa, 'aux_labels'):
        aux_labels = fsa.aux_labels.to(torch.int32)
    else:
        aux_labels = None
    return _fsa_to_str(fsa.arcs, openfst, aux_labels)