MCPcopy Create free account
hub / github.com/debjitpaul/refiner / get_synonyms_antonyms

Function get_synonyms_antonyms

data_preprocessing/utils.py:377–405  ·  view source on GitHub ↗
(word, top=2, pos="adj")

Source from the content-addressed store, hash-verified

375}
376
377def get_synonyms_antonyms(word, top=2, pos="adj"):
378 word = word.lower()
379 synonyms = []
380 antonyms = []
381
382 for syn in wordnet.synsets(word, pos=WN_POS_MAP[pos]):
383 for lem in syn.lemmas():
384 synonyms.append(lem.name())
385 for ant in lem.antonyms():
386 antonyms.append(ant.name())
387
388 top_syns = []
389 top_ants = []
390
391 for syn in synonyms:
392 if len(top_syns) == top:
393 break
394
395 if syn.lower().strip() != word:
396 top_syns.append(syn)
397
398 for ant in antonyms:
399 if len(top_ants) == top:
400 break
401
402 if ant.lower().strip() != word:
403 top_ants.append(ant)
404
405 return top_syns, top_ants
406
407def get_adjectives(text):
408 doc = nlp(text)

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected