Package nltk :: Package chunk :: Module api
[hide private]
[frames] | no frames]

Source Code for Module nltk.chunk.api

 1  # Natural Language Toolkit: Chunk parsing API 
 2  # 
 3  # Copyright (C) 2001-2011 NLTK Project 
 4  # Author: Edward Loper <edloper@gradient.cis.upenn.edu> 
 5  #         Steven Bird <sb@csse.unimelb.edu.au> (minor additions) 
 6  # URL: <http://www.nltk.org/> 
 7  # For license information, see LICENSE.TXT 
 8   
 9  ##////////////////////////////////////////////////////// 
10  ##  Chunk Parser Interface 
11  ##////////////////////////////////////////////////////// 
12   
13  from nltk.parse import ParserI 
14  import nltk 
15   
16 -class ChunkParserI(ParserI):
17 """ 18 A processing interface for identifying non-overlapping groups in 19 unrestricted text. Typically, chunk parsers are used to find base 20 syntactic constituants, such as base noun phrases. Unlike 21 L{ParserI}, C{ChunkParserI} guarantees that the C{parse} method 22 will always generate a parse. 23 """
24 - def parse(self, tokens):
25 """ 26 @return: the best chunk structure for the given tokens 27 and return a tree. 28 29 @param tokens: The list of (word, tag) tokens to be chunked. 30 @type tokens: C{list} of L{tuple} 31 @rtype: L{Tree} 32 """ 33 assert 0, "ChunkParserI is an abstract interface"
34
35 - def evaluate(self, gold):
36 """ 37 Score the accuracy of the chunker against the gold standard. 38 Remove the chunking the gold standard text, rechunk it using 39 the chunker, and return a L{ChunkScore<nltk.chunk.util.ChunkScore>} 40 object reflecting the performance of this chunk peraser. 41 42 @type gold: C{list} of L{Tree} 43 @param gold: The list of chunked sentences to score the chunker on. 44 @rtype: L{ChunkScore<nltk.chunk.util.ChunkScore>} 45 """ 46 chunkscore = nltk.chunk.util.ChunkScore() 47 for correct in gold: 48 chunkscore.score(correct, self.parse(correct.leaves())) 49 return chunkscore
50