Hello, As I think more about this exercise I am beginning to believe
that the exercise is asking me to find the offset of the first synset
of each word in a text rather than the offset of the first sunset of
each word in WordNet. That being the case I changed my code to:
class SymanticIndexedText(object):
def __init__(self):
self._text = nltk.corpus.webtext.words('grail.txt')
from nltk.corpus import wordnet as wn
self._wn = wn
self._index = nltk.Index((self._wn.synsets(word)[0].offset, i)
for (i, word) in
enumerate(self._text))
Here I used the same text as in Example 3-1
(nltk.corpus.webtext.words('grail.txt')). When I run this I get the
following error:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
SymanticIndexedText()
File "/Users/georgeorton/textproc3.py", line 598, in __init__
for (i, word) in enumerate(self._text))
File "/Library/Python/2.7/site-packages/nltk/util.py", line 118, in
__init__
for key, value in pairs:
File "/Users/georgeorton/textproc3.py", line 598, in <genexpr>
for (i, word) in enumerate(self._text))
IndexError: list index out of range
It seems to me that the argument for nltk.Index that I am using
(self._wn.synsets(word)[0].offset, i)
for (i, word) in
enumerate(self._text)
is similar to a list comprehension where (self._wn.synsets(word)
[0].offset, i) is being returned for each word in the enumerated text.
I don't see how my list index is out of range if I am just stepping
through each word in my text. I may just be holding a conversation
with myself here but if anybody has any thoughts I'd appreciate
hearing them. Sincerely, George