Thanks for the extra detail Wolfgang.
2010/10/15 Wolfgang Laun <wolfgang.laun(a)gmail.com>
All simple field constraints (the expressions you write between
commas in a
pattern) must follow the same
syntactic pattern, which is
[ <variable> ':' ] <fieldname> <restriction>
This means that you may use a binding (e.g. "$foo :"), but the next thing
must be a field name from the
fact class. The <restriction> can have many forms; one of them is a name
denoting an operator
followed by the other operand, where you have a little more freedom, e.g.,
by using a bound variable
or an access to a field or other forms.
Hence, not being able to reverse the operands of subsetOf is not a compiler
bug; it is a (perhaps
regrettable) consequence of the overall structure of constraints.
Thus, if you need an operator supersetOf (which is to subsetOf just like >=
is to <=) you'll have
to define it, too. This is simple, since it is practically the same as
subsetOf, with some operand
swapping down in the works.
Cheers
Wolfgang
2010/10/14 Kumar Pandey <kumar.pandey(a)gmail.com>
Thanks for this tip.
> This works but only if the second rule's $f.numbers is on the RHS and
> numbers is on the LHS of the subsetOf operator.
> i.e Element(name="Super set - Rule 1", numbers subsetOf $f.numbers)
>
> Which is what I want in my case (to check if values in the fact is subset
> of values in the rule).
>
> If I wanted it the other way round though the compiler seems to
> disapprove.
>
> I get a compiler error like so --
>
> java.lang.RuntimeException: Unable to compile rule
> Unable to determine the used declarations.
> [Error: unknown class or illegal statement:
> org.mvel2.ParserContext@1aed5f9]
> [Near : {... $f.numbers subsetOf dat ....}]
>
> If you try the Wolfgang's example and in the rule swap check like so - s1
> disjoint numbers
>
> e2: Element( this != e1, n2 : name, s1 disjoint numbers )
>
> then you get error like so
>
> Unable to create Field Extractor for 's1' of '[ClassObjectType
> class=com.test.context.Element]' in rule 'find disjoint pairs' : [Rule
> name='find disjoint pairs']
>
> Sounds like a compiler bug as the operation should be commutative right?
>
>
> Thanks
> Kumar
> 2010/10/13 Michael Anstis <michael.anstis(a)gmail.com>
>
>> OK, unless I'm missing something else you should be able to do something
>> like this:-
>>
>> rule "setup superset - Rule 1"
>> when
>> then
>> Element ss = new Element("Super set - Rule 1", 1, 2, 3);
>> insert(ss);
>> end
>>
>> rule "rule 1"
>> when
>> $f : Fact()
>> Element(name="Super set - Rule 1", $f.numbers subsetOf
numbers)
>> then
>> //Do something
>> end
>>
>> This uses Wolfgang's Element Class from his example creating custom
>> operators and assumes Fact exposes a "numbers" property which returns
a
>> Collection. This remains untested but I have no reason to doubt Wolfgang.
>>
>> With kind regards,
>>
>> Mike
>>
>>
>>
>>
>>
>> 2010/10/13 Kumar Pandey <kumar.pandey(a)gmail.com>
>>
>>> Well the problem is in forming the DRL :)
>>> My use case is each rule represents an item with its specific property.
>>> Fact is a user property and I want to filter the items for this user based
>>> on the users incoming property as facts.
>>>
>>>
>>> I have been able to get it working like so but eval is not optimum for
>>> Rete. I was hoping for a better solution that would utilize the Rete
>>> optimization.
>>>
>>> Here's my unit test DRL. Note, I have a isNotSubset method in my fact
>>> object and I'm getting the list from rule and doing a check.
>>>
>>> package com.test
>>> import com.rule.OfferFact;
>>> global java.util.List list
>>>
>>> rule rule_not_sub_set
>>> when
>>> $context : Fact()
>>> eval($context.isNotSubset("SINGER","DANCER",
"DOCTOR"))
>>> then
>>> list.add(drools.getRule().getName());
>>> end
>>>
>>>
>>> 2010/10/13 Michael Anstis <michael.anstis(a)gmail.com>
>>>
>>>> Not as clear as I'd hoped; can you provide an actual rule DRL?
>>>>
>>>> 2010/10/13 Kumar Pandey <kumar.pandey(a)gmail.com>
>>>>
>>>> Michael
>>>>> Here are some examples
>>>>>
>>>>> Rule1 has "str1", "Str2", "Str3"
>>>>>
>>>>> Rule2 has "str2", "Str3", "Str5",
"Str6", "Str7"
>>>>>
>>>>> Rule3 has "str1", "Str3", "Str6"
>>>>>
>>>>> etc.
>>>>>
>>>>> With fact1 that has "str1", "Str3" , since this
is subset of values
>>>>> in Rule1 and Rule3, they should not fire but Rule2 should fire
>>>>>
>>>>> With fact2 that has "str2", "Str6",
"Str7", Rule 2 should not fire and
>>>>> Rule1 and Rule3 should fire.
>>>>>
>>>>> Hope this is clear.
>>>>>
>>>>> Thanks
>>>>> Kumar
>>>>>
>>>>> 2010/10/13 Michael Anstis <michael.anstis(a)gmail.com>
>>>>>
>>>>>> Thanks, please provide a specific example rule too.
>>>>>>
>>>>>> Don't forget to keep your posts to the mailing list for the
good of
>>>>>> the community.
>>>>>>
>>>>>>
>>>>>> On 12 October 2010 22:18, Kumar Pandey
<kumar.pandey(a)gmail.com>wrote:
>>>>>>
>>>>>>> Michale
>>>>>>> Thanks for the response.
>>>>>>> Here's the link for the thread .
>>>>>>>
>>>>>>>
>>>>>>>
http://drools-java-rules-engine.46999.n3.nabble.com/Check-if-fact-is-subs...
>>>>>>>
>>>>>>> and the original about matching strings in two arrays.
>>>>>>>
>>>>>>>
http://drools-java-rules-engine.46999.n3.nabble.com/Matching-strings-in-t...
>>>>>>>
>>>>>>>
>>>>>>> My use case is that I could have hundreds of rule and each
rule
>>>>>>> could have its own set of strings.
>>>>>>> A fact object is run through these rules to see which ones
are
>>>>>>> fired.
>>>>>>> One of the condition to check is that the a list in the fact
is not
>>>>>>> a subset of list in the rule.
>>>>>>> That is fire the rule only if list in fact is not a subset of
list
>>>>>>> in rule.
>>>>>>>
>>>>>>> Thanks
>>>>>>> Kumar
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Oct 12, 2010 at 12:38 PM, Michael Anstis <
>>>>>>> michael.anstis(a)gmail.com> wrote:
>>>>>>>
>>>>>>>> OK, I admit I don't have the original thread
anymore.
>>>>>>>>
>>>>>>>> If I am not wrong (which is always a possibility) for
Wolfgang's
>>>>>>>> operator to work you'd need to externalise the
superset from the rule into
>>>>>>>> WorkingMemory. You could have a rule with higher salience
construct the
>>>>>>>> superset WM fact.
>>>>>>>>
>>>>>>>> If you don't mind re-posting or providing a link to
the complete
>>>>>>>> thread (on Nabble or somewhere) I'll happily try to
help further.
>>>>>>>>
>>>>>>>> On 12 October 2010 17:23, <kumar.pandey(a)gmail.com>
wrote:
>>>>>>>>
>>>>>>>>> <quote author='Michael Anstis-2'>
>>>>>>>>>
>>>>>>>>> Wolfgang gave a great solution.
>>>>>>>>> </quote>
>>>>>>>>> Don't know if I'm missing something obvious
here. I have a
>>>>>>>>> superset in the rule itself. Each rule has a superset
list. In this case how
>>>>>>>>> would I use Wolfgang's solution. Its comparing
through two arrays in
>>>>>>>>> runtime. I have not been able to construct an array
construct with specific
>>>>>>>>> values in the rule itself.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> rules-users mailing list
>>>>>> rules-users(a)lists.jboss.org
>>>>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>> rules-users(a)lists.jboss.org
>>>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users(a)lists.jboss.org
>>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
> Kumar Pandey
>
http://www.linkedin.com/in/kumarpandey
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users