{"id":25205220,"url":"https://github.com/sparna-git/jsonldtransformer","last_synced_at":"2025-09-10T00:42:25.851Z","repository":{"id":204492040,"uuid":"711843402","full_name":"sparna-git/jsonldtransformer","owner":"sparna-git","description":"Python API to convert an input RDF file using SHACL rules, then serialize the result using JSON-LD framing","archived":false,"fork":false,"pushed_at":"2023-11-06T12:54:42.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-28T14:52:41.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sparna-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-30T09:36:48.000Z","updated_at":"2023-11-06T12:53:54.000Z","dependencies_parsed_at":"2023-11-06T13:52:05.530Z","dependency_job_id":null,"html_url":"https://github.com/sparna-git/jsonldtransformer","commit_stats":null,"previous_names":["sparna-git/jsonldtransformer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sparna-git/jsonldtransformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparna-git%2Fjsonldtransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparna-git%2Fjsonldtransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparna-git%2Fjsonldtransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparna-git%2Fjsonldtransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sparna-git","download_url":"https://codeload.github.com/sparna-git/jsonldtransformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparna-git%2Fjsonldtransformer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274390719,"owners_count":25276408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-10T09:19:25.550Z","updated_at":"2025-09-10T00:42:25.807Z","avatar_url":"https://github.com/sparna-git.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON LD Transformer\n\nThis Python library applies [SHACL rules](https://www.w3.org/TR/shacl-af/#rules) to an input [RDFLib Graph](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#graph), then serializes the output Graph in a clean JSON structure by applying a [JSON-LD framing](https://www.w3.org/TR/json-ld11-framing/) specification.\n\n## Prerequisites\n\n- Python 3.10+\n- Poetry. To install and use Poetry, please refer to https://python-poetry.org/\n\n## Usage\n\n1. Clone the code\n\n2. Install dependencies with poetry\n\n```Shell\n  poetry install\n```\n\n3. To make a small test, run the following:\n\n```Shell\npoetry run python3 jsonldtransformer/Cli.py --rules rules/datacube-2-statdcatap.ttl  --frame rules/framing-context.jsonld --data tests/small-test-data/input.ttl --output output.json\n```\n\n## Python integration\n\nSee in Cli.py for an example of how to call the transformer. This boils down to the following:\n\n```python\n# 1. Read SHACL rules Graph\ngraph_rules = Graph().parse(...)\n\n# 2. Read JSON-LD framing spec\nframe = json.loads(...)\n\n# 3. Create new transformer\ntransformer = JsonLdTransformer(graph_rules,frame)\n\n# 4. Read input RDF data Graph\ndata_graph = Graph().parse(...)\n\n# 5. Apply data conversion rules and JSON-LD transformation on the input data Graph\nresult = transformer.transform(data_graph)\n```\n\n## How-to configure the transformer\n\nThis lib requires 2 input files : a SHACL rules file, and a JSON-LD framing specification\n\n### How to write the SHACL rules\n\nSee [this example file](https://github.com/sparna-git/jsonldtransformer/blob/main/rules/datacube-2-statdcatap.ttl) for an example of how to write rules. The important aspects when writing the rules are:\n  - Declare instances of `sh:NodeShape` with a `sh:target` targetting the instances of the classes you want to transform.\n\n```turtle\nthis:DataStructureDefinition_Shape\n  rdf:type sh:NodeShape ;\n  sh:targetClass \u003chttp://purl.org/linked-data/cube#DataStructureDefinition\u003e ;\n.\n```\n  \n  - Attach transformation rules to this NodeShape with `sh:rule`.\n\n```turtle\nthis:DataStructureDefinition_Shape\n  rdf:type sh:NodeShape ;\n  sh:targetClass \u003chttp://purl.org/linked-data/cube#DataStructureDefinition\u003e ;\n  sh:rule this:CreateDataset;\n  sh:rule this:reify_dctLanguage;\n  # other rules ...\n.\n```\n  \n  - Each rule is an instance of `sh:SPARQLRule`. Express the transformation rule as a SPARQL CONSTRUCT query in the `sh:construct` property. Each rule can refer to the prefixes defined at the top of the file using `sh:prefixes`.\n\n```turtle\nthis:CreateDataset\n  rdf:type sh:SPARQLRule ;\n  rdfs:comment \"Creates DCAT Dataset\" ;\n  rdfs:label \"Creates DCAT Dataset\" ;\n  sh:construct \"\"\"\n      CONSTRUCT {\n        $this a dcat:Dataset .\n      }\n      WHERE {\n        $this a qb:DataStructureDefinition .\n      }\n      \"\"\" ;\n  sh:order 1 ;\n  sh:prefixes \u003chttp://data.sparna.fr/ontologies/datacube-2-statdcatap\u003e ;\n.\n```\n\n### How to write the JSON-LD framing specification\n\nSee [this example file](https://github.com/sparna-git/jsonldtransformer/blob/main/rules/framing-context.jsonld) for an example of JSON-LD framing spec. A JSON-LD framing file is composed of 2 sections : the JSON-LD @context, and the frame specification.\n\n#### The @context\n\nThe @context section :\n  - declares prefixes, for example:\n\n```\n      \"dcat\": \"http://www.w3.org/ns/dcat#\",\n      \"qb\": \"http://purl.org/linked-data/cube#\",\n      \"dct\":  \"http://purl.org/dc/terms/\",\n```\n\n  - maps RDF URIs to JSON terms\n\n```\n      \"Dataset\": \"dcat:Dataset\",\n      \"DimensionProperty\": \"qb:DimensionProperty\",\n      \"LanguageProperty\": \"ngsi-ld:LanguageProperty\",\n```\n\n  - specifies how certain keys should behave\n\n```\n      \"languageMap\": {\n        \"@id\": \"ngsi-ld:languageMap\",\n        \"@container\":\"@language\"\n      },\n```\n\nThis indicates that the property `ngsi-ld:languageMap` will be mapped to the JSON key `languageMap`, using a [JSON-LD language index](https://www.w3.org/TR/json-ld/#language-indexing).\n\n#### The frame specification\n\nThe frame shapes how the output JSON structure should look. In the example it simply looks like this:\n\n```\n\"@type\": [ \"Dataset\", \"DimensionProperty\" ]\n```\n\nThis simply indicates that the top-level elements should be Dataset and DimensionProperty. The JSON-LD framing processor will then apply the default behavior to these objects, which will nest their properties inside these objects.\n\n## Development Note\n\nTo run ruff, call:\n\n```Shell\npoetry run ruff check .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparna-git%2Fjsonldtransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsparna-git%2Fjsonldtransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparna-git%2Fjsonldtransformer/lists"}