Serious Bug Found with SPARQL Queries

27 views
Skip to first unread message

James Hudson

unread,
Jun 8, 2020, 9:49:54 AM6/8/20
to rdflib-dev
I was hoping to get some quick attention on this as this appears to be a serious issue with RDFLib. If someone could confirm that I have found a bug, that would be helpful.

I submitted the bug report at https://github.com/RDFLib/rdflib/issues/1113


```
import rdflib
from pprint import pprint


data = """
@prefix ex: <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .


ex:CCCC a rdfs:Class ;
    rdfs:subClassOf ex:AAAA .


ex:DDDD rdfs:subClassOf ex:BBBB,
        ex:AAAA .
"""


g = rdflib.Graph().parse( data = data, format = 'ttl' )


# print( f"{g.serialize( format = 'ttl' ).decode( 'utf8' )}" )


query = """
        PREFIX sch:  <http://schema.org/>
        PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
       
        SELECT ?class ?subclass
        WHERE {        
                ?class rdfs:subClassOf+ ?subclass .                              
        }
        ORDER BY ?class ?subclass
        """


qres = g.query( query )


for row in qres:    
             
    aclass    = str( row['class'] )
    subclass  = str( row['subclass'] )
    print( f"{aclass:30s} {subclass:50s}" )  
```


This outputs:

```
http://example.org/CCCC        http://example.org/AAAA                          
http://example.org/CCCC        http://example.org/BBBB                          
http://example.org/DDDD        http://example.org/AAAA                          
http://example.org/DDDD        http://example.org/BBBB  
```


The output declares there is a subClassOf path from CCCC to BBBB and there clearly is not. 

I downloaded a SPARQL playground from http://sparql-playground.sib.swiss which is trivial to get up and running on a local machine and tried the same data an query. The results were:



which is *exactly* what one expects.

James Hudson

unread,
Jun 8, 2020, 10:10:51 AM6/8/20
to rdfli...@googlegroups.com
It appears that I was still using 4.2.2 of rdflib and the bug (whatever it was) was fixed in 5.0.0 which I have upgraded to.

--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/7dc69ed6-8607-492b-9f23-1797dc01264do%40googlegroups.com.

Nicholas Car

unread,
Jun 18, 2020, 7:01:43 PM6/18/20
to rdfli...@googlegroups.com
Sorry for the delay here - end of financial year work panic - I’ll look into this next week

— 
Dr Nicholas Car
Data Systems Architect
SURROUND Australia
0477 560 177

On 9 Jun 2020, at 12:10 am, James Hudson <jameshu...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages