Hi all,
I am trying to reason over data using Generic Rule Reasoning having Jena rules
(in a separate txt file) and a data file (which is an ontology file having
instances). The aim of the rule is to do unit conversion from Celsius to
Fahrenheit. I have performed this task in Ontology reasoning using SWRL rules
for the same data but now I want to do it using Jena Framework. Below, I have
provided the piece of code, the Jena rule and the sample data. I will be really
grateful if someone could have a look at these three components (especially the
rule's syntax) that why the rule is not firing to do unit conversion.
The piece of code is given below:
public static void main(String[] args) throws MalformedURLException {
Model instances = ModelFactory.createDefaultModel();
instances.read ("/Users/Desktop/Ontology/IoT-Ontology-file.owl", "TURTLE");
Reasoner reasoner = new
GenericRuleReasoner(Rule.rulesFromURL("/Users/Desktop/rules_iot.txt"));
reasoner.setDerivationLogging(true);
InfModel inf = ModelFactory.createInfModel(reasoner, instances);
The Jena rule is given below:
[rule1: (?t rdf:type units:GroveAirTemperatureValue), (?t
units:hasTemperatureInCelsius ?tempval), (?t units:hasUnitOfMeasurement
?Celsius),
product(?tempval, 1.8, ?prod), sum(?prod, 32, ?add)
-> (?t units:hasTemperatureInFahrenheit ?add),
(?t units:hasUnitOfMeasurement ?Fahrenheit)]
The sample data from the data file (which is an ontology file) is given below:
<?xml version="1.0"?>
<rdf:RDF
xmlns="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#"
xml:base="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:units="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:swrla="http://swrl.stanford.edu/ontologies/3.3/swrla.owl#">
<owl:Ontology
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled -->
<owl:AnnotationProperty
rdf:about="http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#MeasuresQuality
-->
<owl:ObjectProperty
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#MeasuresQuality">
<rdfs:domain
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
<rdfs:range
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PhysicalQuality"/>
</owl:ObjectProperty>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasUnitOfMeasurement
-->
<owl:ObjectProperty
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasUnitOfMeasurement">
<rdfs:range
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
</owl:ObjectProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PreferredSymbol
-->
<owl:DatatypeProperty
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PreferredSymbol"/>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasTemperatureInCelsius
-->
<owl:DatatypeProperty
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasTemperatureInCelsius">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
</owl:DatatypeProperty>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasTemperatureInFahrenheit
-->
<owl:DatatypeProperty
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasTemperatureInFahrenheit">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
</owl:DatatypeProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue
-->
<owl:Class
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasUnitOfMeasurement"/>
<owl:someValuesFrom
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasUnitOfMeasurement"/>
<owl:hasValue
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeCelsius"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#hasTemperatureInCelsius"/>
<owl:someValuesFrom
rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PhysicalQuality
-->
<owl:Class
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PhysicalQuality"/>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement
-->
<owl:Class
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeCelsius
-->
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeCelsius">
<rdf:type
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
<MeasuresQuality
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#Temperature"/>
<PreferredSymbol>°C</PreferredSymbol>
</owl:NamedIndividual>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeFahrenheit
-->
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeFahrenheit">
<rdf:type
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#UnitOfMeasurement"/>
<MeasuresQuality
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#Temperature"/>
<PreferredSymbol>°F</PreferredSymbol>
</owl:NamedIndividual>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue1
-->
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue1">
<rdf:type
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue"/>
<hasUnitOfMeasurement
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeCelsius"/>
<hasTemperatureInCelsius
rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasTemperatureInCelsius>
</owl:NamedIndividual>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveTemperatureValue2
-->
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveTemperatureValue2">
<rdf:type
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#GroveAirTemperatureValue"/>
<hasUnitOfMeasurement
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#DegreeFahrenheit"/>
<hasTemperatureInFahrenheit
rdf:datatype="http://www.w3.org/2001/XMLSchema#float">212.0</hasTemperatureInFahrenheit>
</owl:NamedIndividual>
<!--
http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#Temperature
-->
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#Temperature">
<rdf:type
rdf:resource="http://www.semanticweb.org/ullahi/ontologies/2017/6/untitled-ontology-110#PhysicalQuality"/>
</owl:NamedIndividual>
</rdf:RDF>
<!-- Generated by the OWL API (version 4.2.8.20170104-2310)
https://github.com/owlcs/owlapi -->
Many thanks in advance.
Best regards,
Izhar