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


Python enchant.Dict方法代码示例

本文整理汇总了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 
开发者ID:laugustyniak,项目名称:textlytics,代码行数:21,代码来源:generate_lexicons_and_results.py

示例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) 
开发者ID:ApostropheEditor,项目名称:Apostrophe,代码行数:25,代码来源:auto_correct.py

示例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] 
开发者ID:ApostropheEditor,项目名称:Apostrophe,代码行数:27,代码来源:auto_correct.py

示例4: __init__

# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import Dict [as 别名]
def __init__(self, lang="en_US"):
        self.checker = enchant.Dict(lang) 
开发者ID:chakki-works,项目名称:typot,代码行数:4,代码来源:spell_checker.py

示例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 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:43,代码来源:spelling.py

示例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) 
开发者ID:5hirish,项目名称:adam_qas,代码行数:15,代码来源:qa_init.py

示例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 '' 
开发者ID:TimKam,项目名称:compound-word-splitter,代码行数:32,代码来源:compound_word_splitter.py

示例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 
开发者ID:caspartse,项目名称:python-translate,代码行数:13,代码来源:translate.py

示例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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:utils_spell_check.py

示例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)) 
开发者ID:wikimedia,项目名称:revscoring,代码行数:9,代码来源:util.py

示例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) 
开发者ID:Carleslc,项目名称:CryptTools,代码行数:10,代码来源:validator.py

示例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) 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:8,代码来源:spelling_enchant.py

示例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 
开发者ID:zdenop,项目名称:lector,代码行数:36,代码来源:textwidget.py

示例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 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:28,代码来源:__init__.py

示例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 
开发者ID:smxlabs,项目名称:gibbersense,代码行数:16,代码来源:string_scan.py


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