Py SPARQL Transformer
=====================
Write your SPARQL query directly in the JSON-LD you would like to have in output.
> Looking for the [JavaScript Version](https://github.com/D2KLab/sparql-transformer)?
## News
- It is now possible to set a different **merging anchor** instead of `id`/`@id` using the `$anchor` modifier.
**Table of Contents**
- [Motivation](https://github.com/D2KLab/sparql-transformer/blob/master/motivation.md)
- [Query in JSON](https://github.com/D2KLab/sparql-transformer#query-in-json)
- [How to use](#how-to-use)
- [Credits](#credits)
## Query in JSON
The core idea of this module is writing in a single file the query and the expected output in JSON.
Two syntaxes are supported: plain JSON and JSON-LD.
Here the examples in the 2 formats for the query of cities.
- plain JSON
```json
{
"proto": [{
"id" : "?id",
"name": "$rdfs:label$required",
"image": "$foaf:depiction$required"
}],
"$where": [
"?id a dbo:City",
"?id dbo:country dbr:Italy"
],
"$limit": 100
}
```
- JSON-LD
```json
{
"@context": "http://schema.org/",
"@graph": [{
"@type": "City",
"@id" : "?id",
"name": "$rdfs:label$required",
"image": "$foaf:depiction$required"
}],
"$where": [
"?id a dbo:City",
"?id dbo:country dbr:Italy"
],
"$limit": 100
}
```
For the list of all properties and modifiers, read the **[full documentation](https://github.com/D2KLab/sparql-transformer#query-in-json)**.
## How to use
Install by pip.
```bash
pip install SPARQLTransformer
```
Use in your JS application (node or browser).
```python
from SPARQLTransformer import sparqlTransformer
out = sparqlTransformer(query, options)
```
The first parameter (`query`) is the query in the JSON format. The JSON can be:
- an already parsed (or defined real time) `dict`,
- the local path of a JSON file (that will then be read and parsed).
The `options` parameter is optional, and can define the following:
| OPTION | DEFAULT | NOTE |
| --- | --- | --- |
|context | <http://schema.org/> | The value in `@context`. It overwrites the one in the query.|
| sparqlFunction | `None` | A function receiving in input the transformed query in SPARQL, returning a Promise. If not specified, the module performs the query on its own<sup id="a1">[1](#f1)</sup> against the specified endpoint. |
| endpoint | <http://dbpedia.org/sparql> | Used only if `sparqlFunction` is not specified. |
| debug | `False` | Enter in debug mode. This allow to print in console the generated SPARQL query. |
See [`tests.py`](./test.py) for further examples.
## Credits
If you use this module for your research work, please cite:
> Pasquale Lisena, Albert Meroño-Peñuela, Tobias Kuhn and Raphaël Troncy. Easy Web API Development with SPARQL Transformer. In 18th International Semantic Web Conference (ISWC), Auckland, New Zealand, October 26-30, 2019.
[BIB file](https://github.com/D2KLab/sparql-transformer/blob/master/bib/lisena2019easyweb.bib)
> Pasquale Lisena and Raphaël Troncy. Transforming the JSON Output of SPARQL Queries for Linked Data Clients. In WWW'18 Companion: The 2018 Web Conference Companion, April 23–27, 2018, Lyon, France.
<https://doi.org/10.1145/3184558.3188739>
[BIB file](https://github.com/D2KLab/sparql-transformer/blob/master/bib/lisena2018sparqltransformer.bib)
<!--
python setup.py sdist
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
twine upload dist/*
-->
Raw data
{
"_id": null,
"home_page": "https://github.com/D2KLab/py-sparql-transformer",
"name": "SPARQLTransformer",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "sparql json json-ld semantic",
"author": "Pasquale Lisena",
"author_email": "pasquale.lisena@eurecom.fr",
"download_url": "https://files.pythonhosted.org/packages/b6/af/0ef7933efc5d8b83e613234f6c5315195a72b7e72d3cc63b283cc4574178/SPARQLTransformer-2.4.0.tar.gz",
"platform": null,
"description": "Py SPARQL Transformer\n=====================\n\nWrite your SPARQL query directly in the JSON-LD you would like to have in output.\n\n> Looking for the [JavaScript Version](https://github.com/D2KLab/sparql-transformer)?\n\n\n## News\n\n- It is now possible to set a different **merging anchor** instead of `id`/`@id` using the `$anchor` modifier.\n\n**Table of Contents**\n\n- [Motivation](https://github.com/D2KLab/sparql-transformer/blob/master/motivation.md)\n- [Query in JSON](https://github.com/D2KLab/sparql-transformer#query-in-json)\n- [How to use](#how-to-use)\n- [Credits](#credits)\n\n## Query in JSON\n\nThe core idea of this module is writing in a single file the query and the expected output in JSON.\n\nTwo syntaxes are supported: plain JSON and JSON-LD.\nHere the examples in the 2 formats for the query of cities.\n\n- plain JSON\n\n```json\n{\n \"proto\": [{\n \"id\" : \"?id\",\n \"name\": \"$rdfs:label$required\",\n \"image\": \"$foaf:depiction$required\"\n }],\n \"$where\": [\n \"?id a dbo:City\",\n \"?id dbo:country dbr:Italy\"\n ],\n \"$limit\": 100\n}\n```\n\n- JSON-LD\n\n```json\n{\n \"@context\": \"http://schema.org/\",\n \"@graph\": [{\n \"@type\": \"City\",\n \"@id\" : \"?id\",\n \"name\": \"$rdfs:label$required\",\n \"image\": \"$foaf:depiction$required\"\n }],\n \"$where\": [\n \"?id a dbo:City\",\n \"?id dbo:country dbr:Italy\"\n ],\n \"$limit\": 100\n}\n```\n\n\nFor the list of all properties and modifiers, read the **[full documentation](https://github.com/D2KLab/sparql-transformer#query-in-json)**.\n\n## How to use\n\nInstall by pip.\n\n```bash\npip install SPARQLTransformer\n```\nUse in your JS application (node or browser).\n\n```python\nfrom SPARQLTransformer import sparqlTransformer\n\nout = sparqlTransformer(query, options)\n```\n\nThe first parameter (`query`) is the query in the JSON format. The JSON can be:\n- an already parsed (or defined real time) `dict`,\n- the local path of a JSON file (that will then be read and parsed).\n\nThe `options` parameter is optional, and can define the following:\n\n| OPTION | DEFAULT | NOTE |\n| --- | --- | --- |\n|context | <http://schema.org/> | The value in `@context`. It overwrites the one in the query.|\n| sparqlFunction | `None` | A function receiving in input the transformed query in SPARQL, returning a Promise. If not specified, the module performs the query on its own<sup id=\"a1\">[1](#f1)</sup> against the specified endpoint. |\n| endpoint | <http://dbpedia.org/sparql> | Used only if `sparqlFunction` is not specified. |\n| debug | `False` | Enter in debug mode. This allow to print in console the generated SPARQL query. |\n\n\nSee [`tests.py`](./test.py) for further examples.\n\n\n## Credits\n\nIf you use this module for your research work, please cite:\n\n> Pasquale Lisena, Albert Mero\u00f1o-Pe\u00f1uela, Tobias Kuhn and Rapha\u00ebl Troncy. Easy Web API Development with SPARQL Transformer. In 18th International Semantic Web Conference (ISWC), Auckland, New Zealand, October 26-30, 2019.\n\n[BIB file](https://github.com/D2KLab/sparql-transformer/blob/master/bib/lisena2019easyweb.bib)\n\n\n> Pasquale Lisena and Rapha\u00ebl Troncy. Transforming the JSON Output of SPARQL Queries for Linked Data Clients. In WWW'18 Companion: The 2018 Web Conference Companion, April 23\u201327, 2018, Lyon, France.\n<https://doi.org/10.1145/3184558.3188739>\n\n[BIB file](https://github.com/D2KLab/sparql-transformer/blob/master/bib/lisena2018sparqltransformer.bib)\n\n\n<!--\npython setup.py sdist\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\ntwine upload dist/*\n-->\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Write your SPARQL query directly in the JSON-LD you would like to have in output",
"version": "2.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/D2KLab/py-sparql-transformer/issues",
"Documentation": "https://github.com/D2KLab/py-sparql-transformer",
"Homepage": "https://github.com/D2KLab/py-sparql-transformer",
"Source Code": "https://github.com/D2KLab/py-sparql-transformer"
},
"split_keywords": [
"sparql",
"json",
"json-ld",
"semantic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c42945a85be012ffa16d03769aa6cf10a837ffb33968b1d500460698f6cf9d32",
"md5": "67a56c8f0f73c9c30d1a5b80d81b7a92",
"sha256": "5263718c2b51a9a2d4c85ddbbcde3cff089faa4dc6455dde4dca2999ab35e68e"
},
"downloads": -1,
"filename": "SPARQLTransformer-2.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "67a56c8f0f73c9c30d1a5b80d81b7a92",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13541,
"upload_time": "2024-03-01T14:44:48",
"upload_time_iso_8601": "2024-03-01T14:44:48.268450Z",
"url": "https://files.pythonhosted.org/packages/c4/29/45a85be012ffa16d03769aa6cf10a837ffb33968b1d500460698f6cf9d32/SPARQLTransformer-2.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b6af0ef7933efc5d8b83e613234f6c5315195a72b7e72d3cc63b283cc4574178",
"md5": "9626790c1e060d75a0422585a8df7840",
"sha256": "a5796d76e7e56f47ea6880055a00032adc9b7729f2b03c6d50b1813b5d2a4967"
},
"downloads": -1,
"filename": "SPARQLTransformer-2.4.0.tar.gz",
"has_sig": false,
"md5_digest": "9626790c1e060d75a0422585a8df7840",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13237,
"upload_time": "2024-03-01T14:44:50",
"upload_time_iso_8601": "2024-03-01T14:44:50.145936Z",
"url": "https://files.pythonhosted.org/packages/b6/af/0ef7933efc5d8b83e613234f6c5315195a72b7e72d3cc63b283cc4574178/SPARQLTransformer-2.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-01 14:44:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "D2KLab",
"github_project": "py-sparql-transformer",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sparqltransformer"
}