Now with Drools demo (Rete System to match which level building rules to fire for which PlayerProfiles/Archetypes).
This commit is contained in:
@@ -8,6 +8,15 @@
|
|||||||
<classpathentry kind="lib" path="lib/slf4j-api-1.6.4.jar"/>
|
<classpathentry kind="lib" path="lib/slf4j-api-1.6.4.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/xuggle-xuggler.jar"/>
|
<classpathentry kind="lib" path="lib/xuggle-xuggler.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="lib" path="lib/drools-compiler-5.3.0.Final.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/drools-core-5.3.0.Final.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/drools-decisiontables-5.3.0.Final.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/drools-jsr94-5.3.0.Final.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/drools-api-5.2.0.M1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/xstream-1.4.2.jar"/>
|
<classpathentry kind="lib" path="lib/xstream-1.4.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/knowledge-api-5.3.0.Final.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/ecj.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/antlr-3.4-complete-no-antlrv2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/mvel2-2.1.Beta8.jar"/>
|
||||||
<classpathentry kind="output" path="classes"/>
|
<classpathentry kind="output" path="classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
BIN
lib/antlr-3.4-complete-no-antlrv2.jar
Normal file
BIN
lib/antlr-3.4-complete-no-antlrv2.jar
Normal file
Binary file not shown.
BIN
lib/drools-api-5.2.0.M1.jar
Normal file
BIN
lib/drools-api-5.2.0.M1.jar
Normal file
Binary file not shown.
BIN
lib/drools-compiler-5.3.0.Final.jar
Normal file
BIN
lib/drools-compiler-5.3.0.Final.jar
Normal file
Binary file not shown.
BIN
lib/drools-core-5.3.0.Final.jar
Normal file
BIN
lib/drools-core-5.3.0.Final.jar
Normal file
Binary file not shown.
BIN
lib/drools-decisiontables-5.3.0.Final.jar
Normal file
BIN
lib/drools-decisiontables-5.3.0.Final.jar
Normal file
Binary file not shown.
BIN
lib/drools-jsr94-5.3.0.Final.jar
Normal file
BIN
lib/drools-jsr94-5.3.0.Final.jar
Normal file
Binary file not shown.
BIN
lib/ecj.jar
Normal file
BIN
lib/ecj.jar
Normal file
Binary file not shown.
BIN
lib/knowledge-api-5.3.0.Final.jar
Normal file
BIN
lib/knowledge-api-5.3.0.Final.jar
Normal file
Binary file not shown.
BIN
lib/mvel2-2.1.Beta8.jar
Normal file
BIN
lib/mvel2-2.1.Beta8.jar
Normal file
Binary file not shown.
7
rules/BasicAccountRule.drl
Normal file
7
rules/BasicAccountRule.drl
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package org.drools.examples.simple;
|
||||||
|
rule "Account balance is less than 100"
|
||||||
|
when
|
||||||
|
$account : Account( balance < 100 ) // condition
|
||||||
|
then
|
||||||
|
System.out.println("Account number: " + $account.getId() + " is below 100"); // consequence
|
||||||
|
end
|
||||||
19
src/org/drools/examples/simple/Account.java
Normal file
19
src/org/drools/examples/simple/Account.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package org.drools.examples.simple;
|
||||||
|
|
||||||
|
public class Account {
|
||||||
|
private int balance;
|
||||||
|
private String Id;
|
||||||
|
public int getBalance() {
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
public void setBalance(int balance) {
|
||||||
|
this.balance = balance;
|
||||||
|
}
|
||||||
|
public String getId() {
|
||||||
|
return Id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
65
src/org/drools/examples/simple/DroolsExample.java
Normal file
65
src/org/drools/examples/simple/DroolsExample.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package org.drools.examples.simple;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import org.drools.KnowledgeBase;
|
||||||
|
import org.drools.KnowledgeBaseFactory;
|
||||||
|
import org.drools.builder.KnowledgeBuilder;
|
||||||
|
import org.drools.builder.KnowledgeBuilderFactory;
|
||||||
|
import org.drools.builder.ResourceType;
|
||||||
|
import org.drools.io.ResourceFactory;
|
||||||
|
import org.drools.runtime.StatefulKnowledgeSession;
|
||||||
|
import org.drools.runtime.StatelessKnowledgeSession;
|
||||||
|
|
||||||
|
public class DroolsExample {
|
||||||
|
/**
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//Create KnowledgeBase...
|
||||||
|
KnowledgeBase knowledgeBase = createKnowledgeBase();
|
||||||
|
//Create a statefull session
|
||||||
|
StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
|
||||||
|
|
||||||
|
//Create Facts - two ban accounts
|
||||||
|
Account account = new Account();
|
||||||
|
account.setBalance(10);
|
||||||
|
account.setId("N1");
|
||||||
|
|
||||||
|
Account account2 = new Account();
|
||||||
|
account2.setBalance(120);
|
||||||
|
account2.setId("N2");
|
||||||
|
|
||||||
|
//Insert the bank account facts into a State full session
|
||||||
|
session.insert(account);
|
||||||
|
session.insert(account2);
|
||||||
|
|
||||||
|
//Note that at this point, afetr fact insertation the Agenda has one activation ready to be fired.
|
||||||
|
//Account1 is less than 100.
|
||||||
|
|
||||||
|
//Only now we will fire the rules which are already in the agenda
|
||||||
|
session.fireAllRules();
|
||||||
|
|
||||||
|
//A message of N1 is less than 100 will be printed to stdout.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new knowledge base
|
||||||
|
*/
|
||||||
|
private static KnowledgeBase createKnowledgeBase() {
|
||||||
|
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
|
||||||
|
//Add drl file into builder
|
||||||
|
File accountRules = new File("rules/BasicAccountRule.drl"); //Where the account rule is.
|
||||||
|
builder.add(ResourceFactory.newFileResource(accountRules), ResourceType.DRL);
|
||||||
|
if (builder.hasErrors()) {
|
||||||
|
throw new RuntimeException(builder.getErrors().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
|
||||||
|
|
||||||
|
//Add to Knowledge Base packages from the builder which are actually the rules from the drl file.
|
||||||
|
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
|
||||||
|
|
||||||
|
return knowledgeBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user