import nltk
from nltk.corpus import wordnet as wn
synsets = wn.synsets('killed','v')
sense=synsets[0]
Here sense is of the type nltk.corpus.reader.wordnet.Synset. It outputs Synset('kill.v.01'). When I try using senti wordnet
k = sentiwordnet.senti_synset('kill.v.01')
print(k)
This outputs the positive and negative scores of 'kill'.
My question is- How can I make use of sense(from code snippet 1) in code snippet 2? When I tried using it directly it threw this error lemma, pos, synset_index_str = name.lower().rsplit('.', 2) AttributeError: 'Synset' object has no attribute 'lower'
Synset properties can be returned with the get functions within the Synset objects, e.g.
>> from nltk.corpus import wordnet as wn
>>> wn.synsets('dog')
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]
>>> dog = wn.synsets('dog')[0]
>>> dog.definition()
u'a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds'
>>> dog.lemma_names()
[u'dog', u'domestic_dog', u'Canis_familiaris']
>>> dog.pos()
u'n'
>>> dog.offset()
2084071
>>> dog.name()
u'dog.n.01'
If you want to keep an index of the synset name, POS and synset ID, use tne synset.name()
which returns a unicode
string:
>>> type(dog.name())
<type 'unicode'>
>>> name, pos, sid = dog.name().split('.')
>>> name
u'dog'
>>> pos
u'n'
>>> sid
u'01'
These are the modules and variables that the Synset
object can access:
>>> dir(dog)
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_all_hypernyms', '_definition', '_examples', '_frame_ids', '_hypernyms', '_instance_hypernyms', '_iter_hypernym_lists', '_lemma_names', '_lemma_pointers', '_lemmas', '_lexname', '_max_depth', '_min_depth', '_name', '_needs_root', '_offset', '_pointers', '_pos', '_related', '_shortest_hypernym_paths', '_wordnet_corpus_reader', 'also_sees', 'attributes', 'causes', 'closure', 'common_hypernyms', 'definition', 'entailments', 'examples', 'frame_ids', 'hypernym_distances', 'hypernym_paths', 'hypernyms', 'hyponyms', 'instance_hypernyms', 'instance_hyponyms', 'jcn_similarity', 'lch_similarity', 'lemma_names', 'lemmas', 'lexname', 'lin_similarity', 'lowest_common_hypernyms', 'max_depth', 'member_holonyms', 'member_meronyms', 'min_depth', 'name', 'offset', 'part_holonyms', 'part_meronyms', 'path_similarity', 'pos', 'region_domains', 'res_similarity', 'root_hypernyms', 'shortest_path_distance', 'similar_tos', 'substance_holonyms', 'substance_meronyms', 'topic_domains', 'tree', 'unicode_repr', 'usage_domains', 'verb_groups', 'wup_similarity']