2011-09-06 117 views
1

从来就这一个人在我的本体论:SPARQL查询返回0

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

我想这是一个命名空间问题:在你的SPARQL查询中,一切都在命名空间''中。你确定在你的本体论中也是这样吗?例如在你有''的本体片段中,但我不确定默认名称空间(用于hasCPV)是否是你期望的。 – MarcoS

+0

但问题在于过滤。如果我删除查询中的最后两个句子,我会公开:Procedure_1和public:Procedure_2。我无法过滤。有任何想法吗? –

+0

我编辑了问题 –

回答

2

FILTER regex (?cpvp, "^CPV1")是真实的?cpvp开始与CPV1,但是,如果我没看错,的?cpvp值将与命名空间字符串&Public_Contracting;开始。在没有FILTER的情况下尝试查询,查看?cpvp的值。也许你想测试这些值是否以CPV1结尾:在这种情况下,你应该使用FILTER regex (?cpvp, "CPV1$")


看着你的意见,似乎你真的想获得与物业hasCPV链接到包含“CPV1”资源Procedure类型的所有个人。然后,你可能需要这个查询(未经测试):

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

如果我删除过滤器,我得不到结果:( –

+0

但是如果我使用“a”代替ns:CPV在最后一句中我得到了proc | cpv | cpvp:public:Procedure_1 | public:CPV1 | public:CPV; public:Procedure_1 | public:CPV1 | ; public:Procedure_2 | public:CPV2 | public:CPV; public:Procedure_2 | public :CPV2 |

+2

您需要从您的正则表达式中删除^,并且您需要围绕REGEX的其他参数使用STR()。正则表达式只能是应用于字符串或普通文字 –

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>