Reputation: 2441
I am trying to use semantic matching in Python on a group of words.
['error 1', '14_7error', 'err_87P', 'configuration 49-ñ', 'confi:p2g%']
['error 1,14_7error,err_87P', 'configuration 49-ñ','confi:p2g%']
I have tried using sklearn
, but can get it to work, code:
from sklearn.feature_extraction.text import TfidfVectorizer
documents = ['error 1', '14_7error', 'err_87P', 'configuration 49-ñ', 'confi:p2g%']
tfidf = TfidfVectorizer().fit_transform(documents)
pairwise_similarity = (tfidf * tfidf.T).toarray()
I have also looked at:
But none of it has helped much.
Upvotes: 1
Views: 829
Reputation: 9639
Looking at your input data, it seems that your goal is not semantic matching, but string matching. You can use fuzzywuzzy to do that:
from fuzzywuzzy import process
documents = ['error 1', '14_7error', 'err_87P', 'configuration 49-ñ', 'confi:p2g%']
results = [[i, process.extractOne(i, [x for x in documents if x != i])] for i in documents]
Results for best matches with matching score:
[['error 1', ('14_7error', 71)], ['14_7error', ('error 1', 71)], ['err_87P', ('error 1', 43)], ['configuration 49-ñ', ('confi:p2g%', 60)], ['confi:p2g%', ('configuration 49-ñ', 60)]]
Upvotes: 2