Reputation: 13
How can I know through similarity how specific string is included in the sentence??
ex) sentence : The community is here to help you with specific coding, algorithm, or language problems.
specific string : algorism
similarity : 0.8248242 (algorism - algorithm)
Now, I'm using Python&jellyfish. What I am planning is to check the mail subject in Outlook and classify it based on a specific string list.
HELP ME.................
Upvotes: 1
Views: 47
Reputation: 250
Try this ?
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"))
Result :
['algorithm', 0.8235294117647058]
Upvotes: 1