如何在特定标签内查询?

时间:2017-04-12 14:07:44

标签: sparql ontology rdfs swrl

您好我是Ontology的初学者,

我已经构建了一个Ontology并使用Protege保存了规则并保存了RDF文件。我将构建一个Web服务,从Ontology获取一些输入。可以通过查询swrl:swrlb:something标签下的参数,类和属性谓词来提供输入。

例如:IF age<5 & weather='Windy' & season='Winter' THEN InfluenzaRisk=High

我需要一个查询来检索age<5 & weather='Windy' & season='Winter'和另一个查询来检索InfluenzaRisk=High

作为SWRL,先行放置在此标记中swrl:body和结果放置在此标记中swrl:head。

我在下面尝试了这些查询,但它在前面和后面都需要参数。我希望有一种方法可以在swrl:body或swrl:head中缩小查询搜索的范围。

有没有办法做到这一点?

SELECT ?subject ?object
    WHERE { ?subject swrl:argument1 ?object }
ORDER BY ?subject ?object
SELECT ?subject ?object
    WHERE { ?subject swrl:argument2 ?object }
ORDER BY ?subject ?object
SELECT ?subject ?object
    WHERE { ?subject swrl:propertyPredicate ?object }
ORDER BY ?subject ?object

下面我在本体中附上一条最短的规则。

<rdf:Description>
    <swrla:isRuleEnabled rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</swrla:isRuleEnabled>
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Anthrax risk to non-vegan</rdfs:comment>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">AnthraxRisk4</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Imp"/>
    <swrl:body>
        <rdf:Description>
            <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
            <rdf:first>
                <rdf:Description>
                    <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#ClassAtom"/>
                    <swrl:classPredicate rdf:resource="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#Person"/>
                    <swrl:argument1 rdf:resource="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#allperson"/>
                </rdf:Description>
            </rdf:first>
            <rdf:rest>
                <rdf:Description>
                    <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
                    <rdf:first>
                        <rdf:Description>
                            <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#IndividualPropertyAtom"/>
                            <swrl:propertyPredicate rdf:resource="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#hasHabits"/>
                            <swrl:argument1 rdf:resource="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#allperson"/>
                            <swrl:argument2 rdf:resource="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#EatingMeats"/>
                        </rdf:Description>
                    </rdf:first>
                    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
                </rdf:Description>
            </rdf:rest>
        </rdf:Description>
    </swrl:body>
    <swrl:head>
        <rdf:Description>
            <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#AtomList"/>
            <rdf:first>
                <rdf:Description>
                    <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#BuiltinAtom"/>
                    <swrl:builtin rdf:resource="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#select"/>
                    <swrl:arguments rdf:parseType="Collection">
                        <rdf:Description rdf:about="http://www.vhynaulia.com/revalina/ontologies/2016/10/pwidas#allperson"/>
                    </swrl:arguments>
                </rdf:Description>
            </rdf:first>
            <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
        </rdf:Description>
    </swrl:head>
</rdf:Description>

0 个答案:

没有答案
相关问题