Reputation: 341
I have a list of words like teacher, professor, lecturer. I want to find all such similar meaning words in my list and count them under a TEACHER category. And I have many such different categories. How can I find similar meaning words in python? Any idea? Before I was simply searching by words like:
def Make_cluster(title,w1,w2,w3,w4,w5,w6):
try:
print(title," ******")
chartTitles.append(title)
afinn= Afinn()
count=0
totalC=0
rows= extract_data('swansea')
for row in rows:
if w1 in row[0] :
totalC += 1
elif w2 in row[0]:
totalC += 1
elif w3 in row[0]:
totalC += 1
elif w4 in row[0]:
totalC += 1
elif w5 in row[0]:
totalC += 1
elif w6 in row[0]:
totalC += 1
print("Total aspects",totalC)
Make_cluster('TEACHING', 'lecturer', 'course', 'library', 'teacher', 'study ', 'research')
But the problem is the above function only search for words given in function, and I can not pass all those words in a function, as some categories may have 5, some 10, some 20.
Is there any way to find all similar words from a list?
Upvotes: -1
Views: 195
Reputation: 77495
Use a loop, and a list (or set). i.e.
count_words(data, ["a", "b", "c"])
and
def count_words(data, words):
...
for w in words:
...
Upvotes: 2