Question

I'm trying to implement a sentence chunker based on a Maxent Classifier, as described in the NLTK book (Example 7.9):

http://nltk.googlecode.com/svn/trunk/doc/book/ch07.html#code-classifier-chunker

When I try to evaluate the chunker with

chunker = ConsecutiveNPChunker(train_sents)
print chunker.evaluate(test_sents)

or to chunk a sentence with

print chunker.parse(test_sents[1])

I receive the following error:

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    print chunker.parse(test_sents[1])
  File "/usr/local/lib/python2.6/dist-packages/nltk/chunk/api.py", line 34, in parse
    assert 0, "ChunkParserI is an abstract interface"
AssertionError: ChunkParserI is an abstract interface

I didn't find anything on google and I'm stuck on this point. Any help would be really useful!

Was it helpful?

Solution

You evidently haven't implemented your chunker yet. "ChunkParserI is an abstract interface" means that you need to derive a class from it and define your own parse() method. The NLTK chapter you link to shows how to define an example class, ConsecutiveNPChunker.

The final step will be to create an instance of your new class and call its eval() method (which it inherits from ChunkParserI, so you don't to provide a replacement).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top