-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnlpnet2go.py
43 lines (37 loc) · 1.13 KB
/
nlpnet2go.py
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
""" Este script eh um script chamador da biblioteca de NLP.
https://github.com/erickrf/nlpnet."""
import sys
import getopt
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser # ver. < 3.0
import nlpnet
CONFIG = ConfigParser()
CONFIG.read('setup.ini')
nlpnet.set_data_dir(CONFIG.get('attributes', 'setdatadir'))
TEXT = ''
METHOD = ''
try:
OPTS, ARGS = getopt.getopt(sys.argv[1:], "ht:m:", ["text=", "method="])
except getopt.GetoptError:
sys.exit(1)
for opt, arg in OPTS:
if opt == '-h':
print 'nlpnet2go.py -t <"text to be analyzed"> -m <method [''pos''] OR [''srl'']>'
print 'Eg.: python nlpnet2go.py -t "teste do edward" -m pos'
sys.exit()
elif opt in ("-t", "--text"):
TEXT = arg
elif opt in ("-m", "--method"):
METHOD = arg
if METHOD == "pos":
TAGGER = nlpnet.POSTagger()
print TAGGER.tag(TEXT)
elif METHOD == "srl":
TAGGER = nlpnet.SRLTagger()
SENT = TAGGER.tag(TEXT)[0]
print SENT.arg_structures
else:
print sys.argv[1:], "Invalid Tagger method operator. Only 'pos' OR 'srl' allowed."
# print sys.argv[1:]