Package com.inrupt.client.rdf4j
package com.inrupt.client.rdf4j
RDF4J RDF support for the Inrupt Java Client Libraries.
The RDF4J module gives two possibilities to read RDF data: through the Service RDF4JService
and through the BodyHandler RDF4JBodyHandlers.
A user of the RDF4JService should ensure that this implementation is
available on the classpath by adding the following dependency:
<dependency>
<groupId>com.inrupt</groupId>
<artifactId>inrupt-client-rdf4j</artifactId>
<version>${project.version}</version>
</dependency>
Example of using the RDF4J Service toDataset() method to read triples
from a trig file into a Dataset:
RdfService service = ServiceProvider.getRdfService();
Dataset dataset;
try (InputStream input = Test.class.getResourceAsStream("/tripleExamples.trig")) {
dataset = service.toDataset(Syntax.TRIG, input);
}
System.out.println("Number of triples in file: " + dataset.size());
Example of using the RDF4J BodyHandler ofModel() method to read the triples
from the same trig file into a Model:
Request request = Request.newBuilder()
.uri(URI.create("https://example.example/tripleExamples.trig"))
.GET()
.build();
Response<Model> response = client.send(request, RDF4JBodyHandlers.ofModel()).toCompletableFuture().join();
System.out.println("HTTP status code: " + response.statusCode());
System.out.println("Number of triples in file: " + response.body().size());
The RDF4JBodyPublishers can be used to write triples. An example that uses the
POST method to write a Model:
ModelBuilder builder = new ModelBuilder();
builder.namedGraph("https://example.example/graph")
.subject("https://example.example/subject")
.add("https://example.example/predicate", "object");
Model model = builder.build();
Request request = Request.newBuilder()
.uri("https://example.example/postEndpoint"))
.header("Content-Type", "text/turtle")
.POST(RDF4JBodyPublishers.ofModel(model))
.build();
Response<Void> response = client.send(request, Response.BodyHandlers.discarding()).toCompletableFuture().join();
System.out.println("HTTP status code: " + response.statusCode());
-
ClassesClassDescription
Response.BodyHandlerimplementations for use with RDF4J types.Request.BodyPublisherimplementations for use with RDF4J types.AnRdfServicethat uses the RDF4J library.