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"^^<http://www.w3.org/2001/XMLSchema/integer> .

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"^^http://www.w3.org/2001/XMLSchema/integer),
    ->
     print('In checkItemHeight:', ?height)
]

The first print clause succeeds:
     'In checkCarHeight antecedent:' 
'8'^^http://www.w3.org/2001/XMLSchema/integer

  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
   http://www.w3.org/2001/XMLSchema#
not
   http://www.w3.org/2001/XMLSchema/

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"^^<http://www.w3.org/2001/XMLSchema#integer> .

Then the rule:

[checkItemHeight:
    (?item, data:hasHeight, ?height),
    print('In checkItemHeight antecedent:', ?height),
    greaterThan(?height, "7"^^http://www.w3.org/2001/XMLSchema#integer)
   ->
    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