Skip to content
Snippets Groups Projects
Unverified Commit 2015252f authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Moving big JSON example to the bottom. Adding ToC.

Resolves #7.
parent f13cb6d0
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,14 @@ print(requests.post('http://localhost/parse', data={'sentence': 'Take the cup.'}
Note that is is not production ready, as it is really slow and not optimized:
Instead of keeping one (or multiple) instances of OpenCCG running to query them faster, each request spawns an individual OpenCCG instance.
- [Usage](#usage)
- [Querying](#querying)
- [Response format](#response-format)
- [JSON format](#json-format)
- [Changing the port](#changing-the-port)
- [Development](#development)
- [Example response](#example-response)
## Usage
......@@ -34,6 +42,7 @@ key-value mechanism for post data. In this case, use the key `sentence`:
requests.post('http://localhost/parse', data={'sentence': 'Take the cup.'})
For an example, see [below](#example-response).
### Response format
......@@ -57,6 +66,96 @@ If at least one successful parse exists, the these fields are included:
If an error occurs, the error field is present:
- `error`: An error description.
### JSON format
Current version: 2.1.0
The JSON format for the OpenCCG parses can be determined from the example above
or by carefully inspecting the fully typed
[OpenCCG.ebnf](https://github.com/shoeffner/web-openccg/blob/master/OpenCCG.ebnf).
There are three different types of objects: Nominal, Variable, and Role. The full
semantic specification (the JSON file) can either be one single entity of any of the
three types or a list of Nominals. If we find parses which are lists of
variables or roles, the grammar will be extended. Please open an issue if you
find sentences which can not be parsed correctly.
#### Nominal and Variable
A nominal is like a special variable, it describes the "main theme" of the sentence.
Since they are practically the same (they actually have very similar parsing
rules), the JSON format represents them with an identical structure:
```json
{
"__class__": "Variable",
"name": "x1",
"type": "gum-OrientationChange",
"roles": []
}
```
- `__class__` is either `Variable` or `Nominal`.
- `name` is the variable named used by OpenCCG, it is a letter followed by a number, for example `x1` or `w12`.
- `type` is a [GUM](https://www.ontospace.uni-bremen.de/ontology/stable/GUM-3-space.owl) specifier denoting the type of the variable. It can also be `null`, if the type is not specified.
- `roles` is a list of roles as described below.
#### Role
A Role defines all properties a Variable or Nominal can have.
It follows a very similar structure:
```json
{
"__class__": "Role",
"type": "quant",
"target": ...
}
```
- `__class__`: `Role`.
- `type`: The role type. This determines the `target` possibilities.
- `target`: The value of the role. This can be multiple different things, see below.
If the type is `entity`, the target will be an instance, like "cup" or "slm-Taking".
If the type has a prefix followed by a dash, e.g. `gs-hasSpatialModality` or `gs-direction`, then the target will be a `Variable`.
If the type is any other string, the target will be an atomic string, e.g. the type `det` can have the target `the`, while the type `quant` can have the target `singular`.
### Changing the port
Most web services use port 80 as a default port, and so does web-openccg.
To change the port, adjust the docker-compose file and change the port line
from `"80:80"` to your port on the left side (but keep the 80 on the right), so
for example to set up the service on Port 9043, you would change it to
`"9043:80"`.
## Development
Although not necessarily needed, I use a pipenv for local development to be
able to compile the grammar to a parser using TatSu.
I rely on [when-changed](https://github.com/joh/when-changed) to trigger
automatic builds:
when-changed OpenCCG.ebnf make
To start the development docker container, use the Makefile:
make run
The development server binds to port 5000 and uses the
[flask](http://flask.pocoo.org/) debug environment. Additionally, the docker
container started with `make run` binds the app directory
so that flask's reloading works properly.
## Example response
An example response for the sentence "Take the cup." is:
```json
......@@ -356,90 +455,3 @@ An example response for the sentence "Take the cup." is:
}
}
```
### JSON format
Current version: 2.1.0
The JSON format for the OpenCCG parses can be determined from the example above
or by carefully inspecting the fully typed
[OpenCCG.ebnf](https://github.com/shoeffner/web-openccg/blob/master/OpenCCG.ebnf).
There are three different types of objects: Nominal, Variable, and Role. The full
semantic specification (the JSON file) can either be one single entity of any of the
three types or a list of Nominals. If we find parses which are lists of
variables or roles, the grammar will be extended. Please open an issue if you
find sentences which can not be parsed correctly.
#### Nominal and Variable
A nominal is like a special variable, it describes the "main theme" of the sentence.
Since they are practically the same (they actually have very similar parsing
rules), the JSON format represents them with an identical structure:
```json
{
"__class__": "Variable",
"name": "x1",
"type": "gum-OrientationChange",
"roles": []
}
```
- `__class__` is either `Variable` or `Nominal`.
- `name` is the variable named used by OpenCCG, it is a letter followed by a number, for example `x1` or `w12`.
- `type` is a [GUM](https://www.ontospace.uni-bremen.de/ontology/stable/GUM-3-space.owl) specifier denoting the type of the variable. It can also be `null`, if the type is not specified.
- `roles` is a list of roles as described below.
#### Role
A Role defines all properties a Variable or Nominal can have.
It follows a very similar structure:
```json
{
"__class__": "Role",
"type": "quant",
"target": ...
}
```
- `__class__`: `Role`.
- `type`: The role type. This determines the `target` possibilities.
- `target`: The value of the role. This can be multiple different things, see below.
If the type is `entity`, the target will be an instance, like "cup" or "slm-Taking".
If the type has a prefix followed by a dash, e.g. `gs-hasSpatialModality` or `gs-direction`, then the target will be a `Variable`.
If the type is any other string, the target will be an atomic string, e.g. the type `det` can have the target `the`, while the type `quant` can have the target `singular`.
### Changing the port
Most webservices use port 80 as a default port, and so does web-openccg.
To change the port, adjust the docker-compose file and change the port line
from `"80:80"` to your port on the left side (but keep the 80 on the right), so
for example to set up the service on Port 9043, you would change it to
`"9043:80"`.
## Development
Although not necessarily needed, I use a pipenv for local development to be
able to compile the grammar to a parser using TatSu.
I rely on [when-changed](https://github.com/joh/when-changed) to trigger
automatic builds:
when-changed OpenCCG.ebnf make
To start the development docker container, use the Makefile:
make run
The development server binds to port 5000 and uses the
[flask](http://flask.pocoo.org/) debug environment. Additionally, the docker
container started with `make run` binds the app directory
so that flask's reloading works properly.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment