Integrating External Spell Checking

It is possible to create your own Web API endpoints and integrate your own spell checking and suggestions into the Writer.

Writer Configuration

In order to enable the spellcheck integration, the Writer's server-config needs to be edited. The following should be added to your server-config's external-config object:

"spellcheck": {
    "check": {
        "url": "[your-spellcheck-endpoint]",
        "headers": {
            "x-foo": "bar"
        }
    },
    "suggestion": {
        "url": "[your-suggestion-endpoint]",
        "headers": {
            "x-foo": "bar"
        }
    }
}

Field Description

Field

Description

external.spellcheck

Contains the configuration for external spellchecking endpoints.

external.spellcheck.check

Optional Object containing configuration for external spellcheck requests.

external.spellcheck.check.url

Required Full url and path to your check request implementation.

external.spellcheck.check.headers

Optional Key-value object with extra header's which will be used in the request to your API.

external.spellcheck.suggestion

Optional Object containing configuration for external suggestion requests.

external.spellcheck.suggestion.url

Required Full url and path to your suggestion request implementation.

external.spellcheck.suggestion.headers

Optional Key-value object with extra header's which will be used in the request to your API.

The headers-properties are useful if you need to send additional headers to your API.

Remember, the writer service needs to be restarted for server config changes to take effect

External API Specification

Your API needs to be able to handle the following requests to integrate with spell checking and suggestion.

Language Codes

Language codes from the writer are sent in the format [language-identifier]_[region_identifier]. Where [language-identifier] follows the ISO 639-1 standard, which is two letters, lowercased. The [region-identifier] follows the ISO 3166-2 standard, which is two letters, uppercased.

Examples: sv_SE, en_GB, en_US, nl_NL

Spellcheck Request

The API must be able to receive the following request on an endpoint you define:

Request

    POST [your-spellcheck-endpoint]
    headers
        Accept: application/json
        Content-Type: application/json 
    body
        {
            "lang": "sv_SE",
            "words": [
                { "start": 0, "end": 5, "text": "Lorem" },
                { "start": 6, "end": 11, "text": "ipsum" },
                { "start": 12, "end": 17, "text": "dolor" },
                { "start": 18, "end": 21, "text": "sit" },
                { "start": 22, "end": 26, "text": "amet" },
                { "start": 28, "end": 39, "text": "consectetur" },
                { "start": 40, "end": 50, "text": "adipiscing" },
                { "start": 51, "end": 55, "text": "elit" },
                { "start": 57, "end": 60, "text": "sed" },
                { "start": 61, "end": 63, "text": "do" },
                { "start": 64, "end": 71, "text": "eiusmod" },
                { "start": 72, "end": 78, "text": "tempor" }
            ]
        }

Response

The API should respond with a single array containing the misspelled words in the same json-format as they were sent, if no words were misspelled, response should contain an empty array.

Response Format

headers
    Content-Type: application/json 
body
    [
      { "start": 0, "end": 5, "text": "Lorem" },
      { "start": 6, "end": 11, "text": "ipsum" },
      { "start": 12, "end": 17, "text": "dolor" },
      { "start": 61, "end": 63, "text": "do" },
      { "start": 64, "end": 71, "text": "eiusmod" }
    ]

Example Request

The API should be able to perform the call below, and output an array of the misspelled words, or an empty array.

fetch("[your-spellcheck-endpoint]", {
    method: 'post',
    headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
    body: JSON.stringify({
        "lang": "[language_code]",
        "words": [
            { "start": 0, "end": 5, "text": "Lorem" },
            { "start": 6, "end": 11, "text": "ipsum" },
            { "start": 12, "end": 17, "text": "dolor" },
            { "start": 61, "end": 63, "text": "do" },
            { "start": 64, "end": 71, "text": "eiusmod" }
        ]
    })
})
    .then((res) => res.json())
    .then((json) => console.log(json))

Output:

    [
        {"start":0,"end":5,"text":"Lorem"},
        {"start":6,"end":11,"text":"ipsum"},
        {"start":64,"end":71,"text":"eiusmod"}
    ]

Suggestions

The API must be able to receive the following request on an endpoint you define:

Request

    POST [your-suggestion-endpoint]
    headers
        Accept: application/json
        Content-Type: application/json
    URL Params
        word=String
        lang=[language_code]

Response

The API should respond with a single array containing the misspelled words in the same json-format as they were sent, if no words were misspelled, response should be an empty array.

Response Format

    headers
        Content-Type: application/json
    body
        [
            "tempot",
            "tempo",
            "tempon",
            "tempos",
            "teorem"
        ]

Example Request

The API should be able to perform the call below, and output an array of words, or an empty array.

fetch("[your-suggestion-endpoint]?word=tempor&lang=en_US", {
    headers: {'Accept': 'application/json', 'Content-Type': 'application/json'}
})
    .then((res) => res.json())
    .then((json) => console.log(json))

Output

["tempo", "temper", "tempos", "temp or", "temp-or", "tempo r"]

Last updated