natural language toolkit chunk parsing api c 20012023 nltk project edward loper edlopergmail com steven bird stevenbird1gmail com minor additions url https www nltk org for license information see license txt chunk parser interface a processing interface for identifying nonoverlapping groups in unrestricted text typically chunk parsers are used to find base syntactic constituents such as base noun phrases unlike parseri chunkparseri guarantees that the parse method will always generate a parse return the best chunk structure for the given tokens and return a tree param tokens the list of word tag tokens to be chunked type tokens listtuple rtype tree score the accuracy of the chunker against the gold standard remove the chunking the gold standard text rechunk it using the chunker and return a chunkscore object reflecting the performance of this chunk parser type gold listtree param gold the list of chunked sentences to score the chunker on rtype chunkscore natural language toolkit chunk parsing api c 2001 2023 nltk project edward loper edloper gmail com steven bird stevenbird1 gmail com minor additions url https www nltk org for license information see license txt chunk parser interface a processing interface for identifying non overlapping groups in unrestricted text typically chunk parsers are used to find base syntactic constituents such as base noun phrases unlike parseri chunkparseri guarantees that the parse method will always generate a parse return the best chunk structure for the given tokens and return a tree param tokens the list of word tag tokens to be chunked type tokens list tuple rtype tree score the accuracy of the chunker against the gold standard remove the chunking the gold standard text rechunk it using the chunker and return a chunkscore object reflecting the performance of this chunk parser type gold list tree param gold the list of chunked sentences to score the chunker on rtype chunkscore
from nltk.chunk.util import ChunkScore
from nltk.internals import deprecated
from nltk.parse import ParserI


class ChunkParserI(ParserI):
    

    def parse(self, tokens):
        
        raise NotImplementedError()

    @deprecated("Use accuracy(gold) instead.")
    def evaluate(self, gold):
        return self.accuracy(gold)

    def accuracy(self, gold):
        
        chunkscore = ChunkScore()
        for correct in gold:
            chunkscore.score(correct, self.parse(correct.leaves()))
        return chunkscore