regular expresions
by Brian Trezise
For the following line of code in the LHS of a rule, is it possible to save
the matched string, and/or the starting and ending index of said match?
sd : SmartDescription(description matches "<some regular expression>",
description : description)
___________________________________________________
Brian Trezise
Staff Software Engineer
IntelliData, Inc
3173 s. uravan way
aurora, colorado 80013
T: 720.524.4864
brian.trezise(a)intellidata.net
16 years, 10 months
compare string and int in LHS
by brenner
Hi,
I have a class, wich contains a string value. This value is in some use
cases an integer.
For this use case I want to convert (parse) the string typ to an integer
because I want that the following rule matches:
rule
when
t : Test(value <= 1)
then
System.out.println(t)
end
class Test {
String value;
getValue();
setValue();
}
Have anyone a solution or some help for me?
Is that possible what I want to do?
Thanks
Daniel
--
View this message in context: http://www.nabble.com/compare-string-and-int-in-LHS-tp15337728p15337728.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 10 months
Re: rules-users Digest, Vol 15, Issue 16
by siddhartha banik
Hi,
Sorry, the Problem statement did not come with the attchment.
The problem is:
I am serializing working memory(WM). But after deserializing that, if I try
to modify the corresponding RuleBase that is not getting reflected.
I mean, after loading the serialized WM even I add a package to the
corresponding RuleBase, new Rules are not getting fired for newly added
facts. Or I remove a package from the corresponding RuleBase, even removed
Rules are getting fired for newly added facts.
So, Once WM is deserialized any chage to the corresponding RuleBase is
failing.
I have attached the test program & test rules.
Thanks
Siddhartha
>
> Message: 3
> Date: Wed, 6 Feb 2008 10:12:40 +0530
> From: "siddhartha banik" <siddhartha.banik(a)gmail.com>
> Subject: [rules-users] Facing Problem with Working Memory
> Serialization/DeSerialization
> To: rules-users(a)lists.jboss.org
> Message-ID:
> <c3d0203e0802052042t65e14fe0h107028b0d37ff723(a)mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Skipped content of type multipart/alternative-------------- next part
> --------------
> A non-text attachment was scrubbed...
> Name: attach.zip
> Type: application/zip
> Size: 6367 bytes
> Desc: not available
> Url :
> http://lists.jboss.org/pipermail/rules-users/attachments/20080206/406aee5...
>
>
16 years, 10 months
java.lang.ClassCastException comparing BigDecimals (compareTo)
by José Arrarte
Hello,
First of all, I'd like to thank all the people involved in making this tool
such a great one (this includes whoever writes the reference manual as
well).
I've been having some problems when comparing BigDecimals (using the
compareTo method). I didn't find this issue in any previous post or in
Drools' JIRA. However, I've been using Drools for a short time, so I hope
you people can help me.
The problem:
Firing this (simple) rule:
rule "Test Rule"
when
$dec : java.math.BigDecimal() from java.math.BigDecimal.TEN;
eval( $dec.compareTo(java.math.BigDecimal.ONE) > 0 )
then
System.out.println("OK!");
end
Fires this exception:
org.drools.RuntimeDroolsException: java.lang.ClassCastException:
java.lang.Integer cannot be cast to java.math.BigDecimal
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple(
SingleTupleSinkAdapter.java:20)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:90)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(
SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(
LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(
SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(
ReteooWorkingMemory.java:179)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(
AbstractWorkingMemory.java:1315)
at org.drools.common.AbstractWorkingMemory.fireAllRules(
AbstractWorkingMemory.java:462)
at org.drools.common.AbstractWorkingMemory.fireAllRules(
AbstractWorkingMemory.java:433)
at com.sample.DroolsTest.main(DroolsTest.java:33)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to
java.math.BigDecimal
at com.sample.Rule_Test_Rule_0Eval0Invoker.evaluate(Rule_Test_Rule_0Eval0Invoker.java:12)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 14 more
I've reported the issue in JIRA (
http://jira.jboss.com/jira/browse/JBRULES-1433)
Best regards,
José
16 years, 10 months
Grouping rules
by Jai Vasanth
Hi,
I am building a system where I would need to fire different sets of rules
based on some attribute in the fact object.
Here are someways which I thought of, I was wondering if there was something
better than that.
1) I could do this by creating different sessions based on the data attrbute
(different sessions would have different rule packages based on the
attribute)
or
2) Have all the rules fire (all the different sets of rules) irrespective of
the attribute and have them insert fact new objects into the working memory.
In the second round of rules, collect the (newly made) fact objects based
on the attribute and take that action.
Thanks
Jai
16 years, 10 months
boolean == String?
by Carlsen, Len
Hi,
I have an expression where I am comparing a Boolean to a String which I
would expect to fail but the expression always returns true. Is this
expected behaviour?
I modified the Drools HelloWorldExample and changed the status from an
int to a boolean.
import org.drools.examples.HelloWorldExample.Message;
rule "Hello World"
when
m : Message( status == "hello", message : message )
then
System.out.println( message );
end
public static class Message {
public static final boolean HELLO = false;
public static final boolean GOODBYE = true;
private String message;
private Boolean status;
public Message() {}
public String getMessage() { return this.message; }
public void setMessage(final String message) { this.message =
message; }
public boolean getStatus() { return this.status; }
public void setStatus(final boolean status) { this.status =
status; }
}
final Message message = new Message();
message.setMessage( "Hello World" );
message.setStatus( Message.HELLO );
final StatefulSession session = ruleBase.newStatefulSession();
session.insert( message );
session.fireAllRules();
Thanks very much,
Len
16 years, 10 months
having a little problem when using LHS variable in RHS
by nemesis29@free.fr
Hello All,
Well i'm trying to create a rule witch need to get some infos in the RHS that
are available in variables declared in the LHS part of the rule.
To make it clear (as my english is not on top ;-) here is an exemple:
the rule file :
rule "NODSLVIP"
dialect "java"
when
$rt : RuleTargetContainer()
$travellers : TravellerListType() from $rt.metaDossier.travellers
$traveller : TravellerType() from $travellers.traveller
$user : UserType() from $traveller.user
$personalInfo : PersonalInfoType(isVIP == true) from $user.personalInfo
then
System.out.println("VIP");
System.out.println($user.getName());
end
When i use it in my code i have the following exception trhown :
org.mvel.CompileException: problem encountered at node [11] 5{172,191}: unable
to resolve token: declr.identifier
If i remove the line printing the user name all goes well (ie : i have VIP in my
trace when user is vip ^^ ).
What am i missing here? I have seen in the documentation that using LHS variable
is possible bu can't make it work for my case :-( .
Thant in advance for any help you can supply.
N Beucler.
16 years, 10 months
missing parameters in the fact object
by Jai Vasanth
Hi,
I am using agenda groups to pick sets of rules to fire based on an
attribute value. The presence or absence of other attributes is dependent
on the value of this attribute based on which I select a particular agenda
group.
Here is an example
rule "ABC"
when
Shape( type = "rectangle" )
then
drools.setFocus("twodimensional")
end
rule "PQR"
when
Shape( type = "cube" )
then
drools.setFocus("threedimensional")
end
rule "area threshold"
agenda-group "twodimensional"
when
Shape( area > 20 )
then
System.out.println ("large object" );
end
rule "volume threshold"
agenda-group "threedimensional"
when
Shape( volume > 20 )
then
System.out.println ("large object" );
end
Suppose if my shape object is a rectangle, then it wouldnt have the volume
attribute. In this case when we try to run these rules it would throw a
NoSuchElementException.
Is there a way to avoid this? Agenda groups help us fire the RHSs
conditionally, Is there a way by which I can conditionally fire LHS of
certain sets of rules ?
Thanks
Jai
16 years, 10 months