NLP | Proper Noun Extraction
Chunking all proper nouns (tagged with NNP) is a very simple way to perform named entity extraction. A simple grammar that combines all proper nouns into a NAME chunk can be created using the RegexpParser class.
Then, we can test this on the first tagged sentence of treebank_chunk to compare the results with the previous recipe:
Code #1 : Testing it on the first tagged sentence of treebank_chunk
Named Entities : [[('Pierre', 'NNP'), ('Vinken', 'NNP')], [('Nov.', 'NNP')]]
Note : The code above returns all the proper nouns – ‘Pierre’, ‘Vinken’, ‘Nov.’
NAME chunker is a simple usage of the RegexpParser class. All sequences of NNP tagged words are combined into NAME chunks.
PersonChunker class can be used if one only want to chunk the names of people.
Code #2 : PersonChunker class
PersonChunker class checks whether each word is in its names_set (constructed from the names corpus) by iterating over the tagged sentence. It either uses B-PERSON or I-PERSON IOB tags if the current word is in the names_set, depending on whether the previous word was also in the names_set. O IOB tag is assigned to the word that’s not in the names_set argument. IOB tags list is converted to a Tree using
conlltags2tree() after completion.
Code #3 : Using PersonChunker class on the same tagged sentence
Person name : [[('Pierre', 'NNP')]]