-
Notifications
You must be signed in to change notification settings - Fork 1
/
posTaggeRpy2.r
48 lines (39 loc) · 1.35 KB
/
posTaggeRpy2.r
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
# convert to R with rPython
# raw python version
import nltk
import sys
from nltk.tokenize import RegexpTokenizer
sentence = "I am the walrus. I am the eggman. The man eats the apple. Ivan shot the bear."
for arg in sys.argv:
print arg
sentences = nltk.sent_tokenize(arg)
print(sentences)
tokenizer = RegexpTokenizer(r'\w+')
for sentence in sentences:
# tokens = nltk.word_tokenize(sentence)
# print(tokens)
tokens = tokenizer.tokenize(sentence)
tagged = nltk.pos_tag(tokens)
print(tagged)
entities = nltk.ne_chunk(tagged)
print(entities)
######### SNIP SNIP######################
#########################################
#########################################
# R version ----------- INCOMPLETE!!!
python.exec("import nltk")
python.exec("import sys")
python.exec("from nltk.tokenize import RegexpTokenizer")
python.exec("sentence = \"I am the walrus. I am the eggman. The man eats the apple. Ivan shot the bear.\"")
python.exec("for arg in sys.argv: print arg
sentences = nltk.sent_tokenize(arg)
print(sentences)
tokenizer = RegexpTokenizer(r'\w+')")
python.exec("for sentence in sentences:
# tokens = nltk.word_tokenize(sentence)
# print(tokens)
tokens = tokenizer.tokenize(sentence)
tagged = nltk.pos_tag(tokens)
print(tagged)
entities = nltk.ne_chunk(tagged)
print(entities)")