简体   繁体   中英

"For all" using Apache Jenas rule engine

I'm currently working on some small examples about Apache Jena. What I want to show is universal quantification.

Let's say I have balls that each have a different color. These balls are stored within boxes. I now want to determine whether these boxes only contain balls that have the same color of if they are mixed.

So basically something along these lines: SAME_COLOR = ∃x∀y:{y in Box a → color of y = x}

I know that this is probably not possible with Jena, and can be converted to the following: SAME_COLOR = ∃x¬∃y:{y in Box a → color of y != x}

With "not exists" Jena's "NoValue" can be used, however, this does (at least for me) not work and I don't know how to translate above logical representations in Jena. Any thoughts on this?

See the code below, which is the only way I could think of:

(?box, ex:isA, ex:Box)
(?ball, ex:isIn, ?box)
(?ball, ex:hasColor, ?color)
(?ball2, ex:isIn, ?box)
(?ball2, ex:hasColor, ?color2)
NotEqual(?color, ?color2)
->
(?box, ex:hasSomeColors, "No").


(?box, ex:isA, ex:Box)
NoValue(?box, ex:hasSomeColors)
->
(?box, ex:hasSomeColors, "Yes").

A box with mixed content now has both values "Yes" and "No".

I've ran into the same sort of problem, which is more simplified. The question is how to get a collection of objects or count no. of objects in rule engine. Given that res:subj ont:has res:obj_xxx (several objects), how to get this value in rule engine?

But I just found a Primitive called Remove(), which may inspire me a bit.

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