[Moved from answer here on "query using SPARQL with RDF inference model (reasoner)". /Signified]

To get SPARQL query results based on inferences, for example, the RDFS sub-class rule needs to be applied on the dataset (i.e. using a reasoner). After that I can use the original SELECT-query.

But what if I don't have the possibility to run a reasoner on my dataset (for example if I have a remote dataset which I can't write on or if the dataset is just too large and running a reasoner would be too time consuming). Is there a way to use the rule with the SPARQL-query.

asked 17 Jan '13, 15:19

imikbox's gravatar image

accept rate: 0%

edited 18 Jan '13, 11:06

Signified's gravatar image

Signified ♦

I'm converting this to a separate question. ;)

(18 Jan '13, 10:55) Signified ♦ Signified's gravatar image

Writing a generic reasoner on top of an external plain-ol' SPARQL engine is possible for something like RDFS using multiple queries, but won't be very efficient in many cases. You could query for all of the RDFS schema information and then cache that, using it on the client side for a technique called "query-rewriting". (This might be an interesting research problem.)

However, the more practical option in many scenarios is to try capture the inference directly in the query. For example, to find all instances of foaf:Agent (inferred or otherwise), you could try the following in SPARQL 1.1 using property-paths:

   SELECT ?s
   WHERE {
      ?s a ?class . ?class rdfs:subClassOf* foaf:Agent .

(Edited to use zero-to-many match instead of union based on Andy's comment. Thanks!)

Of course, with this approach, you would not find instances inferred to be foaf:Agent through the other rules like rdfs:domain or rdfs:range. You could extend the query further to find such inferences, but could not support all of RDFS in a single query like this (due to potential cycles in rule dependencies and the lack of true recursion in SPARQL).

permanent link

answered 18 Jan '13, 11:11

Signified's gravatar image

Signified ♦
accept rate: 37%

edited 19 Jan '13, 15:34


No need to union: { ?s a ?class . ?class rdfs:subClassOf* foaf:Agent . }

(18 Jan '13, 12:39) AndyS ♦ AndyS's gravatar image

Building on @Signified's answer: you can cache locally for any given query (with any set of rules). Take each of the triple, or quad patterns in the query, break them out of the query and run them separately, then cache them in your triple store. Then run your inferences and add them to the cache. Then run your original query on your cache. This doesn't always work if any of the individual triple/quad patterns return results that are too large to transmit or store.

permanent link

answered 18 Jan '13, 14:23

harschware's gravatar image

harschware ♦
accept rate: 20%

Building on @harschware's answer, you don't have to limit yourself to your remote store's intended semantics. If you use a CONSTRUCT query to extract out your triples, you can merge that with any old ontology you come up with, using a reasoner on the whole.

permanent link

answered 18 Jan '13, 20:48

Ryan%20Kohl's gravatar image

Ryan Kohl
accept rate: 17%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 17 Jan '13, 15:19

question was seen: 1,490 times

last updated: 19 Jan '13, 15:34