deeppavlov/models/spelling_correction/levenshtein/tabled_trie.py
def precompute_future_symbols(trie, n, allow_spaces=False):
    """
    Collecting possible continuations of length <= n for every node
    """
    if n == 0:
        return
    if trie.is_terminated and trie.precompute_symbols:
        # символы уже предпосчитаны
        return
    for index, final in enumerate(trie.final):
        trie.data[index] = [set() for i in range(n)]
    for index, (node_data, final) in enumerate(zip(trie.data, trie.final)):
        node_data[0] = set(trie._get_letters(index))
        if allow_spaces and final:
            node_data[0].add(" ")
    for d in range(1, n):
        for index, (node_data, final) in enumerate(zip(trie.data, trie.final)):
            children = set(trie._get_children(index))
            for child in children:
                node_data[d] |= trie.data[child][d - 1]
            # в случае, если разрешён возврат по пробелу в стартовое состояние
            if allow_spaces and final:
                node_data[d] |= trie.data[trie.root][d - 1]
    trie.terminated = True
def precompute_future_symbols(trie, n, allow_spaces=False):
    if n == 0:
        return
    if trie.is_terminated and trie.precompute_symbols:
        # символы уже предпосчитаны
        return
    for index, final in enumerate(trie.final):
        trie.data[index] = [set() for i in range(n)]
    for index, (node_data, final) in enumerate(zip(trie.data, trie.final)):
        node_data[0] = set(trie._get_letters(index))
        if allow_spaces and final:
            node_data[0].add(" ")
    for d in range(1, n):
        for index, (node_data, final) in enumerate(zip(trie.data, trie.final)):
            children = set(trie._get_children(index))
            for child in children:
                node_data[d] |= trie.data[child][d - 1]
            # в случае, если разрешён возврат по пробелу в стартовое состояние
            if allow_spaces and final:
                node_data[d] |= trie.data[trie.root][d - 1]
    trie.terminated = True
def precompute_future_symbols ( trie , n , allow_spaces = False ) : if n == 0 : return if trie . is_terminated and trie . precompute_symbols : # символы уже предпосчитаны return for index , final in enumerate ( trie . final ) : trie . data [ index ] = [ set ( ) for i in range ( n ) ] for index , ( node_data , final ) in enumerate ( zip ( trie . data , trie . final ) ) : node_data [ 0 ] = set ( trie . _get_letters ( index ) ) if allow_spaces and final : node_data [ 0 ] . add ( " " ) for d in range ( 1 , n ) : for index , ( node_data , final ) in enumerate ( zip ( trie . data , trie . final ) ) : children = set ( trie . _get_children ( index ) ) for child in children : node_data [ d ] |= trie . data [ child ] [ d - 1 ] # в случае, если разрешён возврат по пробелу в стартовое состояние if allow_spaces and final : node_data [ d ] |= trie . data [ trie . root ] [ d - 1 ] trie . terminated = True
Collecting possible continuations of length <= n for every node
Collecting possible continuations of length < = n for every node