MCPcopy Create free account
hub / github.com/clips/pattern / synsets

Function synsets

pattern/text/en/wordnet/__init__.py:90–110  ·  view source on GitHub ↗

Returns a list of Synset objects, one for each word sense. Each word can be understood in different "senses", each of which is part of a set of synonyms (= Synset).

(word, pos=NOUN)

Source from the content-addressed store, hash-verified

88 "NN", "VB", "JJ", "RB"
89
90def synsets(word, pos=NOUN):
91 """ Returns a list of Synset objects, one for each word sense.
92 Each word can be understood in different "senses",
93 each of which is part of a set of synonyms (= Synset).
94 """
95 word, pos = normalize(word), pos.lower()
96 try:
97 if pos.startswith(NOUN.lower()): # "NNS" or "nn" will also pass.
98 w = wn.N[word]
99 elif pos.startswith(VERB.lower()):
100 w = wn.V[word]
101 elif pos.startswith(ADJECTIVE.lower()):
102 w = wn.ADJ[word]
103 elif pos.startswith(ADVERB.lower()):
104 w = wn.ADV[word]
105 else:
106 raise TypeError, "part of speech must be NOUN, VERB, ADJECTIVE or ADVERB, not %s" % repr(pos)
107 return [Synset(s.synset) for i, s in enumerate(w)]
108 except KeyError:
109 return []
110 return []
111
112class Synset(object):
113

Callers 1

__init__Method · 0.85

Calls 2

normalizeFunction · 0.70
SynsetClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…