5 Replies Latest reply: Jun 21, 2012 11:05 PM by Rajan.Panchal

# ForScope & ForAllScope

Please provide me explanation on these two with examples.
Note: I have gone through the OPM help on this, But could not understand well. So please provide some fresh examples.
• ###### 1. Re: ForScope & ForAllScope
Hi RP

ForScope is to "look at" a single instance in a to-one relationship.
So if the person-->the house is a one-to-one relationship ("the person's house"), and you wanted to go from the person to the house, you would write:

the person lives in a nice house if
...ForScope(the person's house)
.....the house is big and
.....the house is expensive

In reality, a person may have many houses (lucky them!). So the relationship will probably be a one-to-many relationship ("the person's houses").
Now we would need to use ForAllScope()... this runs the rule for ALL of the instances of "the house" in the relationship "the person's houses". If all of them are big and expensive, then this returns TRUE. If 3 of them are big and expensive, but one of them isn't, then this returns false. Instance 1 is true AND instance 2 is true AND instance 3 is true... etc. Note that the conclusion has been re-worded to make more sense:

all of the person's houses are nice houses if
...ForAllScope(the person's houses)
.....the house is big and
.....the house is expensive

ExistsScope() could be used to check that at least one of the person's houses is nice, and would probably be more appropriate to model the meaning of the original rule:

the person lives in a nice house if
...ExistsScope(the person's houses)
.....the house is big and
.....the house is expensive

But if person-->house was a one-to-one relationship, you have to use ForScope, since it doesn't make sense to say ForAll when there can only ever be one of them.

Hope this helps.
Ben
• ###### 2. Re: ForScope & ForAllScope
Thanks..but cant we use ForAll() instead of ForAllScope()??
• ###### 3. Re: ForScope & ForAllScope
Yes, ForAll() is only when there is one condition, and you can put it all one line.
ForAllScope() is when there is more than one condition to check, and you need to go down a level. They do the same thing, it all depends on what is more appropriate to use based on your source material.
Example.

Rulebase 1 - using ForAll()

all of the person's houses are nice houses if
...ForAll(the person's houses, the house is a nice house)

the house is a nice house if
...the house is big and
...the house is expensive

Rulebase 2 - using ForAllScope()

All of the person's houses are nice houses if
...ForAllScope(the person's houses)
.....the house is big and
.....the house is expensive

ForAll just takes one condition and is all on one line. ForAllScope can take many conditions and is a level below.
I prefer ForAllScope(), even if there is just one condition, because I personally find it easier to read... but others find ForAll() easier...

Again, it all depends on your source material and agreed conventions etc which one you use (you may also want to look at the natural language forms of these to avoid using the function form... again... depends on the material..)

Ben
• ###### 4. Re: ForScope & ForAllScope
Hi RP,
Please let me know if this solved the problem?
Thanks,
Ben
• ###### 5. Re: ForScope & ForAllScope
Thanks..It solved my confusion..