python类get_close_matches()的实例源码

__init__.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    close_commands = get_close_matches(name, commands.keys())

    if close_commands:
        guess = close_commands[0]
    else:
        guess = False

    return guess
__init__.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
thx.py 文件源码 项目:beproudbot 作者: beproud 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def find_thx(s, text):
    """Slack?????????????thx???????

    :param s: sqlalchemy.orm.session.Session
    :param str text: ???????????
    :return dict word_map_names_dict:
       ???thx??????????Slack????????
    :return list hint_names: Slack??????????????????
    :return list not_matched: Slack???????????????????
    """
    word_map_names_dict = {}
    hint_names = []
    not_matched = []

    thx_matcher = re.compile('(?P<user_names>.+)[ \t\f\v]*\+\+[ \t\f\v]+(?P<word>.+)',
                             re.MULTILINE)
    for thx in thx_matcher.finditer(text):
        user_names = [x for x in thx.group('user_names').split(' ') if x]
        for name in user_names:
            if get_user_name(name.lstrip('<@').rstrip('>')):
                slack_id = name.lstrip('<@').rstrip('>')
            else:
                slack_id = get_slack_id(s, name)

            if slack_id:
                word_map_names_dict.setdefault(
                    thx.group('word'), []
                ).append((slack_id, name))
            else:
                # ????????????
                hint = get_close_matches(name, get_users_info().values())
                if hint:
                    hint_names.append(hint[0])
                # ?????????????????
                else:
                    not_matched.append(name)

    return word_map_names_dict, hint_names, not_matched
__init__.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
corrector.py 文件源码 项目:isthislegit 作者: duo-labs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def suggest(word, cutoff=0.77):
    """
    Given a domain and a cutoff heuristic, suggest an alternative or return the
    original domain if no suggestion exists.
    """
    if word in LOOKUP_TABLE:
        return LOOKUP_TABLE[word]

    guess = difflib.get_close_matches(word, MOST_COMMON_DOMAINS, n=1, cutoff=cutoff)
    if guess and len(guess) > 0:
        return guess[0]
    return word
spell.py 文件源码 项目:bay 作者: eventbrite 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def spell_correct(input, choices, threshold=0.6):
        """
        Find a possible spelling correction for a given input.
        """
        guesses = difflib.get_close_matches(input, choices, 1, cutoff=threshold)
        return next(iter(guesses), None)
__init__.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
utils.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_best_similar(data):
    import difflib
    key, use_similar, similar_pool = data

    # try to find some close key in existing messages...
    # Optimized code inspired by difflib.get_close_matches (as we only need the best match).
    # We also consider to never make a match when len differs more than -len_key / 2, +len_key * 2 (which is valid
    # as long as use_similar is not below ~0.7).
    # Gives an overall ~20% of improvement!
    #tmp = difflib.get_close_matches(key[1], similar_pool, n=1, cutoff=use_similar)
    #if tmp:
        #tmp = tmp[0]
    tmp = None
    s = difflib.SequenceMatcher()
    s.set_seq2(key[1])
    len_key = len(key[1])
    min_len = len_key // 2
    max_len = len_key * 2
    for x in similar_pool:
        if min_len < len(x) < max_len:
            s.set_seq1(x)
            if s.real_quick_ratio() >= use_similar and s.quick_ratio() >= use_similar:
                sratio = s.ratio()
                if sratio >= use_similar:
                    tmp = x
                    use_similar = sratio
    return key, tmp
__init__.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
kifield.py 文件源码 项目:KiField 作者: xesscorp 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def lc_get_close_matches(lbl, possibilities, num_matches=3, cutoff=0.6):
    '''Return list of closest matches to lbl from possibilities (case-insensitive).'''

    if USING_PYTHON2:
        lc_lbl = str.lower(unicode(lbl))
        lc_possibilities = [str.lower(unicode(p)) for p in possibilities]
    else:
        lc_lbl = str.lower(lbl)
        lc_possibilities = [str.lower(p) for p in possibilities]
    lc_matches = get_close_matches(lc_lbl, lc_possibilities, num_matches, cutoff)
    return [possibilities[lc_possibilities.index(m)] for m in lc_matches]
__init__.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:isni-reconcile 作者: cmh2166 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:habilitacion 作者: GabrielBD 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    name = name.lower()

    close_commands = get_close_matches(name, commands_dict.keys())

    if close_commands:
        return close_commands[0]
    else:
        return False
__init__.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_similar_commands(name):
    """Command name auto-correct."""
    from difflib import get_close_matches

    close_commands = get_close_matches(name, commands.keys())

    if close_commands:
        guess = close_commands[0]
    else:
        guess = False

    return guess
sniper.py 文件源码 项目:PokemonGo-Bot 作者: PokemonGoF 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _get_closest_name(self, name):
        if not name:
            return

        pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
        closest_names = difflib.get_close_matches(name, pokemon_names, 1)

        if closest_names:
            closest_name = closest_names[0]
            return closest_name

        return name

# Represents the JSON params mappings
pokemon_optimizer.py 文件源码 项目:PokemonGo-Bot 作者: PokemonGoF 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_closest_name(self, name):
        mapping = {ord(x): ord(y) for x, y in zip("\u2641\u2642.-", "fm  ")}
        clean_names = {n.lower().translate(mapping): n for n in self.pokemon_names}
        closest_names = difflib.get_close_matches(name.lower().translate(mapping), clean_names.keys(), 1)

        if closest_names:
            closest_name = clean_names[closest_names[0]]

            if name != closest_name:
                self.logger.warning("Unknown Pokemon name [%s]. Assuming it is [%s]", name, closest_name)

            return closest_name
        else:
            raise ConfigException("Unknown Pokemon name [%s]" % name)
matchdata.py 文件源码 项目:StarCraft-Casting-Tool 作者: teampheenix 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __selectMyTeam(self, string):
        teams = [self.getTeam(0).lower(), self.getTeam(1).lower()]
        matches = difflib.get_close_matches(string.lower(), teams, 1)
        if(len(matches) == 0):
            return 0
        elif(matches[0] == teams[0]):
            return -1
        else:
            return 1


问题


面经


文章

微信
公众号

扫码关注公众号