3

When querying some linked data SPARQL endpoints via SPARQL queries, what is the type of reasoning provided (if any)?

For example, DBpedia SNORQL endpoint doesn't even provide the basic subclass inference (if A subClassOf B and B subClassOf C, then A subClassOf C). While FactForge SPARQL endpoint provides some inference (though it is not clear what kind of inference it is), and provides the possibility to switch that inference on and off.

My question: How is it possible to identify the kind of inference applied? and if the inference support is limited, could it be extended using the endpoint only?

TallTed
  • 9,069
  • 2
  • 22
  • 37
Median Hilal
  • 1,483
  • 9
  • 17
  • 2
    There are a number of inferences that you can do in SPARQL alone. E.g., to traverse the class hierarchy, you can do `?subclass rdfs:subClassOf* ?superclass` to get the `A subclassOf C` result that you mentioned. – Joshua Taylor Mar 31 '16 at 02:03
  • Well, 1. Is there any place you refer me to check the full list of SPARQL enabled inference? – Median Hilal Apr 04 '16 at 12:52
  • 2. Couldn't this inference be enabled on the SPARQL endpoint level? i.e. writing only typical SPARQL queries, while the endpoint is responsible for the inference? – Median Hilal Apr 04 '16 at 12:53
  • 1
    1. I don't know of a full list like that. I know that some inferences are possible mostly because I've answered questions on Stack Overflow about doing a bit of inference using SPARQL. 2. Sure, an endpoint could return results based on a reasoner, but if the endpoint doesn't do that and you don't have control over the endpoint, you're going to have to end up doing the reasoning yourself, whether with a SPARQL query, or by grabbing enough of the data and applying a reasoner yourself. – Joshua Taylor Apr 04 '16 at 12:58

2 Answers2

4

Inference controls will vary with the engine as well as the endpoint.

The public DBpedia SPARQL endpoint (powered by Virtuoso, from my employer, OpenLink Software) does provide various inference rules (accessible through the "Inference rules" link at the top right corner of the SPARQL endpoint query form page) which are controlled by pragmas in your SPARQL (not SNORQL, to which form you linked), such as --

DEFINE  input:inference  'urn:rules.skos'

You can see the content of any predefined ruleset via SPARQL -- for the above

SELECT  * 
  FROM  <urn:rules.skos> 
 WHERE  { ?s ?p ?o }

You can see the live query and results.

See this tutorial containing many examples.

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • Perfect. However, how to know the contents of the rule set? for example, skos-trans stands for urn:rules.skos. What are the applied rules when including this rules set? – Median Hilal Apr 01 '16 at 10:26
  • 1
    Thanks again. But it seems that the term 'inference rules' is a bit misleading. What they really are is a kind of vocabulary inclusion. So, when stating DEFINE input:inference 'urn:rules.skos' inside the query, that only includes the referred vocabulary. Now again, the problem is how to enable the reasoning of the kind (if A subClassOf B and B subClassOf C, then A subClassOf C) without using SPARQL itself, i.e. not using rdfs:subClassOf* ? – Median Hilal Apr 04 '16 at 12:45
  • 1
    The inference rules are used to *infer* triples which are not explicitly present in the original data, but may be explicitly included in the result set. I'm not understanding why the options presented don't serve your need, so perhaps you might provide a bigger picture? SPARQL 1.1 Property Paths do cover the simple case of `subClassOf` entailment, but it seems you want something more? – TallTed Apr 04 '16 at 14:04
  • I want to get the results including the inferred triples, without having to specify that within the sparql query. For example the query `select COUNT DISTINCT ?x WHERE{?x rdfs:subClassOf .}` returns 50 results, while repeating the same query but adding a star symbol `select COUNT DISTINCT ?x WHERE{?x rdfs:subClassOf* .}` returns 184 results. What I want is not to handle the inference manually, i.e. not adding the star symbol to the query, and leaving the inference responsibility on the endpoint itself. – Median Hilal Apr 05 '16 at 15:45
  • 1
    This is a thing you cannot reliably have, because you cannot be certain how any given endpoint will handle things. Also, you're asking for two different things above -- and neither actually uses Inference, which involves "missing" triples. The first query asks for `?x` where triples exist explicitly stating that `?x rdfs:subClassOf `. The second query asks for those `?x` plus `?x` where a series of existing triples explicitly state that `?x rdfs:subClassOf other . other rdfs:subClassOf ` where `other` might recurse. – TallTed Apr 05 '16 at 16:01
  • The second query does not report `?x rdfs:subClassOf ` for those `?x` which are not explicitly described so. – TallTed Apr 05 '16 at 16:04
  • So what you mean is that the second query is only a kind of subClassOf closure? Not implying any other type of inference, right? – Median Hilal Apr 06 '16 at 13:06
  • Yes. Inference lets you say, for instance, `{ _:ClassB subClassOf _:ClassA . _:ClassC subClassOf _:ClassB . _:ThingA a _:ClassC }`, `SELECT ?x WHERE { ?x a _:ClassA }` — and get `_:ThingA` in your result set. This doesn't happen in the examples posited above. Further reading: "[How to exploit RDF Schema and OWL Inference Rules with minimal effort?](http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtTipsAndTricksGuideRDFSchemaOWLInferenceRules)", "[Tutorial Demonstrating Reasoning via SPARQL](http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtSPARQLReasoningTutorial)". – TallTed Apr 06 '16 at 13:38
2

While inference is not universally supported across SPARQL endpoints, most of the inferences supported by RDFS, RSFS+ and OWL 2 RL profiles are supported by SPARQL itself. For example, querying for instances of :A using your subClassOf entailment can be supported with SPARQL property paths:

SELECT ?inst 
WHERE {
   ?cls rdfs:subClassOf* :A .
   ?inst a ?cls .
}

The first triple pattern gets all subclasses of :A, including :A (use + instead of * if you just want subclasses of :A), and the second triple finds all instances of all those classes.

To see how most of OWL 2 can be implemented with SPARQL, see Reasoning in OWL 2 RL and RDF Graphs using Rules. With a couple of exceptions, all of these can be implemented in SPARQL (and in fact you probably won't need some of them, such as eq-ref, (which is good for a computational lol that logicians may scoff at)).

There are few uses cases, beyond heavy-lifting classification problems, that can't be solved with a subset of the OWL 2 RL rules.

So, in the end, a recommendation is to understand what entailments you need. Chances are that OWL has totally overthought the issue and you can live with a few SPARQL patterns. And then you can hit the SPARQL endpoints without having to worry about whether specific inference profiles are supported.

scotthenninger
  • 3,921
  • 1
  • 15
  • 24
  • Thanks. That was useful. I checked the specification of SPARQL SPIN for rules specification. However, I was basically concerning the endpoint capabilities. – Median Hilal Apr 01 '16 at 10:28