1
votes

I have a problem using SWRL rules. I have a robot that should notify a human in case of two abnormal situations. For my test case I use the tension of a user:

  • if the tension is less than 14, then the robot alert that the tension is low:

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

  • if the tension is greater than 14, the robot alert that the tension is high.

    (:hasTension :Charles ?x) ∧ lessThan(?x, "14.0"^^xsd:float) → (:hasAlert :Samii "Your tension is low"^^xsd::string)

I am Using OWL API with pellet reasoner (openllet fork of pellet). To do so I have my SWRL rules using builtin swrlb:greaterThan and swrlb:lessThan. For the test I add the axiom

    :Charles :hasTension "10"^^xsd:float

and query the data property

    :Samii :hasAlert ?alert

But when I query the ontology, I get two alerts: one for greaterThan and the other for lessThan. I think my rules are well formed, and I don't have any warning or error from the API saying the builtin are not implemented, so I believe that the rules should work as I'd expect. Any idea why I'm getting the unexpected alert?

Resources

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 => \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 );
            }
        }
    }
}

The core:

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;
    }
}

and my 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>

The output of my test case:

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

1 Answers

0
votes

It seems that the problem comes from the version of Pellet or OWL-API used. I was originally using openllet 2.5.1.

Using the last "official" version of Pellet (2.3.6-ansell) with its version of OWL-API (3.4.9.2-ansell), the result is what I was expecting:

  • with "tension" < 14:

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

  • with "tension" >14

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

By the way, I tried with the version of ignazio1977 to used OWL-API version 4.0.2, but I got the same problem than with openllet 2.5.1.