Executing a SPARQL query USING rdf and owlready2 doesn't stop

63 Views Asked by At

I perform an advanced query in Quran 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, the run doesn't stop using both owlready2 and rdf.

This is my code using owlready2:

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/")
query = """
PREFIX qu: <http://purl.oclc.org/NET/ssnx/qu/qu#>
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  distinct ?prophetLabel
WHERE {
?person rdfs:subClassOf* qur:Person.   
?prophet rdf:type  ?person.  
?prophet  rdfs:label ?prophetLabel.
?verse rdf:type qur:Verse.
?prophet qur:MentionedIn ?verse.
?verse2 rdf:type qur:Verse.  
?word rdf:type qur:Word. 
?letter rdf:type qur:PronounRefDifferentVerse. 
?word qur:IsPartOf ?verse2.
?letter qur:IsPartOf ?word.
?letter  qur:ReferToVerse ?verse.
?verse2 rdfs:label ?textSimple2.
?verse rdfs:label ?textSimple.
FILTER ((REGEX(STR(?prophetLabel), "[ء-ي]+" ,"i"))).
FILTER (REGEX(STR(?textSimple2), "برا بوالديه" ,"i")).
  } 
"""
d = list(default_world.sparql(query))
print(d)

This is my code using rdf:

parsingGraph = rdflib.Graph()
parsingGraph.parse ('/gdrive/MyDrive/Quran Corpus/quran_data_full.owl', format='application/rdf+xml')
quran_data_full = rdflib.Namespace('/gdrive/MyDrive/Quran Corpus/quran_data_full.owl')
parsingGraph.bind('quran_data_full', quran_data_full)
query = """
PREFIX qu: <http://purl.oclc.org/NET/ssnx/qu/qu#>
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  distinct ?prophetLabel
WHERE {
?person rdfs:subClassOf* qur:Person.   
?prophet rdf:type  ?person.  
?prophet  rdfs:label ?prophetLabel.
?verse rdf:type qur:Verse.
?prophet qur:MentionedIn ?verse.
?verse2 rdf:type qur:Verse.  
?word rdf:type qur:Word. 
?letter rdf:type qur:PronounRefDifferentVerse. 
?word qur:IsPartOf ?verse2.
?letter qur:IsPartOf ?word.
?letter  qur:ReferToVerse ?verse.
?verse2 rdfs:label ?textSimple2.
?verse rdfs:label ?textSimple.
FILTER ((REGEX(STR(?prophetLabel), "[ء-ي]+" ,"i"))).
FILTER (REGEX(STR(?textSimple2), "برا بوالديه" ,"i")).
  } 
"""
result = parsingGraph.query(query)
for row in result:
    print(row.prophetLabel)

This is the output in Apache Jena Fuseki: enter image description here

What are the possible alternatives to execute this query?

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

0

There are 0 best solutions below