pythonjenavalueerrorfusekiowlready

Running SPARQL query using owlready2 gave ValueError: Unknown block type MinusBlock


I have an ontology in an 'owl' file (quran_data_full.owl) and I saved it in a folder in my google drive (Quran Corpus). To perform some queries in this ontology, first I tried the query on Apache Jena Fuseki. It gave me the correct results so I copied the query into my code in google collab but unfortunately it gave me a value error related to MinusBlock.

This is my code in google collab:

from owlready2 import *
onto_path.append("/gdrive/MyDrive/Quran Corpus")
go = get_ontology("/gdrive/MyDrive/Quran Corpus/quran_data_full.owl").load()
obo = get_namespace("/gdrive/MyDrive/Quran Corpus/")
d = list(default_world.sparql("""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX qur: <http://quranontology.com/Resource/>
SELECT ?verse ?text 
WHERE {?verse rdf:type qur:Verse.
?verse qur:DiscussTopic ?topic.
?verse rdfs:label ?text.
?topic qur:TopicCompleteName ?topicName.
FILTER (REGEX(STR(?topicName), "زكاة" ,"i")).
FILTER langMatches(lang(?text),"ar")
MINUS { ?verse rdfs:label ?text.
FILTER (REGEX(STR(?text), "زكاة" ,"i")).} 
}
"""))

This gave me this error: ValueError: Unknown block type '<MinusBlock [(VAR:'?verse', IRI:'http://www.w3.org/2000/01/rdf-schema#label', VAR:'?text'), <owlready2.sparql.parser.Filter object at 0x7f8b5a75b970>]>'!

This is the result from running the query on Apache Jena Fuseki:

enter image description here

You can see the full content of quran_data_full.owl file here.

How to handle this error?


Solution

  • owlready2 does not support all of SPARQL 1.1. The coverage is documented at

    https://owlready2.readthedocs.io/en/v0.37/sparql.html#sparql-elements-supported

    MINUS is listed in "not supported"

    https://owlready2.readthedocs.io/en/v0.37/sparql.html#sparql-elements-not-supported