문제

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!

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top