Skip to content

Commit c099cee

Browse files
committed
Use syntaxnet-wrapper
Migrates to Docker installation
1 parent 1f2df20 commit c099cee

File tree

7 files changed

+32
-252
lines changed

7 files changed

+32
-252
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM gliacloud/syntaxnet
2+
3+
COPY * /usr/src/api/
4+
RUN cd /usr/src/api && pip install -r requirements.txt
5+
6+
ENV PORT 7000
7+
EXPOSE $PORT
8+
9+
CMD cd /usr/src/api && gunicorn flask_server:app

README.md

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,18 @@ SyntaxNet API
33

44
A small HTTP API for SyntaxNet under Apache 2 Licence.
55
Live version at [http://syntaxnet.askplatyp.us](http://syntaxnet.askplatyp.us).
6+
It relies on [https://github.com/livingbio/syntaxnet_wrapper](syntaxnet_wrapper).
67

7-
Currently only provides a way to call Parsey trained with universal dependencies.
8-
9-
The API documentation is availlable as a Swagger API description in the swagger.yaml file.
10-
11-
Are available languages with the following Universal Dependencies training sets:
12-
13-
* grc: Ancient_Greek-PROIEL
14-
* eu: Basque
15-
* bg: Bulgarian
16-
* zh: Chinese
17-
* hr: Croatian
18-
* cs: Czech
19-
* da: Danish
20-
* nl: Dutch
21-
* en: English
22-
* et: Estonian
23-
* fi: Finnish
24-
* fr: French
25-
* gl: Galician
26-
* de: German
27-
* el: Greek
28-
* he: Hebrew
29-
* hi: Hindi
30-
* hu: Hungarian
31-
* id: Indonesian
32-
* it: Italian
33-
* la: Latin-PROIEL
34-
* no: Norwegian
35-
* pl: Polish
36-
* pt: Portuguese
37-
* sl: Slovenian
38-
* es: Spanish
39-
* sv: Swedish
8+
Currently only provides a way to call Parsey McParseface and it universal dependencies version.
409

4110
## Install
4211

43-
On Debian/Ubuntu
12+
Docker is currently the only supported installation way:
4413

4514
```
46-
git clone --recursive --recurse-submodules https://github.com/askplatypus/syntaxnet-api
15+
git clone https://github.com/askplatypus/syntaxnet-api
4716
cd syntaxnet-api
48-
sh install-syntaxnet-debian.sh
49-
pip3 install -r requirements.txt
50-
python3 flask_server.py
17+
docker build . -t syntaxnet-api
5118
```
19+
20+
It creates a new Docker image called `syntaxnet-api` exposing the service on port 7000.

flask_server.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright 2016 Thomas Pellissier Tanon All Rights Reserved.
2+
Copyright 2016-2017 Thomas Pellissier Tanon All Rights Reserved.
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
@@ -14,40 +14,38 @@
1414

1515
from flask import Flask, request, jsonify, redirect
1616
from flask_swaggerui import build_static_blueprint, render_swaggerui
17-
from werkzeug.exceptions import BadRequest
18-
19-
import parsey
17+
from syntaxnet_wrapper import parser, language_code_to_model_name
18+
from werkzeug.exceptions import BadRequest, InternalServerError
2019

2120
# Flask setup
22-
_flask_app = Flask(__name__)
21+
app = Flask(__name__)
2322
logging.basicConfig(level=logging.INFO)
2423

2524

26-
@_flask_app.route('/')
25+
@app.route('/')
2726
def _root():
2827
return redirect('/v1')
2928

3029

31-
@_flask_app.route('/v1')
30+
@app.route('/v1')
3231
def _v1():
3332
return render_swaggerui(swagger_spec_path='/v1/swagger.json')
3433

3534

36-
@_flask_app.route('/v1/parsey-universal-full', methods=['POST'])
35+
@app.route('/v1/parsey-universal-full', methods=['POST'])
3736
def _parsey_universal_full_handler():
3837
text = request.get_data()
3938
language_code = request.headers.get('Content-Language', 'en').lower()
40-
print(text)
41-
print(language_code)
42-
4339
try:
44-
conllu = parsey.parsey_universal_full_conllu(text, language_code)
45-
return _flask_app.response_class(conllu, mimetype='text/plain; charset=utf-8')
40+
conllu = parser[language_code].query(text, returnRaw=True)
41+
if conllu is None:
42+
raise InternalServerError('Bad SyntaxNet output')
43+
return app.response_class(conllu, mimetype='text/plain; charset=utf-8')
4644
except ValueError as e:
4745
raise BadRequest(e)
4846

4947

50-
@_flask_app.route('/v1/swagger.json')
48+
@app.route('/v1/swagger.json')
5149
def _v1_spec():
5250
return jsonify({
5351
'swagger': '2.0',
@@ -83,7 +81,7 @@ def _v1_spec():
8381
'description': 'The text language.',
8482
'required': True,
8583
'type': 'string',
86-
'enum': sorted(parsey.available_languages.keys())
84+
'enum': sorted(language_code_to_model_name.keys())
8785
}
8886
],
8987
'consumes': [
@@ -106,6 +104,7 @@ def _v1_spec():
106104
})
107105

108106

109-
_flask_app.register_blueprint(build_static_blueprint('swaggerui', __name__))
107+
app.register_blueprint(build_static_blueprint('swaggerui', __name__))
110108

111-
_flask_app.run(port=7000)
109+
if __name__ == '__main__':
110+
app.run(port=7000)

install-syntaxnet-debian.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

parsey.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

tensorflow-models

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)