Tengo un conjunto de palabras question_roots
y me gustaría agregarle todos los sinónimos de las palabras de este conjunto.
Por ejemplo con question
: When did Beyonce start becoming popular?
obtengo question_roots
con tamizando
question_roots = [st.stem(chunk.root.head.text.lower()) for chunk in en_nlp(question).noun_chunks]
Y obtengo : [start]
.
Por lo momento intenté :
from itertools import chain
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet
print(question)
question_roots = [st.stem(chunk.root.head.text.lower()) for chunk in en_nlp(question).noun_chunks]
synonyms = []
synonyms += wordnet.synsets(word for word in question_roots)
print(synonyms)
Pero obtengo :
When did Beyonce start becoming popular?
['start']
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-132-e9c1e94c1799> in <module>()
10 synonyms = []
11 print(type(word) for word in question_roots)
---> 12 synonyms += wordnet.synsets(word for words in question_roots)
13 print(synonyms)
~/Documents/programming/mybot/mybotenv/lib/python3.5/site-packages/nltk/corpus/reader/wordnet.py in synsets(self, lemma, pos, lang, check_exceptions)
1531 of that language will be returned.
1532 """
-> 1533 lemma = lemma.lower()
1534
1535 if lang == 'eng':
AttributeError: 'generator' object has no attribute 'lower'
En efecto parece que word
en question_roots
son <generator object <genexpr> at 0x7fb2a9406780>