A library of algorithms for working with JSON-LD and translating between various forms of RDF.
Project description
TRLD
TRLD is a transpilable implementation of algorithms for working with Linked Data as JSON-LD. This includes translating to and from various RDF syntaxes and mapping of vocabularies.
Transpiling Linked Data Algorithms
TRLD is written in typed Python, with some extra care taken to support transpilation. The implementation can currently be transpiled into:
- Java
- Javascript
The transpiler is part of the codebase and only supports the small (somewhat redundantly cast) subset of type-annotated Python needed to implement these algorithms. It is not a generic transpiler.
Transcribing Linked Data
When parsing RDF, the syntactic statements are transcribed verbatim into JSON-LD, keeping compact forms and ordering as much as possible. Conversely, serialization is done by writing the JSON-LD shape out as is, using the chosen syntax.
In order to control the exact shape of this data, use the JSON-LD algorithms for expansion, flattening and compaction.
Serializing JSON-LD as Turtle or TriG
At this time, care must be taken to use simple JSON-LD contexts in order for Turtle or TriG serialization to work. That means that, apart from prefixes and some support for language indexes and type coercion, no advanced compaction features of JSON-LD 1.1 will work when transcribing the data out as Turtle or TriG. If you process such compacted data, ensure to expand it first, and preferably re-compact it into a simpler form.
Implemented Algorithms
JSON-LD 1.1 (W3C Spec)
- Expansion
- Compaction
- Flattening
- RDF Serialization/Deserialization
N-Quads (W3C Spec)
- Parser
- Serializer
TriG (W3C Spec)
- Parser
- Serializer
Target Vocabulary Maps (Experimental)
- Basic RDFS & OWL
- Property chains
- Reified forms
- SKOS matches
Running
Python-based command-line usage:
$ python3 -m trld [-h] [-c CONTEXT] [-e [EXPAND_CONTEXT]] [-b BASE] [-f] \
[-i INPUT_FORMAT] [-o OUTPUT_FORMAT] [SOURCE ...]
Java-based command-line usage:
$ java -jar build/java/build/libs/trld-with-deps.jar [-f] [-c CONTEXT] FILE
JS-based command-line usage:
$ cd build/js
$ node -r esm lib/jsonld/cli.js [-f] [-c CONTEXT] FILE
Building & Testing (& Status)
Build requirements:
- Make
- For Python: Python 3.6+ (and mypy for development)
- For Java: Java 8+ (uses Gradle Wrapper)
- For JS: Node 11+ (using ES6 & ESM)
For Python, this runs mypy and the test suite:
$ make pytest
[...]
python3 -m trld.jsonld.test [...]
Running test suite: cache/json-ld-api/tests/expand-manifest.jsonld
Ran 371 test cases. Passed: 367. Failed: 3. Errors: 1.
Running test suite: cache/json-ld-api/tests/compact-manifest.jsonld
Ran 242 test cases. Passed: 239. Failed: 2. Errors: 1.
Running test suite: cache/json-ld-api/tests/flatten-manifest.jsonld
Ran 55 test cases. Passed: 55. Failed: 0. Errors: 0.
Running test suite: cache/json-ld-api/tests/fromRdf-manifest.jsonld
Ran 51 test cases. Passed: 51. Failed: 0. Errors: 0.
Running test suite: cache/json-ld-api/tests/toRdf-manifest.jsonld
Ran 451 test cases. Passed: 401. Failed: 49. Errors: 1.
python3 -m trld.tvm.test
Running [...]: OK
python3 -m trld.trig.test | grep '^Ran '
Ran 335 tests. Passed 301, failed 34
python3 -m trld.trig.test_serializer | grep '^Examined '
Examined 335 tests. Round-tripped 232, passed 216, failed 13
For the other languages, this will generate packages for each language in the build directory, then run their respective test suites:
$ make java
[...]
java -cp build/java/build/libs/trld-with-deps.jar trld.jsonld.TestRunner [...]
Ran 371 test cases. Passed: 330. Failed: 14. Errors: 27.
java -cp build/java/build/libs/trld-with-deps.jar trld.trig.Test [...]
Ran 335 tests. Passed 252, failed 83
$ make js
[...]
1..551
# tests 551
# pass 540
# fail 11
[...] node [...] lib/trig/test.js [...]
Ran 335 tests. Passed 270, failed 65
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file trld-0.2.0.tar.gz
.
File metadata
- Download URL: trld-0.2.0.tar.gz
- Upload date:
- Size: 60.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d59aa5dea542b55e9c0f3b6ea795994560888f458362eda21eba21e8db735ea3 |
|
MD5 | 33a1d30250998afc6a97c17e2c1cdc6f |
|
BLAKE2b-256 | 81ccab76ca7b0ab9880240064a2ec622128dc5f8b1b37a2a87e67167be97968a |
File details
Details for the file trld-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: trld-0.2.0-py3-none-any.whl
- Upload date:
- Size: 69.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab0524f0660b573134e6b27384fe718bdf46436836e0e47f131f02c470b25ec5 |
|
MD5 | 2732dd1f2adf67aea5de3d7df28f1b32 |
|
BLAKE2b-256 | e3936cb05e1df0df3adbbff8b7ac5568b56cded6a6fff6dcb1e9abe7e0ebda97 |