Skip to content

Commit 553fc68

Browse files
authored
Merge pull request #430 from filip26/feat/rdf-conv
1.7.0
2 parents 224b1d4 + 3d969d7 commit 553fc68

File tree

18 files changed

+274
-318
lines changed

18 files changed

+274
-318
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ local.properties
5858
**/nbactions.xml
5959
META-INF
6060
.flattened-pom.xml
61+
/titanium-json-ld-earl.ttl

README.md

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) (JSON-bas
2525
- [Titanium RDFC](https://github.com/filip26/titanium-rdfc) - W3C Standard RDF Dataset Canonicalization
2626
- [Titanium N-QUADS](https://github.com/filip26/titanium-rdf-n-quads) - W3C RDF 1.1 N-Quads
2727
- [Titanium JCS](https://github.com/filip26/titanium-jcs) - RFC 8785 JSON Canonicalization Scheme (JCS)
28-
- [Iridium CBOR-LD](https://github.com/filip26/iridium-cbor-ld) - A CBOR-based Processor for Linked Data
29-
- [RDF-URDNA](https://github.com/simon-greatrix/rdf-urdna) - Universal RDF Dataset Normalization Algorithm 2015
28+
- [Iridium CBOR-LD](https://github.com/filip26/iridium-cbor-ld) - CBOR-based Processor for Linked Data
3029

3130
## Table of Contents
3231
- [Conformance](#conformance)
@@ -52,106 +51,117 @@ See [EARL results from the JSON-LD 1.1 Test Suite](https://w3c.github.io/json-ld
5251

5352
## Examples
5453

55-
Titanium provides a high-level [JsonLd](https://javadoc.io/doc/com.apicatalog/titanium-json-ld/latest/com/apicatalog/jsonld/JsonLd.html) API to interact with the processor.
54+
Titanium provides a high-level [JsonLd](https://javadoc.io/doc/com.apicatalog/titanium-json-ld/latest/com/apicatalog/jsonld/JsonLd.html) API for interacting with JSON-LD documents.
5655

5756
### Transformations
5857

58+
Perform standard JSON-LD operations such as expansion, compaction, flattening, framing, and conversion from/to RDF. The JSON-LD document to process can be remote or local, while context documents may also be local or remote.
59+
5960
```javascript
60-
// Expansion
61+
// Expansion from a remote JSON-LD document
6162
JsonLd.expand("https://w3c.github.io/json-ld-api/tests/expand/0001-in.jsonld")
6263
.ordered()
6364
.get();
6465

66+
// Expansion from a local file with an external context
6567
JsonLd.expand("file:/home/filip/document.json") // HTTP(S) and File schemes supported
6668
.context("file:/home/filip/context.jsonld") // external context
6769
.get();
6870

69-
// Compaction
71+
// Compaction with a remote context
7072
JsonLd.compact("https://example/expanded.jsonld", "https://example/context.jsonld")
71-
.compactToRelative(false)
73+
.compactToRelative(false) // use absolute IRIs
7274
.get();
7375

74-
// Flattening
76+
// Flattening a JSON-LD document
7577
JsonLd.flatten("https://example/document.jsonld").get();
7678

77-
// JSON-LD to RDF
78-
JsonLd.toRdf("https://example/document.jsonld").get();
79-
// or, since 1.6.0
79+
// Convert JSON-LD to RDF
8080
JsonLd.toRdf("https://example/document.jsonld").provide(RdfConsumer);
8181

82-
// Standard RDF Dataset Canonicalization with Titanium RDFC, since 1.6.0
82+
// RDF Dataset Canonicalization with Titanium RDFC
8383
var canonicalizer = new RdfCanon.create(...);
8484
JsonLd.toRdf("https://example/document.jsonld").provide(canonicalizer);
8585
canonicalizer.provide(RdfConsumer);
86-
// or, with NQuadsWriter
86+
// or with N-Quads output
8787
canonicalizer.provide(new NQuadsWriter(...));
8888

89-
// RDF to JSON-LD
90-
JsonLd.fromRdf("https://example/document.nq").get();
89+
// Convert RDF to JSON-LD
90+
var consumer = JsonLd.fromRdf();
91+
consumer.quad(...); // feed manually or via a reader
92+
(new NquadsReader(...)).provide(consumer);
93+
94+
// Get the final JSON-LD result
95+
consumer.toJsonLd();
9196

92-
// Framing
97+
// Framing a document
9398
JsonLd.frame("https://example/document.jsonld", "https://example/frame.jsonld").get();
9499
```
95100

96101
### Local JSON Document
97102

103+
Load and process JSON-LD documents directly from an `InputStream` or `Reader`. You can perform expansion or compaction using local documents and contexts.
104+
98105
```javascript
99-
// Create a JSON document from InputStream or Reader
100-
Document document = JsonDocument.of(InputStream) or JsonDocument.of(Reader) ...
106+
// Load JSON from InputStream or Reader
107+
Document document = JsonDocument.of(inputStream);
108+
Document context = JsonDocument.of(reader);
101109

102-
// Expand the document
110+
// Expand the local document
103111
JsonLd.expand(document).get();
104112

105-
// Compact the document with a context document
106-
JsonLd.compact(document, contextDocument).get();
107-
...
113+
// Compact using a local context
114+
JsonLd.compact(document, context).get();
108115
```
109116

110117
### Processing Timeout [Experimental]
111-
The processor will be terminated after a specified duration.
112-
Please note that the duration does not include the time taken by `DocumentLoader` for processing.
113-
You must set up a separate read timeout for document loading.
118+
119+
Set a maximum processing duration for JSON-LD operations. The timeout does not include time spent loading external documents.
114120

115121
```javascript
116-
// Available since 1.4.0
117-
JsonLd.expand(...).timeout(duration)...get();
122+
// Terminates processing after the specified duration (excluding DocumentLoader time)
123+
JsonLd.expand(document)
124+
.timeout(Duration.ofSeconds(5))
125+
.get();
118126
```
119127

120128
### HTTP Document Loader Timeout
121-
You can configure a custom HTTP document loader instance with a set read timeout.
129+
130+
Customize the HTTP loader to apply a read timeout when fetching remote JSON-LD or context documents.
122131

123132
```javascript
124-
// Available since 1.4.0 - Set read timeout for HTTP document loader
133+
// Configure a custom HTTP loader with a 30-second read timeout
125134
static DocumentLoader LOADER = HttpLoader.defaultInstance().timeout(Duration.ofSeconds(30));
126135
...
127136
JsonLd.expand(...).loader(LOADER).get();
128137
```
129138

130139
### Document Caching
131-
Configure an LRU-based cache for loading documents. The `capacity` argument specifies the size of the LRU cache.
132140

133-
```javascript
134-
// Available since 1.4.0 - Load documents with an LRU-based cache
135-
JsonLd.toRdf("https://example/document.jsonld").loader(new LRUDocumentCache(loader, capacity)).get();
136-
```
137-
138-
You can reuse an instance of `LRUDocumentCache` across multiple calls to benefit from cached documents.
141+
Use an LRU-based cache to reuse previously loaded documents and reduce network calls. A cache instance can be shared across multiple operations.
139142

140143
```javascript
141-
// Available since 1.4.0 - Reuse LRU cache across multiple document loads
142-
DocumentLoader cachedLoader = new LRUDocumentCache(loader, capacity);
144+
// LRU cache for remote documents (capacity = 100)
145+
JsonLd.expand("https://example.com/document.jsonld")
146+
.loader(new LRUDocumentCache(loader, 100))
147+
.get();
148+
149+
// Reuse cache across multiple documents
150+
DocumentLoader cachedLoader = new LRUDocumentCache(loader, 100);
143151

144-
JsonLd.toRdf("https://example/document.jsonld").loader(cachedLoader).get();
145-
JsonLd.toRdf("https://example/another-document.jsonld").loader(cachedLoader).get();
152+
JsonLd.expand("https://example.com/document.jsonld").loader(cachedLoader).get();
153+
JsonLd.expand("https://example.com/another-document.jsonld").loader(cachedLoader).get();
146154
```
147155

148156
### Undefined Terms Processing Policy
149157

150-
Set a processing policy for undefined terms. The default policy is `Ignore`.
158+
Define how the processor handles terms not defined in the context. Options include Fail, Warn, or `Ignore` (default).
151159

152160
```javascript
153-
// Available since 1.4.1 - Define processing policy for undefined terms
154-
JsonLd.expand(...).undefinedTermsPolicy(Fail|Warn|Ignore).get();
161+
// Define behavior for undefined terms: Fail, Warn, or Ignore (default)
162+
JsonLd.expand(document)
163+
.undefinedTermsPolicy(Fail) // or Warn | Ignore
164+
.get();
155165
```
156166

157167
## Installation
@@ -164,14 +174,14 @@ JsonLd.expand(...).undefinedTermsPolicy(Fail|Warn|Ignore).get();
164174
<dependency>
165175
<groupId>com.apicatalog</groupId>
166176
<artifactId>titanium-json-ld</artifactId>
167-
<version>1.6.0</version>
177+
<version>1.7.0</version>
168178
</dependency>
169179
```
170180

171181
#### Gradle (Java 8+, Android API Level >= 24)
172182

173183
```gradle
174-
implementation("com.apicatalog:titanium-json-ld-jre8:1.6.0")
184+
implementation("com.apicatalog:titanium-json-ld-jre8:1.7.0")
175185
```
176186

177187
### JSON-P Provider

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.apicatalog</groupId>
88
<artifactId>titanium</artifactId>
9-
<version>1.7.0-SNAPSHOT</version>
9+
<version>1.7.0</version>
1010
<relativePath>pom_parent.xml</relativePath>
1111
</parent>
1212
<artifactId>titanium-json-ld</artifactId>

pom_jre8.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.apicatalog</groupId>
88
<artifactId>titanium</artifactId>
9-
<version>1.7.0-SNAPSHOT</version>
9+
<version>1.7.0</version>
1010
<relativePath>pom_parent.xml</relativePath>
1111
</parent>
1212
<artifactId>titanium-json-ld-jre8</artifactId>
@@ -34,7 +34,7 @@
3434
<dependency>
3535
<groupId>com.apicatalog</groupId>
3636
<artifactId>titanium-jcs</artifactId>
37-
<version>1.1.0</version>
37+
<version>1.1.1</version>
3838
</dependency>
3939
<dependency>
4040
<groupId>com.apicatalog</groupId>

pom_parent.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.apicatalog</groupId>
88
<artifactId>titanium</artifactId>
9-
<version>1.7.0-SNAPSHOT</version>
9+
<version>1.7.0</version>
1010
<packaging>pom</packaging>
1111

1212
<name>Titanium JSON-LD 1.1</name>

0 commit comments

Comments
 (0)