On 05/08/13 21:41, Igor Brussilowski wrote:
Hi, thank you for reply.
I sure know all these builtin functions but I'm not sure that they pass to my
case. May be I have to describe the scenario in more details.
Here pseudo code:
given (?s hasList ?list)
if for all ?p in ?list
(?s1 ?p ?o1) (?s2 ?p ?o2) equal(?o1 ?o2)
then
-> do smth
No that's not directly possible in Jena rules since it involves implicit
negation (for all in the head). Jena is designed for monotonic deductive
closure. Jena does have the various non-monotonic hacks like noValue but
there is no real negation supported.
However *if* your hasList values are fixed throughout the rule
processing then you could achieve this through rule compilation.
Pre-process your rule set to translate such a rule into:
(?sa1 ?pa ?oa1) (?sa2 ?pa ?oa2) equal(?oa1 ?oa2)
(?sb1 ?pb ?ob1) (?sb2 ?pb ?ob2) equal(?ob1 ?ob2)
...
-> do smth
Where pa, pb etc are the fixed set of entries in your list.
However, the equals in that case is pointless so this would be much
better as:
(?sa1 ?pa ?oa) (?sa2 ?pa ?oa)
(?sb1 ?pb ?ob) (?sb2 ?pb ?ob)
...
-> do smth
Since you have equals in there maybe you actually mean something
stronger than your pseudo code suggests.
I have already written a bultin function for this functionality (pseudo):
(?s hasList ?list)
-> myBuiltin(?s1 ?s2 ?list)
but I have to do graph find within the builtin's headAction to get the results
of (?s1 ?p ?o1) (?s2 ?p ?o2) and I'm afraid that this decrease the performance
of the rule processing (or is it ok to do this?), therefore I'm looking for
rule optimization.
The problem with that is the non-monotonicity. If some ?p value changes
then you would get a different result from your builtin but your rule
will not refire.
Dave
Regards,
Igor
----- Ursprüngliche Message -----
Von: Joshua TAYLOR <[email protected]>
An: [email protected]; Igor Brussilowski <[email protected]>
CC:
Gesendet: 20:50 Montag, 5.August 2013
Betreff: Re: Access list values in rules
On Mon, Aug 5, 2013 at 9:02 AM, Igor Brussilowski
<[email protected]> wrote:
Hi all,
I'm looking for how to access list items in a reasoner rule. E.g the
pattern (?S owl:kasKey ?L) returns a list of all matching objects. Is there any
way to access here the elements of the list for further processing, e.g. to
print them all out?
According to the documentation [1], there are a number of builtins for
working with lists:
listContains(?l, ?x)
listNotContains(?l, ?x)
Passes if ?l is a list which contains (does not contain) the element
?x, both arguments must be ground, can not be used as a generator.
listEntry(?list, ?index, ?val)
Binds ?val to the ?index'th entry in the RDF list ?list. If there is
no such entry the variable will be unbound and the call will fail.
Only useable in rule bodies.
listLength(?l, ?len)
Binds ?len to the length of the list ?l.
listEqual(?la, ?lb)
listNotEqual(?la, ?lb)
listEqual tests if the two arguments are both lists and contain the
same elements. The equality test is semantic equality on literals
(sameValueAs) but will not take into account owl:sameAs aliases.
listNotEqual is the negation of this (passes if listEqual fails).
listMapAsObject(?s, ?p ?l)
listMapAsSubject(?l, ?p, ?o)
These can only be used as actions in the head of a rule. They deduce a
set of triples derived from the list argument ?l : listMapAsObject
asserts triples (?s ?p ?x) for each ?x in the list ?l,
listMapAsSubject asserts triples (?x ?p ?o).
[1] http://jena.apache.org/documentation/inference/#RULEbuiltins
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/