-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb_server.py
44 lines (26 loc) · 1.03 KB
/
web_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
import json
import pathlib
from bottle import route, run, request, template, post, get, static_file
from spacy import displacy
from pipeline.full_pipeline import full_pipeline
from pipeline.spacy_shared._spacy import spacify_with_coref
@post('/analyze')
def index():
body = request.body.read().decode("UTF-8")
return json.dumps({"text": body, "infos": full_pipeline(body)})
@get('/displacy')
def _displacy():
doc = spacify_with_coref(request.query['doc'])
return displacy.render(doc, style="dep")
@get('/tagging')
def _tagging():
doc = spacify_with_coref(request.query['doc'])
result = "<table>"
for word in doc:
result = result + f"<tr><td>{word.text}</td><td>{word.pos_}</td><td>{word.tag_}</td><td>{word.morph}</td><td>{word.lemma_}</td></tr>"
result = result + "</table>"
return result
@route('/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root=pathlib.Path(__file__).parent.joinpath("client").joinpath("build").resolve())
run(host='localhost', port=8080)