Using drools with cassandra
by Saumitra S
Hi guys,
I am trying to figure out a way to use drools with Cassandra. I am new to
drools. I will appreciate any links to get started with my research.
-Saumitra
10 years, 11 months
"OR"-constraint doesn't work
by rob_87
Hey guys,
I'm trying to build a simple score-calculator with optaplanner.
Method "A_at_Index2_or_Index3" should force "A" to be at index 2 or index 3.
Method "no_A_at_Index2" forces "A" not to be at Index 2. So, "A" only can be
at index 3 ... but it doesn't.
Optaplanner says the score is -1, but the score has to be 0. Method
"no_A_at_Index2" works well. "A_at_Index2_or_Index3" seems to be wrong.
Does anyone know what I am doing wrong? Do u have any examples for building
complex constraints like XOR, AND, ...)?
@Override
public SimpleScore calculateScore(NCells nCells) {
int score = 0;
if (!(this.A_at_Index2_or_Index3(nCells))){
score--;
}
if (!(this.no_A_at_Index2(nCells))){
score--;
}
return SimpleScore.valueOf(score);
}
public boolean A_at_Index2_or_Index3(NCells nCells){
List<Cell> cellList = nCells.getCellList();
ChomskyRule rule1 = cellList.get(2).getRule();
ChomskyRule rule2 = cellList.get(3).getRule();
int a_counter = 0;
if ( rule1 != null && rule1.getLeftSide().equals("A")){
a_counter++;
}
if ( rule2 != null && rule2.getLeftSide().equals("A")){
a_counter++;
}
if (a_counter==0 && rule1!=null && rule2!=null){
return false;
}
return true;
}
public boolean no_A_at_Index2(NCells nCells){
List<Cell> cellList = nCells.getCellList();
ChomskyRule rule = cellList.get(2).getRule();
if(rule!=null && rule.getLeftSide().equals("A")){return false;}
return true;
}
--
View this message in context: http://drools.46999.n3.nabble.com/OR-constraint-doesn-t-work-tp4027525.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
Is rule introspection available from the Drools API?
by milen igrachev
Hello, is there a way to introspect a Drools file from within java code? What I need is to be able to identify the facts and the fact attributes that are used in a given DRL file.
For example if I have a rule stored in a customer.drl DRL file within my project, containing the following definition:
package myRulePackage
import org.rules.model.Customer import org.rules.model.Mambership
rule "is eligible customer" when $c:Customer(status == "active") Membership(customer == $c, type == "premium") then $c.setEligibilityStatus(true); end
What i need is a way to understand that this ruleset customer.drl is using two fact types - Customer and Membership and three of their attributes - Customer.status, Membership.customer and Membership.type.
I found some information on the internet that such functionality is not supported, however the information was a bit too old, so I decided to ask again.
Big thanks for the support!
Milen
10 years, 11 months
how can I resolve java.lang.RuntimeException: Unknown accessor type
by brachi
I'm using drools 5.5.0.Final.
I noticed that I got the bellow exception in my logs, but my process is
finished. I mean that this exception wasn't break the process, only logged
out.
what is the meaning of this exception and how can I resolve it.
I tried to upgrade mvel2 to the latest final version (2.1.8.Final) but it
wasn't solve the exception.
java.lang.RuntimeException: Unknown accessor type:
org.mvel2.optimizers.impl.refl.collection.ArrayCreator@5b8452eb
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:264)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
at
org.drools.rule.constraint.ConditionAnalyzer.statementToExpression(ConditionAnalyzer.java:467)
at
org.drools.rule.constraint.ConditionAnalyzer.readInvocationParams(ConditionAnalyzer.java:450)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:345)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeExpressionNode(ConditionAnalyzer.java:326)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:286)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeSingleCondition(ConditionAnalyzer.java:133)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:99)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:70)
at
org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:83)
at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:270)
at
org.drools.rule.constraint.MvelConstraint.access$200(MvelConstraint.java:51)
at
org.drools.rule.constraint.MvelConstraint$ConditionJitter.run(MvelConstraint.java:250)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
--
View this message in context: http://drools.46999.n3.nabble.com/how-can-I-resolve-java-lang-RuntimeExce...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
DRL file not getting picked
by dwipin
Hi,
I am using kie-spring.6.0.0.Final artefact to build my project.
This is my app ctx data -
<kie:kmodule id="module-1">
<kie:kbase name="kbase" packages="validation_rules">
<kie:ksession name="ksession">
<kie:consoleLogger />
</kie:ksession>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor"
class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
<bean id="ruleService" class="com.poc.RuleService">
<property name="ksession" ref="ksession" />
</bean>
My Rule Service ->
ksession.fireAllRules();
log.debug("...finished running .");
My DRL File input ->
package validation_rules
rule "Test Rule"
when
then
System.out.println("Testing...");
end
I wanted to test with a sample rule without any conditions. However this
never gets executed. This DRL file is present under
src/main/resources/validation_rules. The KieSession gets injected properly
though.
Thanks and Regards,
Dwipin Chandran.
--
View this message in context: http://drools.46999.n3.nabble.com/DRL-file-not-getting-picked-tp4027476.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
getting object from hashMap in when clause and using it across the rule
by Avin
Hi,
I have an list of objects (objectList) and an hashmap (referenceMap) with
similiar kind of objects. I have to check which objects in list matches with
hashMap.
i can iterate list and check it with hashMap but i am not able to get value
from from the hashmap which itself is an custom object and i need to check
its value
below code i am using to iterate list and check it from hashMap
when
TempStorage($object : concentrationDataTable )
TempStorage($mapObject : concPercentRefObjects)
$dataObject : ConcentrationDataTable($keyObject : concPercentRefkey) from
$object
eval( $mapObject.get($keyObject) != null)
I want to add variable to get this value *$mapObject.get($keyObject)* and
also check if its property getMax returns me other than 10
--
View this message in context: http://drools.46999.n3.nabble.com/getting-object-from-hashMap-in-when-cla...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
iterating through list of object and checking if object is present in Hashmap
by Avin
Hi Guys,
I am new to drools and i have done some PoC of small things. Now i want to
implement a business functionality and it seems very complex to me. I didnt
get much time to go through docs but i went through it as much as can do.
but still no luck
My issue is I have list of employee objects it has methods say empId,
empPhone and empFName.
this employee class has overridden hashcode and equals method. It uses empId
and empPhone to check if user is right user.
I have hashMap of emp objects this map contains all employees of all depts
and locations.
I want to check if objects present in list are present in hashmap. if they
are present then i want to add them to different list and return
corresponding java code is as below
List <Emp> empList = new ArrayList<Emp>();
Map<Emp,Emp> map = new HashMap<Emp,Emp>();
for(Emp emp : empList){
if(map.contains(emp)){
// do something
}
}
I need to convert above code in drools format in drl file. can I iterate
list and use contains in when clause ? so that i can put my actions in then.
through java i am providing drl with employeelist and hashmap
Please help i am in real trouble now
I tried doing
rule "rule for emp"
when
//$o : MyClass( id == "1", name == "name" )
empDetails : TempStorage($object : empDetails)
empTable: TempStorage($mapObject : empTableData)
$mapObject.contains($object)
and
Emp(empId == $object.empId , empPhone == $object.empPhone) from $object
then
System.out.println("hiiiii");
end
but no luck i get exception as *Unable to resolve ObjectType
'$mapObject.contains' : [Rule name='calculation for 10%']*
--
View this message in context: http://drools.46999.n3.nabble.com/iterating-through-list-of-object-and-ch...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
write a rule file, longest matching?
by merry0900
hello,here is my java code
main(){
MyPojo myPojo=new MyPojo();
myPojo.setA("aaa")
myPojo.setB("bbb")...
.
.
.
List<MyPojo> myPojos=getAllFromDb()// get all object by mybatis form
database ,and each one is different from another.
ksession.setGlobal("myPojos", myPojos);
ksession.insert(myPojo);
}
class MyPojo {
private Long id;
private String a;
private String b;
private String c;
private String d;
//getters;
//setters;
}
i want to write a drl file whitch can find a List<MyPojo> myPojoSub that
Each MyPojo From myPojoSub is come from myPojos and limited by some rules。
for example:
myPojos={{id:1,a:"kkk",b:"iii",c:"ppp"},{id:2,a:"kkk",b:"iii"},{id:3,a:"kkk"},{id:4,a:"kkk",b:"iii",c:"ooo"},{id:5,a:"mmm",b:"fff",c:"ttt"}}
and if there is a myPojo{a:kkk,b:"iii",c:"ppp"} then
{id:1,a:"kkk",b:"iii",c:"ppp"} from myPojos is a member of myPojoSub
if there is a myPojo{a:kkk,b:"iii",c:"ttt"} then
{id:2,a:"kkk",b:"iii",}from myPojos is a member of myPojoSub
if there is a myPojo{a:kkk,b:"fff",c:"ttt"} then {id:3,a:"kkk"}from myPojos
is a member of myPojoSub
if there is a myPojo{a:"lll",b:"fff",c:"ttt"} then
{id:5,a:"mmm",b:"fff",c:"ttt"}from myPojos is a member of myPojoSub
if there is a myPojo{a:"ppp",b:"jjj",c:"zzz"} then no any MyPojo from
myPojos is a member of myPojoSub
how do i write my drl rules? any one can help me or give some
suggestions? thank you
here is a rule file templet:
package com.test.tules;
import com.test.MyPojo;
import java.util.List;
globle List<com.test.MyPojo> myPojos;
rule "aaaaa"
salience 65523
when
then
--
View this message in context: http://drools.46999.n3.nabble.com/write-a-rule-file-longest-matching-tp40...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months