On 07/08/14 03:43, Wang Darrell wrote:
Thanks you !

I have some concept about list now.

So it looks like I can't count the facts for a rule right?

Not sure what that means. If you mean the number of times that a pattern matches on a given set of data then no, there's no built in for that. You could do hack around it with arithmetic builtins but basically SPARQL would be a better choice there.

Dave

2014-08-06 18:54 GMT+08:00 Dave Reynolds <[email protected]>:

On 06/08/14 11:11, Wang Darrell wrote:

Hello there

I got the link that have many builtin function and I want to use the
listLength( ?l , ?len) in my own rules.

Here is my rules :

   [TestList:    ( ?x   yago:created  ?l)
                 listLength(?l, ?len)
                  ->
                  (?x  yago:HasCreated ?len)
                  ]

I count it manually , there should be more than ten facts can be triggered
by this rules.

Can someone give some example to deal with listLength(?l , ?len)


temp.ttl
[[[
@prefix data: <http://www.openjena.org/tests#>

data:i data:list (1 2 3).
]]]

test.rules
[[[
@prefix data: <http://www.openjena.org/tests#>

(?x data:list ?l) listLength(?l, ?len) -> (?x data:listLength ?len) .
]]]

Code:
[[[
         Model data = FileManager.get().loadModel("data/temp.ttl");
         List<Rule> rules = Rule.rulesFromURL("file:data/test.rules");
         GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
         InfModel inf = ModelFactory.createInfModel(reasoner, data);
         inf.write(System.out, "Turtle");
]]]

Output:
[[[
data:i  data:list        ( 1 2 3 ) ;
         data:listLength  "3"^^xsd:int .
]]]

Dave




Reply via email to