I'm writing a rule file(Fuseki Generic Reasoner) expecting to count rdf objects number of a certain subject so I can use the number to decide whether to make a new triple. However, I cannot find a feasible approach to deal with it.
Using sparql, it is easy to count objects.
select (count(?object) as ?c) where {foo:bar foo:p ?object}.
But it seems difficult for me to implement the operation with rule file.
Here is the rdf turtle file:
@prefix foo: <http://example/>
foo:bar1 foo:p foo:obj_A .
foo:bar1 foo:p foo:obj_B .
foo:bar1 foo:p foo:obj_C .
foo:bar2 foo:p foo:obj_A .
foo:bar2 foo:p foo:obj_B .
What I expect (pseudo code):
[rule1: (?s foo:is 'true') <- (count ?s foo:p ?o number as ?c), greaterThan(?c, 2)]
[rule2: (?s foo:is 'false') <- (count ?s foo:p ?o number as ?c), le(?c, 2)]
So I can get triple (foo:bar1 foo:is 'true') and (foo:bar2 foo:is 'false')