parametrized rules
by Tim van Heugten
Hi all,
I'm new to Drools, and wonder how I can most cleanly write down rules for
the following.
(For the sake of example) Say I have an object that needs to be processed
season-dependent. I basically need a rule like:
rule
when
Date( month == X, day >= Y, day <= Z)
// Some date containing object
then
System.out.println("Season is "+R)
// Store season in associated object
end
And fill in X, Y, Z and R with:
X Y Z R
1 1 31 Winter
2 1 29 Winter
3 1 21 Winter
3 22 31 Spring
4 1 30 Spring
5 1 31 Spring
6 1 21 Spring
6 22 30 Summer
7 1 31 Summer
...
Should I expand all this rules by hand, and define 16 rules in my rule
file? Or can I parametrize the rules and have this done automagically?
Thanks a lot,
Tim van Heugten
12 years, 8 months
drl problem
by arup
Hi,
i'm having some problems(more like i'm just getting confused) while creating
a rule for my project.
I have 2 classes say Phone() and PhoneTC() like below:
Phone()
{
String number;
}
PhoneTC()
{
String tc;
}
also PhoneTC() is inside the Phone() class. like:
Phone()--String number
PhoneTC()--------String tc
now i need to create a rule like this....
when phone numbers are same and the tc values are different for that number
then do something.
will this work??
when
ph1: Phone(number1 : number)
phtc1: PhoneTC(tc1 : tc)
Phone(number == number1) and PhoneTC(tc != tc1)
then
........
can u suggest better rule for the requirement??.... thanks in advance... :)
:) :)
--
View this message in context: http://drools.46999.n3.nabble.com/drl-problem-tp3877814p3877814.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
ontologies
by Olfa h
hello,
how I can create ontologies with Drools ?
thx
12 years, 8 months
Rule Compilation error when using custom classloader
by M. Kramer
Hello everybody,
I would appreciate some help with the compilation of a rule that involves
dynamically generated POJOs (minimal example at the end of the mail).
When I add the packages of the generated POJOs manually to the imported
packages of my Eclipse plug-in that executes the knowledge session
everything works fine.
When I use my custom classloader (that successfully loads all involved
classes, I checked this thoroughly) I get the following errors:
Unable to generate rule invoker. lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Do I need to change my rules just because the involved classes are now
loaded using my custom classloader?
Thanks for your help!
M. Kramer
This is the rule that only works if the package "lts" is listed under
"Import-Package" in the MANIFEST.MF:
import java.lang.String;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.emf.ecore.EObject;
global java.lang.String output;
global java.util.List list;
global java.util.List pclist;
rule "Aspect"
when
$s0Decl: lts.State(name == "a")
$s0: lts.State(this == $s0Decl)
then
java.util.List param = new ArrayList<HashMap<String,EObject>>();
java.util.List ids = new ArrayList<String>();
param.add($s0);
ids.add("0");
list.add(param);
pclist.add(ids);
end
This is the code that I am using to execute the rule:
void executeKnowledgeSession(String droolsRules, URLClassLoader
urlClassLoader, Iterable<EObject> iterable) {
KnowledgeBuilderConfiguration kBuilderConfiguration =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
urlClassLoader);
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
Resource droolsRulesResource =
ResourceFactory.newByteArrayResource(droolsRules.getBytes());
knowledgeBuilder.add(droolsRulesResource, ResourceType.DRL);
if (knowledgeBuilder.hasErrors()) {
...
}
KnowledgeBaseConfiguration kBaseConfiguration =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, urlClassLoader);
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(kBaseConfiguration);
knowledgeBase.getKnowledgePackages().clear();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
StatelessKnowledgeSession knowledgeSession =
knowledgeBase.newStatelessKnowledgeSession();
knowledgeSession.setGlobal(...);
// execute the knowledge session
knowledgeSession.execute(iterable);
}
These are the exact errors that I get:
Unable to generate rule invoker. lts cannot be resolved to a type
lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Unable to generate rule invoker. : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:883) : lts
cannot be resolved to a type
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:901) : lts
cannot be resolved to a type
Rule Compilation error : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0.java (6:322) : lts cannot be resolved to a type
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Compilation-error-when-using-custo...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
drl execution problem
by arup
i have one drl like below:
rule "FirstNameDifference"
no-loop true
lock-on-active true
when
person1: Person( $firstName1: firstName )
person2: Person( firstName != $firstName1 )
then
dataDifferenceVO.getDataDiffArray().add("Person/FirstName");
end
i'm passing a list of objects in which i have 2 person type objects. my aim
is to check if the firstnames are same or different. if its different i need
to add one String to the DataDiffArray that is declared inside
DataDifferenceVO class.
but as i pass 2 person objects in the WM the rule is getting executed twice.
i.e, the string "Person/FirstName" is getting added twice in the array list.
why is this happening?... the rule should compare 2 firstnames and return
one String...is not that?... what step should i take to achive what i
want....
Thanks a lot i advance... :) :) :)
--
View this message in context: http://drools.46999.n3.nabble.com/drl-execution-problem-tp3866929p3866929...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
Interface and @key in declare
by Findulas
Hello,
I want to declare a new fact base on an interface, f.e.: (i leave away all
those publics)
interface BoInterface {
int getId();
void setId(int id);
}
when i declare the fact
declare BoFact (
bo : BoInterface @key
)
the system throws an exception the a class is expected but an interface is
found, when trying to
perform the equals method.
Is there a restriction that @key cannot be used in a declare?
Greetings,
Bernd
--
View this message in context: http://drools.46999.n3.nabble.com/Interface-and-key-in-declare-tp3868085p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
ClassCastException when comparing date type with literal
by Zeke
Hi, guys:
I meet a strange issue and need your help again... I am using Drools
4.0.7.
When my rule condition is as *Message( date > "Mar-01-2012" )*,
everything is OK. But if I change it to be as below:
*$msg : Message()
Order ( $msg.date > "Mar-01-2012" )*
I will meet "java.lang.String cannot be cast to java.util.Date"
ClassCastException. "Order" is another fact. I attach the exception call
stack. Please check it. It looks like a bug to me. Do we fix it in later
release? If so, can you tell me which release contains the fix? Thanks!
12 years, 8 months