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


Python fuzz.ratio方法代码示例

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


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

示例1: tieBreak

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def tieBreak(self, query, i, j):
        """
        當去除停用詞後導致兩個字串的匹配度一樣時,從原文裡挑選出更適合的

        Args:
            - query: 使用者的輸入
            - i: index 為 i 的 title
            - j: index 為 j 的 title

        Return: (target, index)
            - target: 較適合的標題
            - index : 該標題的 id
        """
        raw1 = self.titles[i]
        raw2 = self.titles[j]

        r1 = fuzz.ratio(query, raw1)
        r2 = fuzz.ratio(query, raw2)

        if r1 > r2:
            return (raw1,i)
        else:
            return (raw2,j) 
开发者ID:zake7749,项目名称:Chatbot,代码行数:25,代码来源:fuzzyMatcher.py

示例2: test_ratio

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def test_ratio():
    """Test Korean-specific fuzzy search."""

    assert fuzz.ratio('강', '공') == 0
    assert ratio('강', '공') == 67

    assert fuzz.ratio('안녕', '인형') == 0
    assert ratio('안녕', '인형') == 67

    assert fuzz.ratio('사당', 'ㅅㄷ') == 0
    assert ratio('사당', 'ㅅㄷ') == 57

    assert fuzz.ratio('사당', 'ㅏㅏ') == 0
    assert ratio('사당', 'ㅏㅏ') == 57

    assert fuzz.ratio('사당', 'ㅅㅏㄷㅏㅇ') == 0
    assert ratio('사당', 'ㅅㅏㄷㅏㅇ') == 80 
开发者ID:item4,项目名称:yui,代码行数:19,代码来源:fuzz_test.py

示例3: is_mispelling

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def is_mispelling(self, token1, token2):
        mis_t1 = set(self.get_misspellings(token1))
        mis_t2 = set(self.get_misspellings(token2))
        common = mis_t1.intersection(mis_t2).difference({''})  # Difference in case '' included in tokens

        if len(common) > 0:
            return True

        # Misspellings only really make sense if the tokens are words not numbers
        if token1.isalpha() and token2.isalpha():
            if fuzz.ratio(token1, token2) > self.fuzz_ratio_threshold:
                return True

        try:
            t1f = float(token1)
            t2f = float(token2)
            if max(t1f, t2f)/min(t1f, t2f) < self.number_fuzz_threshold:
                return True

        except (ValueError, ZeroDivisionError):
            pass



        return False 
开发者ID:RobinL,项目名称:fuzzymatcher,代码行数:27,代码来源:tokencomparison.py

示例4: get_fixture_channels

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def get_fixture_channels(self, events, fixture):
    chann = []
    items = []

    for item in events:
      evnt = item['event']
      comp = fuzz.ratio(fixture.competition.name, evnt['competition'])
      home = fuzz.ratio(fixture.home_team.name, evnt['home'])
      away = fuzz.ratio(fixture.away_team.name, evnt['away'])
      comb = (comp + home + away) / 3

      items.append({ 'ratio': comb, 'channels': item['channels'] })

    if items:
      sort = sorted(items, key=itemgetter('ratio'), reverse=True)[0]

      if sort['ratio'] > 70:
        chann = self.data.get_multiple('channel', 'name', sort['channels'])
        chann = [c.id for c in chann]

    return chann 
开发者ID:jonian,项目名称:kickoff-player,代码行数:23,代码来源:streams.py

示例5: ratio

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def ratio(string_a, string_b):
        """At the most basic level, return a Levenshtein distance ratio via
        fuzzywuzzy.
        :param string_a: str
        :param string_b: str
        :return: float
        """
        from cltk.utils.cltk_logger import logger
        try:
            from fuzzywuzzy import fuzz

        except ImportError as imp_err:  # pragma: no cover
            message = "'fuzzywuzzy' library required for this module: %s. Install with " \
                      "`pip install fuzzywuzzy python-Levenshtein`" % imp_err
            logger.error(message)
            print(message)
            raise ImportError

        return fuzz.ratio(string_a, string_b) / 100 
开发者ID:cltk,项目名称:cltk,代码行数:21,代码来源:levenshtein.py

示例6: similar_string_fast

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def similar_string_fast(first_string, second_string):
    """Determine if two strings are similar (using two most effective methods).

    Params:
    - first_string: (type: string) first string.
    - second_string: (type: string) second string.

    Returns:
    - result: (type: bool) match result.
    """
    partial_score = fuzz.ratio(first_string, second_string)
    token_score = fuzz.token_set_ratio(first_string, second_string)

    if max(partial_score, token_score) >= SCORE_THRESHOLD_FAST:
        return True

    return False 
开发者ID:phage-nz,项目名称:ph0neutria,代码行数:19,代码来源:string_utils.py

示例7: _get_page

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def _get_page(self, topic, request_options=None):
        topics_list = self.get_topics_list()
        if topic.startswith(':'):
            topics_list = [x for x in topics_list if x.startswith(':')]
        else:
            topics_list = [x for x in topics_list if not x.startswith(':')]

        if _USING_FUZZYWUZZY:
            possible_topics = process.extract(topic, topics_list, scorer=fuzz.ratio)[:3]
        else:
            possible_topics = process.extract(topic, topics_list, limit=3, scorer=fuzz.ratio)
        possible_topics_text = "\n".join([("    * %s %s" % x) for x in possible_topics])
        return """
Unknown topic.
Do you mean one of these topics maybe?

%s
    """ % possible_topics_text 
开发者ID:chubin,项目名称:cheat.sh,代码行数:20,代码来源:internal.py

示例8: findItemName

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def findItemName(self, itemDictionary, messageItem):

		bestScore = 0
		score = 0
		bestItem = None

		try:
			for itemName, itemLabel in list(itemDictionary.items()):
				score = fuzz.ratio(messageItem, itemLabel)
				if score > bestScore:
					bestScore = score
					bestItem = itemName
		except KeyError:
                    pass

		return bestItem 
开发者ID:openhab,项目名称:openhab-mycroft,代码行数:18,代码来源:__init__.py

示例9: normalize

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def normalize(self,string):
        original_string = string
        string = string.lower()
        if string[0] == 'x':
            if len(string) == 1:
                return 'tak'
            result_string = 'tak '
            string = string[1:]
        else:
            result_string = ''
        results = []
        for i in range(len(self.user)):
            total = 0
            for k in self.user[i]: total += fuzz.ratio(string, k)
            results.append(total)
        if len(np.where(np.array(results) > 60)[0]) < 1:
            return original_string
        ids = np.argmax(results)
        return result_string + self.corpus[ids] 
开发者ID:huseinzol05,项目名称:Python-DevOps,代码行数:21,代码来源:main.py

示例10: normalize

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def normalize(self, string):
        original_string = string
        string = string.lower()
        if string[0] == 'x':
            if len(string) == 1:
                return 'tak'
            result_string = 'tak '
            string = string[1:]
        else:
            result_string = ''
        results = []
        for i in range(len(self.user)):
            total = 0
            for k in self.user[i]:
                total += fuzz.ratio(string, k)
            results.append(total)
        if len(np.where(np.array(results) > 60)[0]) < 1:
            return original_string
        ids = np.argmax(results)
        return result_string + self.corpus[ids] 
开发者ID:huseinzol05,项目名称:Python-DevOps,代码行数:22,代码来源:main.py

示例11: _expand_df

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def _expand_df(df):
    """
    Add alternate forms to DataFrame, then sort DataFrame by alias length
    (for order of extraction from text) and similarity to original name (in
    order to select most appropriate term to associate with alias).
    """
    df = df.copy()
    df['alias'] = df['alias'].apply(uk_to_us)
    new_rows = []
    for index, row in df.iterrows():
        alias = row['alias']
        alt_forms = _gen_alt_forms(alias)
        for alt_form in alt_forms:
            temp_row = row.copy()
            temp_row['alias'] = alt_form
            new_rows.append(temp_row.tolist())
    alt_df = pd.DataFrame(columns=df.columns, data=new_rows)
    df = pd.concat((df, alt_df), axis=0)
    # Sort by name length and similarity of alternate form to preferred term
    # For example, "task switching" the concept should take priority over the
    # "task switching" version of the "task-switching" task.
    df['length'] = df['alias'].str.len()
    df['ratio'] = df[['alias', 'name']].apply(_get_ratio, axis=1)
    df = df.sort_values(by=['length', 'ratio'], ascending=[False, False])
    return df 
开发者ID:neurostuff,项目名称:NiMARE,代码行数:27,代码来源:utils.py

示例12: _create_fuzzy_wuzzy_features

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def _create_fuzzy_wuzzy_features(self, df):
        df['fuzzy_ratio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.ratio(row['spn_1'], row['spn_2']), axis=1)
        df['fuzzy_set_ratio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.token_set_ratio(row['spn_1'], row['spn_2']), axis=1)
        df['fuzzy_partial_ratio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.partial_ratio(row['spn_1'], row['spn_2']), axis=1)
        df['fuzzy_token_sort_ratio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.token_sort_ratio(row['spn_1'], row['spn_2']), axis=1)
        df['fuzzy_qratio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.QRatio(row['spn_1'], row['spn_2']), axis=1)
        df['fuzzy_WRatio'] = df[['spn_1', 'spn_2']].apply(lambda row: fuzz.WRatio(row['spn_1'], row['spn_2']), axis=1)
   
        def _get_longest_substr_ratio(a, b):
            strs = list(distance.lcsubstrings(a, b))
            if len(strs) == 0:
                return 0
            else:
                return len(strs[0]) / (min(len(a), len(b)) + 1)

        df['longest_substr_ratio'] = df[['spn_1', 'spn_2']].apply(lambda row: _get_longest_substr_ratio(row['spn_1'], row['spn_2']), axis=1) 
开发者ID:zake7749,项目名称:CIKM-AnalytiCup-2018,代码行数:18,代码来源:feature_engineering.py

示例13: find_near_matches

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def find_near_matches(w, sentence):
    ret = []
    max_ratio = 0
    t = 0
    for word in sentence.split():
        while sentence[t] != word[0]:
            t += 1
        score = (fuzz.ratio(w, word) + fuzz.partial_ratio(w, word)) / 2
        if score > max_ratio:
            max_ratio = score
            ret = [(t, t + len(word))]
        elif score == max_ratio:
            ret.append((t, t + len(word)))
        else:
            pass
        t += len(word)
    return ret if max_ratio > 85 else [] 
开发者ID:THUDM,项目名称:CogQA,代码行数:19,代码来源:process_train.py

示例14: check_name

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def check_name(self, ctx, team, name):
        """Checks the name of the team"""
        tba_parser = ctx.cog.tba_parser
        ftc_teams = ctx.cog.ftc_teams

        actual_name = ""

        if self.mode == "frc":
            # check for existence
            team_data = tba_parser.get_team(team)
            try:
                getattr(team_data, "Errors")
            except tbapi.InvalidKeyError:
                """There is no error, so do nothing"""
            else:
                return -1
            actual_name = team_data.nickname
        elif self.mode == "ftc":
            if team not in ftc_teams:
                return -1
            actual_name = ftc_teams[team]

        self.last_name = actual_name
        self.last_team = team
        return fuzz.ratio(actual_name.lower(), name.lower()) 
开发者ID:FRCDiscord,项目名称:Dozer,代码行数:27,代码来源:namegame.py

示例15: fitness

# 需要导入模块: from fuzzywuzzy import fuzz [as 别名]
# 或者: from fuzzywuzzy.fuzz import ratio [as 别名]
def fitness(agents):

    for agent in agents:

        agent.fitness = fuzz.ratio(agent.string, in_str)

    return agents 
开发者ID:tmsquill,项目名称:simple-ga,代码行数:9,代码来源:simple-ga.py


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