1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
|
wn.web
======
.. automodule:: wn.web
This module provides a RESTful API with `JSON:API`_ responses to
queries against a Wn database. This API implements the primary queries
of the Python API (see :ref:`primary-queries`). For instance, to
search all words in the ``ewn:2020`` lexicon with the form *jet* and
part-of-speech *v*, we can perform the following query::
/lexicons/ewn:2020/words?form=jet&pos=v
This query would return the following response:
.. code-block:: javascript
{
"data": [
{
"id": "ewn-jet-v",
"type": "word",
"attributes": {
"pos": "v",
"lemma": "jet",
"forms": ["jet", "jetted", "jetting"]
},
"links": {
"self": "http://example.com/lexicons/ewn:2020/words/ewn-jet-v"
},
"relationships": {
"senses": {
"links": {"related": "http://example.com/lexicons/ewn:2020/words/ewn-jet-v/senses"}
},
"synsets": {
"data": [
{"type": "synset", "id": "ewn-01518922-v"},
{"type": "synset", "id": "ewn-01946093-v"}
]
},
"lexicon": {
"links": {"related": "http://example.com/lexicons/ewn:2020"}
}
},
"included": [
{
"id": "ewn-01518922-v",
"type": "synset",
"attributes": {"pos": "v", "ili": "i29306"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-01518922-v"}
},
{
"id": "ewn-01946093-v",
"type": "synset",
"attributes": {"pos": "v", "ili": "i31432"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-01946093-v"}
}
]
}
],
"meta": {"total": 1}
}
Currently, only ``GET`` requests are handled.
.. _JSON\:API: https://jsonapi.org
Installing Dependencies
-----------------------
By default, Wn does not install the requirements needed for this
module. Install them with the ``[web]`` extra:
.. code-block:: bash
$ pip install "wn[web]"
Running and Deploying the Server
--------------------------------
This module does not provide an ASGI server, so one will need to be
installed and ran separately. Any ASGI-compliant server should
work.
For example, the `Uvicorn <https://www.uvicorn.org/>`_ server may be
used directly for local development, optionally with the ``--reload``
option for hot reloading:
.. code-block:: bash
$ uvicorn --reload wn.web:app
For production, see Uvicorn's `documentation about deployment
<https://www.uvicorn.org/deployment/>`_.
Requests: API Endpoints
-----------------------
The module provides the following endpoints:
.. table::
:width: 100%
====================================== ========================================================
Endpoint Description
====================================== ========================================================
``/words`` List words in all available lexicons
``/senses`` List senses in all available lexicons
``/synsets`` List synsets in all available lexicons
``/lexicons`` List available lexicons
``/lexicons/:lex`` Get lexicon with specifier ``:lex``
``/lexicons/:lex/words`` List words for lexicon with specifier ``:lex``
``/lexicons/:lex/words/:id/senses`` List senses for word ``:id`` in lexicon ``:lex``
``/lexicons/:lex/words/:id`` Get word with ID ``:id`` in lexicon ``:lex``
``/lexicons/:lex/senses`` List senses for lexicon with specifier ``:lex``
``/lexicons/:lex/senses/:id`` Get sense with ID ``:id`` in lexicon ``:lex``
``/lexicons/:lex/synsets`` List synsets for lexicon with specifier ``:lex``
``/lexicons/:lex/synsets/:id`` Get synset with ID ``:id`` in lexicon ``:lex``
``/lexicons/:lex/synsets/:id/members`` Get member senses for synset ``:id`` in lexicon ``:lex``
====================================== ========================================================
Requests: Query Parameters
--------------------------
``lang``
''''''''
Specifies the language in `BCP 47`_ of the lexicon(s) from which
results are returned.
.. _BCP 47: https://en.wikipedia.org/wiki/IETF_language_tag
Example::
/words?lang=fr
Valid for::
/lexicons
/words
/senses
/synsets
``form``
''''''''
Specifies the word form of the objects that are returned.
Example::
/words?form=chat
Valid for::
/words
/senses
/synsets
/lexicon/:lex/words
/lexicon/:lex/senses
/lexicon/:lex/synsets
``pos``
'''''''
Specifies the part-of-speech of the objects that are returned. Valid
values are given in :ref:`parts-of-speech`.
Example::
/words?pos=v
Valid for::
/words
/senses
/synsets
/lexicon/:lex/words
/lexicon/:lex/senses
/lexicon/:lex/synsets
``ili``
'''''''
Specifies the interlingual index of a synset.
Example::
/synsets?ili=i57031
Valid for::
/synsets
/lexicon/:lex/synsets
``page[offset]`` and ``page[limit]``
''''''''''''''''''''''''''''''''''''
Used for pagination: ``page[offset]`` specifies the starting index of
a set of results, and ``page[limit]`` specifies how many results from
the offset will be returned.
Example::
/words?page[offset]=150
Valid for::
/words
/senses
/synsets
/lexicon/:lex/words
/lexicon/:lex/senses
/lexicon/:lex/synsets
Responses
---------
Responses are JSON data following the `JSON:API`_ specification. A
full description of JSON:API is left to the linked specification, but
a brief walkthrough is provided here. First, the top-level structure
of "to-one" responses (e.g., getting a single synset) is:
.. code-block:: javascript
{
"data": { ... }, // primary response data as a JSON object
"meta": { ... } // metadata for the response
}
For "to-many" responses (e.g., getting a list of matching synsets), it
is the same as above except the ``data`` key maps to an array and it
includes pagination links:
.. code-block:: javascript
{
"data": [{ ... }, ...], // primary response data as an array of objects
"links": { ... }, // pagination links
"meta": { ... } // metadata; e.g., total number of results
}
Each JSON:API *resource object* (the primary data given by the
``data`` key) has the following structure:
.. code-block:: javascript
{
"id": "...", // Lexicon specifier or entity ID
"type": "...", // "lexicon", "word", "sense", or "synset"
"attributes": { ... }, // Basic resource information
"links": { "self": ... }, // URL for this specific resource
"relationships": { ... }, // Word senses, synset members, other relations
"included": [ ... ], // Data for related resources
}
Lexicons
''''''''
.. code-block:: javascript
{
"id": "ewn:2020",
"type": "lexicon",
"attributes": {
"version": "2020",
"label": "English WordNet",
"language": "en",
"license": "https://creativecommons.org/licenses/by/4.0/"
},
"links": {"self": "http://example.com/lexicons/ewn:2020"},
"relationships": {
"words": {"links": {"related": "http://example.com/lexicons/ewn:2020/words"}},
"synsets": {"links": {"related": "http://example.com/lexicons/ewn:2020/synsets"}},
"senses": {"links": {"related": "http://example.com/lexicons/ewn:2020/senses"}}
}
}
Words
'''''
.. code-block:: javascript
{
"id": "ewn-brick-v",
"type": "word",
"attributes": {"pos": "v", "lemma": "brick", "forms": ["brick"]},
"links": {"self": "http://example.com/lexicons/ewn:2020/words/ewn-brick-v"},
"relationships": {
"senses": {"links": {"related": "http://example.com/lexicons/ewn:2020/words/ewn-brick-v/senses"}},
"synsets": {"data": [{"type": "synset", "id": "ewn-90011761-v"}]},
"lexicon": {"links": {"related": "http://example.com/lexicons/ewn:2020"}}
},
"included": [
{
"id": "ewn-90011761-v",
"type": "synset",
"attributes": {"pos": "v", "ili": null},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-90011761-v"}
}
]
}
Senses
''''''
.. code-block:: javascript
{
"id": "ewn-explain-v-00941308-01",
"type": "sense",
"links": {"self": "http://example.com/lexicons/ewn:2020/senses/ewn-explain-v-00941308-01"},
"relationships": {
"word": {"links": {"related": "http://example.com/lexicons/ewn:2020/words/ewn-explain-v"}},
"synset": {"links": {"related": "http://example.com/lexicons/ewn:2020/synsets/ewn-00941308-v"}},
"lexicon": {"links": {"related": "http://example.com/lexicons/ewn:2020"}},
"derivation": {
"data": [
{"type": "sense", "id": "ewn-explanatory-s-01327635-01"},
{"type": "sense", "id": "ewn-explanation-n-07247081-01"}
]
}
},
"included": [
{
"id": "ewn-explanatory-s-01327635-01",
"type": "sense",
"links": {"self": "http://example.com/lexicons/ewn:2020/senses/ewn-explanatory-s-01327635-01"}
},
{
"id": "ewn-explanation-n-07247081-01",
"type": "sense",
"links": {"self": "http://example.com/lexicons/ewn:2020/senses/ewn-explanation-n-07247081-01"}
}
]
}
Synsets
'''''''
.. code-block:: javascript
{
"id": "ewn-03204585-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i52917"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-03204585-n"},
"relationships": {
"members": {"links": {"related": "http://example.com/lexicons/ewn:2020/synsets/ewn-03204585-n/members"}},
"words": {
"data": [
{"type": "word", "id": "ewn-dory-n"},
{"type": "word", "id": "ewn-rowboat-n"},
{"type": "word", "id": "ewn-dinghy-n"}
]
},
"lexicon": {"links": {"related": "http://example.com/lexicons/ewn:2020"}},
"hypernym": {"data": [{"type": "synset", "id": "ewn-04252125-n"}]},
"mero_part": {
"data": [
{"type": "synset", "id": "ewn-03911849-n"},
{"type": "synset", "id": "ewn-04439177-n"}
]
},
"hyponym": {
"data": [
{"type": "synset", "id": "ewn-04122550-n"},
{"type": "synset", "id": "ewn-04584425-n"}
]
}
},
"included": [
{
"id": "ewn-dory-n",
"type": "word",
"attributes": {"pos": "n", "lemma": "dory", "forms": ["dory"]},
"links": {"self": "http://example.com/lexicons/ewn:2020/words/ewn-dory-n"}
},
{
"id": "ewn-rowboat-n",
"type": "word",
"attributes": {"pos": "n", "lemma": "rowboat", "forms": ["rowboat"]},
"links": {"self": "http://example.com/lexicons/ewn:2020/words/ewn-rowboat-n"}
},
{
"id": "ewn-dinghy-n",
"type": "word",
"attributes": {"pos": "n", "lemma": "dinghy", "forms": ["dinghy"]},
"links": {"self": "http://example.com/lexicons/ewn:2020/words/ewn-dinghy-n"}
},
{
"id": "ewn-04252125-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i59107"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-04252125-n"}
},
{
"id": "ewn-03911849-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i57094"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-03911849-n"}
},
{
"id": "ewn-04439177-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i60240"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-04439177-n"}
},
{
"id": "ewn-04122550-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i58319"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-04122550-n"}
},
{
"id": "ewn-04584425-n",
"type": "synset",
"attributes": {"pos": "n", "ili": "i61103"},
"links": {"self": "http://example.com/lexicons/ewn:2020/synsets/ewn-04584425-n"}
}
]
}
|