SPARQL Query returns 0
i´ve this individuals in my ontology:
<!-- http://127.0.0.1/Public_Contracting.owl#CPV1 -->
<owl:NamedIndividual rdf:about="&Public_Contracting;CPV1">
<rdf:type rdf:resource="&Public_Contracting;CPV"/>
<isCPVOf rdf:resource="&Public_Contracting;Procedure_1"/>
</owl:NamedIndividual>
<!-- http://127.0.0.1/Public_Contracting.owl#CPV2 -->
<owl:NamedIndividual rdf:about="&Public_Contracting;CPV2">
<rdf:type rdf:resource="&Public_Contracting;CPV"/>
<isCPVOf rdf:resource="&Public_Contracting;Procedure_2"/>
</owl:NamedIndividual>
<!-- http://127.0.0.1/Public_Contracting.owl#Procedure_1 -->
<owl:NamedIndividual rdf:about="&Public_Contracting;Procedure_1">
<rdf:type rdf:resource="&Public_Contracting;Procedure"/>
<hasCPV rdf:resource="&Public_Contracting;CPV1"/>
</owl:NamedIndividual>
<!-- http://127.0.0.1/Public_Contracting.owl#Procedure_2 -->
<owl:NamedIndividual rdf:about="&Public_Contracting;Procedure_2">
<rdf:type rdf:resource="&Public_Contracting;Procedure"/>
<hasCPV rdf:resource="&Public_Contracting;CPV2"/>
</owl:NamedIndividual>
And i´m trying to retrieve all procedures that contain CPV1.
How can i do it with SPARQL?
I tried this:
PREFIX ns: <http://127.0.0.1/Public_Contracting.owl#>
SELECT ?proc
WHERE {
?proc a ns:Procedure ;
ns:hasCPV ?cpv.
?cpv ns:CPV ?cpvp
FILTER regex (?cpvp, "^CPV1")
}
but i get no results.
This is my ontology:
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY Public_Contracting "http://127.0.0.1/Public_Contracting.owl#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >]>
<rdf:RDF xmlns="http://127.0.0.1/Public_Contracting.owl#"
xml:base="http://127.0.0.1/Public_Contracting.owl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:Public_Contracting="http://127.0.0.1/Public_Contracting.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Ontology rdf:about="http://127.0.0.1/Public_Contracting.owl"/>
<!-- http://127.0.0.1/Public_Contracting.owl#Procedure -->
<owl:Class rdf:about="&Public_Contracting;Procedure">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasSupplier"/>
<owl:someValuesFrom rdf:resource="&Public_Contracting;Supplier"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasBuyer"/>
<owl:onClass rdf:resource="&Public_Contracting;Buyer"/>
<owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasProposal"/>
<owl:someValuesFrom rdf:resource="&Public_Contracting;Proposal"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasProcedureTeam"/>
<owl:onClass rdf:resource="&Public_Contracting;Procedure_Team"/>
<owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasStatus"/>
<owl:onClass rdf:resource="&Public_Contracting;Procedure_Status"/>
<owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rd开发者_Go百科f:resource="&Public_Contracting;hasAdjudicationCriterion"/>
<owl:someValuesFrom rdf:resource="&Public_Contracting;Adjudication_Criterion"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&Public_Contracting;hasCPV"/>
<owl:someValuesFrom rdf:resource="&Public_Contracting;CPV"/>
</owl:Restriction>
</rdfs:subClassOf>
<owl:disjointWith rdf:resource="&Public_Contracting;Procedure_Team"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Proposal"/>
</owl:Class>
<!-- http://127.0.0.1/Public_Contracting.owl#CPV -->
<owl:Class rdf:about="&Public_Contracting;CPV">
<owl:disjointWith rdf:resource="&Public_Contracting;Candidature"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Clarifications"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Entity"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Person"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Procedure"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Procedure_Team"/>
<owl:disjointWith rdf:resource="&Public_Contracting;Proposal"/>
</owl:Class>
FILTER regex (?cpvp, "^CPV1")
is true is ?cpvp
starts with CPV1
, but, if I'm not wrong, the values of ?cpvp
will start with the namespace string &Public_Contracting;
. Try your query without the FILTER, and see what the values for ?cpvp
look like. Maybe you want to test if those values end with CPV1
: in this case you should use FILTER regex (?cpvp, "CPV1$")
.
Looking at your comments, it seems that you actually want to get all individuals of type Procedure
linked with property hasCPV
to a resource containing "CPV1". Then, you probably need this query (untested):
PREFIX ns: <http://127.0.0.1/Public_Contracting.owl#>
SELECT ?proc
WHERE {
?proc a ns:Procedure ;
ns:hasCPV ?cpv.
FILTER regex (STR(?cpv), "CPV1$")
}
It seems you want to match a specific resource, identified by the URI http://127.0.0.1/Public_Contracting.owl#CPV1
. Then the answer (or rather the query) is simpler:
PREFIX ns: <http://127.0.0.1/Public_Contracting.owl#>
SELECT ?proc
WHERE {
?proc a ns:Procedure ;
ns:hasCPV ns:CPV1.
}
This selects each procedure that hasCPV <http://127.0.0.1/Public_Contracting.owl#CPV1>
.
精彩评论