6

I'm trying to make a request which uses both bibleontology and dbpedia semantic databases:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT ?art ?abstract WHERE { 
bibleontology:Ezra owl:sameAs ?art .
?art dbo:abstract ?abstract .
}

This kind of request works on neither the bibleontology SPARQL endpoint, nor on the dbpedia SPARQL endpoint. Individual parts of the requests work fine on the each SPARQL endpoints.

Is it possible to join databases this way?

raphink
  • 3,625
  • 1
  • 28
  • 39
  • 1
    How can you perform cross query, when the model is not merged. May be you could perform data collation yourself, by merging the two rdf stores ( models), but as is, you cannot perform a cross query. – uncaught_exceptions Jan 30 '11 at 07:52
  • So RDF provides links to the places where the models are described, but never to the data themselves? I thought one of the goals of semantic web was to allow distributed queries over various datasets? – raphink Jan 30 '11 at 07:55
  • Maybe I didn't understand the comment, as in the model being merged. The sameAs entry for bibleontology:Ezra does give a link to a dbo entry. This is what made me think it would be possible to join them. – raphink Jan 30 '11 at 08:03
  • As I explain in my answer you can do this by using The Semantic Web Client Library, in essence this library caches for you parts of databases in order to answer your SPARQL query. I hope this is what you're looking for. – Manuel Salvadores Jan 30 '11 at 11:16
  • Take a look at my answer - if your endpoints support the SPARQL 1.1 `SERVICE` keyword or you have a local endpoint/tool that does then you can use that to achieve your goal – RobV Jan 30 '11 at 11:51

3 Answers3

12

I'm Engineer for bibleontology.com

bibleontology.com adopted SPARQL1.1

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?art ?abstract
WHERE {
SERVICE <http://bibleontology.com/sparql/> { bibleontology:Ezra owl:sameAs ?art . }
SERVICE <http://dbpedia.org/sparql> { ?art dbo:abstract ?abstract . } }
wonseok oh
  • 121
  • 2
7

That query doesn't work on neither dbpedia or bibleontology because the information is stored in two different databases and when you run a SPARQL query you basically hit one or the other. This means that you have to you download the data from both databases to put them in a local triple store in order to able to run a SPARQL query like the one you showed. Another option is to use a library that does that for you.

The Semantic Web Client Library will follow all URIs that you have in your SPARQL query and download the RDF data from each resource so that it can join all the triple patterns that appear in you query and give the answers.

You could run your query with some minor changes :

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dbpedia: <http://dbpedia.org/ontology/> 

SELECT * WHERE { 
bibleontology:Ezra owl:sameAs ?art .
?art dbpedia:abstract ?abstract .
FILTER langMatches( lang(?abstract), "EN" )
} 

Explanation of the changes:

  1. Included owl and dbpedia namespaces
  2. ?art dbpedia:abstract ?abstract . you need to match the dbpedia:abstract predicate to get the abstract instead of bibleontology:abstract in order to get the abstract from dbpedia
  3. I have also included a filter to only retrieve abstracts in English, this is of course optional.

Once you download "The Semantic Web Library" and you put your query in a file (i.e: query.sparql) you can run the following command to test your query:

./semwebquery -sparqlfile query.sparql -retrieveduris -maxsteps 5

All the command params are explained in the Semantic Web Client Library documentation.

You would get the following output:

| ?art                               | ?abstract
| <http://dbpedia.org/resource/Ezra> | "Ezra is a major .... "@en |

Successfully dereferenced URIs: 

http://www.w3.org/2002/07/owl
http://bibleontology.com/data/Ezra
http://dbpedia.org/data/Ezra.xml
http://dbpedia.org/data3/abstract.n3

I have omitted the long abstract from dbpedia for simplicity. The list of "Successfully dereferenced URIs" are documents retrieved by the library in order to answer your query. In the documentation of the library you'll see how to run queries programatically in Java.

Manuel Salvadores
  • 16,287
  • 5
  • 37
  • 56
  • That is interesting, although the tool is quite slow. For some reason, this tool seems to only return one result, even if the request should return more than one result, such as `PREFIX bo: PREFIX bop: PREFIX dbo: PREFIX owl: PREFIX dbpedia: SELECT DISTINCT ?Parent ?Abstract WHERE { bo:Moses bop:hasParents ?Parent . ?Parent owl:sameAs ?art . ?art dbpedia:abstract ?Abstract . FILTER ( LANG(?Abstract) = "en" ) }` – raphink Jan 30 '11 at 21:31
  • Actually, if I only search for the parents, it gives me a list of two entries, but if I search for the abstracts, it only lists the abstracts for the first parent, not for the second one. – raphink Jan 30 '11 at 21:47
6

All the other answers are correct in saying that you can't make the query as is because the data is not combined in a single SPARQL endpoint. If one of the endpoints supports SPARQL 1.1 Federated Querying then you may be able to use the SERVICE keyword like so:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  bibleontology:Ezra owl:sameAs ?art .
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

You'd submit the above query to the bibleontology SPARQL endpoint and provided that it supports the SERVICE keyword it sends part of your query to the DBPedia SPARQL endpoint.

Even if your SPARQL endpoint supports the SERVICE keyword then you are still reliant on the relevant data being in the two datasets i.e. the Bible Ontology needs to have a owl:sameAs that points to a DBPedia resource in order that the SERVICE clause actually find anything.

Alternatively

If neither of your endpoints support the SERVICE keyword then you can set up a local endpoint or use a command line tool that supports the SERVICE keyword (I'll dig some links up if you're interested) and then issue the following:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  SERVICE <http://bibleontology.com/sparql> { bibleontology:Ezra owl:sameAs ?art . }
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

If your local tool/endpoint supports SERVICE then it will be able to send the relevant parts of the query to the relevant endpoints and do the Joining locally and hopefully give back the results you are after

RobV
  • 28,022
  • 11
  • 77
  • 119
  • That looks very interesting, but it doesn't work for any of the two SPARQL endpoints I tried. I will keep trying on other endpoints. How do I install a local endpoint? – raphink Jan 30 '11 at 21:29
  • Yes unforunately the above is SPARQL 1.1 so not widely adopted yet – RobV Jan 31 '11 at 10:46
  • I am just getting into SPARQL and so on. Could you give me some local endpoints that support SPARQL 1.1? – Karsten May 06 '13 at 19:54
  • Take a look at [Fuseki](http://jena.apache.org/documentation/serving_data/index.html) or [Store Manager](https://bitbucket.org/dotnetrdf/dotnetrdf/wiki/UserGuide/Tools/Store%20Manager) (use the In-Memory connection) - *disclaimer* - I'm a developer on both these tools – RobV Jan 18 '14 at 11:25