SWRLb -大于小于触发



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

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

    (:hasTension:Charles ?x) ∧greaterThan (?X, "14.0"^^xsd:float) &right;(:hasAlert:Samii "Your tension is high"^^xsd::string)

  • 如果张力大于14,机器人报警张力过高。

    (:hasTension:Charles ?x) ∧小于(?X, "14.0"^^xsd:float) &right;(:hasAlert:Samii "Your tension is low"^^xsd::string)

我正在使用OWL API与颗粒推理器(openllet fork of pellet)。为此,我使用内置的SWRL规则swrlb:greaterThanswrlb:lessThan。对于这个测试,我添加了公理

    ;

和查询data属性

    ;

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

资源

My test "main"

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 => nn== Before adding axiom ==" );
        owl_management.printOntology();
        System.out.println( "[main].main => nn== 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 => nn== After adding axiom ==" );
        owl_management.printOntology();
        System.out.println( "[main].main => nn== 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;
    }
}

和我的本体

<?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

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

使用最后一个"官方"版本的Pellet (2.3.6-ansell)及其版本的OWL-API (3.4.9.2-ansell),结果是我所期望的:

  • 带"tension" <14:

    ==查询==[OWLManagement].printOntology() ->字面数:1[OWLManagement].printOntology() ->对象数量:1[main].main() ->字面数:1->Samii hasAlert T'as tension test drôlement base

  • with "tension">14

    ==查询==[OWLManagement].printOntology() ->字面数:1[OWLManagement].printOntology() ->对象数量:1[main].main() ->字面数:1->Samii hasAlert T'as tension est drôlement haute

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

相关内容

  • 没有找到相关文章

最新更新