Virtuoso SPARQL endpoints inference rules - sparql

When using an endpoint that is hosted in Virtuoso, (like DBpedia endpoint), there are a predefined set of rules that can be used (accessible through the Inference rules link on the top right).
If I need to use one of these rules I can include as the following within the query space at the endpoint:
define input:inference 'ldp'
However, when I try to include an external inference rules set, which is not predefined at the previous list, it triggers an error, as the following:
define input:inference <http://purl.org/goodrelations/v1>
Virtuoso 37000 Error SP031: SPARQL compiler: 'define input:inference refers to undefined inference rule set "http://purl.org/goodrelations/v1"
QUESTION:
Is it possible to include external rules from other vocabularies? and if yes, how?

The DBpedia instance (and any other Virtuoso instance, for that matter) includes a list of preloaded inference rules. Naturally, for a variety of reasons (security, fair use, etc.), we don't allow ad-hoc inclusion of inference rules from external sources.
Note: An inference rule in Virtuoso is a mapping between a Rule and an Ontology (see Using British Royal Family Data Snippets — to demonstrate SPARQL Query Language-based Reasoning & Inference). It's the Rule Name that's used in the Inference Rule pragma of the query, which then indicates the following to the SPARQL processor:
Need to invoke inference context
Specific Rules (again, mappings to an Ontology where relation semantics are defined) to be invoked.

Related

Does RDF4J's AST allow for SPARQL Query Rewriting?

According to a couple answers here and here, it seems that it might be possible to use the AST produced by RDF4J's SyntaxTreeBuilder to modify a parsed SPARQL query in memory and then serialize it back to a SPARQL string. However, I have not found any implementations that handle this serialization given the AST. The closest thing of course is the SparqlQueryRenderer but my use case demands working with the AST, not the SPARQL algebra model.
Naturally, I could imagine implementing a class that rebuilds the SPARQL query string as an AST visitor, but I would rather use a different library if it is not already supported or implemented for RDF4J.

Is it possible to infer new knowledge about an ontology only from a query in SPARQL?

Is it possible to infer new knowledge about an ontology only from a query in SPARQL?
I have a question about the use of the SPARQL language about ontologies. So far I have thought that SPARQL is the equivalent to the SQL language in the relational databases, that is to say, that with SPARQL it is only possible to consult the data that are explicitly in the ontology, without having access to the data that can be inferred , leaving the responsibility of the inference to the reasoners.
However, I have read documents from which I infer that SPARQL does have the capacity to infer implicit and non-explicit knowledge in the ontology. Is my inference true? That is, is it possible to infer knowledge through a SPARQL query without the need for a reasoner? If the answer is true, then what advantages does the use of a reasoner have over the use of SPARQL?
Greetings, Manuel Puebla.
Yes, on-the-fly inference may be a feature of the SPARQL processor, so you can get the benefits of inference/reasoning directly from a SPARQL query. (See Virtuoso SPARQL endpoints inference rules for some discussion of how this is done in Virtuoso, for example.)

Does SPARQL works for Inferred statements also?

I am using SPARQL plugin in protege to query my ontology, and I found out that it only works for asserted statements and not inferred ones. How can I change this?
SPARQL is defined by several standards. SPARQL 1.1 Query, the main standard, only shallowly relies on RDF semantics. A typical SPARQL query engine is not inferring anything from the RDF/RDFS terms like rdfs:subClassOf, rdfs:range, etc. However, the SPARQL standards also define SPARQL 1.1 Entailment Regimes, which defines how SPARQL engines should answer queries when they do implement inference, which is optional. In order to know whether a SPARQL query engine implements an entailment regime (such as RDFS or OWL DL), you may have to look at the documentation of the engine, or there may be a SPARQL service description available in RDF. SPARQL 1.1 Service Description is yet another SPARQL standard that provides an RDF vocabulary, and a standard way to interpret it, for knowing what features a SPARQL engine is implementing.

Inference over linked data SPARQL endpoints

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?
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.
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.

semantic web reasoner and on the fly rules injection

Is there any semantic web reasoner (e.g. Pellet) that accepts rules (SWRL) on the fly ?
or rules must be hard coded before starting the reasoner
It is unclear what you mean by "on the fly". You can edit a reasoner's rule base, so it is not something you need to set in stone from the outset. But the reasoner will need to perform some book keeping if you add new rules, or any other axioms, before it can be used to answer queries. There's no way around that.