Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**


[<img src="https://images.gitads.io/spacy-api-docker" alt="GitAds"/>](https://tracking.gitads.io/?repo=spacy-api-docker)
---

### Features

- Use the awesome spaCy NLP framework with other programming languages.
Expand Down Expand Up @@ -101,7 +108,7 @@ displaCy frontend is available here.

---

### `POST` `/dep/`
### `POST` `/dep`

Example request:

Expand Down Expand Up @@ -251,7 +258,7 @@ curl -s localhost:8000/dep -d '{"text":"Pastafarians are smarter than people wit

---

### `POST` `/ent/`
### `POST` `/ent`

Example request:

Expand Down Expand Up @@ -307,19 +314,21 @@ 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"
}
]
```

---

### `POST` `/sents/`
### `POST` `/sents`

Example request:

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -618,7 +627,7 @@ Example response:

---

### `GET` `/{model}/schema/`
### `GET` `/{model}/schema`

Example request:

Expand Down Expand Up @@ -656,6 +665,6 @@ Example response:

```json
{
"spacy": "1.9.0"
"spacy": "2.2.4"
}
```
18 changes: 18 additions & 0 deletions displacy_service/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions displacy_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions displacy_service_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion frontend/_data.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down