[英]How can I know through similarity how specific string is included in the sentence?
我如何通过相似性知道句子中如何包含特定字符串?
ex) sentence :社区在这里可以帮助您解决特定的编码、算法或语言问题。
特定字符串:算法
相似度:0.8248242(算法-算法)
现在,我正在使用 Python 和水母。 我打算在 Outlook 中检查邮件主题并根据特定的字符串列表对其进行分类。
帮我.................
尝试这个 ?
import string
from difflib import SequenceMatcher
def similarity(a, b): # EDIT WITH YOU OWN SIMILARITY OF NOT CORRECT
return SequenceMatcher(None, a, b).ratio()
def max_similar(sentence, string_to_find):
result = ["", 0]
# Remove punctuation
sentence = sentence.translate(str.maketrans('', '', string.punctuation))
# split to list
sentence = sentence.split()
for word in sentence:
coeff = similarity(word, string_to_find)
if coeff > result[1]:
result[0] = word
result[1] = coeff
return result
print(max_similar("The community is here to help you with specific coding, algorithm, or language problems.", "algorism"))
结果 :
['algorithm', 0.8235294117647058]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.