deeppavlov/models/spelling_correction/levenshtein/tabled_trie.py
def save(self, outfile):
        """
        Сохраняет дерево для дальнейшего использования
        """
        with open(outfile, "w", encoding="utf8") as fout:
            attr_values = [getattr(self, attr) for attr in Trie.ATTRS]
            attr_values.append(any(x is not None for x in self.data))
            fout.write("{}\n{}\t{}\n".format(
                " ".join("T" if x else "F" for x in attr_values),
                self.nodes_number, self.root))
            fout.write(" ".join(str(a) for a in self.alphabet) + "\n")
            for index, label in enumerate(self.final):
                letters = self._get_letters(index, return_indexes=True)
                children = self._get_children(index)
                fout.write("{}\t{}\n".format(
                    "T" if label else "F", " ".join("{}:{}".format(*elem)
                                                    for elem in zip(letters, children))))
            if self.precompute_symbols is not None:
                for elem in self.data:
                    fout.write(":".join(",".join(
                        map(str, symbols)) for symbols in elem) + "\n")
        return
def save(self, outfile):
        """
        Сохраняет дерево для дальнейшего использования
        """
        with open(outfile, "w", encoding="utf8") as fout:
            attr_values = [getattr(self, attr) for attr in Trie.ATTRS]
            attr_values.append(any(x is not None for x in self.data))
            fout.write("{}\n{}\t{}\n".format(
                " ".join("T" if x else "F" for x in attr_values),
                self.nodes_number, self.root))
            fout.write(" ".join(str(a) for a in self.alphabet) + "\n")
            for index, label in enumerate(self.final):
                letters = self._get_letters(index, return_indexes=True)
                children = self._get_children(index)
                fout.write("{}\t{}\n".format(
                    "T" if label else "F", " ".join("{}:{}".format(*elem)
                                                    for elem in zip(letters, children))))
            if self.precompute_symbols is not None:
                for elem in self.data:
                    fout.write(":".join(",".join(
                        map(str, symbols)) for symbols in elem) + "\n")
        return
def save ( self , outfile ) : with open ( outfile , "w" , encoding = "utf8" ) as fout : attr_values = [ getattr ( self , attr ) for attr in Trie . ATTRS ] attr_values . append ( any ( x is not None for x in self . data ) ) fout . write ( "{}\n{}\t{}\n" . format ( " " . join ( "T" if x else "F" for x in attr_values ) , self . nodes_number , self . root ) ) fout . write ( " " . join ( str ( a ) for a in self . alphabet ) + "\n" ) for index , label in enumerate ( self . final ) : letters = self . _get_letters ( index , return_indexes = True ) children = self . _get_children ( index ) fout . write ( "{}\t{}\n" . format ( "T" if label else "F" , " " . join ( "{}:{}" . format ( * elem ) for elem in zip ( letters , children ) ) ) ) if self . precompute_symbols is not None : for elem in self . data : fout . write ( ":" . join ( "," . join ( map ( str , symbols ) ) for symbols in elem ) + "\n" ) return
Сохраняет дерево для дальнейшего использования
Сохраняет дерево для дальнейшего использования