1
2
3
4
5
6
7
8
9
10
11
12
13 from nltk.parse import ParserI
14 import nltk
15
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 """
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
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