Marko.V.
Marko.V.

Reputation: 11

RDF4j v3.0.0 Export graph without inferred triples in it

in version 3.0.0, since inferred triples are added into an actual graph (not into the default as before), is it somehow possible to export/fetch an actual graph without the inferred triples? Thanks a lot.

Upvotes: 1

Views: 162

Answers (1)

Jeen Broekstra
Jeen Broekstra

Reputation: 22053

Yes, this is possible.

1. Via the Java API

You can retrieve the statements from named graph http://example.org/graph1 in several ways. Showing two alternatives here:

 IRI graph1 = valueFactory.createIRI("http://example.org/graph1");

 try(RepositoryConnection conn = repository.getConnection()) {

     // option 1: getStatements of everything in a named graph, setting
     // includeInferred to false
     RepositoryResult<Statement> result = conn.getStatement(null, null, null, false, graph1);

    // option 2: using export with an RDFHandler (export never includes inferred triples)
    RDFHandler collector = new StatementCollector(); 
    conn.export(graph1, collector);
 }

2. Via the RDF4J Workbench

The simplest way to do this in the workbench is to use a SPARQL CONSTRUCT query:

construct from <http://example.org/graph1> where { ?s ?p ?o }

Make sure that the "include inferred statements" option is unchecked before hitting 'Execute'. Then on the query result screen, pick your preferred download format, and hit 'Download'.

Upvotes: 0

Related Questions