Hey Dave,

You are a STAR, you made my day. I followed what you said and changed my rule 
like (as you mentioned) 
  
  (?p rdf:type enviot:Phenomenon)
   (?p enviot:hasField ?field)
   (?field rdf:type enviot:FieldWithSheep)

So this was the trick (it sounds like we have to write Jena rules exactly like 
SPARQL Syntax) and it worked successfully, hurray.

I owe you a great debt of gratitude. I really appreciate your invaluable 
suggestions, time and effort.

Best regards and have a good Sunday.

Izhar

________________________________________
From: Dave Reynolds [dave.e.reyno...@gmail.com]
Sent: 22 July 2017 21:36
To: users@jena.apache.org
Subject: Re: Generic Rule Reasoning over Data using Jena Framework 3.1

On 22/07/17 19:37, Ullah, Izhar wrote:
> Many thanks Lorenz and Dave for the correction but I'm afraid it is still not 
> working. :(

So look at the individual you expect it to match and work through the
clauses to check if that can.

For example, looking at the first few patterns:

   (?p rdf:type enviot:Phenomenon)
   (?p enviot:hasField enviot:FieldWithSheep)
   ...

You might be thinking those would match :PhenomenonPollution, the type
matches but the value of :hasField is not :FieldWithSheep but
:FieldWithSheep1 which is an instance of :FieldWithSheep so no match.

So maybe you meant that to match a different individual or maybe you
meant a rule more like:

   (?p rdf:type enviot:Phenomenon)
   (?p enviot:hasField ?field)
   (?field rdf:type enviot:FieldWithSheep)
   ...

If that's not enough of a hint then follow my earlier advice and prune
this down to a complete minimal example. In this case such an example
would be data with a single individual (ideally expressed in turtle)
since the class and property declarations are irrelevant to this rule,
plus a simplified version of rule4 that still doesn't match but you
think it should.

Dave


>
> Best,
>
> Izhar
> ________________________________________
> From: Lorenz B. [buehm...@informatik.uni-leipzig.de]
> Sent: 22 July 2017 10:22
> To: users@jena.apache.org
> Subject: Re: Generic Rule Reasoning over Data using Jena Framework 3.1
>
> Dave is absolutely right! According to the grammar of the Jena rules
> [1], which among others define nodes as
>
> /node/:= /uri-ref/// e.g. http://foo.com/eg or prefix:localname // e.g.
> rdf:type or </uri-ref/> // e.g. <myscheme:myuri> or ?/varname ///
> variable or 'a literal' // a plain string literal or 'lex'^^typeURI // a
> typed literal, xsd:* type names supported or number // e.g. 42 or 25.5
>
>
> you have to use 'false'^^xsd:boolean, i.e. the rule would be
>
> [rule4: (?p rdf:type enviot:Phenomenon), (?p enviot:hasField
> enviot:FieldWithSheep), (?p enviot:hasRainfall
> enviot:HighIntensiveRain), (?p enviot:hasSoilMoistureCondition
> enviot:SaturatedSoil), (?p enviot:hasRiparianZone
> 'false'^^xsd:boolean)      -> (?p rdf:type enviot:RiskOfPollution)]
>
> Cheers,
> Lorenz
>
>
> [1] https://jena.apache.org/documentation/inference/#rules
>> Hi Izhar,
>>
>> Not sure I would call that a minimal example.
>>
>> Without working through any details the first thing I noticed is that
>> you are testing for enviot:hasRiparianZone with string "false",
>> whereas your sample data has a boolean false, different things.
>>
>> That may or may not be the only issue. It would not explain why the
>> rule would work after OWL inference.
>>
>> Dave
>>
>> On 21/07/17 12:48, Ullah, Izhar wrote:
>>> Dear Lorenz, Adrian and Dave,
>>>
>>> Many thanks for your replies. Actually, the data is so scattered in
>>> the ontology file I thought it would be really hard for you to
>>> understand it if I took a sample of it and put it here. Let me try to
>>> do so. Please have a look at the relevant data related to the rule
>>> given below:
>>>
>>> <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#RiskOfPollution
>>> -->
>>>
>>>       <owl:Class
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#RiskOfPollution";>
>>>           <owl:equivalentClass>
>>>               <owl:Class>
>>>                   <owl:intersectionOf rdf:parseType="Collection">
>>>                       <rdf:Description
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#Phenomenon"/>
>>>                       <owl:Restriction>
>>>                           <owl:onProperty
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasField"/>
>>>                           <owl:someValuesFrom
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#FieldWithSheep"/>
>>>                       </owl:Restriction>
>>>                       <owl:Restriction>
>>>                           <owl:onProperty
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasRainfall"/>
>>>                           <owl:someValuesFrom
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#HighIntensiveRain"/>
>>>                       </owl:Restriction>
>>>                       <owl:Restriction>
>>>                           <owl:onProperty
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasSoilMoistureCondition"/>
>>>                           <owl:someValuesFrom
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SaturatedSoil"/>
>>>                       </owl:Restriction>
>>>                       <owl:Restriction>
>>>                           <owl:onProperty
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasRiparianZone"/>
>>>                           <owl:hasValue
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean";>false</owl:hasValue>
>>>                       </owl:Restriction>
>>>                   </owl:intersectionOf>
>>>               </owl:Class>
>>>           </owl:equivalentClass>
>>>       </owl:Class>
>>>
>>>
>>>    <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#PhenomenonPollution
>>> -->
>>>
>>>       <owl:NamedIndividual
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#PhenomenonPollution";>
>>>           <rdf:type
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#Phenomenon"/>
>>>           <hasField
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#FieldWithSheep1"/>
>>>           <hasRainfall
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#HighIntensiveRain1"/>
>>>           <hasSoilMoistureCondition
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SaturatedSoil1"/>
>>>           <hasRiparianZone
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean";>false</hasRiparianZone>
>>>       </owl:NamedIndividual>
>>>
>>> <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#FieldWithSheep1
>>> -->
>>>
>>>       <owl:NamedIndividual
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#FieldWithSheep1";>
>>>           <rdf:type
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#FieldWithSheep"/>
>>>           <hasSheep
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SheepDolly2"/>
>>>       </owl:NamedIndividual>
>>>
>>> <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#HighIntensiveRain1
>>> -->
>>>
>>>       <owl:NamedIndividual
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#HighIntensiveRain1";>
>>>           <rdf:type
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#HighIntensiveRain"/>
>>>           <hasRainfallValue
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal";>60.0</hasRainfallValue>
>>>       </owl:NamedIndividual>
>>>
>>> <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SaturatedSoil1
>>> -->
>>>
>>>       <owl:NamedIndividual
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SaturatedSoil1";>
>>>           <rdf:type
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#SaturatedSoil"/>
>>>           <hasSoilMoistureValue
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal";>650</hasSoilMoistureValue>
>>>       </owl:NamedIndividual>
>>>
>>> <!--
>>> http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasRiparianZone
>>> -->
>>>
>>>       <owl:DatatypeProperty
>>> rdf:about="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasRiparianZone";>
>>>           <rdf:type
>>> rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
>>>           <rdfs:range
>>> rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
>>>       </owl:DatatypeProperty>
>>>
>>> <owl:Restriction>
>>>                           <owl:onProperty
>>> rdf:resource="http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#hasRiparianZone"/>
>>>                           <owl:hasValue
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean";>false</owl:hasValue>
>>>                       </owl:Restriction>
>>>
>>> The rule from the rule file (along with all prefixes) is given below:
>>>
>>> @prefix enviot:
>>> <http://www.environmental-iot.com/enviot_ontology/IotSemanticModel#>.
>>> @prefix foaf: <http://xmlns.com/foaf/0.1/>.
>>> @prefix time: <http://www.w3.org/2006/time#>.
>>> @prefix owl: <http://www.w3.org/2002/07/owl#>.
>>> @prefix sf: <http://www.opengis.net/ont/sf#>.
>>> @prefix dc: <http://purl.org/dc/elements/1.1/>.
>>> @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
>>> @prefix muo: <http://purl.oclc.org/NET/muo/muo#>.
>>> @prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#>.
>>> @prefix DUL: <http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#>.
>>> @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
>>> @prefix geosparql: <http://www.opengis.net/ont/geosparql#>.
>>> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
>>> @prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
>>> @prefix geof: <http://www.opengis.net/def/function/geosparql/>.
>>>
>>> [rule4: (?p rdf:type enviot:Phenomenon), (?p enviot:hasField
>>> enviot:FieldWithSheep), (?p enviot:hasRainfall
>>> enviot:HighIntensiveRain), (?p enviot:hasSoilMoistureCondition
>>> enviot:SaturatedSoil), (?p enviot:hasRiparianZone “false”)      ->
>>> (?p rdf:type enviot:RiskOfPollution)]
>>>
>>> If you need further information or chuck of the data regarding the
>>> rule please let me know.
>>>
>>> I would really appreciate your effort, time and help.
>>>
>>> Best regards,
>>>
>>> Izhar
>>>
>>>
>>> ________________________________________
>>> From: Lorenz Buehmann [buehm...@informatik.uni-leipzig.de]
>>> Sent: 21 July 2017 09:59
>>> To: users@jena.apache.org
>>> Subject: Re: Generic Rule Reasoning over Data using Jena Framework 3.1
>>>
>>> Exactly, and this should be quite obvious.
>>>
>>> How can we explain why _your rule_ doesn't fire on _your data_
>>> without seing
>>>
>>> * the rule and
>>>
>>> * sample data
>>>
>>>
>>> At least the rule should be shown here. And if you're not allowed to
>>> publish the data you should make an anonymized, minimal sample (it's
>>> usually enough to replace the URIs by some simply URIs) and post it here
>>> as well.
>>>
>>>
>>> On 20.07.2017 22:28, Dave Reynolds wrote:
>>>> Don't see any way anyone can help without at least seeing the rule
>>>> that doesn't fire!
>>>>
>>>> [And I'm not offering off-list consultancy, please do not send me any
>>>> confidential data!]
>>>>
>>>> However, if it runs after you've done a full inference closure then
>>>> presumably that's the issue. It suggests that your rule is relying on
>>>> some OWL inference and won't fire on the raw data. In which case you
>>>> either need to modify your rule to not require that inference or
>>>> extend your rule set to perform the required OWL inference (if
>>>> possible, and bearing in mind that forward rules won't see the results
>>>> of backward inference).
>>>>
>>>> If that doesn't help then I suggest you cut both your data and rule
>>>> down a complete minimal example that is sufficiently abstract you can
>>>> post it.
>>>>
>>>> Dave
>>>>
>>>> On 20/07/17 21:07, Ullah, Izhar wrote:
>>>>> Hi all,
>>>>>
>>>>> I am trying to reason over data using Jena rules (a separate txt
>>>>> file) and a data file (which is an ontology file having instances).
>>>>> Just to give an idea of how my simple code looks like, have a look at
>>>>> the piece of code 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);
>>>>>
>>>>>
>>>>>
>>>>> Let me clearly say that the above code is not complete. I have run my
>>>>> code over three Jena rules successfully and derived/inferred new
>>>>> facts from the data file (ontology file) but it does not work for one
>>>>> rule. It does not give any error but the rule seems to be not firing.
>>>>> Though, when I run the Ontology reasoner (Pellet reasoner) over my
>>>>> ontology, it successfully fires and infers a new fact.
>>>>>
>>>>>
>>>>> Can someone please help me out? I can't send my data file (ontology
>>>>> file) to the group because of confidentiality and privacy issues but
>>>>> I can send it to a particular individual at his/her email address who
>>>>> could help.
>>>>>
>>>>>
>>>>> Should you require any further information please let me know.
>>>>>
>>>>>
>>>>> Many thanks in advance.
>>>>>
>>>>>
>>>>> Best regards,
>>>>>
>>>>>
>>>>> Izhar
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>

Reply via email to