3

文字列のコレクションから文字列に最も近い一致を見つけるアルゴリズムはありますか? 例えば:

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?'
4

1 に答える 1

4

探している検索語は、「文字列距離アルゴリズム」と「近似文字列一致」です。Google を簡単にチェックすると、次のような興味深いオプションが見つかります。

  • Sift3 距離
  • レーベンシュタイン距離
  • 最適な弦の整列距離
  • ダメラウ・レーベンシュタイン距離
  • Qwerty キーボードの距離

次のような便利なリンクがあります。

これを書いている時点で、Debian ベースの Linux ディストリビューションには、リポジトリに agrep とTRE-agrepも含まれています。

于 2012-05-31T13:22:20.533 に答える