63

私はfuzzywuzzyPythonで学んでいます。

fuzz.ratiofuzz.partial_ratiofuzz.token_sort_ratioおよびの概念を理解していfuzz.token_set_ratioます。私の質問は、どの機能をいつ使用するかです。

  • 最初に 2 つの文字列の長さを確認し、類似していない場合は除外しfuzz.partial_ratioますか?
  • 2 つの文字列の長さが似ている場合は、 fuzz.token_sort_ratio? を使用します。
  • 常に使用する必要がありますfuzz.token_set_ratioか?

SeatGeek が使用する基準を知っている人はいますか?

fuzzywuzzy住所の比較に使用することを考えて、不動産のウェブサイトを構築しようとしています。

4

2 に答える 2

28

2017 年 6 月現在、fuzzywuzzyその他の比較関数もいくつか含まれています。受け入れられた回答に欠けているものの概要を次に示します(ソースコードから取得):

fuzz.partial_token_sort_ratio

と同じアルゴリズムですが、トークンのソート後token_sort_ratioに適用する代わりに、 を使用します。ratiopartial_ratio

fuzz.token_sort_ratio("New York Mets vs Braves", "Atlanta Braves vs New York Mets")
> 85
fuzz.partial_token_sort_ratio("New York Mets vs Braves", "Atlanta Braves vs New York Mets")
> 100    
fuzz.token_sort_ratio("React.js framework", "React.js")
> 62
fuzz.partial_token_sort_ratio("React.js framework", "React.js")
> 100

fuzz.partial_token_set_ratio

と同じアルゴリズムですが、トークンのセットにtoken_set_ratio適用する代わりに、 を使用します。ratiopartial_ratio

fuzz.token_set_ratio("New York Mets vs Braves", "Atlanta vs New York Mets")
> 82
fuzz.partial_token_set_ratio("New York Mets vs Braves", "Atlanta vs New York Mets")
> 100    
fuzz.token_set_ratio("React.js framework", "Reactjs")
> 40
fuzz.partial_token_set_ratio("React.js framework", "Reactjs")
> 71   

fuzz.QRatio、fuzz.UQRatio

fuzz.ratio完全を期すためにここに含まれている、いくつかの検証と短絡を含む 単なるラッパーです。UQRatioのユニコード版ですQRatio

fuzz.WRatio

重み付け (名前は「加重比率」の略) の試行は、「最良の」スコアを計算するためのさまざまなアルゴリズムから生じます。ソースコードからの説明:

1. Take the ratio of the two processed strings (fuzz.ratio)
2. Run checks to compare the length of the strings
    * If one of the strings is more than 1.5 times as long as the other
      use partial_ratio comparisons - scale partial results by 0.9
      (this makes sure only full results can return 100)
    * If one of the strings is over 8 times as long as the other
      instead scale by 0.6
3. Run the other ratio functions
    * if using partial ratio functions call partial_ratio,
      partial_token_sort_ratio and partial_token_set_ratio
      scale all of these by the ratio based on length
    * otherwise call token_sort_ratio and token_set_ratio
    * all token based comparisons are scaled by 0.95
      (on top of any partial scalars)
4. Take the highest value from these results
   round it and return it as an integer.

fuzz.UWRatio

のユニコード版WRatio

于 2017-06-13T19:43:26.060 に答える