SWRLb - 更大但更少触发

时间:2016-06-28 10:29:09

标签: owl owl-api pellet swrl

我在使用SWRL规则时遇到问题。我有一个机器人应该在两种异常情况下通知人。对于我的测试用例,我使用了用户的张力:

  • 如果张力小于14,则机器人警告张力低:

    (:hasTension:Charles?x)∧byveThan(?x,“14.0”^^ xsd:float)→(:hasAlert:Samii“你的紧张感很高”^^ xsd :: string)

    < / LI>
  • 如果张力大于14,机器人会发出张力高的警报。

    (:hasTension:Charles?x)∧lessThan(?x,“14.0”^^ xsd:float)→(:hasAlert:Samii“你的紧张程度很低”^^ xsd :: string)

    < / LI>

我正在使用带有颗粒推理器的OWL API(颗粒的openllet fork)。为此,我使用内置 swrlb:greaterThan swrlb:lessThan 来获得SWRL规则。为了测试,我添加了公理

:Charles:hasTension“10”^^ xsd:float

并查询数据属性

:Samii:hasAlert?alert

但是当我查询本体时,我收到两个警报:一个用于更大的,另一个用于更少的。我认为我的规则已经很好了,我没有任何来自API的警告或错误,说内置版没有实现,所以我相信这些规则应该像我期望的那样工作。知道为什么我会收到意外警报吗?

资源

我的测试“主要”

package com.samii.restful;

import java.util.ArrayList;

import org.apache.jena.rdf.model.Statement;

public class Local {

    public static void main(String[] args)
    {
        String path = ""+ Servlet.class.getResource("/Ontologies/justAtest_RDFXML.owl");
        Local.mainPelletOWLAPI(path);
    }

    public static void mainPelletOWLAPI( String path ){
        OWLManagement owl_management = new OWLManagement( path );
        System.out.println( "[main].main => \n\n== Before adding axiom ==" );
        owl_management.printOntology();

        System.out.println( "[main].main => \n\n== Query ==" );

        String URI = "file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#";
        String ssubject = "Samii";
        String spredicate = "hasAlert";
        ArrayList<Object> literals = owl_management.queryDataProperty(URI, ssubject, spredicate);
        System.out.println("[main].main() -> Number of literals: " + literals.size() );

        if( !literals.isEmpty() ){
            for( Object literal : literals){
                System.out.print( "->" + ssubject + " " + spredicate + " " + literal );
            }
        }

        ssubject = "Charles";
        spredicate = "hasTension";
        String sobject = "10";
        owl_management.updateFunctionalObjectsProperty(URI, ssubject, spredicate, sobject, "float");

        System.out.println( "[main].main => \n\n== After adding axiom ==" );
        owl_management.printOntology();

        System.out.println( "[main].main => \n\n== Query ==" );

        ssubject = "Samii";
        spredicate = "hasAlert";
        literals = owl_management.queryDataProperty(URI, ssubject, spredicate);
        System.out.println("[main].main() -> Number of literals: " + literals.size() );

        if( !literals.isEmpty() ){
            for( Object literal : literals){
                System.out.println( "->" + ssubject + " " + spredicate + " " + literal );
            }
        }
    }
}

核心:

package com.samii.restful;


import java.util.ArrayList;
import java.util.Set;
import java.lang.Object;

import com.clarkparsia.pellet.owlapi.PelletReasoner;
import com.clarkparsia.pellet.owlapi.PelletReasonerFactory;

import org.mindswap.pellet.exceptions.InconsistentOntologyException;
import org.semanticweb.owlapi.apibinding.OWLManager;

import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.RemoveAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.FreshEntitiesException;
import org.semanticweb.owlapi.reasoner.Node;
import org.semanticweb.owlapi.reasoner.NodeSet;
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
import org.semanticweb.owlapi.reasoner.TimeOutException;
import org.semanticweb.owlapi.vocab.OWL2Datatype;

import org.semanticweb.owlapi.util.ShortFormProvider;
import org.semanticweb.owlapi.util.SimpleShortFormProvider;

import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat;

public class OWLManagement {
    OWLOntologyManager _manager;
    OWLOntology _ontology;
    OWLDataFactory _factory;
    PelletReasoner _reasoner;
    OWLManagement(String ontology_file_path){
        _manager = OWLManager.createOWLOntologyManager();
        _factory = _manager.getOWLDataFactory();
        try{
            _ontology = _manager.loadOntology(IRI.create( ontology_file_path ));
        }
        catch(Exception e){
            System.out.println("Exception " + e.toString());
        }
        //_reasoner = PelletReasonerFactory.getInstance().createReasoner(_ontology);
        _reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(_ontology);

        _reasoner.prepareReasoner();
    }

    public boolean updateFunctionalObjectsProperty( String URI, String ssubject, String spredicate, String sobject, String stype ){
        OWLLiteral literal;
        switch(stype){
            case "float":
                OWLDatatype xsd_float = _factory.getOWLDatatype( OWL2Datatype.XSD_FLOAT );
                literal = _factory.getOWLLiteral(sobject , xsd_float);
                break;
            default:
                literal = _factory.getOWLLiteral("undefined type");
                break;
        }
        OWLNamedIndividual individual = _factory.getOWLNamedIndividual(URI, ssubject);
        OWLDataProperty data_property = _factory.getOWLDataProperty(URI, spredicate);
        //OWLFunctionalDataPropertyAxiom functional_data_property = _factory.getOWLFunctionalDataPropertyAxiom( data_property );
        OWLAxiom axiom = _factory.getOWLDataPropertyAssertionAxiom( data_property, individual, literal);

        Set<OWLLiteral> literals = _reasoner.getDataPropertyValues( individual, data_property );
        if( !literals.isEmpty() ){
            //_manager.removeAxiom( _ontology, axiom );
            _manager.applyChange(new RemoveAxiom( _ontology, axiom) );
        }

        _manager.applyChange(new AddAxiom( _ontology, axiom) );

        return true;
    }

    public void printOntology(){
        try{
            // print out the ontology on System.out
            _manager.saveOntology(_ontology, new OWLFunctionalSyntaxOntologyFormat(), new SystemOutDocumentTarget());
        } catch(Exception e){
            System.out.println("[OWLManagement].printOntology() -> Catched exception:");
            System.out.println("Exception " + e.toString());
        }
        //_manager.saveOntology(o, new OWLXMLOntologyFormat(), documentIRI2);
        // save in RDF/XML
        //_manager.saveOntology(o, documentIRI2);

        // Remove the ontology from the manager
        //_manager.removeOntology(o);
    }

    public ArrayList<Object> queryDataProperty( String URI, String ssubject, String spredicate ){
        OWLNamedIndividual individual = _factory.getOWLNamedIndividual(URI, ssubject);
        OWLDataProperty data_property = _factory.getOWLDataProperty(URI, spredicate);

        Set<OWLLiteral> literals = null;
        try{
            literals = _reasoner.getDataPropertyValues( individual, data_property );
            System.out.println("[OWLManagement].printOntology() -> Number of literals: " + literals.size() );
        } catch( InconsistentOntologyException e ){
            System.out.println("[OWLManagement].printOntology() -> Catched InconsistentOntologyException:");
            System.out.println("Exception " + e.toString());
        } catch( FreshEntitiesException e ){
            System.out.println("[OWLManagement].printOntology() -> Catched FreshEntitiesException:");
            System.out.println("Exception " + e.toString());
        } catch( ReasonerInterruptedException e ){
            System.out.println("[OWLManagement].printOntology() -> Catched ReasonerInterruptedException:");
            System.out.println("Exception " + e.toString());
        } catch( TimeOutException e ){
            System.out.println("[OWLManagement].printOntology() -> Catched TimeOutException:");
            System.out.println("Exception " + e.toString());
        } catch( Exception e){
            System.out.println("[OWLManagement].printOntology() -> Catched exception:");
            System.out.println("Exception " + e.toString());
        }
        ArrayList<Object> objects = new ArrayList<Object>();
        if( !literals.isEmpty() ){
            for(OWLLiteral literal: literals){
                if( literal.isInteger() ){
                    objects.add( literal.parseInteger() );
                } else if( literal.isFloat() ){
                    objects.add( literal.parseFloat() );
                } else if( literal.isDouble() ){
                    objects.add( literal.parseDouble() );
                } else if( literal.isBoolean() ){
                    objects.add( literal.parseBoolean() );
                } else{
                    objects.add( literal.getLiteral() );
                }
            }
        }
        System.out.println("[OWLManagement].printOntology() -> Number of objects: " + literals.size() );
        return objects;
    }
}

和我的ontolgy

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY owl                    "http://www.w3.org/2002/07/owl#" >
    <!ENTITY owl11                  "http://www.w3.org/2006/12/owl11#" >
    <!ENTITY xsd                    "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl11xml               "http://www.w3.org/2006/12/owl11-xml#" >
    <!ENTITY rdfs                   "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY CR-owl-guide-20030818  "http://www.w3.org/TR/2003/CR-owl-guide-20030818/" >
    <!ENTITY local                  "file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#" >
    <!ENTITY swrlb                  "http://www.w3.org/2003/11/swrlb#" >
    <!ENTITY swrl                   "http://www.w3.org/2003/11/swrl#" >
]>

<rdf:RDF xml:base   ="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML"
         xmlns      ="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"
         xmlns:local="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"
         xmlns:owl="http://www.w3.org/2002/07/owl#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
         xmlns:var="urn:swrl#"
         xmlns:xml="http://www.w3.org/XML/1998/namespace"
         xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
         xmlns:swrl="http://www.w3.org/2003/11/swrl#">

    <!--owl:Ontology rdf:about="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"/-->
    <owl:Ontology rdf:about=""/>

    <!--Defining classes about robots-->

    <owl:Class rdf:about="&local;Robot"/>
    <owl:Class rdf:about="&local;Humanoid">
        <rdfs:subClassOf rdf:resource="&local;Robot"/>
    </owl:Class>

    <owl:AllDisjointClasses>
        <owl:members rdf:parseType="Collection">
            <owl:Class rdf:about="&local;Animal"/>
            <owl:Class rdf:about="&local;Robot"/>
        </owl:members>
    </owl:AllDisjointClasses>   

    <!--Defining classes about animals-->

    <owl:Class rdf:about="&local;Animal"/>
    <owl:Class rdf:about="&local;Mammal"/>

    <owl:Class rdf:about="&local;Human">
        <rdfs:subClassOf rdf:resource="&local;Mammal"/>
    </owl:Class>

    <owl:Class rdf:about="&local;Person">
        <owl:equivalentClass rdf:resource="&local;Human"/>
    </owl:Class>

    <owl:Class rdf:about="&local;Man">
        <rdfs:subClassOf rdf:resource="&local;Human"/>
    </owl:Class>

    <owl:Class rdf:about="&local;Woman">
        <rdfs:subClassOf rdf:resource="&local;Human"/>
    </owl:Class>

    <owl:AllDisjointClasses>
        <owl:members rdf:parseType="Collection">
            <owl:Class rdf:about="&local;Man"/>
            <owl:Class rdf:about="&local;Woman"/>
        </owl:members>
    </owl:AllDisjointClasses>

    <owl:ObjectProperty rdf:about="&local;hasRobot">
        <rdfs:domain rdf:resource="&local;Human"/>
        <rdfs:range rdf:resource="&local;Robot"/>
    </owl:ObjectProperty>

    <owl:DatatypeProperty rdf:about="&local;hasAlert"/>
    <!--owl:DatatypeProperty rdf:about="&local;hasAlert">
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty-->
    <!--rdfs:Property rdf:about="&local;hasAlert">
        <rdfs:domain rdf:resource="&local;Robot"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </rdfs:Property-->

    <owl:DatatypeProperty rdf:about="&local;hasTemperature">
        <rdf:type rdf:resource="&owl;FunctionalProperty"/>
        <!--rdfs:range rdf:resource="&xsd;nonNegativeInteger"/-->
    </owl:DatatypeProperty>

    <owl:DatatypeProperty rdf:about="&local;hasTension">
        <rdf:type rdf:resource="&owl;FunctionalProperty"/>
        <!--rdfs:range rdf:resource="&xsd;nonNegativeInteger"/-->
    </owl:DatatypeProperty>

    <owl:NamedIndividual rdf:about="&local;Charles">
        <rdf:type rdf:resource="&local;Man"/>
        <!--local:hasTension rdf:datatype="&xsd;float">14</local:hasTension-->
    </owl:NamedIndividual>
    <owl:NegativePropertyAssertion>
        <owl:sourceIndividual rdf:resource="&local;Charles"/>
        <owl:assertionProperty rdf:resource="&local;hasRobot"/>
        <owl:targetIndividual rdf:resource="&local;Samii"/>
    </owl:NegativePropertyAssertion>

    <owl:NamedIndividual rdf:about="&local;Walid">
        <rdf:type rdf:resource="&local;Man"/>
        <local:hasRobot rdf:resource="&local;Samii"/>
        <local:hasTemperature rdf:datatype="&xsd;float">37.5</local:hasTemperature>
    </owl:NamedIndividual>

    <owl:NamedIndividual rdf:about="&local;Samii">
        <rdf:type rdf:resource="&local;Humanoid"/>
    </owl:NamedIndividual>

    <!-- Rules -->

    <swrl:Variable rdf:about="&local;x" />
    <swrl:Variable rdf:about="&local;alert" />

    <swrl:Imp rdf:about="&local;ruleAlertTensionBasse">
        <swrl:head rdf:parseType="Collection">
            <swrl:DatavaluedPropertyAtom> 
              <swrl:propertyPredicate rdf:resource="&local;hasAlert"/> 
              <swrl:argument1 rdf:resource="&local;Samii" />
              <swrl:argument2 rdf:datatype="&xsd;string">T'as tension est drôlement basse</swrl:argument2>
            </swrl:DatavaluedPropertyAtom>
        </swrl:head>

        <swrl:body rdf:parseType="Collection">
            <swrl:DatavaluedPropertyAtom> 
              <swrl:propertyPredicate rdf:resource="&local;hasTension"/> 
              <swrl:argument1 rdf:resource="&local;Charles" />
              <swrl:argument2 rdf:resource="&local;x" />
            </swrl:DatavaluedPropertyAtom>
            <swrl:BuiltinAtom>
                <swrl:builtin rdf:resource="&swrlb;lessThan" />
                <swrl:arguments>
                    <rdf:List>
                        <rdf:first rdf:resource="&local;x"/>
                        <rdf:rest>
                            <rdf:List>
                                <rdf:first rdf:datatype="&xsd;float">14.0</rdf:first>
                                <rdf:rest rdf:resource="&rdf;nil"/>
                            </rdf:List>
                        </rdf:rest>
                    </rdf:List>
                </swrl:arguments>
            </swrl:BuiltinAtom>
        </swrl:body>
    </swrl:Imp>

    <swrl:Imp rdf:about="&local;ruleAlertTensionHaute">
        <swrl:head rdf:parseType="Collection">
            <swrl:DatavaluedPropertyAtom> 
              <swrl:propertyPredicate rdf:resource="&local;hasAlert"/> 
              <swrl:argument1 rdf:resource="&local;Samii" />
              <swrl:argument2 rdf:datatype="&xsd;string">T'as tension est drôlement haute</swrl:argument2>
            </swrl:DatavaluedPropertyAtom>
        </swrl:head>

        <swrl:body rdf:parseType="Collection">
            <swrl:DatavaluedPropertyAtom> 
              <swrl:propertyPredicate rdf:resource="&local;hasTension"/> 
              <swrl:argument1 rdf:resource="&local;Charles" />
              <swrl:argument2 rdf:resource="&local;x" />
            </swrl:DatavaluedPropertyAtom>
            <swrl:BuiltinAtom>
                <swrl:builtin rdf:resource="&swrlb;greaterThan" />
                <swrl:arguments>
                    <rdf:List>
                        <rdf:first rdf:resource="&local;x"/>
                        <rdf:rest>
                            <rdf:List>
                                <rdf:first rdf:datatype="&xsd;float">14.0</rdf:first>
                                <rdf:rest rdf:resource="&rdf;nil"/>
                            </rdf:List>
                        </rdf:rest>
                    </rdf:List>
                </swrl:arguments>
            </swrl:BuiltinAtom>
        </swrl:body>
    </swrl:Imp>
</rdf:RDF>

我的测试用例的输出:

== Before adding axiom ==
Prefix(:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(var:=<urn:swrl#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(local:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl11:=<http://www.w3.org/2006/12/owl11#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl11xml:=<http://www.w3.org/2006/12/owl11-xml#>)
Prefix(CR-owl-guide-20030818:=<http://www.w3.org/TR/2003/CR-owl-guide-20030818/>)


Ontology(<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML>

Declaration(Class(local:Animal))
Declaration(Class(local:Human))
Declaration(Class(local:Humanoid))
Declaration(Class(local:Mammal))
Declaration(Class(local:Man))
Declaration(Class(local:Person))
Declaration(Class(local:Robot))
Declaration(Class(local:Woman))
Declaration(ObjectProperty(local:hasRobot))
Declaration(DataProperty(local:hasAlert))
Declaration(DataProperty(local:hasTemperature))
Declaration(DataProperty(local:hasTension))
Declaration(NamedIndividual(local:Charles))
Declaration(NamedIndividual(local:Samii))
Declaration(NamedIndividual(local:Walid))
############################
#   Object Properties
############################

# Object Property: local:hasRobot (local:hasRobot)

ObjectPropertyDomain(local:hasRobot local:Human)
ObjectPropertyRange(local:hasRobot local:Robot)


############################
#   Data Properties
############################

# Data Property: local:hasTemperature (local:hasTemperature)

FunctionalDataProperty(local:hasTemperature)

# Data Property: local:hasTension (local:hasTension)

FunctionalDataProperty(local:hasTension)



############################
#   Classes
############################

# Class: local:Animal (local:Animal)

DisjointClasses(local:Animal local:Robot)

# Class: local:Human (local:Human)

EquivalentClasses(local:Human local:Person)
SubClassOf(local:Human local:Mammal)

# Class: local:Humanoid (local:Humanoid)

SubClassOf(local:Humanoid local:Robot)

# Class: local:Man (local:Man)

SubClassOf(local:Man local:Human)
DisjointClasses(local:Man local:Woman)

# Class: local:Woman (local:Woman)

SubClassOf(local:Woman local:Human)


############################
#   Named Individuals
############################

# Individual: local:Charles (local:Charles)

ClassAssertion(local:Man local:Charles)
NegativeObjectPropertyAssertion(local:hasRobot local:Charles local:Samii)

# Individual: local:Samii (local:Samii)

ClassAssertion(local:Humanoid local:Samii)

# Individual: local:Walid (local:Walid)

ClassAssertion(local:Man local:Walid)
ObjectPropertyAssertion(local:hasRobot local:Walid local:Samii)
DataPropertyAssertion(local:hasTemperature local:Walid "37.5"^^xsd:float)


DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:greaterThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement haute"^^xsd:string)))
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:lessThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement basse"^^xsd:string)))
)[main].main => 

== Query ==
[OWLManagement].printOntology() -> Number of literals: 0
[OWLManagement].printOntology() -> Number of objects: 0
[main].main() -> Number of literals: 0
[main].main => 

== After adding axiom ==
Prefix(:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(var:=<urn:swrl#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(local:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl11:=<http://www.w3.org/2006/12/owl11#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl11xml:=<http://www.w3.org/2006/12/owl11-xml#>)
Prefix(CR-owl-guide-20030818:=<http://www.w3.org/TR/2003/CR-owl-guide-20030818/>)


Ontology(<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML>

Declaration(Class(local:Animal))
Declaration(Class(local:Human))
Declaration(Class(local:Humanoid))
Declaration(Class(local:Mammal))
Declaration(Class(local:Man))
Declaration(Class(local:Person))
Declaration(Class(local:Robot))
Declaration(Class(local:Woman))
Declaration(ObjectProperty(local:hasRobot))
Declaration(DataProperty(local:hasAlert))
Declaration(DataProperty(local:hasTemperature))
Declaration(DataProperty(local:hasTension))
Declaration(NamedIndividual(local:Charles))
Declaration(NamedIndividual(local:Samii))
Declaration(NamedIndividual(local:Walid))
############################
#   Object Properties
############################

# Object Property: local:hasRobot (local:hasRobot)

ObjectPropertyDomain(local:hasRobot local:Human)
ObjectPropertyRange(local:hasRobot local:Robot)


############################
#   Data Properties
############################

# Data Property: local:hasTemperature (local:hasTemperature)

FunctionalDataProperty(local:hasTemperature)

# Data Property: local:hasTension (local:hasTension)

FunctionalDataProperty(local:hasTension)



############################
#   Classes
############################

# Class: local:Animal (local:Animal)

DisjointClasses(local:Animal local:Robot)

# Class: local:Human (local:Human)

EquivalentClasses(local:Human local:Person)
SubClassOf(local:Human local:Mammal)

# Class: local:Humanoid (local:Humanoid)

SubClassOf(local:Humanoid local:Robot)

# Class: local:Man (local:Man)

SubClassOf(local:Man local:Human)
DisjointClasses(local:Man local:Woman)

# Class: local:Woman (local:Woman)

SubClassOf(local:Woman local:Human)


############################
#   Named Individuals
############################

# Individual: local:Charles (local:Charles)

ClassAssertion(local:Man local:Charles)
NegativeObjectPropertyAssertion(local:hasRobot local:Charles local:Samii)
DataPropertyAssertion(local:hasTension local:Charles "10.0"^^xsd:float)

# Individual: local:Samii (local:Samii)

ClassAssertion(local:Humanoid local:Samii)

# Individual: local:Walid (local:Walid)

ClassAssertion(local:Man local:Walid)
ObjectPropertyAssertion(local:hasRobot local:Walid local:Samii)
DataPropertyAssertion(local:hasTemperature local:Walid "37.5"^^xsd:float)


DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:greaterThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement haute"^^xsd:string)))
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:lessThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement basse"^^xsd:string)))
)[main].main => 

== Query ==
[OWLManagement].printOntology() -> Number of literals: 2
[OWLManagement].printOntology() -> Number of objects: 2
[main].main() -> Number of literals: 2
->Samii hasAlert T'as tension est drôlement haute
->Samii hasAlert T'as tension est drôlement basse

1 个答案:

答案 0 :(得分:0)

似乎问题来自于使用的Pellet或OWL-API版本。我最初使用的是openllet 2.5.1。

使用最新的“官方”版Pellet(2.3.6-ansell)及其版本的OWL-API(3.4.9.2-ansell),结果就是我所期待的:

  • 具有“张力”&lt; 14:

    ==查询== [OWLManagement] .printOntology() - &gt;文字数量:1 [OWLManagement] .printOntology() - &gt;对象数量:1 [main] .main() - &gt;文字数量:1 - &gt; Samii hasAlert T'as tensionestdrôlementasese

  • “张力”> 14

    ==查询== [OWLManagement] .printOntology() - &gt;文字数量:1 [OWLManagement] .printOntology() - &gt;对象数量:1 [main] .main() - &gt;文字数量:1 - &gt; Samii hasAlert T'as tensionestdrôlementautute

顺便说一句,我尝试使用版本的ignazio1977来使用OWL-API版本4.0.2,但是我遇到了与openllet 2.5.1相同的问题。