On 31/12/13 16:12, Olivier Torres wrote:
Thank you Dave,
in my use case i have implemented the brute force version. The problem is that all the
rules infer. I want only the more specific deduction b="value3",
Ah, sorry I miss read the question.
That is much harder, you are asking for something non-monotonic which is
outside the comfort zone for JenaRules.
The easy way would be to simply not do the subClassOf closure and assume
the data is asserting the direct type but I guess you have some reason
to want the type closure.
In which case the next easiest option is to do the type closure using
forward rules then do the value assignment rules backwards (so you know
that the type inference has completed):
(?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c)
-> (?a rdfs:subClassOf ?c) .
(?a rdf:type ?c) (?c rdfs:subClass ?d)
-> (?a rdf:type ?d) .
(?a eg:B "value3") <- (?a rdf:type eg:A3) .
(?a eg:B "value2") <- (?a rdf:type eg:A2) noValue(?a rdf:type eg:A3) .
(?a eg:B "value1") <- (?a rdf:type eg:A1) noValue(?a rdf:type eg:A2) .
Having the type hierarchy explicitly encoded in the rules is pretty
unsatisfying but the easiest thing to do in this case.
Dave
Olivier
Le 31 déc. 2013 à 16:54, Dave Reynolds <[email protected]> a écrit :
On 31/12/13 15:35, Olivier Torres wrote:
Hi,
i have the following type hierarchy, from the more general to the more specific
:
A1, A2, A3,
and the rules :
if A1 then B= "value1"
if A2 then B= "value2"
if A3 then B= "value3"
When a triple matches with A3 then the rules infer the triples : B= "value1", B=
"value2", B= "value3".
In my use case i want only the deduced triple B= "value3",
Is someone know how to implement this behavior ?
You have a couple of options. Either include the RDFS closure rules and write
your rules as backward rules [1] or include the type inference directly in your
own rules.
A simple brute force version without need for transitive caching would be
something like:
(?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c)
-> (?a rdfs:subClassOf ?c) .
(?a rdf:type ?c) (?c rdfs:subClass ?d)
-> (?a rdf:type ?d) .
(?a rdf:type eg:A1) -> (?a eg:B "value1") .
(?a rdf:type eg:A2) -> (?a eg:B "value2") .
(?a rdf:type eg:A3) -> (?a eg:B "value3") .
Dave
[1] http://jena.apache.org/documentation/inference/#RDFSPlusRules