2017 年 6 月現在、fuzzywuzzy
その他の比較関数もいくつか含まれています。受け入れられた回答に欠けているものの概要を次に示します(ソースコードから取得):
fuzz.partial_token_sort_ratio
と同じアルゴリズムですが、トークンのソート後token_sort_ratio
に適用する代わりに、 を使用します。ratio
partial_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
適用する代わりに、 を使用します。ratio
partial_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
。