当前位置: 首页>>代码示例>>Python>>正文


Python Trie.add方法代码示例

本文整理汇总了Python中trie.Trie.add方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.add方法的具体用法?Python Trie.add怎么用?Python Trie.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trie.Trie的用法示例。


在下文中一共展示了Trie.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: trie_dictionary

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
def trie_dictionary(dictionary):
    trie = Trie()
    
    for key in dictionary.keys():
        #print key
        trie.add(key, dictionary[key])
        
    return trie
开发者ID:Barneyjm,项目名称:Free-Time,代码行数:10,代码来源:points.py

示例2: gen_suffix_trie

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
def gen_suffix_trie (fname):
    from trie import Trie, DATrie
    
    trie = Trie ()
    pytrie = DATrie ()

    for s in valid_syllables:
        trie.add (s[::-1], valid_syllables[s])
    
    pytrie.construct_from_trie (trie)
    pytrie.output_static_c_arrays (fname)
开发者ID:iksky,项目名称:sunpinyin,代码行数:13,代码来源:pinyin_data.py

示例3: mkEncTrie

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
def mkEncTrie(dct):
    """
  Makes an "encoding" trie from a description dict.
  Only call from mkTries to ensure that the reverse trie gets built as well
  """
    rv = Trie()
    for key, value in dct.iteritems():
        try:
            if value[1] is not NoReverse:
                raise Exception
        except:
            rv.add(key, value)
        else:
            rv.add(key, value[0])
    return rv
开发者ID:encukou,项目名称:devanagari,代码行数:17,代码来源:table.py

示例4: __init__

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
class ControlIt:
    def __init__(self):
        self.the_trie = Trie()

    def file_grab(self):
        log = open("content/words1.txt", 'r')
        loglist = log.readlines()
        log.close()
        cl = []
        sendc = []
        pattern = '^\w+-\s'
        for index, line in enumerate(loglist, 0):
            if re.search(pattern, line) is not None:
                test = re.search(pattern, line)
                firstFound = test.string.split(' ', 1)[0]
                secondFound = loglist[index + 1]
                if not secondFound.split(' ', 1)[0] == "ship":
                    sendc.append(secondFound.split(' ', 1)[0].lower())
                cl.append(firstFound.__add__(secondFound.split(' ', 1)[0]).lower())
        try:
            with open("content/words1.txt", encoding='UTF-8') as f:
                lines = f.read().translate({ord(i): None for i in ';:*.,[]|"�<>()!°&¶/'}).lower().split()
                f.close()
        except:
            with open("content/words1.txt", encoding='latin_1') as f:
                lines = f.read().translate({ord(i): None for i in ';:*.,[]|"�<>()!°&¶/'}).lower().split()
                f.close()
        for index, i in enumerate(lines):
            if i.count('-') >= 3 or i == re.search('\w+-\n', i):
                lines[index] = None
        [lines.append(i) for i in cl]
        for i in sendc:
            lines = list((x for x in lines if re.sub(i, "", str(x))))
        return lines

    def grab_file(self):
        start_list = self.file_grab()
        for i in start_list:
            self.the_trie.add(self.the_trie.trie, str(i))
        mytrie = self.the_trie.get_trie()
        self.the_trie.trie_pickle(mytrie)
        # self.ct = self.the_trie
        print(mytrie)

    def main(self):
        self.grab_file()
        self.the_trie.create_binary_tree()
        self.the_trie.create_avl_tree()
开发者ID:brettcarr1970,项目名称:AssignmentTwo,代码行数:50,代码来源:controller.py

示例5: mkDecTrie

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
def mkDecTrie(dct):
    """
  Makes a "decoding", or "reverse" trie from a description dict
  Only call from mkTries to ensure that the encoding trie gets built as well
  """
    rv = Trie()
    for key, value in dct.iteritems():
        try:
            if value[1] is not NoReverse:
                raise Exception
        except:
            try:
                if not callable(value[1].find_prefix):
                    raise Exception
            except:
                rv.add(value, key)
            else:
                new_key = value[0]
                new_val = (key, revTrie(value[1])) + value[2:]
                rv.add(new_key, new_val)
    return rv
开发者ID:encukou,项目名称:devanagari,代码行数:23,代码来源:table.py

示例6: create_dictionary

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
def create_dictionary():
    with open(DICTIONARY_FILE) as f:
        global dictionary
        dictionary = Trie()
        for word in f:
            dictionary.add(word.strip())
开发者ID:apeschel,项目名称:Spell-Checker,代码行数:8,代码来源:spell.py

示例7: TestWords

# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add [as 别名]
class TestWords(unittest.TestCase):
    """Tests for function words"""
    
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.mytrie = Trie()
        self.mytrie.add('ant',1)
        self.mytrie.add('ante',2)
        self.mytrie.add('antic',3)
        self.mytrie.add('antsy',4)
        self.mytrie.add('antse',5)
        self.mytrie.add('ban',6)
        self.mytrie.add('banana',7)

    def test_default_case(self):
        """Test words retrieves all words properly from Trie."""
        expected = ['ante','antic','ant','antsy','antse','banana','ban']
        actual = []
        for words in self.mytrie.words():
            actual.append(words)
        #print 'actual',actual
        #print 'expected',expected
        self.assertTrue(sorted(actual)==sorted(expected))
开发者ID:codedragon,项目名称:trie,代码行数:26,代码来源:test_trie.py


注:本文中的trie.Trie.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。