forked from UKPLab/props-de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_server.py
49 lines (36 loc) · 1.23 KB
/
parse_server.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
44
45
46
47
48
49
#!/usr/bin/env python
#coding:utf8
import os.path, sys, time, datetime
import codecs
from cStringIO import StringIO
from subprocess import call
from bottle import route, run, get, post, request, response, static_file
from nltk.tokenize.punkt import PunktSentenceTokenizer
from propsde.applications.run import loadParser, parseSentences
from propsde.visualizations.brat_visualizer import BratVisualizer
try:
PORT = int(sys.argv[1])
except:
PORT = 8081
sent_tokenizer = PunktSentenceTokenizer()
@get('/gparse')
def gparse():
print "in gparse"
input = request.GET.get('text').strip().decode("utf8")
print input
sents = sent_tokenizer.tokenize(input)
gs = parseSentences(sents[:1])
g,tree = gs[0]
b = BratVisualizer()
ret = b.to_html(g)
ret = ret.replace('PROPOSITIONS_STUB', '<br>'.join([unicode(prop) for prop in g.getPropositions('html')]))
print "returning...."
return ret
@route('/brat/<filename:path>')
def server_static(filename):
return static_file(filename, root='./propsde/visualizations/brat')
@route('/<filename>')
def server_static(filename):
return static_file(filename, root='./propsde/webinterface')
loadParser()
run(host='',port=PORT)