SPARQL查询返回0

SPARQL查询返回0,sparql,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="&Pub

我在我的本体论中有这样的个体:

 <!-- 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>
<!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>
我试图检索所有包含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")
}
但我没有得到任何结果

这是我的本体:

 <!-- 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>
<!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>
FILTER regex?cpvp,^CPV1为true是?cpvp以CPV1开头,但是,如果我没有错的话,?cpvp的值将以名称空间字符串&Public_;开头;。尝试不使用筛选器的查询,然后查看?cpvp的值是什么样子的。也许您想测试这些值是否以CPV1结尾:在这种情况下,您应该使用FILTER regex?cpvp,CPV1$

查看您的注释,似乎您实际上希望将Procedure类型的所有个人与属性hasCPV链接到包含CPV1的资源。然后,您可能需要此查询未经测试:

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

似乎您想要匹配由URI标识的特定资源http://127.0.0.1/Public_Contracting.owlCPV1. 那么答案或者说查询就更简单了:

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

这将选择拥有CPV的每个过程。

我想这是一个名称空间问题:在SPARQL查询中,所有内容都在名称空间中。你确定你的本体论也是这样吗?例如,在您的本体代码片段中,但我不确定用于hasCPV的默认名称空间是否是您所期望的名称空间。但问题在于过滤。若我从查询中删除最后两个设置,我将得到public:Procedure_1和public:Procedure_2。我不能过滤。有什么想法吗?我编辑了这个问题如果我删除了过滤器,我不会得到任何结果:但是如果我在最后一个设置中使用ns:CPV,我会得到proc | CPV | cpvp:public:Procedure | 1 | public:CPV1 | public:CPV;公共:程序1 |公共:CPV1 |;公共:程序2 |公共:CPV2 |公共:CPV;public:Procedure|u 2 | public:CPV2 |需要从正则表达式中删除^。正则表达式只能应用于字符串或纯文本。