| 375 | } |
| 376 | |
| 377 | def 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 | |
| 407 | def get_adjectives(text): |
| 408 | doc = nlp(text) |