openlink / virtuoso-opensource

Virtuoso is a high-performance and scalable Multi-Model RDBMS, Data Integration Middleware, Linked Data Deployment, and HTTP Application Server Platform
https://vos.openlinksw.com
Other
863 stars 210 forks source link

Transitivity in Virtuoso vs SPARQL 1.1? #1103

Closed mkarikom closed 1 year ago

mkarikom commented 1 year ago

Here is a simple query that utilizes the property path operator +:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?type
WHERE {
  ?type rdfs:subClassOf+ rdf:Property.
}

Based on section 5.1.5 (rdfs:ContainerMembershipProperty) of the RDF core schema, the expected result is:

rdf:Property
rdfs:ContainerMembershipProperty

However, when this query is run in 7.2 I get this:

<html><head></head><body>

type
--
http://www.w3.org/2002/07/owl#DeprecatedProperty
http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#ObjectProperty
http://www.w3.org/2002/07/owl#AnnotationProperty
http://www.w3.org/2002/07/owl#OntologyProperty
http://www.w3.org/2002/07/owl#FunctionalProperty
http://www.w3.org/2002/07/owl#TransitiveProperty
http://www.w3.org/2002/07/owl#SymmetricProperty
http://www.w3.org/2002/07/owl#InverseFunctionalProperty

</body></html>

Note that because RDF schema section 5.1.5 asserts rdfs:ContainerMembershipProperty rdfs:subClassOf rdf:Property, the above result should parse the same as the following query, where I omit the + operator from the predicate rdfs:subClassOf:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?type
WHERE {
  ?type rdfs:subClassOf rdf:Property.
}

However, when I run that version of the query in 7.2, I get a different result:


type
--
http://www.w3.org/2002/07/owl#FunctionalProperty
http://www.w3.org/2002/07/owl#OntologyProperty
http://www.w3.org/2002/07/owl#AnnotationProperty
http://www.w3.org/2002/07/owl#ObjectProperty
http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#DeprecatedProperty

What is going on here?

timhaynesopenlink commented 1 year ago

Howdo,

Looks like sql:signal-void-variables doing its job, to me: https://docs.openlinksw.com/virtuoso/rdfsparqlimplementatioptragmas/ .

HTH

TallTed commented 1 year ago

Worth noting — sql:signal-void-variables may be enabled/disabled via the Strict checking of void variables checkbox on the SPARQL query form (.../sparql). For several years, this defaulted to ON, though most use cases (including our own) generally wanted it OFF, which is the default in current builds and has been for some years now.

mkarikom commented 1 year ago

Hi @timhaynesopenlink, @TallTed , Thanks for following up! Embarrassingly, I saw fit to immediately close this after opening it yesterday. You see, I started the post based on a real result that (while actually transitive )was not an MRE, then tried to make it an MRE, then realized that the hastily chosen example was neither transitive, nor an error, nor what I was expecting, hahaha 🤦🏻‍♂️.

Since yesterday, I've updated my post to:

  1. not read like an indictment
  2. provide more accurate and comprehensive description of the observed behavior, and relevant documentation

If you are willing to indulge me for a bit, I'd like to dig a bit deeper into what's going on here, because I'm still struggling to understand the behavior above. Since yesterday, I've come across the documentation on Virtuoso's implementation of the SPARQL 1.1 transitivity logic. Here comes the 'indulgence ask': Because I'm struggling a bit with that piece of documentation, I have the following (slightly out of scope) questions:

  1. Is there a summary on transitivity operators in SPARQL 1.1 vs Virtuoso I can use to ?
  2. If I just need to convert a bunch of queries that were written for SPARQL 1.1 to Virtuoso, what is the most efficient way to do so?

Thanks in advance!

TallTed commented 1 year ago

Recent versions of Virtuoso should be SPARQL 1.1 compliant, so you shouldn't need to change your queries much, if at all.

Please clarify which specific version of Virtuoso you're testing.

Note that 7.2.0 shipped in February 2015, and 7.2.8 shipped in October 2022. (releases)

Also note, the specific git_head value of the build you're running may matter. You can get this with a variant of this SPARQL query, or by running virtuoso -? on the command line.

mkarikom commented 1 year ago

Hi @TallTed, thanks for following up!

Here is the output of the bif: query:

OpenLink Virtuoso   Server | 07.20.3235 | Oct 19 2022 | -pthreads | Linux
TallTed commented 1 year ago

I'm sorry; I was unclear.

The git_head line of the bif: query must be uncommented (remove the leading #) in order to collect that detail — the last commit in the code from which the binary was built.

(The build_date reflects only that — the date the binary was built — without any reference to the codebase from which it was built.)

You can copy and paste this one-liner, to get only that missing detail --

PREFIX bif: <bif:> SELECT ( bif:sys_stat('git_head') AS ?git_head ) WHERE { ?s ?p ?o } LIMIT 1
mkarikom commented 1 year ago

Oh I see, here is the output:

git_head
--
64e6ecd39
TallTed commented 1 year ago

Perfect. You can click this — 64e6ecd39 — to see that you're testing the 7.2.8 Release. There have been a few dozen commits since then, but none that appear likely to impact your current experience.

Next question is, have you loaded the RDFS ontology into your instance? This is usually loaded when you install the rdf_mappers.vad...

mkarikom commented 1 year ago

Thanks! So after loading rdf_mappers.vad, the queries for my application is returning the expected results! Furthermore, the minimal query above now contains the following two expected lines:

http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty

Regarding the original 9 lines of output, which are still being returned, is there any way to get VOS to show me some kind of visualization for how those were inferred?

http://www.w3.org/2002/07/owl#DeprecatedProperty
http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#ObjectProperty
http://www.w3.org/2002/07/owl#AnnotationProperty
http://www.w3.org/2002/07/owl#OntologyProperty
http://www.w3.org/2002/07/owl#FunctionalProperty
http://bblfish.net/work/atom-owl/2006-06-06/#RelationType
http://www.w3.org/2002/07/owl#TransitiveProperty
http://www.w3.org/2002/07/owl#SymmetricProperty
http://www.w3.org/2002/07/owl#InverseFunctionalProperty
TallTed commented 1 year ago

I think there remains the question of whether they actually were inferred, or were found in explicit rdfs:subClassOf statements as part of a loaded ontology, possibly contained in one of the VADs installed in your instance.

You could try iterating DESCRIBE <http://www.w3.org/2002/07/owl#DeprecatedProperty> over the list, to get all the explicit statements about each, or running queries like this —

PREFIX  rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?superclass ?subclass
WHERE
  { { <http://www.w3.org/2002/07/owl#DeprecatedProperty> 
        rdfs:subClassOf ?superclass
    }
    UNION
    { ?subclass
        rdfs:subClassOf <http://www.w3.org/2002/07/owl#DeprecatedProperty> 
  } }

It may also be helpful to see the named graphs that contain these statements, as in —

PREFIX  rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?graph ?superclass ?subclass
WHERE
  { { GRAPH ?graph
      { <http://www.w3.org/2002/07/owl#DeprecatedProperty> 
          rdfs:subClassOf ?superclass
    } }
    UNION
    { GRAPH ?graph
      { ?subclass
        rdfs:subClassOf <http://www.w3.org/2002/07/owl#DeprecatedProperty> 
  } } }

You may also find 16.14.4.Subclasses and Subproperties as well as the rest of 16.14.Inference Rules & Reasoning informative.

For further advice and discussion, I would suggest posting to our Community Forum, where Virtuoso developers and users provide mutual assistance on a wide range of matters related to our software and other products, Virtuoso and otherwise.

Please let me know if this is sufficient to consider this issue resolved.

mkarikom commented 1 year ago

Thanks, @TallTed I confirm that this issue is resolved. Thanks for this very informative response and I'll dig into that soon! Since this discussion is out of scope for bug reports, I'll probably open a Discourse topic on it.