diff --git a/README.md b/README.md index 9e2c46a..ea53031 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ **Ready-to-use Docker images for the [spaCy NLP library](https://github.com/explosion/spaCy).** +--- +**[spaCy API Docker](https://github.com/jgontrum/spacy-api-docker) is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial** + + +[GitAds](https://tracking.gitads.io/?repo=spacy-api-docker) +--- + ### Features - Use the awesome spaCy NLP framework with other programming languages. @@ -101,7 +108,7 @@ displaCy frontend is available here. --- -### `POST` `/dep/` +### `POST` `/dep` Example request: @@ -251,7 +258,7 @@ curl -s localhost:8000/dep -d '{"text":"Pastafarians are smarter than people wit --- -### `POST` `/ent/` +### `POST` `/ent` Example request: @@ -307,11 +314,13 @@ curl -s localhost:8000/ent -d '{"text":"Pastafarians are smarter than people wit { "end": 12, "start": 0, + "text": "Pastafarians", "type": "NORP" }, { "end": 51, "start": 42, + "text": "Coca Cola", "type": "ORG" } ] @@ -319,7 +328,7 @@ curl -s localhost:8000/ent -d '{"text":"Pastafarians are smarter than people wit --- -### `POST` `/sents/` +### `POST` `/sents` Example request: @@ -358,9 +367,9 @@ Example response: --- -### `POST` `/sents_dep/` +### `POST` `/sents_dep` -Combination of `/sents/` and `/dep/`, returns sentences and dependency parses +Combination of `/sents` and `/dep`, returns sentences and dependency parses Example request: @@ -618,7 +627,7 @@ Example response: --- -### `GET` `/{model}/schema/` +### `GET` `/{model}/schema` Example request: @@ -656,6 +665,6 @@ Example response: ```json { - "spacy": "1.9.0" + "spacy": "2.2.4" } ``` diff --git a/displacy_service/parse.py b/displacy_service/parse.py index 910711b..d204590 100644 --- a/displacy_service/parse.py +++ b/displacy_service/parse.py @@ -45,6 +45,15 @@ def to_json(self): 'text': str(word), 'dir': 'right' }) + else: + arcs.append( + { + 'start': word.head.i, + 'end': word.i, + 'label': word.dep_, + 'text': str(word), + 'dir': 'root' + }) return {'words': words, 'arcs': arcs} @@ -123,6 +132,15 @@ def to_json(self): 'text': str(word), 'dir': 'right' }) + else: + arcs.append( + { + 'start': word.head.i, + 'end': word.i, + 'label': word.dep_, + 'text': str(word), + 'dir': 'root' + }) sents.append({'sentence': sent.string.strip(), 'dep_parse': {'words': words, diff --git a/displacy_service/server.py b/displacy_service/server.py index 288e8af..5eead8c 100644 --- a/displacy_service/server.py +++ b/displacy_service/server.py @@ -191,8 +191,8 @@ def on_post(self, req, resp): json_data = json.loads(req_body.decode('utf8')) text = json_data.get('text') model_name = json_data.get('model', 'en') - collapse_punctuation = json_data.get('collapse_punctuation', False) - collapse_phrases = json_data.get('collapse_phrases', False) + collapse_punctuation = json_data.get('collapse_punctuation', True) + collapse_phrases = json_data.get('collapse_phrases', True) try: model = get_model(model_name) diff --git a/displacy_service_tests/test_server.py b/displacy_service_tests/test_server.py index 2b52c32..e8dd968 100644 --- a/displacy_service_tests/test_server.py +++ b/displacy_service_tests/test_server.py @@ -59,6 +59,26 @@ def test_sents_dep(api): ["Is", "this", "the", "third", "?"], ] + arcs = [[arc for arc in sp['dep_parse']['arcs']] for sp in sentence_parse.json] + assert arcs == [[{'start': 0, 'end': 2, 'label': 'det', 'text': 'This', 'dir': 'left'}, + {'start': 1, 'end': 2, 'label': 'det', 'text': 'a', 'dir': 'left'}, + {'start': 2, 'end': 2, 'label': 'ROOT', 'text': 'test', 'dir': 'root'}, + {'start': 3, 'end': 5, 'label': 'nsubj', 'text': 'that', 'dir': 'left'}, + {'start': 4, 'end': 5, 'label': 'aux', 'text': 'should', 'dir': 'left'}, + {'start': 2, 'end': 5, 'label': 'relcl', 'text': 'split', 'dir': 'right'}, + {'start': 5, 'end': 6, 'label': 'prep', 'text': 'into', 'dir': 'right'}, + {'start': 6, 'end': 7, 'label': 'pobj', 'text': 'sentences', 'dir': 'right'}, + {'start': 2, 'end': 8, 'label': 'punct', 'text': '!', 'dir': 'right'}], + [{'start': 9, 'end': 10, 'label': 'nsubj', 'text': 'This', 'dir': 'left'}, + {'start': 10, 'end': 10, 'label': 'ROOT', 'text': 'is', 'dir': 'root'}, + {'start': 11, 'end': 12, 'label': 'det', 'text': 'the', 'dir': 'left'}, + {'start': 10, 'end': 12, 'label': 'attr', 'text': 'second', 'dir': 'right'}, + {'start': 10, 'end': 13, 'label': 'punct', 'text': '.', 'dir': 'right'}], + [{'start': 14, 'end': 14, 'label': 'ROOT', 'text': 'Is', 'dir': 'root'}, + {'start': 14, 'end': 15, 'label': 'nsubj', 'text': 'this', 'dir': 'right'}, + {'start': 16, 'end': 17, 'label': 'det', 'text': 'the', 'dir': 'left'}, + {'start': 14, 'end': 17, 'label': 'attr', 'text': 'third', 'dir': 'right'}, + {'start': 14, 'end': 18, 'label': 'punct', 'text': '?', 'dir': 'right'}]] @pytest.mark.parametrize('endpoint, expected_message', [ ('/dep', 'Dependency parsing failed'), diff --git a/frontend/_data.json b/frontend/_data.json index e607634..41d383d 100644 --- a/frontend/_data.json +++ b/frontend/_data.json @@ -1,6 +1,6 @@ { "index": { - "api": "/dep/", + "api": "/dep", "default_language": "", "description": "Visualise spaCy's guess at the syntactic structure of a sentence. Arrows point from children to heads, and are labelled by their relation type.", "github": "explosion/displacy",