1
$\begingroup$

Suppose I have a dictionary:

{apple:large apple, apple:red apple, apple:aple, orange:mandarin, orange:orang, orange:blood orange}

and so on...

And then I want to replace a large document of entries with the keys. However, occasionally a new value will come up, i.e. {apple:green apple}

Is there a method where I can replace all values with the corresponding key, but then also replace 'close' values like the one given if they appear?

Example document:

var1
_____
aple
apple
orange
Apple
Red apple
gren Apple
blood Orange
orang

var1_replaced
______________
apple
apple
orange
apple
apple
apple
orange
orange
$\endgroup$
  • $\begingroup$ Yes there is. Plz just clarify what "replace all values with the corresponding key" means? Can u update with a concrete example of input-output? $\endgroup$ – Kasra Manshaei Feb 27 '18 at 19:20
  • $\begingroup$ @KasraManshaei yes, like the example I added above $\endgroup$ – jchaykow Feb 27 '18 at 21:21
1
$\begingroup$

Well ... the simplest approach is using Fuzzy String Matching and it will work. Just go through the examples in python implementation of it (fuzzywuzzy) and you will understand how it works. You need to find a threshold by practice to determine if two strings are similar enough to be considered as same concept.

If it didn't work please drop a line in the comments so I can propose more sophisticated algorithms.

Good luck!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.