Why My Query Doesn't Work Using RDFlib
Solution 1:
When I run this query (with prefixes defined) at sparql.org's query processor, I get a bunch of results:
PREFIX ns: <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?varClass ?varSubClass ?varSubClassComment ?varProperty ?varPropComment
FROM <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf>
WHERE {
{
?varClass rdf:type owl:Class .
?varProperty rdf:type owl:ObjectProperty ; rdfs:domain ?varClass . OPTIONAL{?varProperty rdfs:comment ?varPropComment} .
OPTIONAL{?varSubClass rdfs:subClassOf ?varClass ; rdfs:comment ?varSubClassComment} .
}
UNION
{
?varClass rdf:type owl:Class .
?varProperty rdf:type owl:DatatypeProperty ; rdfs:domain ?varClass . OPTIONAL{?varProperty rdfs:comment ?varPropComment}.
}
}
I'd note that you can significantly simplify this query with values since you're using union
just to specify owl:ObjectProperty
and owl:DatatypeProperty
:
PREFIX ns: <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?varClass ?varSubClass ?varSubClassComment ?varProperty ?varPropComment
FROM <http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf>
WHERE {
VALUES ?propertyType { owl:ObjectProperty owl:DatatypeProperty }
?varClass rdf:type owl:Class .
?varProperty rdf:type ?propertyType ;
rdfs:domain ?varClass .
OPTIONAL{ ?varProperty rdfs:comment ?varPropComment }
OPTIONAL{ ?varSubClass rdfs:subClassOf ?varClass ;
rdfs:comment ?varSubClassComment }
}
I don't see any reason that you need to be defining any prefixes for http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf
in your query, since you don't use any such namespace in your query. I'm assuming that that's the dataset that you're trying to query against, or perhaps that you expect the results to begin with that prefix (so perhaps defining the namespace makes their printed output nicer).
This strongly suggests that the problem is that the graph you're actually querying, from /localPath/a.owl
isn't the same as that dataset, or that you're running some outdated versions of RDFlib, rdfextras, or both. I was able to run your Python code locally with RDFlib version 4.0.1 and rdfextras 0.4.
Post a Comment for "Why My Query Doesn't Work Using RDFlib"