How to recognize Named Entity from a python list using Stanford NERTagger

Viewed 373

I am a beginner in NLP and first time using StanfordNERTagger. For learning purpose I am playing with Stanford NERTagger. I have a python list of country name

['France', 'India', 'Bangladesh', 'England', 'Germany', 'Brazil', 'Egypt', 'Bhutan', 'Srilanka']

I want to get 'location' entity which belongs to NERTagger but i am getting the 'Organization' Entity

[('France', 'ORGANIZATION'), ('India', 'ORGANIZATION'), ('Bangladesh', 'ORGANIZATION'), ('England', 'ORGANIZATION'), ('Germany', 'ORGANIZATION'), ('Brazil', 'ORGANIZATION'), ('Egypt', 'ORGANIZATION'), ('Bhutan', 'ORGANIZATION'), ('Srilanka', 'ORGANIZATION')]

May be i am missing something here

1 Answers

Firs you need to install Stanford NER on your comp. Depending of OS, both procedures how to configure Stanford ner tagger

Now take a look at this sample code

import nltk
from nltk.tokenize.toktok import ToktokTokenizer
from nltk.tag import StanfordNERTagger
stanford_classifier = os.environ.get('STANFORD_MODELS').split(':')[0]
stanford_ner_path = os.environ.get('CLASSPATH').split(':')[0]
st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')

Check st

<nltk.tag.stanford.StanfordNERTagger at 0x7f897c44e6d8>

My sentance

sentence = u'France is the biggest county in EU'
words = nltk.word_tokenize(sentence)
st.tag(words)

Result

[('France', 'LOCATION'),
 ('is', 'O'),
 ('the', 'O'),
 ('biggest', 'O'),
 ('county', 'O'),
 ('in', 'O'),
 ('EU', 'LOCATION')]
Related