# NLP grouping word categories

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

• 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? Feb 27, 2018 at 19:20
• @KasraManshaei yes, like the example I added above Feb 27, 2018 at 21:21

## 1 Answer

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!