Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

A docker container which runs SpaCy and NodeJS API

License

Notifications You must be signed in to change notification settings

jlundan/spacy-nodejs-alpine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This docker container runs spaCy behind NodeJS API allowing clients to communicate with spaCy via HTTP requests.

Prebuilt Docker images are available at https://hub.docker.com/r/jlundan/spacy-nodejs-alpine/

Supported tags and Dockerfile links

Examples

Running

docker run -p 5000:3000 jlundan/spacy-nodejs-alpine

Get some info about the API

curl http://localhost:5000

You should receive following kind of response

{
  "title": "spaCy JSON service",
  "spacyInfo": {
    "name": "spacy",
    "version": "1.9.0",
    "website": "https://spacy.io/"
  }
}

Processing a sentence

curl -X POST --data '{"input": "This is a test."}' \
    -H "Content-Type: application/json" http://localhost:5000

You should receive following response

[{
  "text": "This is a test.",
  "len": 5,
  "tokens": [
    "This",
    "is",
    "a",
    "test",
    "."
  ],
  "noun_phrases": [
    "a test"
  ],
  "parse_tree": [
    {
      "word": "is",
      "lemma": "be",
      "NE": "",
      "POS_fine": "VBZ",
      "POS_coarse": "VERB",
      "arc": "ROOT",
      "modifiers": [
        {
          "word": "This",
          "lemma": "this",
          "NE": "",
          "POS_fine": "DT",
          "POS_coarse": "DET",
          "arc": "nsubj",
          "modifiers": []
        },
        {
          "word": "test",
          "lemma": "test",
          "NE": "",
          "POS_fine": "NN",
          "POS_coarse": "NOUN",
          "arc": "attr",
          "modifiers": [
            {
              "word": "a",
              "lemma": "a",
              "NE": "",
              "POS_fine": "DT",
              "POS_coarse": "DET",
              "arc": "det",
              "modifiers": []
            }
          ]
        },
        {
          "word": ".",
          "lemma": ".",
          "NE": "",
          "POS_fine": ".",
          "POS_coarse": "PUNCT",
          "arc": "punct",
          "modifiers": []
        }
      ]
    }
  ],
  "parse_list": [
    {
      "word": "This",
      "lemma": "this",
      "NE": "",
      "POS_fine": "DT",
      "POS_coarse": "DET"
    },
    {
      "word": "is",
      "lemma": "be",
      "NE": "",
      "POS_fine": "VBZ",
      "POS_coarse": "VERB"
    },
    {
      "word": "a",
      "lemma": "a",
      "NE": "",
      "POS_fine": "DT",
      "POS_coarse": "DET"
    },
    {
      "word": "test",
      "lemma": "test",
      "NE": "",
      "POS_fine": "NN",
      "POS_coarse": "NOUN"
    },
    {
      "word": ".",
      "lemma": ".",
      "NE": "",
      "POS_fine": ".",
      "POS_coarse": "PUNCT"
    }
  ]
}]

Processing multiple sentences

curl -X POST --data '{"input": ["This is a test.", "This is another test, it has \"quotes\" in it."]}' \
    -H "Content-Type: application/json" http://localhost:5000

The response is similar than with processing single sentence. Responses are returned for each sentence in the input array in the same order input sentences were given.

Building

docker build -t [tag]:[version] --build-arg SPACY_VERSION=[spacy version] .