简体   繁体   中英

semantic web rule use “all”

Assume that I have the following statements:

A p B, A p C, B p C  ( p is a symmetric property, i.e.  B p A, C p A and C p B)
A v 2, B v 1, C v 1,

I want to use a rule to do something like:

?a p all(?b)
if ?b v 1
than ?a q 'Yes'

that means that you can infer (A q 'Yes'), but B can't since B p A and A v 2(although B p C and C v 1).

[rule: (?a eg:p ?b), (?b eg:v 1) -> (?a eg:q 'Yes')]

I've used the above rule in Jena, but I got A,B,C eg:q 'Yes', which is wrong. Any help will be greatly appreciated.

Update (originally posted as an answer)

the meaning of (?ap all(?b)) is that I like to get a set which all ?mem in this set fulfill the (?ap ?mem). And all member must fulfill (?mem v 1) to infer (?aq 'Yes').

For example,

A p B and A p C,so I get a set which contains (B, C).since B and C v 1,so A q 'Yes.

B p A and B p C,so I get a set(A, C),but A v 2,so can't infer that B q 'Yes'.

Problem Solved

Thanks to Joshua Taylor.

Firstly, these two rules can't use at the same time.The rule2 should be used after rule1.

And, the rule2 should be [rule2: (?s ?p ?o) noValue(?s, connectedToNonOne) -> (?sq 'Yes')].

but I got A,B,C eg:q 'Yes', which is wrong.

The rule you have actually written in Jena says

For any two individuals X and Y, if (X p Y) and (Y v 1) then (X q 'Yes').

From the rule you've written, this is correct, by:

(A p C), (C v 1) → (A q 'Yes')
(B p C), (C v 1) → (B q 'Yes')
(C p B), (B v 1) → (C q 'Yes')

What you're actually trying to say is:

For any individual X, if for every individual Y, (X p Y) implies (Y v 1), then (X q 'Yes').

In first order logic, your original rule could be written as:

∀ x,y ([p(x,y) ∧ v(y,1)] → q(x,'yes')

What you're actually trying to capture would be:

∀x[(∀y[p(x,y) → v(y,1)]) → q(x,'yes')]

That's harder to capture in Jena rules, because to check whether (∀y[p(x,y) → v(y,1)]) holds or not, all Jena can do is check whether there are currently any counterexamples. If one were added later, you might have incorrect inferences.

Using the builtins available in the rule reasoner, you could do something with noValue and notEqual along the lines of:

#-- If an individual is disqualified by being
#-- connected to a something that is connected
#-- to something that is not equal to 1, then 
#-- add a connectedToNonOne triple.
[rule1: 
  (?x p ?y), (?y v ?z), notEqual(?z,1)
  ->
  (?x connectedToNonOne true)]

#-- Mark everything that is *not* disqualified
#-- with `q 'Yes'`.
[rule2:
  noValue(?x, connectedToNonOne)
  ->
  (?x q 'Yes')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM