如何使用sparql查询protege创建的个人

How to query an individual created by protege using sparql

我正在使用 Protege-5.0.0-beta-17 开发 ontology 并使用 apache-jena-fuseki-2.0.0 来托管 ontology。它有以下人员。这个场景的背景是http://mywebsite.com/module/ontologies/local_policy下有policy individuals。政策基本上是 local_policies.

类型
<!-- http://mywebsite.com/module/ontologies/policy1 -->

    <owl:NamedIndividual rdf:about="http://mywebsite.com/module/ontologies/policy1">
        <rdf:type rdf:resource="http://mywebsite.com/module/ontologies/local_policy"/>
        <PolicyName rdf:datatype="&xsd;string">1.1.1</PolicyName>
        <PolicyResponsibility rdf:datatype="&xsd;string">CIO</PolicyResponsibility>
        <PolicyKeyword rdf:datatype="&xsd;string">Information Security</PolicyKeyword>
        <PolicyMaturityLevel rdf:datatype="&xsd;string">Interactive-Information</PolicyMaturityLevel>
        <PolicyConsulted rdf:datatype="&xsd;string">CERT</PolicyConsulted>
        <PolicyDesc rdf:datatype="&xsd;string">The relevant sections of Information Security Policy which has been published by government should be used for classifying organizational data and information.  The particular policies have been elaborated in &quot;Information assets classification and control&quot; of the Information Security (IS) policy  (http://www.government.lk/images/secPolicy/Asset_Classification_and_Control.doc). The Assistance of Computer Emergency Readiness Team (CERT) could be obtained for this purpose.</PolicyDesc>
        <apply rdf:resource="http://mywebsite.com/module/ontologies/focusArea1"/>
    </owl:NamedIndividual>



    <!-- http://mywebsite.com/module/ontologies/policy2 -->

    <owl:NamedIndividual rdf:about="http://mywebsite.com/module/ontologies/policy2">
        <rdf:type rdf:resource="http://mywebsite.com/module/ontologies/local_policy"/>
        <PolicyName rdf:datatype="&xsd;string">2</PolicyName>
        <PolicyResponsibility rdf:datatype="&xsd;string">CIO</PolicyResponsibility>
        <PolicyKeyword rdf:datatype="&xsd;string">Information Security</PolicyKeyword>
        <PolicyMaturityLevel rdf:datatype="&xsd;string">Interactive-Information</PolicyMaturityLevel>
        <PolicyConsulted rdf:datatype="&xsd;string">CERT</PolicyConsulted>
        <PolicyDesc rdf:datatype="&xsd;string">The policies defined under the “Privacy and Citizen Information Protection” of the IS policy which have been  published by government should be implemented. The guidelines provided in the above section of IS policy could be accessed through  (http://www.government.lk/images/secPolicy/Privacy__Citizen_Information_Protection.doc). The assistance of CERT could be obtained for achieving this purpose.</PolicyDesc>
        <apply rdf:resource="http://mywebsite.com/module/ontologies/focusArea2"/>
    </owl:NamedIndividual>



    <!-- http://mywebsite.com/module/ontologies/policy3 -->

    <owl:NamedIndividual rdf:about="http://mywebsite.com/module/ontologies/policy3">
        <rdf:type rdf:resource="http://mywebsite.com/module/ontologies/local_policy"/>
        <PolicyName rdf:datatype="&xsd;string">3</PolicyName>
        <PolicyDesc rdf:datatype="&xsd;string">A matrix  could be defined for identifying all possible audience  and possible delivery channels of  organizational data/information. The template given in Annex 001 could be used for this purpose. (refer Annex 001 – Information/Data classification matrix)</PolicyDesc>
        <PolicyResponsibility rdf:datatype="&xsd;string">CIO</PolicyResponsibility>
        <PolicyConsulted rdf:datatype="&xsd;string">government</PolicyConsulted>
        <PolicyMaturityLevel rdf:datatype="&xsd;string">Initial Infomration</PolicyMaturityLevel>
        <PolicyKeyword rdf:datatype="&xsd;string">Service Delivery Channels</PolicyKeyword>
        <apply rdf:resource="http://mywebsite.com/module/ontologies/focusArea3"/>
    </owl:NamedIndividual>

我想做的是查询 ontology 并获取这些人。另请注意,还有其他人。下面是我正在使用的查询。

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 ?x
WHERE {
  ?x rdf:type "http://mywebsite.com/module/ontologies/local_policy"
}

但是它并没有像预期的那样获取个人。

  1. 我该如何解决这个问题,以便我可以获取类型为 local_policies 的所有政策?
  2. 我还想缩小适用于特定 focusArea 的政策的搜索查询,例如 <apply rdf:resource="http://mywebsite.com/module/ontologies/focusArea1"/>。如果是这样,我如何扩展这个也有 focusArea 的查询策略?

您需要将查询更改为:

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#>
prefix : <http://mywebsite.com/module/ontologies/>

SELECT ?x
WHERE {
  ?x a :local_policy
}

您要查找的元素不是字符串,而是一个概念。

此外,要添加另一个限制,您只需添加等价于:

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#>
prefix : <http://mywebsite.com/module/ontologies/>

SELECT ?x
WHERE {
  ?x a :local_policy.
  ?x ?y :focusArea1.
  ?x ?w :PolicyName.
}

这里你基本上是在说我正在寻找 ?x 类型 :local_policy 并且它对属性 :focusArea1 有限制。如果它不适用于 :focusArea1:PolicyName 尝试用另一个变量替换它们,例如 ?s 并查看 focusArea1 出现在哪里。它是否出现在 ?y?s 的位置。然后你知道把你的变量放在哪里。但我怀疑你需要把它放在最后一个元素。