Mauricio,

I would like to take this example as the base to play around.  That is what
I did:

1. Make a project "try" that generates the HellowWorld for me in Eclipse.

2. add directory "log"

3. Move file Guess.java to the Java/com/sample directory.  Move Guess.drl
and Guss.rf to rule directory.

 4. Change Package and Implort location from org/drools/examples to
com/sample in the above three files.

Eclipse shows compiler error pointing to ShoppingExample.*class.  *
**
*I did the same to Shopping.java and Shopping.drl and the compiler error is
removed, and the following is the run time error messages:*
**
*

Exception in thread "main" java.lang.IllegalArgumentException: Unknown
process ID: Number Guess

at org.drools.common.AbstractWorkingMemory.startProcess(
AbstractWorkingMemory.java:1615)

at org.drools.common.AbstractWorkingMemory.startProcess(
AbstractWorkingMemory.java:1604)

at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(
StatefulKnowledgeSessionImpl.java:267)

at com.sample.NumberGuessExample.main(NumberGuessExample.java:38)
*
Could you please point me the right direction?

Thanks,

Tak
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**





2009/6/10 Mauricio Salatino <[email protected]>

> This is only a reference to know in which class loader is the resource...
> The idea is to know that the resource (in this case: NumberGuess.drl and
> NumberGuess.rf) is in the same class loader that the ShoppingExample.*
> class*
>
> 2009/6/10 Tak-po Li <[email protected]>
>
>>
>> I am a newbie with Drools rules.  I just download the examples.  I notice
>> in line19 of  NumberGuessExample.java, there are two statement that
>> referring to ShoppingExample.*class.*
>>
>> It seems this is different example.  Could someone help me out?
>>
>> Thanks,
>>
>> Tak
>>
>>
>>
>> kbuilder.add( ResourceFactory.*newClassPathResource*(
>> "NumberGuess.drl",
>>
>> ShoppingExample.
>> *class* ),
>>
>> ResourceType.
>> *DRL* );
>>
>> kbuilder.add( ResourceFactory.*newClassPathResource*(
>> "NumberGuess.rf",
>>
>> ShoppingExample.
>> *class* ),
>>
>> ResourceType.
>> *DRF* );
>>
>> _______________________________________________
>> rules-users mailing list
>> [email protected]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
> - http://salaboy.wordpress.com
> - http://www.jbug.com.ar
> - Salatino "Salaboy" Mauricio -
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
package com.sample

dialect "mvel"

import com.sample.NumberGuessExample.RandomNumber
import com.sample.NumberGuessExample.Guess
import com.sample.NumberGuessExample.Game
import com.sample.NumberGuessExample.GameRules

import java.io.InputStreamReader;
import java.io.BufferedReader;
 
rule "Get user Guess"
        ruleflow-group "Guess"
        no-loop
        when    
            $r : RandomNumber()
            rules : GameRules( allowed : allowedGuesses )
            game : Game( guessCount < allowed )
            not ( Guess() )
        then
            System.out.println( "You have " + ( rules.allowedGuesses - 
game.guessCount ) + " out of " + rules.allowedGuesses + " guesses left.\nPlease 
enter your guess from 0 to " + rules.maxRange );
        br = new BufferedReader( new InputStreamReader( System.in ) );
        modify ( game ) { guessCount += 1 }
        i = br.readLine();        
            insert( new Guess( i ) );
end      

rule "Record the biggest Guess"
        ruleflow-group "Guess"
        no-loop
        when    
            game : Game( biggestGuess : biggest )
            Guess( $value : value > biggestGuess )
        then
        modify ( game ) { biggest = $value };
end      

rule "Record the smallest Guess"
        ruleflow-group "Guess"
        no-loop 
        when    
            game : Game( smallestGuess : smallest )
            Guess( $value : value < smallestGuess )
        then
        modify ( game ) { smallest = $value };
end      

rule "Guess incorrect, retract Guess"
        ruleflow-group "Guess incorrect"
        when    
            guess : Guess()
        then
        retract( guess );
end     

rule "No more Guesses notification"
        ruleflow-group "No more Guesses"
        when
        r : RandomNumber()    
            game : Game( )        
        then    
        System.out.println( "\nYou have no more guesses\nThe correct guess was 
" + r.value );
        System.out.println( "Your smallest guess  was " + game.smallest + 
"\nYour biggest guess  was " + game.biggest );
end     

Attachment: NumberGuessExample.java
Description: Binary data

Attachment: ShoppingExample.java
Description: Binary data

<?xml version="1.0" encoding="UTF-8"?> 
<process xmlns="http://drools.org/drools-5.0/process";
         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance";
         xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
         type="RuleFlow" name="Number Guess" id="Number Guess" package-name="org.drools.examples" >

  <header>
    <imports>
      <import name="org.drools.examples.NumberGuessExample.Game" />
      <import name="org.drools.examples.NumberGuessExample.GameRules" />
      <import name="org.drools.examples.NumberGuessExample.Guess" />
      <import name="org.drools.examples.NumberGuessExample.RandomNumber" />
    </imports>
  </header>

  <nodes>
    <end id="4" name="End" x="373" y="336" width="80" height="40" />
    <split id="8" name="More Guesses?" x="629" y="261" width="93" height="40" type="2" >
      <constraints>
        <constraint toNodeId="3" toType="DROOLS_DEFAULT" name="No more Guesses" priority="1" type="rule" dialect="mvel" >GameRules( allowed : allowedGuesses  )
Game( guessCount &gt;= allowed )</constraint>
        <constraint toNodeId="6" toType="DROOLS_DEFAULT" name="More guesses" priority="1" type="rule" dialect="mvel" >GameRules( allowed : allowedGuesses  )
Game( guessCount &lt; allowed )</constraint>
      </constraints>
    </split>
    <ruleSet id="11" name="Guess incorrect" x="79" y="455" width="80" height="40" ruleFlowGroup="Guess incorrect" />
    <ruleSet id="3" name="No more Guesses" x="499" y="260" width="109" height="40" ruleFlowGroup="No more Guesses" />
    <ruleSet id="7" name="Guess" x="76" y="198" width="80" height="40" ruleFlowGroup="Guess" />
    <actionNode id="12" name="Too high" x="3" y="325" width="80" height="40" >
        <action type="expression" dialect="mvel" >System.out.println( "Your guess was too high" );</action>
    </actionNode>
    <actionNode id="2" name="Guess correct" x="219" y="260" width="102" height="40" >
        <action type="expression" dialect="mvel" >System.out.println( "You guessed correctly" );</action>
    </actionNode>
    <actionNode id="13" name="Too low" x="154" y="324" width="80" height="40" >
        <action type="expression" dialect="mvel" >System.out.println( "Your guess was too low" );</action>
    </actionNode>
    <join id="9" name="Incorrect guess" x="67" y="387" width="103" height="40" type="2" />
    <join id="6" name="More guesses Join" x="57" y="135" width="119" height="40" type="2" />
    <start id="1" name="Start" x="76" y="60" width="80" height="40" />
    <join id="10" name="No more guesses Join" x="350" y="261" width="128" height="40" type="2" />
    <split id="5" name="Guess correct?" x="59" y="261" width="115" height="40" type="2" >
      <constraints>
        <constraint toNodeId="12" toType="DROOLS_DEFAULT" name="too high" priority="1" type="rule" dialect="mvel" >RandomNumber( randomValue : value )
Guess( value &gt; randomValue )</constraint>
        <constraint toNodeId="2" toType="DROOLS_DEFAULT" name="correct" priority="1" type="rule" dialect="mvel" >RandomNumber( randomValue : value )
Guess( value == randomValue )</constraint>
        <constraint toNodeId="13" toType="DROOLS_DEFAULT" name="too low" priority="1" type="rule" dialect="mvel" >RandomNumber( randomValue : value )
Guess( value &lt; randomValue )</constraint>
      </constraints>
    </split>
  </nodes>

  <connections>
    <connection from="10" to="4" />
    <connection from="11" to="8" bendpoints="[675,474]" />
    <connection from="9" to="11" />
    <connection from="8" to="3" />
    <connection from="6" to="7" />
    <connection from="5" to="12" />
    <connection from="5" to="2" />
    <connection from="5" to="13" />
    <connection from="12" to="9" />
    <connection from="13" to="9" />
    <connection from="1" to="6" />
    <connection from="8" to="6" bendpoints="[675,154]" />
    <connection from="3" to="10" />
    <connection from="2" to="10" />
    <connection from="7" to="5" />
  </connections>

</process>
package com.sample
 
dialect "mvel"

import com.sample.ShoppingExample.Customer
import com.sample.ShoppingExample.Product
import com.sample.ShoppingExample.Purchase
import com.sample.ShoppingExample.Discount
 
rule "Purchase notification"
    salience 10

        when
                $c : Customer()
                $p : Purchase( customer == $c)      
        then
            System.out.println( "Customer " + $c.name + " just purchased " + 
$p.product.name );
end      
 
rule "Discount removed notification"
        when
            $c : Customer()
                not Discount( customer == $c )
        then
                $c.discount = 0;
                System.out.println( "Customer " + $c.name + " now has a 
discount of " + $c.discount );
end

rule "Discount awarded notification"
        when
            $c : Customer()
                $d : Discount( customer == $c )
        then
                System.out.println( "Customer " + $c.name + " now has a 
discount of " + $d.amount );
end

rule "Apply 10% discount if total purcahses is over 100"                        
        no-loop true    
        dialect "java"
    when
                $c : Customer()
                $i : Double(doubleValue  > 100) from accumulate ( Purchase( 
customer == $c, $price : product.price ), 
                                                                            
sum( $price ) )
    then
                $c.setDiscount( 10 );
                insertLogical( new Discount($c, 10) );  
                System.out.println( "Customer " + $c.getName() + " now has a 
shopping total of " + $i );
end
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to