Thanks for taking a look, and finding the problem, Dave!

I don't know how I missed that. Seems like a case of not seeing the trees 
because of the forest.

--- David
--- with personal assistance by Siri

> On Apr 28, 2016, at 3:48 AM, Dave Reynolds <dave.e.reyno...@gmail.com> wrote:
> 
> Hi David,
> 
>> On 27/04/16 23:27, Martin, David wrote:
>> Rules engine built-ins that take numeric arguments, such as sum and 
>> greaterThan, are not working for me.  My situation is as follows:
>> 
>> I'm loading a simple NT file into a default model:
>>        Model contextData = FileManager.get().loadModel(contextPath, "N3");
>> 
>> The NT file includes the following triple:
>>       <item1> <hasHeight> 
>> "8"^^<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema_integer&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=A0ZCnA3lEfZmMJuRbxFZB3kjMYUuEfiwPSalXzjWLNw&e=
>>  > .
>> 
>> I'm creating an inference model in the usual way:
>> 
>>     List rules = Rule.rulesFromURL("file:C:/test.rule");
>>    Reasoner reasoner = new GenericRuleReasoner(rules);
>>    Infmodel inf = ModelFactory.createInfModel(reasoner, contextData);
>> 
>> I have the following rule:
>> 
>> [checkItemHeight:
>>     (?item, hasHeight, ?height),
>>     print('In checkItemHeight antecedent:', ?height),
>>     greaterThan(?height, 
>> "7"^^https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema_integer&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=A0ZCnA3lEfZmMJuRbxFZB3kjMYUuEfiwPSalXzjWLNw&e=
>>  ),
>>    ->
>>     print('In checkItemHeight:', ?height)
>> ]
>> 
>> The first print clause succeeds:
>>     'In checkCarHeight antecedent:' 
>> '8'^^https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema_integer&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=A0ZCnA3lEfZmMJuRbxFZB3kjMYUuEfiwPSalXzjWLNw&e=
>>  
>>  but the call to greaterThan never succeeds; the rule never fires. I've 
>> tried different data types in the NT file and in the rules file, but nothing 
>> works. The *only* thing I can get to work is when I use two simple 
>> constants, with no datatype, in the rules file:
>>      greaterThan(8, 7),
>> 
>> I've looked around for discussions and documentation related to this, and 
>> I've looked at the Jena source code for greaterThan, but to no avail. I'd 
>> greatly appreciate some clarification of what's going on here, and what 
>> approaches*will* work.
> 
> My first thought was "that certainly should have worked" and it took a while 
> to spot the deliberate mistake ...
> 
> The RDF namespace for XSD is
>   
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema-23&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=ZQUIuUP_BGNgQbkmNXGI159IIiDpS7vavTw_SiHLhZs&e=
>  not
>   
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema_&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=Ka1WP37ZOigM8tbnkH3GowMMlIeWEZ-HZzdHSK7VPYk&e=
>  
> So what's happening is that both the NT parse and the rules parse are 
> creating typed literals but those literals don't have number semantics 
> because the URI is wrong. The greaterThan builtin returns false for 
> incomparable cases.
> 
> If you change your data to be:
> 
>  <item1> <hasHeight> 
> "8"^^<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema-23integer&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=N43qbXYFgT-W-lRM2Kol6hTbIpCA7zGsVQQbwegvgJA&e=
>  > .
> 
> Then the rule:
> 
> [checkItemHeight:
>    (?item, data:hasHeight, ?height),
>    print('In checkItemHeight antecedent:', ?height),
>    greaterThan(?height, 
> "7"^^https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema-23integer&d=CwIC-g&c=djjh8EKwHtOepW4Bjau0lKhLlu-DxM1dlgP0rrLsOzY&r=RvcUHmbqwXWRvprio0Md4_6qsPsb-hvwu22_Hd-fP_I&m=zY12eZypqbHFzLmEd-BtXmn7Ldz-wbMhYMkKRbuEyLY&s=N43qbXYFgT-W-lRM2Kol6hTbIpCA7zGsVQQbwegvgJA&e=
>  )
>   ->
>    print('In checkItemHeight:', ?height)
> ]
> 
> works, as does
> 
> [checkItemHeight:
>    (?item, data:hasHeight, ?height),
>    print('In checkItemHeight antecedent:', ?height),
>    greaterThan(?height, 7)
>   ->
>    print('In checkItemHeight:', ?height)
> ]
> 
> Dave

Reply via email to