我刚开始使用nltk图书馆。我想找到两个最相似的字符串。在这样做时,我使用了“bleu_score”,如下所示:
import nltk
from nltk.translate import bleu
from nltk.translate.bleu_score import SmoothingFunction
smoothie = SmoothingFunction().method4```
C1 = 'FISSEN Ltds'
C2 = 'FISSEN Ltds Maschinen- und Werkzeugbau'
C3 = 'V.R.P. Baumaschinen Ltds'
print('BLEUscore1:',bleu([C1], C2, smoothing_function=smoothie, auto_reweigh=False))
print('BLEUscore2:',bleu([C2], C3, smoothing_function=smoothie, auto_reweigh=False))
print('BLEUscore3:',bleu([C1], C3, smoothing_function=smoothie, auto_reweigh=False))输出如下:
BLEUscore1: 0.2585784506653774
BLEUscore2: 0.26042143846335913
BLEUscore3: 0.1472821272412462我不知道为什么结果显示C2和C3之间的相似性最好,而C1和C2是最好的答案。那么,如何最好地评估两个字符串之间的相似性,它们的答案是C1和C2?
(我感谢你能提供的任何帮助:)
发布于 2022-09-24 08:59:39
您可以尝试使用SequenceMatcher;
from difflib import SequenceMatcher
C1 = 'FISSEN Ltds'
C2 = 'FISSEN Ltds Maschinen- und Werkzeugbau'
C3 = 'V.R.P. Baumaschinen Ltds'
print(SequenceMatcher(None, C1, C2).ratio())
print(SequenceMatcher(None, C2, C3).ratio())
print(SequenceMatcher(None, C1, C3).ratio())
# Output ->
# 0.4489795918367347
# 0.3548387096774194
# 0.2857142857142857希望这能帮上忙。
https://stackoverflow.com/questions/73835778
复制相似问题