【问题标题】:Are there any algorithms that would find the closest match to a string from a collection of strings?是否有任何算法可以从字符串集合中找到与字符串最接近的匹配项?
【发布时间】:2012-04-27 10:19:28
【问题描述】:

是否有任何算法可以从字符串集合中找到与字符串最接近的匹配项?例如:

string_to_match = 'What color is the sky?'

strings = [
  'What colour is the sea?', 
  'What colour is the sky?', 
  'What colour is grass?', 
  'What colour is earth?'
]

answer = method_using_string_matching_algorithm(string_to_match, strings)
answer # returns strings[1] 'What colour is the sky?'

【问题讨论】:

标签: string algorithm match


【解决方案1】:

您要查找的搜索词是“字符串距离算法”和“近似字符串匹配”。快速浏览一下 Google 会发现一些有趣的选项,例如:

  • Sift3 距离
  • 列文斯坦距离
  • 最佳字符串对齐距离
  • Damerau-Levenshtein 距离
  • Qwerty 键盘距离

一些有用的链接包括:

在撰写本文时,基于 Debian 的 Linux 发行版还在其存储库中包含 agrep 和 TRE-agrep

【讨论】:

  • 感谢关键字和链接。我一直在使用 Ruby Amatch gem,其中包括 Levenshtein flori.github.com/amatch
  • @Neil 不客气。我总是很乐意提供帮助。如果您觉得有用,请采纳答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-13
  • 1970-01-01
  • 2017-03-29
  • 1970-01-01
  • 2018-06-22
  • 2023-01-11
相关资源
最近更新 更多