First Order Logic - METHODS in Drools
by Arjun Dhar
According to First order Logic, (from a rule perspective), one can represent
their statements using:
PREDICATES, METHODS, CONNECTORS (including existential quantifiers)
..while PREDICATES can be synonymous with Object and Object expressions; the
only way of using methods has been via "eval" (AFAIK, as per my outdated
knowledge); and this is discouraged for the fact that evals perhaps dont fit
in the RETE-OO scheme of things.
Please note: By methods I dont bean Bean getter/setters; but work horse
service layer methods.
..however, to be true to FOL, using methods directly should be supported.
Q1) If it is, can one show or state an example?
Q2) If not, for METHODS that return a specific type of Object, cant they be
useful in RETE-OO evaluation?
Q3) I've used "from" for DAO's , conceptually does "from" address this
fully? In FOL (imo) PREDICATES & METHODS can be exchanged freely, not sure
if "from" gives that freedom.
thanks
--
View this message in context: http://drools.46999.n3.nabble.com/First-Order-Logic-METHODS-in-Drools-tp2...
Sent from the Drools: User forum mailing list archive at Nabble.com.
15 years
Fw: Some Querries on Drools
by Sumeet Karawal
Hi Everybody,
I had posted this earlier. It would be very greatful if anybody could help
me on these queries, any suggestions or any document that I can refer to.
Thanks and Regards,
Sumeet Karawal
Mailto: sumeet.karawal(a)tcs.com
From: Sumeet Karawal/MUM/TCS
To: rules-users(a)lists.jboss.org
Date: 04/18/2011 06:58 PM
Subject: Some Querries on Drools
Hello All,
I have some queries regarding use of drools as rule engine for my
Application. It would be very helpful if I get some guidance regarding
these:
1) I have an application in which a user logs in, and according to his
profile he is provided with some benefits, and rule engine check for the
eligibility criteria. But if hundreds of thousands of user will log in at
same time, then what will be the performance accordingly. Like, these
concurrent users hitting the server, and so many threads will be generated
and many number of rules will be fired in the session. Will this hamper the
performance of Rule Engine.
2) Suppose I have an application using drools. I create EAR / WAR file of
that application and deploy it on some other system. Would it be still
possible for me to change the rules on the fly. Or some dependencies might
have to be managed.
3) How can we manage sessions in drools? Suppose we are having different
stateful sessions in our application, but time consumption when we
fireAllRules() exceeds the expected time. So is there a mechanism to kill,
restart the session in drools. Could I get some help/document regarding
session Management on drools.
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
15 years
How to use for loop in drools!!!!
by Sumeet Karawal
Hello Everybody,
I am not getting, on how to do for loop functionality in drools.
Like for instance, my functionality has :
for(i = 0; i<10; i++)
{
c.setCustomerCount(c.getCustomerCount() + 1);
}
How to translate this code into rule language (.drl).
It would be helpful if anybody could guide me on this.
Thanks and 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
15 years
Trying to compare int and String objects
by Manuel Ortiz
Hello everybody:
I'm trying to write rules in which fact int attributes and fact String
attributes should be compared in condition elements. When I compare them,
let's say from int to String,
rule
when
Fact1($intAttr : attrInt1)
Fact2(attrString == $intAttr)
....
the rule seems to behave OK, whereas when I compare them from String to int,
rule
when
Fact1($stringAttr : attrString1)
Fact2(attrInt == $stringAttr)
....
I get a RuntimeDroolsException( "Conversion to long not supported from
java.lang.String").
I've taken a look at the code which throws the exception,
BaseObjectClassField.getLongValue() and found that it only accepts Number
and Date objects to be converted to long.
...
if ( value instanceof Number ) {
return ((Number) value).longValue();
} else if ( value instanceof Date ) {
return ((Date) value).getTime();
}
...
Is it possible to add String to long conversion via Long.parseLong(str) or
is there any reason not to allow this conversion?.
Thank you again for your time.
Best regards,
Manuel Ortiz.
15 years
calling static error function....thread safe?
by marunam
Hello,
I am calling static "error" function in ValidationHelper class from drool
rules. My rules are going to be executed in spring based web application. Is
this call to an "error" function thread safe?
public class ValidationHelper {
public static void error (RuleContext kcontext, Object... context) {
KnowledgeRuntime knowledgeRuntime = drools.getKnowledgeRuntime();
ValidationReport validationReport = (ValidationReport)
knowledgeRuntime
.getGlobal(ValidationConstants.VALIDATION_REPORT_GLOBAL);
ReportFactory reportFactory = (ReportFactory)
knowledgeRuntime
.getGlobal(ValidationConstants.REPORT_FACTORY_GLOBAL);
validationReport.addMessage(reportFactory.createMessage(
Message.Type.ERROR, messageKey, context));
}
}
import org.drools.runtime.rule.RuleContext;
import function ValidationHelper.error;
...
rule test
when
#condition
then
error(drools)
Please advise
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/calling-static-error-function-thread-sa...
Sent from the Drools: User forum mailing list archive at Nabble.com.
15 years
Can't Get Rules To Modify Object State in Mortgage Example of Drools-5.1.1 + Guvnor
by Jeff Drost
Hello, I'm attempting to use the Drools 5.1.1 Guvnor with the
"mortgage-example" available in the drools downloads. It looks like I get
some, but not all of the rules, to run. I suspect it has something to do
with how I insert the rules, as I can debug and poke around and see the
rules present in the KnowledgeBase object when I debug.
The examples distro on the drools homepage is labeled 5.1.1, however if you
go to the directory
"drools-examples-brms\mortgage-example\mortgage-client\lib" you'll see the
5.0.1 Drools JARs . Therefore using the examples in a pristine fashion,
without modification, was not an option.
I've instead written the class below, and used the XML configuration file
below. In guvnor I've turned the authentication off (not that it makes a
difference when you are requesting a PKG file), imported
"mortgage-sample-repository.xml", and rebuilt the packages.
However, when I run the source code below, it looks as if only one rule
runs, and the state of any of the objects below (i.e. approved or unapproved
mortgage app) fails to change.
Any ideas what I'm doing wrong?
*MyMortgageApplication.java:*
public class MyMortgageApplication {
public static void main(String[] args) throws Throwable {
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
FactType appType =
knowledgeBase.getFactType("mortgages","LoanApplication");
FactType incomeType = knowledgeBase.getFactType("mortgages","IncomeSource");
session.addEventListener(new DebugAgendaEventListener());
session.addEventListener(new DebugWorkingMemoryEventListener());
Object application = appType.newInstance();
Object income = incomeType.newInstance();
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1500);
appType.set(application, "lengthYears", 20);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 65000);
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1);
appType.set(application, "lengthYears", 1);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 6);
System.out.println("FactCount: " + session.getFactCount());
session.insert(appType);
session.insert(incomeType);
System.out.println("FireAllRules: " + session.fireAllRules());
System.out.println("FactCount: " + session.getFactCount());
session.dispose();
System.exit(0);
}
private static KnowledgeBase createKnowledgeBase() {
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "false");
kaconf.setProperty("drools.agent.newInstance", "true");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("MortgageAgent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("my-guvnor.xml"));
return kagent.getKnowledgeBase();
}
}
*my-guvnor.xml:*
<change-set xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/change-setdrools-change-set-5.0.xsd">
<add>
<resource
source="
http://localhost/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages...
"
basicAuthentication="enabled" username="admin" password="admin" type="PKG"
/>
</add>
</change-set>
15 years