全文搜索所有猫头鹰:NamedIndividual和返回数据

时间:2015-04-17 11:51:36

标签: sparql jena semantic-web ontology protege

我正在使用Protege-5.0.0-beta-17来开发本体,并使用apache-jena-fuseki-2.0.0来托管本体。它有以下个人。此方案的背景是http://mywebsite.com/module/ontologies/local_policy下有政策人员。基本上,策略是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>

我要做的是查询本体并获取这些个体。另请注意,还有其他人。以下是我正在使用的查询。

SELECT ?s
WHERE
{
  ?s ?p ?o 
  FILTER(REGEX(?o, "policy"))
}

但它并没有按预期获取个人。

<http://mywebsite.com/module/ontologies/policy2>
<http://mywebsite.com/module/ontologies/policy1>

如何在所有owl:NamedIndividual中进行全文搜索,如果匹配,则返回特定匹配owl:NamedIndividual的所有数据?

更新

我在这里尝试做的是当用户输入policy时我想要获取包含policy关键字的所有策略。假设用户输入security,如果是这样,我想要获取包含关键字owl:NamedIndividual的所有security。它也应该是local_policy的类型,如下所示。

<rdf:type rdf:resource="http://mywebsite.com/module/ontologies/local_policy"/>

1 个答案:

答案 0 :(得分:3)

如果您要检索 http://mywebsite.com/module/ontologies/local_policy 类型的元素,那么您需要提出以下要求:

select * where {
  ?s rdf:type <http://mywebsite.com/module/ontologies/local_policy>
}

如果您希望确保它们的某些属性具有其字符串表示包含文本策略的值,则需要添加适当的过滤器。 E.g:

select distinct ?s where {
  ?s ?p ?o ;
     a <http://mywebsite.com/module/ontologies/local_policy>
  filter contains(lcase(str(?o)),"security")
}

如果您想获得个人的所有属性和值,只需选择?p和?o变量:

select distinct ?s ?p ?o where {
  ?s ?p ?o ;
     a <http://mywebsite.com/module/ontologies/local_policy>
  filter contains(lcase(str(?o)),"security")
}

您还可以使用构造查询将这些三元组作为新模型返回:

construct where {
  ?s ?p ?o ;
     a <http://mywebsite.com/module/ontologies/local_policy>
  filter contains(lcase(str(?o)),"security")
}