On 16/01/14 20:34, Christophe FAGOT wrote:
Hi,
I'm trying to implement in Jena rules some behavior such as "If there is no value for property
P, then property Q = v1, else property Q = v2". Since I need Jena to react "live" to
triples adding and removal, I use it in FORWARD_RETE.
Ugh. This should be possible but Jena rules were originally designed for
monotonic inference to match RDF semantics. The novalue/remove builtins
are ugly late additions and can be very confusing and not as easy to use
as a proper production rule system.
[Monotonic reasoning means that whatever you can conclude from some set
of facts remains true when more facts are added.]
I'm using the buildIn "noValue(?x, ?p)" as following :
@prefix test: <http://myURL/mySpace#>
@prefix owl: <http://www.w3.org/2002/07/owl>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix xs: <http://www.w3.org/2001/XMLSchema#>
[Aside: that should be xsd: for what you use below]
[rule1: (?icon rdf:type test:Icon),
noValue(?icon, test:imagePath)
->
(?icon test:scale "1"^^xsd:double)]
[rule2: (?icon rdf:type test:Icon),
(?icon test:imagePath ?value)
->
(?icon test:scale "2"^^xsd:double)]
First of all, am I right if I say that with such rules, I will have the 2
triples
(http://myURL/mySpace#myIcon http://myURL/mySpace#scale
'1'^^http://www.w3.org/2001/XMLSchema#double) and
(http://myURL/mySpace#myIcon http://myURL/mySpace#scale
'2'^^http://www.w3.org/2001/XMLSchema#double)
… if I add my triples in that order :
1) (http://myURL/mySpace#myIcon rdf:type http://myURL/mySpace#Icon)
2) (http://myURL/mySpace#myIcon http://myURL/mySpace#imagePath
'path'^^http://www.w3.org/2001/XMLSchema#string)
And the reason is that when I add my second triple, the buildIn "noValue" don't
"react" like if one would remove a value matching with it, and hence the rule don't
remove its deduced triple.
Yes.
Am I also right if I say that the only way to do it with a FORWARD_RETE is to use a
"remove" builtIn in my rule2 ?
You'll need to split rule2 into two parts. Something like *UNTESTED*
[rule2a: (?icon rdf:type test:Icon),
(?icon test:imagePath ?value)
->
(?icon test:scale "2"^^xsd:double)]
[rule2b: (?icon rdf:type test:Icon),
(?icon test:imagePath ?value)
(?icon test:scale "1"^^xsd:double)
->
remove(2)]
And you'll need something similar for rule1 if you want to allow for
removing triples as well.
Dave