Introduction to Natural Language Processing in Python
Katharine Jarmul
Founder, kjamistan
(Source: Europeana Newspapers (http://www.europeana-newspapers.eu))
nltk
import nltk sentence = '''In New York, I like to ride the Metro to visit MOMA and some restaurants rated well by Ruth Reichl.''' tokenized_sent = nltk.word_tokenize(sentence)
tagged_sent = nltk.pos_tag(tokenized_sent)
tagged_sent[:3]
[('In', 'IN'), ('New', 'NNP'), ('York', 'NNP')]
print(nltk.ne_chunk(tagged_sent))
(S
In/IN
(GPE New/NNP York/NNP)
,/,
I/PRP
like/VBP
to/TO
ride/VB
the/DT
(ORGANIZATION Metro/NNP)
to/TO
visit/VB
(ORGANIZATION MOMA/NNP)
and/CC
some/DT
restaurants/NNS
rated/VBN
well/RB
by/IN
(PERSON Ruth/NNP Reichl/NNP)
./.)
Introduction to Natural Language Processing in Python