SPARQL查询返回0

时间:2011-09-06 11:53:27

标签: sparql

我的本​​体论中有这些人:

 <!-- 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>

我正在尝试检索包含CPV1的所有程序。

如何使用SPARQL进行操作?

我试过了:

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")
}

但我没有结果。

这是我的本体论:

<!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 rdf: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>

2 个答案:

答案 0 :(得分:2)

FILTER regex (?cpvp, "^CPV1")为真,?cpvpCPV1开头,但是,如果我没有错,?cpvp的值将以命名空间字符串{{1}开头}}。在没有FILTER的情况下尝试查询,看看&Public_Contracting;的值是什么样的。也许您想测试这些值是否以?cpvp结尾:在这种情况下,您应该使用CPV1


查看您的评论,您似乎确实希望将所有类型为FILTER regex (?cpvp, "CPV1$")的个人与属性Procedure关联到包含“CPV1”的资源。然后,您可能需要此查询(未经测试):

hasCPV

答案 1 :(得分:0)

您似乎希望匹配由URI http://127.0.0.1/Public_Contracting.owl#CPV1标识的特定资源。然后答案(或更确切地说是查询)更简单:

PREFIX ns: <http://127.0.0.1/Public_Contracting.owl#>
SELECT ?proc 
WHERE {
  ?proc a ns:Procedure ; 
        ns:hasCPV ns:CPV1.
}

这将选择hasCPV <http://127.0.0.1/Public_Contracting.owl#CPV1>

的每个程序