簡體   English   中英

使用Sparql從RDF文件中提取規則

[英]Extract rules from RDF file using Sparql

這是我要以RDF / XML格式提取的規則:

<rdf:Description rdf:about="http://www.semanticweb.org/myCompany/ontologies#x">
    <rdf:type rdf:resource="http://www.w3.org/2003/11/swrl#Variable"/>
</rdf:Description>
<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">testing a rule</rdfs:comment>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TEST</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.semanticweb.org/myCompany/ontologies#depth"/>
                    <swrl:argument1 rdf:resource="http://www.semanticweb.org/myCompany/ontologies#x"/>
                </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#BuiltinAtom"/>
                            <swrl:builtin rdf:resource="http://www.w3.org/2003/11/swrlb#greaterThan"/>
                            <swrl:arguments>
                                <rdf:Description>
                                    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"/>
                                    <rdf:first rdf:datatype="http://www.w3.org/2001/XMLSchema#int">2</rdf:first>
                                    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
                                </rdf:Description>
                            </swrl:arguments>
                        </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#ClassAtom"/>
                    <swrl:classPredicate rdf:resource="http://www.semanticweb.org/myCompany/ontologies#profondeur"/>
                    <swrl:argument1 rdf:resource="http://www.semanticweb.org/myCompany/ontologies#Bad"/>
                </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>

我想知道我是否可以使用類似於以下語法的規則提取規則:

depth(?x) ^ swrlb:greaterThan(2) -> profondeur(Bad)

另外,我不想在protégé或其他軟件中使用規則,而是在尋找Jena或Pellet等外部連接器

等待您的回應,

Sparql用戶Aloïs。

感謝您的幫助,我終於設法使用OWL API編寫了一些代碼

        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        try {
            OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(ONTOLOGY_FILE_NAME));
            Set<SWRLRule> rules = ontology.getAxioms(AxiomType.SWRL_RULE);
            for (SWRLRule r : rules) {
                // body
                for (SWRLAtom a : r.getBody()) {
                    System.out.println(a.getPredicate().toString());
                    for (SWRLArgument ar : a.getAllArguments()) {
                        System.out.println(ar.toString());
                    }
                }

                // head
                for (SWRLAtom a : r.getHead()) {
                    System.out.println(a.getPredicate().toString());
                    for (SWRLArgument ar : a.getAllArguments()) {
                        System.out.println(ar.toString());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM