【问题标题】:Is there a way to do fuzzy string matching for words on string?有没有办法对字符串上的单词进行模糊字符串匹配?
【发布时间】:2021-01-04 12:10:48
【问题描述】:

我想对带有单词的字符串进行模糊匹配。

目标字符串可能是这样的。 “你好,我今天去看电影。”
我要搜索的词在哪里。
“flim toda”。

这有望返回“今日电影”作为搜索结果。

我用过这种方法,但似乎只能用一个词。

import difflib

def matches(large_string, query_string, threshold):
    words = large_string.split()
    matched_words = []
    for word in words:
        s = difflib.SequenceMatcher(None, word, query_string)
        match = ''.join(word[i:i+n] for i, j, n in s.get_matching_blocks() if n)
        if len(match) / float(len(query_string)) >= threshold:
            matched_words.append(match)
    return matched_words
large_string = "Hello, I am going to watch a film today"
query_string = "film"
print(list(matches(large_string, query_string, 0.8)))

这仅适用于一个单词,并且在噪音很小时返回。

有什么办法可以对单词进行这种模糊匹配吗?

【问题讨论】:

    标签: python nlp full-text-search string-matching fuzzy-search


    【解决方案1】:

    您正在考虑的功能称为“查询建议”,它确实依赖于拼写检查,但它依赖于基于搜索引擎查询日志构建的马尔可夫链。

    话虽如此,您使用的方法类似于此答案中描述的方法:https://stackoverflow.com/a/58166648/140837

    【讨论】:

      猜你喜欢
      • 2014-03-04
      • 2012-02-14
      • 2014-11-02
      • 1970-01-01
      • 2017-08-03
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      相关资源
      最近更新 更多