logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

RE: [drools-user] setting application data in the drools file.: msg#00095

java.drools.user

Subject: RE: [drools-user] setting application data in the drools file.

Hear! Hear! That's an approach that I can buy into! I would not want
to see any non-primitive Semaphores implemented as part of Drools.
However, if people want to create Semaphores until the cows come home,
have at it... Kudos to Mark for exposing the Semaphore Interface!
That's what I call giving them enough rope!

Best Regards,

Dave

-----Original Message-----
From: Mark Proctor [mailto:mproctor@xxxxxxxxxxxx]
Sent: Friday, February 11, 2005 9:26 AM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: Re: [drools-user] setting application data in the drools file.

yeah I really wouldn't want to have to make any more, especially as its
so easy to create your own, just by implementing the Semaphore
interface.

Mark
Hamu, Dave wrote:

>Hi Mark,
>
>Since I was the trouble-maker who started this whole SEMAPHORE thing, I

>figured that I ought to weigh in on this...
>
>There is absolutely no need for an Iterator Semphore. The primitives
>were needed, because Drools does not manipulate primitives and you
>always had to wrap them in something to get them to work nicely.
>Furthermore, the concept of a Semaphore is commonly used in Rule-based
>and Expert Systems particularly in determining terminal conditions.
>However, in this case, there is no need for a wrapper, because JAVA
>provides this functionality out of the box and Drools can use iterators

>and the iter.hasNext() and iter.next() syntax is about as easy as it
>needs to be.
>
>I a probably preaching to the choir, but at least to Geoffrey W., I
>would say you need to look at ways to make your Iterators work in
>Drools. My first Drools project was the "Hello World" app. My second
>used Iterators to process data in an Array list of HashMaps and applied

>about 25 rules against the data. It didn't take more than about 4
>hours to get that solution working. That was from design to
integration test.
>
>If you need more help on how to use Iterators, I can provide some
>examples.
>
>- Dave
>
>-----Original Message-----
>From: Mark Proctor [mailto:mproctor@xxxxxxxxxxxx]
>Sent: Friday, February 11, 2005 7:20 AM
>To: user@xxxxxxxxxxxxxxxxxxx
>Subject: Re: [drools-user] setting application data in the drools file.
>
>The semaphore code really is very basic, I guess I can add one for
>Iterator too - I just want to be carefull that I dont end up creating
>semaphores for every single java class out there.
>
>http://cvs.drools.codehaus.org/viewrep/drools/drools/drools-base/src/ma
>i n/org/drools/semantics/base/StringSemaphore.java?r=HEAD
>
>Mark
>Geoffrey Wiseman wrote:
>
>
>
>>Yes, they are picked up based on type; there are various ways to
>>handle
>>
>>
>this, including Semaphores. There isn't an Iterator semaphore,
>although it may be possible to extend the semaphore mechanism to offer
>an Iterator-specific one; I haven't looked at the underlying code in
>great detail.
>
>
>>I wrote up a summary on handling types with differing semantics a
>>month
>>
>>
>or so back that might be helpful:
>
>
>>http://jroller.com/page/diathesis/20050118
>>
>> - Geoffrey
>>
>>-----Original Message-----
>>From: doug.baker@xxxxxxxxx [mailto:doug.baker@xxxxxxxxx]
>>Sent: Thursday, February 10, 2005 10:44 PM
>>To: user@xxxxxxxxxxxxxxxxxxx
>>Subject: RE: [drools-user] setting application data in the drools
file.
>>
>>
>>I am not able to get Drools to work if I have two different instances
>>of an Iterator parameter in my rules. It appears that the working
>>memory is referencing them based on their object type and not the
>>
>>
>identifier.
>
>
>>Does anyone know how I make more than one Iterator parameter work in
>>my
>>
>>
>
>
>
>>drl file?
>>Or are there any other techniques that can be used?
>>
>>Thanks,
>>Doug
>>
>>example..
>>
>> *** First Books Iterator Parameter ***
>> <rule name="loop thru books">
>> <parameter identifier="books">
>> <class>Iterator</class>
>> </parameter>
>> <java:condition>
>> books.hasNext()
>> </java:condition>
>> <java:consequence>
>> Book book = (Book) books.next();
>> drools.assertObject(book);
>> drools.modifyObject(books);
>> </java:consequence>
>> </rule>
>>
>> *** Second Chapters Iterator Parameter ***
>> <rule name="loop thru chapters">
>> <parameter identifier="chapters">
>> <class>Iterator</class>
>> </parameter>
>> <java:condition>
>> chapters.hasNext()
>> </java:condition>
>> <java:consequence>
>> Chapter chapter = (Chapter) chapters.next();
>> drools.assertObject(chapter);
>> drools.modifyObject(chapters);
>> </java:consequence>
>> </rule>
>>
>>
>>-----Original Message-----
>>From: doug.baker@xxxxxxxxx [mailto:doug.baker@xxxxxxxxx]
>>Sent: Thursday, February 10, 2005 3:39 PM
>>To: user@xxxxxxxxxxxxxxxxxxx
>>Subject: RE: [drools-user] setting application data in the drools
file.
>>
>>
>>I wanted to let you know that I was able to answer my question about
>>dealing with ArrayLists in Drools. After discussing the issue with my

>>colleague, we came up with asserting an Iterator into working memory.
>>We thought we would need to retract each object form working memory
>>after applying the rules against it, but it appears that's not
>>
>>
>necessary.
>
>
>>Drools rulez!
>>Doug
>>
>><?xml version="1.0" encoding="UTF-8"?> <rule-set name="Book Rules"
>>xmlns="http://drools.org/rules";
>>xmlns:java="http://drools.org/semantics/java";
>>xmlns:xs="http://www.w3.org/2001/XMLSchema-instance";
>>xs:schemaLocation="http://drools.org/rules rules.xsd
>>http://drools.org/semantics/java java.xsd
>>http://drools.org/semantics/groovy
>>groovy.xsd" xmlns:groovy="http://drools.org/semantics/groovy";>
>>
>> <java:import>test.Book</java:import>
>> <java:import>test.Chapter</java:import>
>> <java:import>java.util.ArrayList</java:import>
>> <java:import>java.util.Iterator</java:import>
>>
>> <rule name="book has no chapters">
>> <parameter identifier="book">
>> <java:class>Book</java:class>
>> </parameter>
>> <java:condition>
>> book.getChapters().size() == 0
>> </java:condition>
>> <java:consequence>
>> System.out.println("this book has no
>>
>>
>chapters.");
>
>
>> </java:consequence>
>> </rule>
>>
>> <rule name="book has chapters">
>> <parameter identifier="book">
>> <java:class>Book</java:class>
>> </parameter>
>> <java:condition>
>> book.getChapters().size() > 0
>> </java:condition>
>> <java:consequence>
>> System.out.println("this book has " +
>>book.getChapters().size() + " chapters");
>> ArrayList chapters = book.getChapters();
>> drools.assertObject(chapters.iterator());
>> </java:consequence>
>> </rule>
>>
>> <rule name="loop thru chapters">
>> <parameter identifier="chapters">
>> <class>Iterator</class>
>> </parameter>
>> <java:condition>
>> chapters.hasNext()
>> </java:condition>
>> <java:consequence>
>> Chapter chapter = (Chapter) chapters.next();
>> drools.assertObject(chapter);
>> drools.modifyObject(chapters);
>> </java:consequence>
>> </rule>
>>
>> <rule name="check chapter number">
>> <parameter identifier="chapter">
>> <class>Chapter</class>
>> </parameter>
>> <java:condition>
>> chapter.getNumber().length() > 0
>> </java:condition>
>> <java:consequence>
>> System.out.println("chapter number: " +
>>
>>
>chapter.getNumber());
>
>
>> </java:consequence>
>> </rule>
>>
>> <rule name="check chapter title">
>> <parameter identifier="chapter">
>> <class>Chapter</class>
>> </parameter>
>> <java:condition>
>> chapter.getTitle().length() > 0
>> </java:condition>
>> <java:consequence>
>> System.out.println("chapter title: " +
>>
>>
>chapter.getTitle());
>
>
>> </java:consequence>
>> </rule>
>>
>></rule-set>
>>
>>Output:
>>
>>this book has 3 chapters
>>chapter number: 1
>>chapter title: The Beginning
>>chapter number: 2
>>chapter title: The Middle
>>chapter number: 3
>>chapter title: The End
>>
>>
>>-----Original Message-----
>>From: Baker,Doug-FICOH
>>Sent: Thursday, February 10, 2005 8:22 AM
>>To: 'user@xxxxxxxxxxxxxxxxxxx'
>>Subject: RE: [drools-user] setting application data in the drools
file.
>>
>>
>>Hi Rodolfo:
>>
>>You mentioned that conditions are not re-evaluated when application
>>data changes.
>>Would you have any suggestions as to how we could evaluate a list of
>>objects in Drools?
>>
>>For example, say our application data is a list of vehicles. We want
>>to have conditions applied against each vehicle's properties in the
>>list. Is there a way we can do this inside of Drools?
>>
>>Thanks,
>>Doug
>>
>>
>>-----Original Message-----
>>From: Rodolfo Martin [mailto:rodolfo@xxxxxxxxxxx]
>>Sent: Wednesday, February 09, 2005 10:35 PM
>>To: user@xxxxxxxxxxxxxxxxxxx
>>Subject: Re: [drools-user] setting application data in the drools
file.
>>
>>
>>Hi,
>> There is several ways to achieve this. One of them is setting a
>>Hashmap in the application data and using that variable to put and
>>remove things from the consequences.
>>
>><java:import>com.test.Task</java:import>
>>
>><application-data
>>identifier="map">java.util.HashMap</application-data>
>>
>><rule name="rule1" no-loop="true">
>><java:condition/>
>><java:consequence>
>>map.put("TASK1", new com.test.Task()); drools.assertObject("fire");
>></java:consequence> </rule>
>>
>><rule name="rule2">
>><parameter identifier="testString">
>> <java:class> java.util.String</java:class> </parameter>
>><java:condition>testString.equals("fire")</java:condition>
>><java:consequence>if(map.get("TASK1")==null){System.out.println("task
>>is null");}</java:consequence> </rule>
>>
>>
>> Nevertheless take account that you can't rely on using those data in
>>your conditions, since conditions are NOT re-evaluated when
>>application
>>
>>
>
>
>
>>data changes. The way you are trying to use it (asking for the value
>>in the consequence) is safe, but , please, note that is not very "rule

>>oriented".
>>
>>Regards
>>
>>Rodolfo Martin
>>Gogineni, Pratima wrote:
>>
>>
>>
>>
>>
>>>Hi,
>>>
>>>is there a way to set a value to the application data in the drools
>>>
>>>
>file?
>
>
>>>For example if I set the value of an applicationdata object"task" in
>>>rule1 as below and then check for its value in rule2 that is fired as

>>>a consequence or rule1 the application data object is null in rule2
>>>(even though I set it in rule1).
>>>I tried to see if the KnowledgeHelper class provided a way to set the

>>>application data but cant find a setApplicationData method on it. Is
>>>there
>>>
>>>
>>>
>>>
>>a
>>
>>
>>
>>
>>>way to do this?
>>>
>>><application-data identifier="task">com.test.Task</application-data>
>>>
>>><rule name="rule1" no-loop="true">
>>><java:condition/>
>>><java:consequence>
>>>task=new com.test.Task();
>>>drools.assertObject("fire");
>>></java:consequence>
>>></rule>
>>>
>>><rule name="rule2">
>>><parameter identifier="testString">
>>> <java:class> java.util.String</java:class> </parameter>
>>><java:condition>testString.equals("fire")</java:condition>
>>><java:consequence>if(task==null){System.out.println("task is
>>>null");}</java:consequence> </rule>
>>>
>>>Thanks
>>>Pratima
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
>
>
>
>








Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo