[rules-users] Call query from other query
Mark Proctor
mproctor at codehaus.org
Tue Nov 29 16:55:51 EST 2011
did this work for you?
I'm hoping users can start to tell others how they are using backward
chaining, we need some successs "how to" stories out there, maybe a
tutorial or two :)
Mark
On Mon, Nov 28, 2011 at 10:48 PM, Mark Proctor <mproctor at codehaus.org>wrote:
> The query is treated just like a pattern. ? indicates whether the query
> should be materialised or not. In general if you aren't sure, then don't
> include the ? and let it materialise.
>
> The queries do not return any results, they are not functions. Like
> patterns the resuls are returned from out variable bindings in the
> parameters. The work in the same way that prolog predicates work, and you
> can find tuns of literatore on that.
>
> see 2.2.2.8 has a fair overview of this:
>
> http://docs.jboss.org/drools/release/5.3.0.Final/droolsjbpm-introduction-docs/html/releaseNotes.html#d0e50
>
> see 5.9 here:
>
> http://docs.jboss.org/drools/release/5.3.0.Final/drools-expert-docs/html/ch05.html#d0e6233
>
> This should work for your example:
> query query1(List $facts)
> $facts := List() from collect( Fact( name == "name1" ) )
> end
>
> query query2
> query1($l;)
> end
>
> The above $l should join with the results of query1, as it's unbound and
> thus an output variable.
>
> Mark
>
>
> On Mon, Nov 28, 2011 at 12:41 PM, Syargey <Syargey at tut.by> wrote:
>
>> I read in Drools guide, that queries can now call other queries.
>>
>> But the guide doesn't give much details, mostly paying attention to a
>> rather
>> specific case.
>>
>> I have two queries having common parts and try to figure out how to get
>> rid
>> of duplicate code.
>>
>> Here is the simplified form of queries I'd like to have:
>> ---------
>>
>> query query1
>> $facts: List()
>> from collect( Fact( name == "name1" ) )
>> end
>>
>> query query2
>> $l: List()
>> from collect( Fact( value == "1" ) from ?query1() )
>> end
>>
>> ---------
>>
>> query2 syntax is invalid and and it is not clear for me how $facts from
>> query1 can be accessed in query2.
>>
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/Call-query-from-other-query-tp3542082p3542082.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111129/535e5685/attachment.html
More information about the rules-users
mailing list