本文整理汇总了Python中enchant.Dict方法的典型用法代码示例。如果您正苦于以下问题:Python enchant.Dict方法的具体用法?Python enchant.Dict怎么用?Python enchant.Dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enchant
的用法示例。
在下文中一共展示了enchant.Dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_unique_sentiment_dict
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def prepare_unique_sentiment_dict(self, df, t=0.01):
sentiment_dict = [{}, {}, {}]
count_dict = [{}, {}, {}]
us = enchant.Dict("en_US")
en = enchant.Dict("en_GB")
s = stopwords.words('english')
l = len(df)
df.apply(
lambda x: self.make_word_dict_unique_per_review(x, sentiment_dict,
count_dict, us, en,
s), axis=1)
for i in range(len(count_dict)):
for w in count_dict[i]:
if count_dict[i][w] < t * l or len(w) < 4 or (
i == 0 and w in s):
del sentiment_dict[i][w]
return sentiment_dict, count_dict
示例2: set_language
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def set_language(self, language):
print("Language changed to: %s" % language)
# handle 2 char cases e.g. "en"
if len(language) == 2:
if "en":
language = "en_US"
if self.language == language:
return
self.language = language
print("Language changing")
config_file = get_media_path("pressagio_config.ini")
pres_config = configparser.ConfigParser()
pres_config.read(config_file)
pres_config.set("Database", "database",
get_media_path("corpora/" + self.language + ".sqlite"))
self.context_tracker = pressagio.context_tracker.ContextTracker(
pres_config, self.predictor_registry, self.callback)
self.prsgio = self.predictor_registry[0]
self.enchant_dict = enchant.Dict(self.language)
示例3: __init__
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def __init__(self, textview, textbuffer):
self.text_view = textview
self.buffer = textbuffer
self.suggestion = ""
self.bubble = self.bubble_label = None
self.buffer.connect_after('insert-text', self.text_insert)
self.text_view.connect('key-press-event', self.key_pressed)
self.language = "en_US"
self.frequency_dict = {}
self.get_frequency_dict(self.language)
self.enchant_dict = enchant.Dict(self.language)
self.use_pressagio = False
config_file = get_media_path("pressagio_config.ini")
pres_config = configparser.ConfigParser()
pres_config.read(config_file)
pres_config.set("Database", "database",
get_media_path("corpora/" + self.language + ".sqlite"))
self.callback = PressagioCallback("")
self.predictor_registry = pressagio.predictor.PredictorRegistry(pres_config)
self.context_tracker = pressagio.context_tracker.ContextTracker(
pres_config, self.predictor_registry, self.callback)
self.prsgio = self.predictor_registry[0]
示例4: __init__
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def __init__(self, lang="en_US"):
self.checker = enchant.Dict(lang)
示例5: open
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def open(self):
self.initialized = False
self.private_dict_file = None
if enchant is None:
return
dict_name = self.config.spelling_dict
if not dict_name:
return
self.ignore_list = [w.strip() for w in self.config.spelling_ignore_words.split(",")]
# "param" appears in docstring in param description and
# "pylint" appears in comments in pylint pragmas.
self.ignore_list.extend(["param", "pylint"])
# Expand tilde to allow e.g. spelling-private-dict-file = ~/.pylintdict
if self.config.spelling_private_dict_file:
self.config.spelling_private_dict_file = os.path.expanduser(
self.config.spelling_private_dict_file)
if self.config.spelling_private_dict_file:
self.spelling_dict = enchant.DictWithPWL(
dict_name, self.config.spelling_private_dict_file)
self.private_dict_file = open(
self.config.spelling_private_dict_file, "a")
else:
self.spelling_dict = enchant.Dict(dict_name)
if self.config.spelling_store_unknown_words:
self.unknown_words = set()
self.tokenizer = get_tokenizer(dict_name,
chunkers=[ForwardSlashChunkder],
filters=[EmailFilter,
URLFilter,
WikiWordFilter,
WordsWithDigigtsFilter,
WordsWithUnderscores,
CamelCasedWord,
SphinxDirectives])
self.initialized = True
示例6: spell_check
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def spell_check(input_question):
pattern = "\w"
prog = re.compile(pattern)
input_question_word_list = input_question.split()
en_dict = enchant.Dict("en_US")
for word_index in input_question_word_list:
if (not en_dict.check(input_question_word_list[word_index]) and
prog.match(input_question_word_list[word_index]) is None):
correct_word = spell(input_question_word_list[word_index])
input_question_word_list[word_index] = correct_word
return " ".join(input_question_word_list)
示例7: split
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def split(word, language='en_us'):
dictionary = enchant.Dict(language)
max_index = len(word)
for index, char in enumerate(word):
left_compound = word[0:max_index-index]
right_compound_1 = word[max_index-index:max_index]
right_compound_2 = word[max_index-index+1:max_index]
if right_compound_1:
right_compound1_upper = right_compound_1[0].isupper()
if right_compound_2:
right_compound2_upper = right_compound_2[0].isupper()
if index > 0 and len(left_compound) > 1 and not dictionary.check(left_compound):
left_compound = __capitalize_first_char(left_compound)
is_left_compound_valid_word = len(left_compound) > 1 and dictionary.check(left_compound)
if is_left_compound_valid_word and \
((not split(right_compound_1, language) == '' and not right_compound1_upper) \
or right_compound_1 == ''):
return [compound for compound in __concat(left_compound, split(right_compound_1, language))\
if not compound == '']
elif is_left_compound_valid_word and word[max_index-index:max_index-index+1] == 's' and \
((not split(right_compound_2, language) == '' and not right_compound2_upper) \
or right_compound_2 == ''):
return [compound for compound in __concat(left_compound, split(right_compound_2, language))\
if not compound == '']
if not word == '' and dictionary.check(word):
return [word]
elif not word == '' and dictionary.check(__capitalize_first_char(word)):
return [__capitalize_first_char(word)]
else:
return ''
示例8: suggest
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def suggest(self):
if re.sub(r'[a-zA-Z\d\'\-\.\s]', '', self.word):
return None
import enchant
try:
d = enchant.DictWithPWL(
'en_US', path + '/data/spell-checker/american-english-large')
except:
d = enchant.Dict('en_US')
suggestion = d.suggest(self.word)
return suggestion
示例9: __init__
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def __init__(self, settings, lang="en_US"):
self.settings = settings
self.dict_spelling = enchant.Dict(lang)
self.cache = set(self.uimsgs)
cache = self.settings.SPELL_CACHE
if cache and os.path.exists(cache):
with open(cache, 'rb') as f:
self.cache |= set(pickle.load(f))
示例10: load_dict
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def load_dict(dict_name, target_package):
try:
return enchant.Dict(dict_name)
except enchant.errors.DictNotFoundError:
raise ImportError(
("No enchant-compatible dictionary found for {0!r}. " +
"Consider installing {1!r}").format(dict_name, target_package))
示例11: __init__
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def __init__(self, lang='en_US', threshold=50, debug=False, beep=False):
if threshold not in range(0, 101):
error("threshold must be between 0 and 100")
self.lang = lang
self.percentage_success = threshold
self.debug = debug
self.beep = beep
self.d = enchant.Dict(lang)
示例12: select_language
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def select_language(self, language):
try:
self._language = enchant.Dict(language)
except enchant.DictNotFoundError:
err = 'Enchant Backend: No language for "%s"' % (language, )
raise NoSuchLangError(err)
示例13: initSpellchecker
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def initSpellchecker(self):
# TODO: disable spellchecker icon in case of not working enchant
try:
import enchant
spellDictDir = settings.get('spellchecker:directory')
if spellDictDir:
if enchant.__ver_major__ >= 1 and enchant.__ver_minor__ >= 6:
enchant.set_param("enchant.myspell.dictionary.path",
spellDictDir)
else:
print("Your pyenchant version is to old. Please " \
"upgrade to version 1.6.0 or higher, if you want " \
"to use spellchecker.")
return None
spellLang = settings.get('spellchecker:lang')
if spellLang in enchant.list_languages():
# enchant.dict_exists(spellLang) do now work for me on linux...
self.dict = enchant.Dict(spellLang)
else:
# try dictionary based on the current locale
try:
self.dict = enchant.Dict()
settings.set('spellchecker:lang', self.dict.tag)
except: # we don not have working dictionary...
return None
if self.dict:
self.usePWL(self.dict)
except:
print("can not start spellchecker!!!")
import traceback
traceback.print_exc()
return None
示例14: check_with_enchant
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def check_with_enchant(words, languages,
threshold=0.7, min_words=1, dictionaries={}):
"""Check against installed spelling dictionaries.
"""
if len(words) < min_words:
return UNKNOWN
best_score = 0
best_tag = UNKNOWN
for tag, enchant_tag in get_enchant_base_languages_dict().items():
if tag not in languages:
continue
try:
d = dictionaries[tag]
except KeyError:
d = dictionaries[tag] = enchant.Dict(enchant_tag)
score = sum([1 for word in words if d.check(word)])
if score > best_score:
best_score = score
best_tag = tag
if float(best_score) / len(words) < threshold:
return UNKNOWN
return best_tag
示例15: english_test
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def english_test(string):
dict_en = enchant.Dict("en_US")
words = string.split()
wcount = 0
for word in words :
if(dict_en.check(word)) :
wcount +=1
pass
pass
return wcount