[Tutor] about nltk
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed May 28 13:11:49 2003
On Tue, 27 May 2003, Abdirizak abdi wrote:
> Hi,
> I was trying to play with python NLTK text classification tutorial , I
> can not run the following code even if the way I installed NLTK is
> correct, I cann't run the followingcode:
>
> >>> import nltk.classifier
> >>> test = nltk.classifier.LabeledText('test','q')
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> AttributeError: 'module' object has no attribute 'LabeledText'
Hi Abdirizak,
This is odd! This works for me:
###
>>> import nltk.classifier
>>> dir(nltk.classifier)
['ClassifierI', 'ClassifierTrainerI', 'ConfusionMatrix', 'LabeledText',
'Numeric', 'Token', '__builtins__', '__doc__', '__file__', '__name__',
'__path__', 'accuracy', 'find_labels', 'label_tokens', 'log_likelihood',
'math']
>>> nltk.classifier.LabeledText
<class nltk.classifier.LabeledText at 0x8179b64>
>>> nltk.classifier.LabeledText('text', 'q')
'text'/'q'
###
Just to check: what directory are you in when you tried to test your
example? What happens if you try:
###
import nltk
print nltk.__file__
###
Show us what the above prints out; it may clue us into why the import
isn't working. If your current directory is the nltk installation
directory, that can cause a problem, because the files in the current
directory may confuse Python's module system.