-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnltk_cheat.py
More file actions
executable file
·54 lines (36 loc) · 879 Bytes
/
nltk_cheat.py
File metadata and controls
executable file
·54 lines (36 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
"""
Natural language processing toolkit.
Homepage: http://www.nltk.org/
Source: https://github.com/nltk/nltk
Install:
sudo pip install nltk
To use ceratin functions, you must data files.
All data files can be downloaded with:
python -m nltk.downloader all
but that takes up 1.8Gb.
Download interactively with a GUI application:
python -c 'import nltk; nltk.download()'
"""
import nltk
sentence = """At eight o'clock on Thursday morning
Arthur didn't feel very good."""
print "Input:"
print sentence
print
print "#word_tokenize"
tokens = nltk.word_tokenize(sentence)
print str(tokens)
print
tagged = nltk.pos_tag(tokens)
print "#pos_tag"
print tagged
print
print "#entities"
entities = nltk.chunk.ne_chunk(tagged)
print entities
print
from nltk.corpus import treebank
t = treebank.parsed_sents('wsj_0001.mrg')[0]
t.draw()
print