nltk/nltk — Issue #148: CategorizedCorpusReader categories() when using fileids and the document has only one category
Author: alexrudnick
Created: 2012-01-17 06:27:10+00:00
State: open

What version of NLTK are you using? (See nltk.__version__). Please only
submit bug reports for the current version.

'2.0b9'

What steps will reproduce the problem? (e.g. include Python source code)

from nltk.corpus import reuters
reuters.categories()[:5]
['acq', 'alum', 'barley', 'bop', 'carcass']
reuters.fileids()[:5]
['test/14826', 'test/14828', 'test/14829', 'test/14832', 'test/14833']
reuters.categories('test/14826')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/nltk-2.0b9-py2.5.egg/nltk/corpus/reader/api.py", line 338, in categories
return sorted(set.union(*[self._f2c[d] for d in fileids]))
TypeError: union() takes exactly one argument (0 given)
reuters.categories(['test/14826'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/nltk-2.0b9-py2.5.egg/nltk/corpus/reader/api.py", line 338, in categories
return sorted(set.union(*[self._f2c[d] for d in fileids]))
TypeError: union() takes exactly one argument (0 given)
reuters.categories(['test/14826',''])
['trade']
reuters.categories(['test/14826','test/14828'])
['grain', 'trade']

What is the expected output? What do you see instead?

List of categories for a text document

List of categories for the document

Please use labels and text to provide additional information.

it seems to be a problem with categories in CategorizedCorpusReader, when a fileid is passed and it has only one Categorie, set.union throw the error.

Migrated from http://code.google.com/p/nltk/issues/detail?id=659

earlier comments

StevenBird1 said, at 2011-08-08T09:51:25.000Z:

This is not a problem in Python 2.6, but shows up in Python 2.5 (and NLTK is supposed to work for Python 2.5).