Marijn
Marijn

Reputation: 1915

Set the base URI when loading triples using Jena tdbloader

I would like to set the base url when I load data into Fuseki using tdbloader or tdbloader2. Currently the local path is used as base, which is not what I want. Example:

# mytriple.ttl

@prefix owl: <http://www.w3.org/2002/07/owl#> .
<#myitem> a owl:Thing .

./tdbloader --loc /path/to/database /path/to/local/file/mytriple.ttl

# sparql query example

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>    
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?subject ?predicate ?object
WHERE {
  ?subject ?predicate ?object .
  ?subject a owl:Thing .
}

Query result:

<file:///path/to/local/file/mytriple.ttl#myitem> rdf:type owl:Thing

This is (1) not very clean to have in the database and (2) it leads to maintainability issues when I want to query a specific item when the base needs to be specified:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?subject ?predicate ?object
WHERE {
  ?subject a owl:Thing .
  <file:///path/to/local/file/mytriple.ttl#myitem> ?predicate ?object .
}

or

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
BASE <file:///path/to/local/file/mytriple.ttl>
SELECT ?subject ?predicate ?object
WHERE {
  ?subject a owl:Thing .
  <#myitem> ?predicate ?object .
}

How can I specify a different base in tdbloader, for example <mydomain:myontology#>?

Upvotes: 1

Views: 517

Answers (1)

AndyS
AndyS

Reputation: 16630

Put in a BASE or @base statement into the data. That way the data is stable - it will provide the same triples when used anywhere.

Or to avoid editing the file is:

cat "MyBase.ttl" "MyData.ttl" > D.ttl 
tdbloader --loc DB D.ttl

Upvotes: 1

Related Questions