Data comparing in CONDITION column decision table
by Sumeet Karawal
Hi,
Can we use a data value of another object in the condition column of a
Spreadsheet.
For example: I have two data types(POJOs) one com.bank.Customer and other
com.bank.Account
in the rules I want to check whether the value entered for a particular
field in Customer class is equal to the value entered for the corresponding
field in the Account class. eg Customer.accType = Account.accType()
How can we achieve this using Decision table (CONDITION Column). I have
tried this:
--------------------------------------------
|RuleTable
|Discount
--------------------------------------------
|CONDITION |CONDITION |
---------------+----------------------------|
|$a : Account |$c : Customer |
---------------+----------------------------|
| |type == "$param"
----------+---------------+----------------------------
| Discount | Account | Type |
| Rules | | |
|----------+---------------+----------------------------|
| 1 | | $a.getType() |
|----------+---------------+----------------------------|
| 2 | | $a.getType() |
|----------+---------------+----------------------------|
| 3 | | $a.getType() |
|----------+---------------+----------------------------|
| 4 | | $a.getType() |
|----------+---------------+----------------------------|
| 5 | | $a.getType() |
|----------+---------------+----------------------------|
| 6 | | $a.getType() |
|----------+---------------+----------------------------|
But it won't work. It would be great if somebody could help me on this.
Thanks & Regards,
Sumeet Karawal
Mailto: sumeet.karawal(a)tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
12 years, 9 months
Guvnor and DB2
by Amin Mohammed-Coleman
Hi
I am trying to integrate Drools Guvnor and DB2 however I'm struggling to get it to work. After changing the repository XML I seem to firstly get:
DbUtility.java:logException failed to close statement Reason already closed.
Followed by nosuchnodetype exception packagenodetype
The db permissions are correct I've confirmed with a separate app.
Any advice would be appreciated.
Thanks
Amin
Sent from my iPhone
12 years, 9 months
List<String> wrongly coerced to Object
by aitchnyu
I want to compare two List<String>'s if they have elements in common. I made
the following rule (actually two of them):
*----rule----*
rule "hardConflictIsIn"
when
$hc : HardConstraint(
$attribute : attribute,
operator == "is in",
$values : strAttributeValue,
$period : period
)
$stp : SubjectTeacherPeriod(
period == $period,
//Collections.disjoint( $t.attributes["tags"], values_list)
eval( Collections.disjoint( *strAttributeMap.get($attribute)*,
$values) == false )
)
then
insertLogical(new IntConstraintOccurrence("hardConflictIsIn",
ConstraintType.NEGATIVE_HARD,1,
$hc,$stp));
end
*----rule----*
But I get the following error:
*----error----*
Exception in thread "main" java.lang.IllegalStateException: There are errors
in the scoreDrl's:
Rule Compilation error : [Rule name='hardConflictNotIn']
in/co/technovia/timetabler/domain/Rule_hardConflictNotIn_8b50378322e744d883618db9941a8e66.java
(9:1204) : The method disjoint(Collection<?>, Collection<?>) in the type
Collections is not applicable for the arguments (*Object*, List)
Rule Compilation error : [Rule name='hardConflictIsIn']
in/co/technovia/timetabler/domain/Rule_hardConflictIsIn_d7f4ca0884754cf894e7cbdb96cee30e.java
(9:1203) : The method disjoint(Collection<?>, Collection<?>) in the type
Collections is not applicable for the arguments (Object, List)
at
org.drools.planner.config.solver.SolverConfig.buildRuleBase(SolverConfig.java:238)
at
org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:170)
at
org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
at
in.co.technovia.timetabler.TimeTableApp.createSolver(TimeTableApp.java:61)
at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:45)
*----error----*
So something get'ted from the map SubjectTeacherPeriod.strAttributeMap is
wrongly coerced to an Object? I defined my SubjectTeacherPeriod class this
way:
*----class snippet----*
public class SubjectTeacherPeriod{
...
private Map<String, Integer> num_attribute_map = new HashMap<String,
Integer>();
private Map<String,List<String>> str_attribute_map = new
HashMap<String,List<String>>();
...
public Map<String,List<String>> getStrAttributeMap(){
return this.str_attribute_map;
}
...
*----class snippet----*
How can I fix this?
--
View this message in context: http://drools.46999.n3.nabble.com/List-String-wrongly-coerced-to-Object-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months
Trouble with the MVEL Map syntax
by barnesjd
I'm interested in using the
http://mvel.codehaus.org/Inline+List,+Maps+and+Arrays compact syntax
available for Maps in MVEL , but I can't quite get it right. I am
attempting to write a simple function to convert English numbers (i.e.
"one", "two", etc) to the integer value. This is how I would LIKE it to
work:
/function int englishToInt(String englishNumber)
{
return ["one":1, "two":2, "three":3, "four":4,
"five":5].get(englishNumber.toLowerCase());
}/
The closest I've gotten to having it work is this:
/function int englishToInt(String englishNumber)
{
Map m = ["one":1, "two":2, "three":3, "four":4, "five":5];
Object obj = m.get(englishNumber.toLowerCase());
if(obj != null)
return Integer.parseInt(obj.toString());
}/
But I get this rather unhelpful error message:
/
Error importing : 'defaultpkg.EnglishToInt.englishToInt'
[ function englishToIntenglishToInt (line:7): Syntax error on tokens, delete
these tokens
]/
... What tokens?? lol
Thanks,
Joe
--
View this message in context: http://drools.46999.n3.nabble.com/Trouble-with-the-MVEL-Map-syntax-tp3844...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months
Problem using BatchExecutionCommand - appears to process same command repeatedly
by Rhodes, Phil
Hey all, I'm working with Drools Expert 5.3.0 Final and have run across
a problem that has me pulling my hair out.
Basically, I'm creating a couple of Commands, adding them to a
BatchExecutionCommand and then executing that
command... but based on the output of the processing, it looks like the
same command was executed repeatedly, instead
of the Commands being iterated.
Here's what my rule file looks like:
package exp
import exp.DriversLicense3Main.Applicant;
import exp.DriversLicense3Main.Application;
rule "Is of valid age"
when
$app: Applicant( age < 18 )
$a : Application()
then
System.out.println( "matched one: " + $app.getName() );
$a.setValid( false );
end
And here's the driver that runs things:
public static void main(String[] args)
{
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add( ResourceFactory.newClassPathResource(
"DriversLicense3.drl",
DriversLicense3Main.class ),
ResourceType.DRL );
// Check the builder for errors
if ( kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors().toString() );
throw new RuntimeException( "Unable to compile
\"DriversLicense3.drl\"." );
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder
.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge
packages).
final KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( pkgs );
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
Applicant applicant1 = new Applicant( "Phillip", 38 );
Application app1 = new Application();
List l1 = new ArrayList();
l1.add( app1);
l1.add( applicant1);
Applicant applicant2 = new Applicant( "Joe", 17 );
Application app2 = new Application();
List l2 = new ArrayList();
l2.add( app2 );
l2.add( applicant2 );
List<Command> cmds = new ArrayList<Command>();
cmds.add( CommandFactory.newInsertElements( l1, "phil", true,
"phil" ) );
cmds.add( CommandFactory.newInsertElements( l2, "joe", true,
"joe" ) );
BatchExecutionCommand batch =
CommandFactory.newBatchExecution(cmds, "ksession1");
ExecutionResults results = ksession.execute( batch );
System.out.println( ((List<Applicant>)results.getValue( "phil"
)).get(1).getName() + ": " + ((List<Application>)results.getValue(
"phil" )).get(0).isValid() );
System.out.println( ((List<Applicant>)results.getValue( "joe"
)).get(1).getName() + ": " + ((List<Application>)results.getValue( "joe"
)).get(0).isValid() );
System.out.println( "done" );
}
Applicant and Application are just some data classes that look like
this:
public static class Applicant
{
private String name;
private int age;
public Applicant() {}
public Applicant( final String name, final int age )
{
this.name = name;
this.age = age;
}
// getter and setter methods here
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
public static class Application
{
private Date dateApplied;
private boolean valid = true;
// getter and setter methods here
public Date getDateApplied()
{
return dateApplied;
}
public void setDateApplied(Date dateApplied)
{
this.dateApplied = dateApplied;
}
public boolean isValid()
{
return valid;
}
public void setValid(boolean valid)
{
this.valid = valid;
}
}
So when I run this, I would expect to see the application "Joe" match
the rule and have the valid attribute on the Application set to false,
while
the "Phil" one should remain true. But when I run this, I get the out
(from my println command in the rule)
matched one: Joe
matched one: Joe
and when I retrieve the results by name, I find that both Applications
have had the valid field set to false.
Can anybody help point me in the right direction here? Am I doing
something wrong, or is this possibly a bug in Drools, or something else?
Thanks,
Phil
Visit us on the Web at mesirowfinancial.com
This communication may contain privileged and/or confidential information. It is intended solely for the use of the addressee. If you are not the intended recipient, you are strictly prohibited from disclosing, copying, distributing or using any of this information. If you received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. Confidential, proprietary or time-sensitive communications should not be transmitted via the Internet, as there can be no assurance of actual or timely delivery, receipt and/or confidentiality. This is not an offer, or solicitation of any offer to buy or sell any security, investment or other product.
12 years, 9 months
Cant check complex boolean expressions with Collections.disjoint
by aitchnyu
I have a `SubjectTeacherPeriod` object which has a property `strAttributeMap`
which is a map of `String` and `List<String>`. I want to check if
`HardConstraint.strAttributeValue` and
`SubjectTeacherPeriod.strAttributeMap[$attribute]` *intersect*. Here is the
rule:
rule "hardConflictIsIn"
when
$hc : HardConstraint(
$attribute : attribute,
operator == "is in",
$values : strAttributeValue,
$period : period
)
$stp : SubjectTeacherPeriod(
period == $period,
//ERROR IN FOLLOWING LINE
Collections.disjoint(strAttributeMap[$attribute], $values) ==
false
)
then
insertLogical(new IntConstraintOccurrence("hardConflictIsIn",
ConstraintType.NEGATIVE_HARD,1,
$hc,$stp));
end
But the rule (actually two of them) throws the error:
Exception in thread "main" java.lang.IllegalStateException: There are errors
in the scoreDrl's:
Unable to Analyse Expression
Collections.disjoint(strAttributeMap[$attribute], $values) == false:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
to java.lang.Class : [Rule name='hardConflictIsIn']
Unable to Analyse Expression
Collections.disjoint(strAttributeMap[$attribute], $values) == true:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast
to java.lang.Class : [Rule name='hardConflictNotIn']
at
org.drools.planner.config.solver.SolverConfig.buildRuleBase(SolverConfig.java:238)
at
org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:170)
at
org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
at
in.co.technovia.timetabler.TimeTableApp.createSolver(TimeTableApp.java:61)
at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:45)
I got it from an answer from my own question at
http://stackoverflow.com/a/9241089/604511 . Is this a bug in Drools itself?
--
View this message in context: http://drools.46999.n3.nabble.com/Cant-check-complex-boolean-expressions-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months
Re: [rules-users] Drools silently fails when I screw up
by ge0ffrey
barnesjd wrote
>
> Hi everyone. I'm new to Drools (using 5.2). I'm using it in Grails
> (2.0.1) with the drools-gorm plugin (0.5.6) (warning: Grails is also new
> for me). I've noticed that whenever I do something that is perhaps
> syntactically invalid, my rules simply don't fire. Given that I'm new to
> Drools, it would be nice if I could actually know what mistake I made.
>
> Are there some options I can use that will make Drools more vocal about my
> mistakes?
>
> Thanks!
> Joe
>
use knowledgebase.hasErrors()
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-silently-fails-when-I-screw-up-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months