Re: [rules-users] Accessing maps (hashmaps) keys and values in rules
by shaz
Hi,
I'll try to explain my case...
I have an Object which has around 90 fields. For each of these fields, there can be unlimited validations that needs to be made. By unlimited, I mean that the user can create rules for each specific field. So not all rules are applicable to all fields. The objects I'm placing on the Map are the field structure of the 90 fields. These are things like the maxlength, mandatory/optional, alphanumeric/numeric of each field.
Here is a sample code wherein I just used the Map in the then clause...
==================
global java.util.HashMap recordTypeMap;
global java.util.TreeMap structMap;
global java.util.ArrayList structList;
function CDRError setCDRError(RaCdrMoc cdr, CDRError cdrError, TreeMap structMap,
String fieldName, String errorType, String editedValue, boolean autoCorrected) {
cdrError = new CDRError();
cdrError.setCdrUploadId(cdr.getId().getCdruploadId());
cdrError.setCdrNo(cdr.getId().getCdrNo());
cdrError.setCdrType(0);
RaCdrStructure cdrStructure = new RaCdrStructure();
cdrStructure = (RaCdrStructure) structMap.get(fieldName);
cdrError.setFieldNo(cdrStructure.getId().getFieldNo());
cdrError.setErrorType(errorType);
cdrError.setEditedFieldValue(editedValue);
cdrError.setAutoCorrected(autoCorrected);
return cdrError;
}
rule "MOC Check Missing Filename"
when
cdr : RaCdrMoc(mocflnm == ""); //this is the Object with 90 fields
cdrError : CDRError(); //the resulting object that will be added to the list
errorList : LinkedList(); //all errors will be placed here
cdrStructure : RaCdrStructure();
then
System.out.println("========No filename================");
cdr.setMocflnm("Testfile.csv");
cdrError = setCDRError(cdr, cdrError, structMap, "MOCFLNM", "01", "Testfile.csv", true);
errorList.addLast(cdrError);
end
=========================
My other rules would require the accessing of Hashmaps from the when clause. IWould there be a need to change my data model
Thanks a lot,
shaz
----- Original Message ----
From: "Anstis, Michael (M.)" <manstis1(a)ford.com>
To: Rules Users List <rules-users(a)lists.jboss.org>
Sent: Friday, November 2, 2007 5:20:38 PM
Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in rules
DIV {
MARGIN:0px;}
IMHO you should still think about putting the Map values
into working memory.
This would both simplify your rules and make their
execution faster (eval cannot be indexed, if I remember
correctly).
You might need to adapt your data model representation into
one that is more efficient for use in a RETE network.
Can you explain your use case to help understand? Unless
you have very good reason to keep the facts in the Map your life will be more
difficult than it need be.
An "eval" returns a boolean indiciating whether the
"pattern" matched and therefore, whilst you can reference other bound LHS facts,
you cannot bind other objects to variables.
Thanks,
Mike
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of
shaz
Sent: 02 November 2007 02:32
To: Rules Users
List
Subject: Re: [rules-users] Accessing maps (hashmaps) keys and
values in rules
Hi,
I am placing objects in the Hashmap that were retrieved from the
database. There are currently a hundred objects that I'm storing in the
HashMap. I just made a simple example earlier :) . What works for me now is
putting the getting of the values in the eval(). However, I don't know how to
assign the values that I've taken from the Map.
eval( (
(MyClass)mapOfObj.get("keyOfObj")).getId() > 30);
How do I assign
(MyClass)mapOfObj.get("keyOfObj") to a
variable?
tnx,
shaz
-----
Original Message ----
From: "Anstis, Michael (M.)"
<manstis1(a)ford.com>
To: Rules Users List
<rules-users(a)lists.jboss.org>
Sent: Friday, November 2, 2007 12:17:51
AM
Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in
rules
By way of example (if you misunderstand how the rule
engine should be used):-
rule
chkobj
when
$o :
MyClass( id == "1", name == "name"
)
then
//Do something
else
$o.doSomething();
end
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson
Tirelli
Sent: 01 November 2007 15:48
To: Rules Users
List
Subject: Re: [rules-users] Accessing maps (hashmaps) keys and
values in rules
Shaz,
We strongly advise you
to move to 4.0.3, but this is not related to your problem.
I think you are misunderstanding something. Why are you using the global map
to store your fact? Simply insert it into the working memory and it will
work fine.
[]s
Edson
2007/11/1, Shaz Tumulak <shauii(a)yahoo.com>:
Hi,
I
can't seem to make this syntax work in Drools 4.0.2. Pls. see my
sample
code below.
________________________________________
class
MyClass {
String
id;
String
name;
MyClass(String
id, String
name){
this.id =
id;
this.name =
name;
}
:
getter,
setter methods
:
}
MyClass
obj = new MyClass("1"", "name");
TreeMap<String, MyClass>
mapOfObj = new TreeMap<String,
MyClass>();
mapOfObj.put("keyOfObj", obj);
________________________________________
DRL
file
-------
global java.util.TreeMap mapOfObj;
rule
chkobj
when
obj :
MyClass(mapOfObj["keyOfObj"].id ==
"1");
eval(obj.getName()
== "name");
________________________________________
I'm getting
this error:
org.drools.RuntimeDroolsException:
java.lang.NullPointerException
at
org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
Is
my syntax correct and has someone used this in 4.0.2 or should I move
on
to Drools 4.0.3? Thanks in
advance.
Regards,
shaz
Edson Tirelli-3
wrote:
>
> Denis,
>
> If
you are using latest build from trunk (I'm not sure it already
works
> in MR3), you can use a simplified MVEL
syntax:
>
> when
> Person(
address["business"].phone == "99999999" )
>
then
> ...
>
end
>
> Although, the above will be
converted into an inline-eval. Not as bad
> as
> a top level
eval, but still more costly then using regular
fields.
>
> []s
> Edson
>
>
2007/7/19, Ryan, Dennis (Dennis) <dennisryan(a)avaya.com
>:
>>
>> We are using Maps (HashMaps)
in our rules and the only way we have found
>> to access keys and
values in the Map in the "when" clauses is thru use on
>> eval()
which I know is a big no-no by rules purists. Is there a better
>> way,
>> maybe some shorthand I'm not familiar with
to deal with Maps in the when
>>
clause?
>>
>>
>>
>>
Thanks,
>>
>> Dennis
>>
>>
_______________________________________________
>> rules-users
mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
>
--
> Edson Tirelli
> Software Engineer
- JBoss Rules Core Developer
> Office: +55 11 3529-6000
> Mobile: +55 11 9287-5646
> JBoss, a
division of Red Hat @ www.jboss.com
>
>
_______________________________________________
> rules-users
mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
shauii(a)yahoo.com
--
View this
message in context: http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-ru...
Sent from the drools - user mailing list archive at Nabble.com.
_______________________________________________
rules-users
mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software
Engineer - JBoss Rules Core Developer
Office: +55 11
3529-6000
Mobile: +55 11 9287-5646
JBoss, a
division of Red Hat @ www.jboss.com
Platonic friends of the opposite sex - the real
deal?
Be a better buddy
Find
out at Yahoo! Answers
____________________________________________________
Organic foods - just how healthy is health food?
Be a better foodie
Find out at Yahoo! Answers - http://ph.answers.yahoo.com/
17 years, 1 month
Problem with removePackage()
by igor_b
Hi,
I'm using drools 4.0.1. I'm first adding one package to my RuleBase object,
and everything works just fine:
...
builder.addPackageFromDrl(new InputStreamReader(resource.getInputStream()));
if(ruleBase == null) {
ruleBase = RuleBaseFactory.newRuleBase();
}
ruleBase.addPackage(builder.getPackage());
But after some time i need to refresh my rules, so i'm using following code
to remove previous package:
ruleBase.removePackage("org.sample.mypackage");
and i'm getting the following error:
java.lang.NullPointerException
at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:222)
at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:272)
at
org.drools.common.AbstractRuleBase.removePackage(AbstractRuleBase.java:460)
at
com.diosphere.diomedia.common.drools.impl.RulesServiceImpl.refresh(RulesServiceImpl.java:121)
at
com.diosphere.diomedia.service.impl.PromotionManagerImpl.refreshDRLs(PromotionManagerImpl.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at uk.ltd.getahead.dwr.impl.ExecuteQuery.execute(ExecuteQuery.java:170)
at
uk.ltd.getahead.dwr.impl.DefaultProcessor.doExec(DefaultProcessor.java:552)
at
uk.ltd.getahead.dwr.impl.DefaultProcessor.handle(DefaultProcessor.java:88)
at uk.ltd.getahead.dwr.DWRServlet.doPost(DWRServlet.java:178)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:167)
at
net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Does anyone have a clue what might be the problem, and how to fix it?
Kind regards!
--
View this message in context: http://www.nabble.com/Problem-with-removePackage%28%29-tf4727072.html#a13...
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 1 month
Agenda filter based on package name
by Hooman Mozaffari
It seems "Rule" class doesn't store its parent "Package" information and Rule.getPackage() always returns null.
I would like to create an AgendaFilter based on package name but there is no way to get the parent package of each rule.
Thanks,
Hooman
public class PackageNameAgendaFilter implements AgendaFilter {
private final String packageSuffix;
private final boolean accept;
public PackageNameAgendaFilter(String packageSuffix){
this(packageSuffix, true);
}
public PackageNameAgendaFilter(String packageSuffix, boolean accept){
this.packageSuffix = packageSuffix;
this.accept = accept;
}
public boolean accept(Activation activation) {
if(activation.getRule().getPackage().startsWith(packageSuffix))
return accept;
else
return false;
}
}
_________________________________________________________________
Discover the new Windows Vista
http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE
17 years, 1 month
DSL rules not validated in Eclipse plugin guided editor
by Shahad Ahmed
I'm having problems using DSL's in the guided editor specifically within the
eclipse plugin. The simplest of rules using a DSL report a syntax error in
eclipse. However, the same DSL rules (using the same DSL) are validated
correctly in the normal drl editor in eclipse, and in the guided editor in
the BRMS. Whatever condition I add to a rule in the eclipse guided editor,
it always reports a validation error along the lines that the first word in
the when part of my DSL rule is an unexpected token. It's as if the editor
is trying to validate the DSL sentence itself, rather than the translation
of the DSL sentence. Here's the simplest example I could think off to
reproduce the issue:
1. I have a single DSL sentence in my .dsl file as follows:
[condition][]string=String()
(I've used String as it avoids having to import a model to recreate this
issue)
2. In eclipse I create a new file called rule.package containing:
package com.example
import java.lang.String
3. In the guided editor in eclipse I create a new rule by clicking on the
add condition on the When part of the rule and choosing the single DSL
sentence in the drop-down list displayed by the add condition dialog to get
the rule:
When
string
Then
4. I get an error in the list of error that says that string is an
unexpected token.
5. I noticed that in the "Generated DRL (read only)" tab under the guided
editor, it also displays the rule in DSL format, and not translated into the
expressions on the right-hand-side of the DSL definition. This made me
wonder if the eclipse guided editor is trying to validate the DSL rule
without applying the DSL translation. So I deliberately changed my DSL so
that the left-hand-side just happened to be a valid technical rule
condition:
[condition][]String()=String()
I also changed the rule in the guided editor to
When
String()
Then
This was validated without any issues, but in theory is exactly the same
rule as in point 3 as, apart from keywords, it shouldn't matter what is on
the left-hand -side of the DSL definition.
As I said at the beginning, the dsl and rule in point 1 and 3 work fine with
the normal drl editor in the eclipse plugin, and within the guided editor in
the BRMS.
I also tried adding the expander definition to point to my DSL file in the
rule.package file, but that made no difference either.
Regards
Shahad
17 years, 1 month
Instatiating Global Variables
by Joshua Undesser
I am having a few issues with Global Variables and was wondering if someone
could possibly explain them to me.....
I am coming from a CLIPS/JESS background where globals are very straight
forward. ie (global ?*FAMILY_NAME* = "SMITH") and you can use it everywhere
after that. You can declare them anywhere you want(ie outside/inside
rules, inside a function call), use them whenever you want (within the
LHS/RHS or in a function) and modify them whenever you want (although you
shouldn't).
In Drools however, they seem overly complicated.
For instance.....I can't declare and initialize a global in the same line.
IE you can't do this.... global String FAMILY_NAME = "SMITH";
Instead you have to just declare the global as.....global String
FAMILY_NAME.
Then after it's declared it can be set. Although for the life of me,
setting it is not straight forward either. In a different thread on this
list someone suggested doing the following....ie making sure the salience
number is the highest of any rule forcing it to always fire first....
rule "Initialize Rule" salience 100
when
eval(FAMILY_NAME == null);
then
WorkingMemory wm = drools.getWorkingMemory();
String familyName = "SMITH";
wm.setGlobal("FAMILY_NAME", familyName);
System.out.println("FAMILY_NAME = " + FAMILY_NAME);
end
this does not seem to set the Global Variable value. The result
is...FAMILY_NAME = null.
and any other rule that I have in place that utilizes this global doesn't
fire.
ie
rule "First Rule to Fire"
when
eval(FAMILY_NAME != null)
then
.....
end
This never fires....
However, if through my java application (not in a DRL file), I call
......code.....
workingMemory.setGlobal("FAMILY_NAME", familyName);
fireAllRules();
....more code....
then my "Firest Rule To Fire" rule fires as expected.
There has to be something I am not fully understanding here because it
doesn't seem right that I can't create and set the Global all in one step,
or the fact that I can't set the variable value in a rule, but only through
a java app.
I also don't understand why the Globals can't be used directly by functions
and why they have to be passed in as a variable to the function. If the
function and the Global are defined within a specific working memory, then
it should be available to all rules and functions within that same working
memory. Similar to Java Class Member Data. The member data is available
anywhere in that class.
If anyone can help shed some light on the subject I would be very grateful!
Joshua
--
View this message in context: http://www.nabble.com/Instatiating-Global-Variables-tf4740897.html#a13556883
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 1 month
"First CfP of ANSyM 2008: Adaptive Networked Systems and Media"
by nicolae oana
[We apologize in advance if you receive multiple copies of this CFP]
ANSyM2008: Adaptive Networked Systems and Media
------------------------------------------------
June 18-20, 2008, Wroclaw, Poland
http://oxygen.informatik.tu-cottbus.de/ANSyM2008
Special session within the framework of IEA/AIE 2008 conference
http://www.iea-aie.pwr.wroc.pl/
Please submit your paper here:
http://www.iea-aie.pwr.wroc.pl/conftool
Session Organizers
------------------
Dan Popescu, http://automation.ucv.ro/membri/Dan%20Popescu/DPopescu.htm
University of Craiova, Romania, dpopescu(a)automation.ucv.ro
Costin Badica, http://software.ucv.ro/~badica_costin
University of Craiova, Romania, badica_costin(a)software.ucv.ro
Adrian Giurca, http://www.informatik.tu-cottbus.de/~agiurca/
Brandenburg University of Technology, Germany, giurca(a)tu-cottbus.de
Call for Papers
---------------
Adaptability is a generic property of a system that consists in the systems capability to self-adjust its behavior according to its input, load or users in order to meet certain performance criteria. Adaptability has been described as a characteristic of autonomous behavior and is often related to possessing learning capabilities through analysis of past behaviors and interactions. Adaptability has been intensely studied by various areas of engineering including artificial intelligence, control systems and human centered systems. Adaptability has been set as an important requirement for systems devised to work in new generation global networked and distributed environments like wireless networks, P2P networks, Web systems, multi-agent systems, grids, etc. Such systems are expected to pose new challenges for the development and application of adaptation techniques, due to their special characteristics including: interconnectivity, interactivity, distribution, heterogeneity
an
default-tolerance.
This special session welcomes submissions covering all aspects of adaptability in networked systems and media, including (but not limited to):
- Self-configuring and self-structuring systems
- Adaptive control in communication networks
- Adaptive networked control systems
- Rule-based adaptive systems
- Computational intelligence and adaptability
- Adaptability in multi-agent systems
- Personalized and adaptive hypermedia
- Adaptive information provisioning
- Adaptive coordination
- Adaptability in e-services, including e-learning and e-commerce
- Adaptive negotiation
- Context-aware systems
- Machine learning methods for adaptive systems
- Adaptive security systems
Papers acceptance will be judged based on their relevance, clarity of presentation, originality and accuracy of results and proposed solutions.
The papers will be published in the IEA/AIE 2008 conference proceedings, in a bound volume by Springer Verlag in their Lecture Notes in Artificial Intelligence series.
Important dates
---------------
Papers submission: November 15, 2007
Notification of acceptance: February 1, 2008
Final submission: February 28, 2008
Workshop date: To be announced (Inside June 18-20, 2008)
Program Committee
-----------------
Rajendra Akerkar, Technomathematics Research Foundation, India
Steve Banks, University of Sheffield, UK
Dumitru Burdescu, University of Craiova, Romania
Dorian Cojocaru, University of Craiova, Romania
Jens Dietrich, Institute of Information Sciences and Technology, New Zealand
Petr Dostal, Tomas Bata University in Zlin, Czech Republic
Dragan Gasevic, Athabasca University, Canada
Maria Ganzha, Elblag University of Humanities and Economics, Poland
Dariusz Krol, Wroclaw University of Technology, Poland
Ronaldo Menezes, Florida Institute of Technology, USA
Masoud Mohammadian, University of Canberra, Australia
Grzegorz J. Nalepa, AGH University of Science and Technology, Poland
Philippe Trigano, University of Technology of Compiegne, France
Marcin Paprzycki, Systems Research Institute, Polish Academy of Science, Poland
Janusz Sobecki, Wroclaw University of Technology, Poland
Vladimir Rasvan, University of Craiova, Romania
Athanasios Vasilakos, University of Western Macedonia, Greece
Gerd Wagner, Brandenburg University of Technology at Cottbus, Germany
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
17 years, 1 month
Dynamically selecting a subflow at runtime
by james_d
Hi,
When creating a ruleflow, is there a mechanism that allows me to select
which subflow is executed at runtime? I don't want to have to hardcode a
specific subflow in the Ruleflow GUI/editor.
Here's a contrived example of what I'm attempting to do:
If the following subflows exist: bake cookies, "bake pizza", "grill steaks",
"fry fish", etc., I'd like to have a ruleflow with the following
rulegroups: |Start| -> Get Order -> Make food -> Cleanup -> |Repeat|. For a
requested order, the corresponding subflow is invoked at the "Make food"
stage then the process repeats.
I saw that calling drools.getWorkingMemory().startProcess(...) might be an
option, however I'm not sure that this will return control to the original
ruleflow when done (causing the "Cleanup" group to not get executed). If I
try to use the subflow widget in the Ruleflow GUI I have to explicitly name
the subflow I want invoked.
thank you
--
View this message in context: http://www.nabble.com/Dynamically-selecting-a-subflow-at-runtime-tf472843...
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 1 month
question on syntax with FROM keyword
by Eric Miles
I'm trying to use the FROM keyword in a way that I think it should be
able to be used, but I'm getting compilation errors. Here are the 2
ways that I'm getting stumped on:
exist SomeObject(val == "5") from dao.find(99)
and
not AnotherObject(val == "Dad") from anotherDao.find(1)
If I remove the exist and not, everything compiles okay. With the first
test, I'd like to ensure an object exists AND it has a value of 5.
dao.find could return a null, so I don't want the test to crap out
because of a NullPointerException.
With the second one, I want to ensure the collection returned from
anotherDao.find call does not have an AnotherObject instance with a
value of "Dad".
These seem like fairly trivial things to test for, so I'm fairly certain
there's an appropriate way to structure these test. Any help is
appreciated.
Thanks all.
Eric
17 years, 1 month
Missing BRMS Classes
by Tong Wang
Greetings,
While looking at the source code of BRMS, I found that some classes are
missing. For example:
org.drools.brms.client.modeldriven.SuggestionCompletionEngine
org.drools.brms.client.modeldriven.brl.ActionFieldValue
org.drools.brms.client.modeldriven.brl.ActionInsertFact
org.drools.brms.client.modeldriven.brl.ActionInsertLogicalFact
and a few others, which seem to be classes under the
org.drools.brms.client.modeldriven package.
I tried the downloadable src zip for 4.0.3 and also checked out src from
SVN, but both were missing these classes. However, the BRMS WAR file
downloaded was working for me, which indicates that the WAR and the src are
out of sync.
Thanks,
Tong
17 years, 1 month