Re: [rules-users] Is rule introspection available from the Drools API?
by milen igrachev
Hello thanks for the quick and precise answer!
I believe that the time difference will be a bit of a problem for the IRC chat , but i will be online (channel: #drools user: igrachev) today and will try to check it often. However big thanks for the support and the willingness to help!
You are saying that the code is there, but is not public and documented. Well being not public seems to be a problem, but do you think it is possible to give me an example with the official Drools "first rule" - Sample.drl. The one that comes with the first Drools project. So do you believe it will be possible to paste me some code on how to retrieve the information that this ruleset is using one fact of type Message and two of it's attributes - status and message. So just some code in a public static void main (String [] args) will be great :), or any kind of explanation :).
Once again thank you.
Have a nice day,
Milen
----Original Letter----
From: Mark Proctor mproctor(a)codehaus.org
About: Re: [rules-users] Is rule introspection available from the Drools
API?
To: Rules Users List
Sent at: Monday, 2014, January 6 16:05:33 EET
The code is there, but it’s not public and not documented, and the code can be a little hard to understand - as it’s grown organically over the years.
You’ll need to cast and unwrap and look at member vars. Start on the Rule and the lhs variable. You can always pop onto irc, with live questions,and we’ll try and respond quickly.
http://www.jboss.org/drools/irc
Mark
On 6 Jan 2014, at 09:51, milen igrachev igrachev(a)abv.bg > wrote:
> 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
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
11 years, 11 months
Best pattern for getting results OUT of Integration server?
by dunnlow
I have some confusion about running rules in the Integration Server (v5.5).
I am sending POJOs to the server from a camel (v2.10) Spring client app.
The client inserts a POJO (via batchexecutioncommand) and the rules change
an attribute on the POJO to return the value to the client.
I know, I know, changing attributes of facts is frowned upon (but when I
started I didn't know any better... I swear).
The problem I'm having (surprise) is that updating the fact (to return to
the client app) is causing unwanted activations, no-loops, lock-on-actives
etc etc. So, I'm looking into changing this and inserting two string
objects into my command so that the rules only modify those string objects.
My questions:
1) Is that the best (/a good) way to implement this?
2) My big question/misunderstanding: Does the integration server handle the
batchexecutioncommands in series or is it inserting into the working memory
in parallel (ie. are all executions from the first insert completed before
the next batchexecutioninsert command is evaluated)?
For example,
If I have a loop that inserts one POJO (Fact.class) and two POJOs (S.class,
a simple class with one string class variable) can I safely do something
like below (is the engine able to keep Fact1 with its inserted S1 and S2
objects separate from the next S objects that might be inserted immediately
after OR might all Facts and S objects get confused (due to multi-threading,
parallel operation, etc):
rule "evaluate a Fact POJO"
when
$fact1 : Fact (value > 100, card=="NONE")
$s1 : S ()
$s2 : S (this != $s1)
then
$s1 = "OK"
$s2 = "BLUECARD"
end
rule "remove inserted objects so memory doesn't fill up"
salience -1000
when
$completedFact : Fact ()
then
retract ($completedFact)
end
rule "remove inserted objects so memory doesn't fill up"
salience -1000
when
$completedS : S ()
then
retract($completedS)
end
My client will use the resulting s1 and s2 values so I obviously don't want
the returned s1 and s2 values for fact1 to be confused with the s1 and s2
values for fact2.
3) Currently, I need to retract the pojos I insert once the processing is
done(like above) -- kinda ugly. Is there a way to implement a "logical"
insert for the integration server or a better way to handle this?
Thanks for any thoughts!
-J
--
View this message in context: http://drools.46999.n3.nabble.com/Best-pattern-for-getting-results-OUT-of...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 11 months
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
11 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.
11 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
11 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.
11 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.
11 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.
11 years, 11 months