best way to write this rule?
by Warner Onstine
I am new to Drools and I've been trying to figure this out through the
user guide and examples I've been finding, but I'm not sure what the
best way is to write this rule (or set of rules).
What I'm trying to write is a set of rules for determining when
someone has earned (or is starting to earn) a badge. I want to be able
to show their progress on badge completion as well as when they
finally complete said badge.
I'm passing in the following to the rule:
- Player
- Earned Badges (list)
- All possible badges
The first rule only deals with one specific badge. So I have something
like this in my when:
$badge : Badge(name == "Something") //my assumption is that Badge
comes from the list of all possible badges I've just passed in
Then, I decided to split the rule into two. One rule for when they had
not earned it yet:
and I call a function
function earnedBadge(List<EarnedBadge> badges, String name) {
boolean found = false;
for(EarnedBadge badge : badges) {
if(badge.getBadge().getName().equals(name)) {
found = true;
}
}
return found;
}
when:
earnedBadge(badges, $badge (name))
Then I got stuck. If they have completed one or more tasks I would
like to create (or use the badge they've started to earn) to track
their progress. So, If I have 5 possible things they need to do and
they've done three of those I'd like to create a new EarnedBadge for
the one they are earning and give it a percentage of 60%. What would
be the best way to do something like this?
Thanks for helping out the newbie, it's greatly appreciated :).
-warner
14 years, 6 months
Guvnor does not like my rule?
by Perrin John - jperri
Noob alert, first post.
I have a rule that works fine when I run it in a JUnit test. I've imported it into Guvnor (along with all my referenced pojos and functions) and it will not build there. Here is the error:
Unable to Analyse Expression for (String curr : (List<String>) $validList) { ValidValue aValidVal = new ValidValue(curr); drools.insert(aValidVal); }; for (int i=0; i<$validList.size(); i++) { String curr = (String)$validList.get(i); ValidValue aValidVal = new ValidValue(curr); drools.insert(aValidVal); };: [Error: unexpected token: $validList] [Near : {... rr : (List<String>) $validList) { ....}] ^ [Line: 1, Column: 35]
What the rules is trying to do is run values from a set of records through a validation function and then add each of the valid values as individual facts. Guvnor apparently doesn't like the way the iteration of the list is being done. I've tried a few different ways of iteration. Thanks in advance for any advice.
Here is the rule:
when
$validList : List()
from accumulate(
InRecord($value : value != ""),
ListValid($value))
then
for (String curr : (List<String>) $validList) {
ValidValue aValidVal = new ValidValue(curr);
insert(aValidVal);
}
for (int i=0; i<$validList.size(); i++) {
String curr = (String)$validList.get(i);
ValidValue aValidVal = new ValidValue(curr);
insert(aValidVal);
}
Regards,
John Perrin
***************************************************************************
The information contained in this communication is confidential, is
intended only for the use of the recipient named above, and may be legally
privileged.
If the reader of this message is not the intended recipient, you are
hereby notified that any dissemination, distribution or copying of this
communication is strictly prohibited.
If you have received this communication in error, please resend this
communication to the sender and delete the original message or any copy
of it from your computer system.
Thank You.
****************************************************************************
14 years, 6 months
Rule one-by-one comparison
by miguel machado
Hi there everybody,
I need to perform rule comparison on a project I'm working on using drools
expert 5.0. For a specific feature implementation, I have two different
knowledge bases with several rules which I need to compare, one by one. By
comparing, I mean "inspect" certain conditions within the LHS.
Currently, I'm able to obtain several attributes from rules
(org.drools.rule.Rule), such as the agenda-group and the rule name and a few
others, but I haven't been able to do it all. Going deeper, there is
LiteralConstraint (for simple conditions) which I can parse and obtain data.
However, I don't know how to do it for OR-conditions, which I guess
represents a MultiRestrictionFieldConstraint. Perhaps there is another way?
I know this may seem like a very unorthodox thing to do, but I don't think
there is a better way of comparing knowledge packages (except for full text
comparison). Is there?
Thanks in advance,
_ miguel, PT
--
"To understand what is recursion you must first understand recursion"
14 years, 6 months
Create a new package in Drools Guvnor repository
by nagarajt
Hi All,
I am using guvnor-distribution-5.3.0.Beta1. I copied
guvnor-5.3.0.Beta1-tomcat-6.0.war from binaries directory into my tomcat
webapps folder (renamed the war file to drools-guvnor.war)
My question is how to create a new package in Drools guvnor repository from
our source.
(we need to create package and deploy rules from our source files)
repository points to
*http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav/packages/*
I want to create a new package name (GreetingTable) in the above repository.
How to do that in my source code?
Waiting for early reply
Regards
Nagaraj
--
View this message in context: http://drools.46999.n3.nabble.com/Create-a-new-package-in-Drools-Guvnor-r...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months
Guvnor - Issues with repository lock on Tomcat re-deployment
by Patricia Bogoevici
I ran Guvnor 5.1 under Tomcat6. If I am using Tomcat manager to re-deploy Guvnor, I get this error about the repository lock:
Caused by: org.drools.repository.RulesRepositoryException: javax.jcr.RepositoryException: The repository home /MY_SERVER_PATH/guvnor/WEB-INF/classes/repository appears to be already locked by the current process.
To fix the lock error I had to stop Tomcat, upload the new Guvnor war, and start Tomcat. It is pretty inconvenient that one has to restart the whole server, as that would disrupt any other application that is deployed on the same server.
I noticed that another user on this forum mentioned the same repository lock error, but on a WebSphere 7 server. (http://drools.46999.n3.nabble.com/Can-Guvnor-provide-client-management-AP...)
I also checked the JackRabbit source code, and Wiki, and the documentation says that this error happens when the repository is not properly closed.
Can anyone from the Drools-Guvnor team add more details about this? Is this a JackRabbit issue, or a Drools-Guvnor?
thx,
--Patricia
14 years, 6 months
(no subject)
by Manohar Kokkula
Hi to All,
I am new to Drools 5.0...
I created three classes(Student, College and StudentCollege) and Decistion
table(manohar.xls) like this:-
Student.java:
package com.model;
public class Student {
private int age;
private int marks;
public String department;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getMarks() {
return marks;
}
public void setMarks(int marks) {
this.marks = marks;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}
College.java:
package com.model;
public class College {
private String ranking;
private String location;
public String status;
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public void setRanking(String ranking) {
this.ranking = ranking;
}
public String getRanking() {
return ranking;
}
}
StudentCollege.java:
package com.model;
import java.io.IOException;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.DecisionTableConfiguration;
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.compiler.DecisionTableFactory;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class Student_College {
public static void main(String args[])
{
Student s=new Student();
College c=new College();
s.setAge(18);
s.setMarks(85);
c.setRanking("A");
c.setLocation("Delhi");
try
{
KnowledgeBase kbase = readBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
ksession.insert(s);
ksession.insert(c);
ksession.fireAllRules();
System.out.println("Department is
"+s.getDepartment());
System.out.println("Status is " + c.getStatus());
ksession.dispose();
}
catch(Exception e)
{
System.out.println("Error is "+e);
}
}
private static KnowledgeBase readBase()
{
DecisionTableConfiguration dconf =
KnowledgeBuilderFactory.newDecisionTableConfiguration();
dconf.setInputType(DecisionTableInputType.XLS);
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("manohar.xls",
Student_College.class), ResourceType.DTABLE, dconf);
//Printing the rules in detail
String drlString = null;
try {
drlString =
DecisionTableFactory.loadFromInputStream(ResourceFactory.newClassPathResource("com/model/manohar.xls").getInputStream(),
dconf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("..........."+drlString);
if(kbuilder.hasErrors())
{
throw new
RuntimeException(kbuilder.getErrors().toString());
}
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
manohar.xls:
RuleSet
com.model
Import
com.model.Student, com.model.College
RuleTable for gettingthe Department and Status of the College
CONDITION
CONDITION
CONDITION
CONDITION
ACTION
ACTION
$s:Student
$s:Student
$c:College
$c:College
age==
marks==
ranking==
location==
$s.setDepartment($param);
$c.setStatus($param);
18
85
A
Delhi
Science
AICTE
18
90
B
Kanpur
Science
AICTE
20
90
A
Mumbai
Maths
AICTE
23
87
C
Hyderabad
Physics
AICTE
I am getting following errors while executing the StudentCollege.java,
Please help me in getting output...
Error is java.lang.RuntimeException: Duplicate declaration for variable
'$s' in the rule 'for gettingthe Department and Status of the College_10'
: [Rule name='for gettingthe Department and Status of the College_10']
Duplicate declaration for variable '$c' in the rule 'for gettingthe
Department and Status of the College_10' : [Rule name='for gettingthe
Department and Status of the College_10']
Duplicate declaration for variable '$s' in the rule 'for gettingthe
Department and Status of the College_11' : [Rule name='for gettingthe
Department and Status of the College_11']
Duplicate declaration for variable '$c' in the rule 'for gettingthe
Department and Status of the College_11' : [Rule name='for gettingthe
Department and Status of the College_11']
Duplicate declaration for variable '$s' in the rule 'for gettingthe
Department and Status of the College_12' : [Rule name='for gettingthe
Department and Status of the College_12']
Duplicate declaration for variable '$c' in the rule 'for gettingthe
Department and Status of the College_12' : [Rule name='for gettingthe
Department and Status of the College_12']
Duplicate declaration for variable '$s' in the rule 'for gettingthe
Department and Status of the College_13' : [Rule name='for gettingthe
Department and Status of the College_13']
Duplicate declaration for variable '$c' in the rule 'for gettingthe
Department and Status of the College_13' : [Rule name='for gettingthe
Department and Status of the College_13']
Rule Compilation error : [Rule name='for gettingthe Department and Status
of the College_10']
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_10_0.java
(7:513) : Science cannot be resolved
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_10_0.java
(8:538) : AICTE cannot be resolved
Rule Compilation error : [Rule name='for gettingthe Department and Status
of the College_12']
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_12_0.java
(7:513) : Maths cannot be resolved
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_12_0.java
(8:536) : AICTE cannot be resolved
Rule Compilation error : [Rule name='for gettingthe Department and Status
of the College_11']
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_11_0.java
(7:513) : Science cannot be resolved
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_11_0.java
(8:538) : AICTE cannot be resolved
Rule Compilation error : [Rule name='for gettingthe Department and Status
of the College_13']
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_13_0.java
(7:513) : Physics cannot be resolved
com/model/Rule_for__gettingthe_Department_and_Status_of_the_College_13_0.java
(8:538) : AICTE cannot be resolved
Thanks and Regards
Manohar Kokkula
Mailto: manohar.kokkula(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
14 years, 6 months
Quotes in decision tables are escaped
by kennywest
Hi all,
I am experiencing the problem that is described here:
http://efreedom.com/Question/1-4874717/Drools-Rules-Quotes-Auto-Escape-Co...
>From what I can see, this has nothing to do with guvnor, since I am using XL
decision tables without Guvnor. I have an XL where I have an action column
that looks like this:
row x : ACTION
row x +1: = empty row =
row x + 2: StringBuilder sb = new StringBuilder();
sb.append($param)
row x + 3: Perform some action
row x + 4: $a.get("test")
What this should do is compile it to a DRL file with the following portion:
StringBuilder sb = new StringBuilder();
sb.append($a.get("test"));
However, this gets translated to:
StringBuilder sb = new StringBuilder();
sb.append($a.get(\"test\"));
... which is wrong. Any ideas why this is happening? (using drools 5.2.0
final)
--
View this message in context: http://drools.46999.n3.nabble.com/Quotes-in-decision-tables-are-escaped-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months
DroolsCompilerAntTask bugs?
by lhorton
I think I have found a couple of bugs in DroolsCompilerAntTask. I am using
it to compile xls decision tables. My config for the compiler is:
<compiler srcdir="${build.web.dir}/packages/venue"
tofile="${build.web.dir}/packages/venue/venue.pkg"
binformat="package" bintype="knowledge" classpathref="model.classpath">
<include name="*.xls" />
</compiler>
I copied the source and added debug log entries. I found two problems:
(1) in the method compileAndAddFiles(KnowledgeBuilder kbuilder), there is a
call to getDroolsPackageFileList(). The call is supposed to return any
package file names in the srcdir, but it is instead it is returning the xls
spreadsheet file names. Then again within compileAndAddFiles, there is a
call to getFileList(), which also returns the xls file names. As a result,
each file gets added to the rule base twice.
(2) in method compileAndAddFile(KnowledgeBuilder kbuilder, String fileName),
the code to compile a spreadsheet (file extension XLSFILEEXTENSION) throws
exception with message "Property storage size inconsistent with block
chain." I changed the source to use a file resource instead of a reader
resource:
kbuilder.add(ResourceFactory.newFileResource(new File(this.srcdir,
fileName)), ResourceType.DTABLE,
dtableconfiguration);
and then the compile works OK.
--
View this message in context: http://drools.46999.n3.nabble.com/DroolsCompilerAntTask-bugs-tp3279120p32...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months