REST API

The web backend provides the following api.

GET /

Serves the frontend/dist/index.html containing the javascript app at the base url /.

GET /favicon.ico

Serves the frontend/dist/favicon.ico containing the favicon.

POST /api/lexical_unit/(id)/

Updates the textual source of the lexical unit whose id is id.

The textual source is parsed and the lexicon collection is updated with the new lexical unit.

Parameters
  • id – The id of the lexical unit to update.

Request JSON Object
  • src (string) – The new textual source of the lexical unit.

Response JSON Object
  • result (LexicalUnit) – The newly parsed lexical unit.

Status Codes
  • 404 Not Found – If a lexical unit with the provided id does not exist.

Example:

http

POST /api/lexical_unit/blu-v-brát-vzít-1/ HTTP/1.1
Host: localhost:8080
Accept: application/json
Content-Type: application/json

{
    "src": "~ impf: brát (si) pf: vzít (si) iter: brávat (si)\n+ ACT(1;obl) PAT(4;obl) ORIG(od+2;opt)\n   -synon: impf: přijímat; získávat pf: přijmout; získat"
}

curl

curl -i -X POST 'http://localhost:8080/api/lexical_unit/blu-v-brát-vzít-1/' -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"src": "~ impf: br\u00e1t (si) pf: vz\u00edt (si) iter: br\u00e1vat (si)\n+ ACT(1;obl) PAT(4;obl) ORIG(od+2;opt)\n   -synon: impf: p\u0159ij\u00edmat; z\u00edsk\u00e1vat pf: p\u0159ijmout; z\u00edskat"}'

wget

wget -S -O- 'http://localhost:8080/api/lexical_unit/blu-v-brát-vzít-1/' --header="Accept: application/json" --header="Content-Type: application/json" --post-data='{"src": "~ impf: br\u00e1t (si) pf: vz\u00edt (si) iter: br\u00e1vat (si)\n+ ACT(1;obl) PAT(4;obl) ORIG(od+2;opt)\n   -synon: impf: p\u0159ij\u00edmat; z\u00edsk\u00e1vat pf: p\u0159ijmout; z\u00edskat"}'

python-requests

requests.post('http://localhost:8080/api/lexical_unit/blu-v-brÃ\x83¡t-vzÃ\x83Â\xadt-1/', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'src': '~ impf: brát (si) pf: vzít (si) iter: brávat (si)\n+ ACT(1;obl) PAT(4;obl) ORIG(od+2;opt)\n   -synon: impf: přijímat; získávat pf: přijmout; získat'})

response

HTTP/1.1 200 OK
Content-Type: application/json

{
    "ts": 1590609536.9895885,
    "result": {
        "id": "blu-v-brát-vzít-1",
        "__type__": "LexicalUnit",
        "lemma": {
            "__type__": "Lemma",
            "type": "~",
            "data": {
                "impf": "brát (si)",
                "pf": "vzít (si)",
                "iter": "brávat (si)"
            },
            "comments":[]
        },
        "frame": {
            "elements":[
                {"functor":"ACT","forms":"1","oblig":"obl","__type__":"FrameElement"},
                {"functor":"PAT","forms":"4","oblig":"obl","__type__":"FrameElement"},
                {"functor":"ORIG","forms":"od+2","oblig":"opt","__type__":"FrameElement"}
            ],
            "comments":[],
            "__type__": "Frame"
        },
        "attrs": {
            "synon": {
                "__type__":"Attrib",
                "type": "synon",
                "data": {
                    "impf": [["přijímat"], ["získávat"]],
                    "pf": [["přijímout"], ["získat"]]
                }
            }
        }
        "comments":[],
        "errors":[],
        "warnings":[],
        "source": {
            "start": {"__type__":"Location", "pos":92, "ln":3, "col":0},
            "end": {"__type__":"Location", "pos":531, "ln":6, "col":0},
            "text": "~ impf: brát (si) pf: vzít (si) iter: brávat (si)\n+ ACT(1;obl) PAT(4;obl) ORIG(od+2;opt)\n   -synon: impf: přijímat; získávat pf: přijmout; získat"
        }

    }
}
POST /api/search

Searches the lexicon collection for lexical units matching a provided pattern.

The query argument is passed to the grep function along with the currently loaded lexicon collection.

Request JSON Object
  • query (List[str]) – A list of strings, each string of the form key=pattern, with pattern a regular expression and key a dot-separated match key.

  • id_only (bool) – Controls whether the full lexical units are returned or just their ids; defaults to False.

Response JSON Object
  • result (list) – The matching lexical units grouped into Lexemes as a list. If id_only` is True key, then it is a list of (lexeme_id, lexical_unit_id) pairs instead, one pair for each matching lexical unit.

Status Codes
  • 400 Bad Request – If the query is not provided or not in the required format or one of the regular expressions is invalid (e.g. wrong syntax).

GET /api/lexical_unit/(id)/match_map

Returns a map mapping match keys to their respective match values for a specified lexical unit.

Response JSON Object
  • result (dict) – A mapping of match keys to match values.

Status Codes
GET /api/stats

Computes several statistics (currently only a histogram) on the set of lexical units matching a query.

Request JSON Object
  • query (str) – A # separated list of conditions where each condition is a string of the form key=pattern, with pattern a regular expression and key a dot-separated match key.

  • select_pattern (str) – A regular expression to be passed to the histogram function; optional, defaults to .*

Response JSON Object
  • result (dict) – A dictionary with two keys: The bins key contains the counts for each encountered value and the total key contains the total number of values encountered.

Status Codes
  • 400 Bad Request – If the query argument is not provided or not in the required format or one of the regular expressions is invalid (e.g. wrong syntax).

POST /api/rpc/(method)

Executes an action on the server.

The actions currently available are:

  • save: saves all modified lexicons to disk in textual format

  • reload: reloads lexicons which have changed on disk

  • log logs an error message to the server log

Parameters
  • method – The action to execute.

Request JSON Object
  • args – Arguments needed by the action

Response JSON Object
  • result (dict) – Results of the action

Status Codes
GET /api/changes

Returns all lexical units which have changed since the specified timestamp.

<param float timestamp

Since what time to return changes. Specified in seconds since the start of the Unix epoch.

Response JSON Object
  • result (dict) – A list of LexicalUnits which have changed,

Status Codes
  • 400 Bad Request – If the query argument is not provided or not in the required format or one of the regular expressions is invalid (e.g. wrong syntax).

GET /api/config

Returns frontend configuration.

Request JSON Object
  • result (dict) – The configuration object.

GET /api/attribs

Returns lexical unit attribute names which appear at least once.

Request JSON Object
  • result (list) – A list of attribute names (simple strings)

GET /api/sources

Returns a list of loaded lexicons.

Request JSON Object
  • result (list) – A list of lexicons (simple strings)

GET /api/tests

Returns a list of data validation tests.

Request JSON Object
  • result (list) – A list of data-validation tests. Each test is an object with a name key, containing the test name, and a doc key, containing a description of the test.

GET /api/help/toc

Returns help contents

Request JSON Object
  • result (dict) – Help contents.

GET /api/help/guide/(section)/

Returns a section from the help guide

Request JSON Object
  • result (dict) – A dict containing the html content in the result key.

Status Codes
GET /api/help/topics/(topic)/

Returns help on the given topic.

Request JSON Object
  • result (dict) – A dict containing at least a title and a content key, The content key contains a html snippet with the help text.

Status Codes
GET /static/(path: path)

Serves files from the frontend/dist/static directory.

POST /api/login

Performs login. Autheticates the user with the user/password saved in the db.

POST /api/logout

Performs logout. Clears the logged_in flag.