本文整理汇总了Python中dictionary.Dictionary.open方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.open方法的具体用法?Python Dictionary.open怎么用?Python Dictionary.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dictionary.Dictionary
的用法示例。
在下文中一共展示了Dictionary.open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import open [as 别名]
class Wordplay:
def __init__(self):
self.dico = Dictionary()
def __del__(self):
self.dico.close()
def open(self, dictionary_path):
self.dico.open(dictionary_path)
def close(self):
self.dico.close()
def search_words(self, pattern):
for word in self.dico.search_words(pattern):
yield word
def letters_for_three_words(self, word1_begin, word2_begin, word3_begin, word_end_len):
word1_suffixes = set(self._search_suffixes(word1_begin, word_end_len))
word2_suffixes = set(self._search_suffixes(word2_begin, word_end_len))
word3_suffixes = set(self._search_suffixes(word3_begin, word_end_len))
common_suffixes = word1_suffixes & word2_suffixes & word3_suffixes
for common_suffix in sorted(common_suffixes):
yield common_suffix
def quatro(self, prefix1, suffix1, prefix2, suffix2, middleLength):
word1_middle = set(self._search_middle(prefix1, suffix1, middleLength))
word2_middle = set(self._search_middle(prefix2, suffix2, middleLength))
common_middles = word1_middle & word2_middle
for common_middle in sorted(common_middles):
yield common_middle
def _search_middle(self, prefix, suffix, middleLength):
for word in self.dico.search_words(prefix + "_" * middleLength + suffix):
middle = word[len(prefix):-len(suffix)]
yield middle
def _search_suffixes(self, word_begin, word_end_len):
for word in self.dico.search_words(word_begin + "_" * word_end_len):
suffix = word[-word_end_len:]
yield suffix
def search_anagrams(self, word):
for anagram in self.dico.search_anagrams(word):
yield anagram
示例2: len
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import open [as 别名]
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from dictionary import Dictionary
import sys
if len(sys.argv) != 3:
sys.exit("Usage: generate_dictionary.py <input file> <ouput dictionary>")
with open(sys.argv[1], 'r') as input_file:
d = Dictionary()
d.open(sys.argv[2])
d.clear()
for word in input_file:
d.add_word(word.strip())
d.save()
d.close()