For a project, I would like to measure the number of "person-oriented words" in the text. I plan to do this using WordNet. I have never used it, and I'm not quite sure how to approach this task. I want to use WordNet to count the number of words related to specific synsets, for example, sysnets 'human and' person.
I came up with the following (simple) piece of code:
word = 'girlfriend'
word_synsets = wn.synsets(word)[0]
hypernyms = word_synsets.hypernym_paths()[0]
for element in hypernyms:
print element
Results in:
Synset('entity.n.01')
Synset('physical_entity.n.01')
Synset('causal_agent.n.01')
Synset('person.n.01')
Synset('friend.n.01')
Synset('girlfriend.n.01')
My first question is: how to properly sort hypernim? The above code prints them just fine. However, when using an if if statement, for example:
count_humancenteredness = 0
for element in hypernyms:
if element == 'person':
print 'found person hypernym'
count_humancenteredness +=1
'AttributeError: ' str ' ' _name '. (, ), .
-, ? , . , WordNet .
!