python - Wordnet Synonyms not returning all values nltk -
i trying synonyms or similar words using nltk's wordnet not returning.
i doing:
>>> nltk.corpus import wordnet wn >>> wn.synsets('swap') [synset('barter.n.01'), synset('trade.v.04'), synset('swap.v.02')]
i tried doing (from 1 of stackoverflow page):
>>> ss in wn.synsets('swap'): sim in ss.similar_tos(): print(' {}'.format(sim))
but not getting synonyms. not want add synonyms wordnet. expecting return exchange,interchange, substitute etc.
how achieve this?
thanks
abhi
to synonyms using wordnet
, this:
>>> nltk.corpus import wordnet wn >>> synset in wn.synsets('swap'): lemma in synset.lemmas(): print lemma.name(), barter swap swop trade trade swap swop switch swap # note overlap between synsets
to obtain of words mentioned, may have include hypernyms well:
>>> synset in wn.synsets('swap'): hypernym in synset.hypernyms(): ss in hypernym.lemmas(): # need iterate through each synset returned synset.hypernyms() print ss.name(), exchange interchange exchange change interchange travel go move locomote # again, overlap
Comments
Post a Comment