# A Spring AMR service and client
[![PyPI][pypi-badge]][pypi-link]
[![Python 3.10][python3100-badge]][python3100-link]
[![Python 3.11][python311-badge]][python311-link]
A client and server that generates AMR graphs from natural language sentences.
This repository has a Docker that compiles the [AMR SPRING parser] using the
original settings of the authors.
The Docker image was created because this parser has a very particular set of
Python dependencies that do not compile under some platforms. Specifically
`tokenizers==0.7.0` fails to compile from source on a `pip` install because of
a Rust (version) compiler misconfiguration.
The [Docker image](#docker) provides a very simple service written in [Flask]
that uses the SPRING model for inferencing and returns the parsed AMRs.
Features:
* Parse natural language sentence (batched) into AMRs.
* Results cached in memory or an SQLite database.
* Both a command line and Pythonic object oriented client API.
## Installing
First install the client:
```bash
pip3 install zensols.amrspring
```
### Server
There is a script to build a local server, but there is also a docker image.
To build a local server:
1. Clone this repo: `git clone https://github.com/plandes/amrspring`
1. Working directory: `cd amrspring`
1. Build out the server: `src/bin/build-server.sh <python installation directory>`
1. Start it `( cd server ; ./serverctl start )`
1. Test it `( cd server ; ./serverctl test-server )`
1. Stop it `( cd server ; ./serverctl top )`
### Docker
To build the Docker image:
1. Download the model(s) from the [AMR SPRING parser] repository.
1. Build the image: `cd docker ; make build`
1. Check for errors.
1. Start the image: `make up`
1. Test using a method from [usage](#usage).
Of course, the server code can be run without docker by cloning the [AMR SPRING
parser] repository and adding the [server code](docker/src). See the
[Dockerfile](docker/Dockerfile) for more information on how to do that.
## Usage
The package can be used from the command line or directly via a Python API.
You can use a combination UNIX tools to `POST` directly to it:
```bash
wget -q -O - --post-data='{"sents": ["Obama was the 44th president."]}' \
--header='Content-Type:application/json' \
'http://localhost:8080/parse' | jq -r '.amrs."0"."graph"'
# ::snt Obama was the 44th president.
(z0 / person
:ord (z1 / ordinal-entity
:value 44)
:ARG0-of (z2 / have-org-role-91
:ARG2 (z3 / president))
:domain (z4 / person
:name (z5 / name
:op1 "Obama")))
```
It also offers a command line:
```bash
$ amrspring --level warn parse 'Obama was the president.'
sent: Obama was the president.
graph:
# ::snt Obama was the president.
(z0 / person
:ARG0-of (z1 / have-org-role-91
:ARG2 (z2 / president))
:domain (z3 / person
:name (z4 / name
:op1 "Obama")))
```
The Python API is very straight forward as well:
```python
>>> from zensols.amrspring import AmrPrediction, ApplicationFactory
>>> client = ApplicationFactory.get_client()
>>> pred = tuple(client.parse(['Obama was the president.']))[0]
2024-02-19 19:41:03,659 parsed 1 sentences in 3ms
>>> print(pred.graph)
# ::snt Obama was the president.
(z0 / person
:ARG0-of (z1 / have-org-role-91
:ARG2 (z2 / president))
:domain (z3 / person
:name (z4 / name
:op1 "Obama")))
```
## Documentation
See the [full documentation](https://plandes.github.io/amrspring/index.html).
The [API reference](https://plandes.github.io/amrspring/api.html) is also
available.
## Changelog
An extensive changelog is available [here](CHANGELOG.md).
## Community
Please star this repository and let me know how and where you use this API.
Contributions as pull requests, feedback and any input is welcome.
## License
[MIT License](LICENSE.md)
Copyright (c) 2024 Paul Landes
<!-- links -->
[pypi]: https://pypi.org/project/zensols.amrspring/
[pypi-link]: https://pypi.python.org/pypi/zensols.amrspring
[pypi-badge]: https://img.shields.io/pypi/v/zensols.amrspring.svg
[python3100-badge]: https://img.shields.io/badge/python-3.10-blue.svg
[python3100-link]: https://www.python.org/downloads/release/python-3100
[python311-badge]: https://img.shields.io/badge/python-3.11-blue.svg
[python311-link]: https://www.python.org/downloads/release/python-3110
[build-badge]: https://github.com/plandes/amrspring/workflows/CI/badge.svg
[AMR SPRING parser]: git clone https://github.com/SapienzaNLP/spring
Raw data
{
"_id": null,
"home_page": "https://github.com/plandes/amrspring",
"name": "zensols.amrspring",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "tooling",
"author": "Paul Landes",
"author_email": "landes@mailc.net",
"download_url": "https://github.com/plandes/amrspring/releases/download/v0.0.1/zensols.amrspring-0.0.1-py3-none-any.whl",
"platform": null,
"description": "# A Spring AMR service and client\n\n[![PyPI][pypi-badge]][pypi-link]\n[![Python 3.10][python3100-badge]][python3100-link]\n[![Python 3.11][python311-badge]][python311-link]\n\nA client and server that generates AMR graphs from natural language sentences.\nThis repository has a Docker that compiles the [AMR SPRING parser] using the\noriginal settings of the authors.\n\nThe Docker image was created because this parser has a very particular set of\nPython dependencies that do not compile under some platforms. Specifically\n`tokenizers==0.7.0` fails to compile from source on a `pip` install because of\na Rust (version) compiler misconfiguration.\n\nThe [Docker image](#docker) provides a very simple service written in [Flask]\nthat uses the SPRING model for inferencing and returns the parsed AMRs.\n\nFeatures:\n\n* Parse natural language sentence (batched) into AMRs.\n* Results cached in memory or an SQLite database.\n* Both a command line and Pythonic object oriented client API.\n\n\n## Installing\n\nFirst install the client:\n```bash\npip3 install zensols.amrspring\n```\n\n\n### Server\n\nThere is a script to build a local server, but there is also a docker image.\n\nTo build a local server:\n1. Clone this repo: `git clone https://github.com/plandes/amrspring`\n1. Working directory: `cd amrspring`\n1. Build out the server: `src/bin/build-server.sh <python installation directory>`\n1. Start it `( cd server ; ./serverctl start )`\n1. Test it `( cd server ; ./serverctl test-server )`\n1. Stop it `( cd server ; ./serverctl top )`\n\n\n### Docker\n\nTo build the Docker image:\n1. Download the model(s) from the [AMR SPRING parser] repository.\n1. Build the image: `cd docker ; make build`\n1. Check for errors.\n1. Start the image: `make up`\n1. Test using a method from [usage](#usage).\n\nOf course, the server code can be run without docker by cloning the [AMR SPRING\nparser] repository and adding the [server code](docker/src). See the\n[Dockerfile](docker/Dockerfile) for more information on how to do that.\n\n\n## Usage\n\nThe package can be used from the command line or directly via a Python API.\n\nYou can use a combination UNIX tools to `POST` directly to it:\n```bash\nwget -q -O - --post-data='{\"sents\": [\"Obama was the 44th president.\"]}' \\\n --header='Content-Type:application/json' \\\n 'http://localhost:8080/parse' | jq -r '.amrs.\"0\".\"graph\"'\n# ::snt Obama was the 44th president.\n(z0 / person\n :ord (z1 / ordinal-entity\n :value 44)\n :ARG0-of (z2 / have-org-role-91\n :ARG2 (z3 / president))\n :domain (z4 / person\n :name (z5 / name\n :op1 \"Obama\")))\n```\n\nIt also offers a command line:\n```bash\n$ amrspring --level warn parse 'Obama was the president.'\nsent: Obama was the president.\ngraph:\n # ::snt Obama was the president.\n (z0 / person\n :ARG0-of (z1 / have-org-role-91\n :ARG2 (z2 / president))\n :domain (z3 / person\n :name (z4 / name\n :op1 \"Obama\")))\n```\n\nThe Python API is very straight forward as well:\n```python\n>>> from zensols.amrspring import AmrPrediction, ApplicationFactory\n>>> client = ApplicationFactory.get_client()\n>>> pred = tuple(client.parse(['Obama was the president.']))[0]\n2024-02-19 19:41:03,659 parsed 1 sentences in 3ms\n>>> print(pred.graph)\n# ::snt Obama was the president.\n(z0 / person\n :ARG0-of (z1 / have-org-role-91\n :ARG2 (z2 / president))\n :domain (z3 / person\n :name (z4 / name\n :op1 \"Obama\")))\n```\n\n\n## Documentation\n\nSee the [full documentation](https://plandes.github.io/amrspring/index.html).\nThe [API reference](https://plandes.github.io/amrspring/api.html) is also\navailable.\n\n\n## Changelog\n\nAn extensive changelog is available [here](CHANGELOG.md).\n\n\n## Community\n\nPlease star this repository and let me know how and where you use this API.\nContributions as pull requests, feedback and any input is welcome.\n\n\n## License\n\n[MIT License](LICENSE.md)\n\nCopyright (c) 2024 Paul Landes\n\n\n<!-- links -->\n[pypi]: https://pypi.org/project/zensols.amrspring/\n[pypi-link]: https://pypi.python.org/pypi/zensols.amrspring\n[pypi-badge]: https://img.shields.io/pypi/v/zensols.amrspring.svg\n[python3100-badge]: https://img.shields.io/badge/python-3.10-blue.svg\n[python3100-link]: https://www.python.org/downloads/release/python-3100\n[python311-badge]: https://img.shields.io/badge/python-3.11-blue.svg\n[python311-link]: https://www.python.org/downloads/release/python-3110\n[build-badge]: https://github.com/plandes/amrspring/workflows/CI/badge.svg\n\n[AMR SPRING parser]: git clone https://github.com/SapienzaNLP/spring\n",
"bugtrack_url": null,
"license": "",
"summary": "A client and server that generates AMR graphs from natural language sentences.",
"version": "0.0.1",
"project_urls": {
"Download": "https://github.com/plandes/amrspring/releases/download/v0.0.1/zensols.amrspring-0.0.1-py3-none-any.whl",
"Homepage": "https://github.com/plandes/amrspring"
},
"split_keywords": [
"tooling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8a2d088b41c10e03eb02d62e231778ddb313624368270114572d7041b9dd9171",
"md5": "863680ba9135c77f331fbd6b7f1c58ba",
"sha256": "bebdd4868ffc6873d94728b955c92d85772148220ce0d9da56cd5486714971c0"
},
"downloads": -1,
"filename": "zensols.amrspring-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "863680ba9135c77f331fbd6b7f1c58ba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7141,
"upload_time": "2024-02-24T21:04:39",
"upload_time_iso_8601": "2024-02-24T21:04:39.717532Z",
"url": "https://files.pythonhosted.org/packages/8a/2d/088b41c10e03eb02d62e231778ddb313624368270114572d7041b9dd9171/zensols.amrspring-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-24 21:04:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plandes",
"github_project": "amrspring",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "zensols.amrspring"
}