drools variable
by freejava
Hello,
I am a newbie to drools and I have a question on the 'drools' global (?)
variable.
rule "035"
when
MessageBodyType($l : lineItems)
eval(! dao.checkParty($l, "BY", drools))
then
appendMessage(drools)
end
In the above rule, when the checkParty method is called, I am getting a null
value for drools variable.
Whereas when the append message is called I am getting a
"DefaultKnowldgeHelper" object for drools variable.
Can I use 'drools' variable in the when part ?
Thanks for your help.
--
View this message in context: http://drools.46999.n3.nabble.com/drools-variable-tp3586514p3586514.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 7 months
More temporal operator questions
by Mike Melton
If you'll indulge me, I have a couple more questions on temporal
operators. I have specific requirements where the built-in operators
don't *quite* fit. I'm finding workarounds but I don't love them and
basically I'm looking for validation of my approach or better ideas.
1. I need an operator that means "includes with endpoints". In other
words, "A includeswithendpoints B" means A.start <= B.start < B.end <=
A.end. Another way to look at it is: A "includes or coincides or
starts or finishedby" B.
I've been messing around with the parameters to includes. Ideally, I'd
represent this as "includes[0, duration]", where "duration" is A's
duration. This would mean that the minimum distance between the start
and end timestamps is 0 and the maximum distance between the start and
end points is Event A's duration. However, I haven't been able to find
a way to pass a dynamic parameter to the operator.
My workaround in this case is "includes[0, 1000000d]", where 1000000d
is just an arbitrarily large number. My tests so far have borne this
out as working, but I don't like it because it's not very
self-explanatory; everywhere I use it, I will need to include a
comment. The beauty of the temporal operators is that they are
intuitive and I feel like this workaround is compromising that.
2. Given an interval-based event A and a point-in-time event B, I need
an operator which means A "finishedby or includes" B; i.e., A.start <
B.timestamp <= A.end.
Similarly, in this case, the workaround is "includes[1ms, 1000000d, 0,
1000000d]". This takes the ugliness and need for explanatory comments
to a new level.
A few questions:
1. Is there any technical reason why my workarounds won't work
(besides the obvious one where there is an event that lasts 1000001
days)?
2. Are there better solutions? (e.g., can I define my own operators?)
3. As a general rule, I avoid using "or" logic in my rules. However,
is this a case where I should consider it? To me, "EventA( this
includes $eventB || this finishedby $eventB )" is much cleaner than
"EventA( this includes[1ms, 1000000d, 0, 1000000d] $eventB )", but
that doesn't mean I like it.
Thanks in advance for any feedback.
Mike
14 years, 7 months
Cross Reference Utility
by ronalbury
Is there a cross reference utility, that will allow me to easily find the
rules which reference a specific class and/or specific attribute? I'm
hoping for something like the standard Java 'references' report.
I'm guessing (based on what I've read) that the Drools compiler generates a
bunch of Java classes behind the scenes ... is there any way to get it to
leave those Java artifacts so that I could get a 'references' report from
them?
Thanks
Ron
--
View this message in context: http://drools.46999.n3.nabble.com/Cross-Reference-Utility-tp3583733p35837...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 7 months
Many to many matching using Drools rules
by Zhuo Li
Folks,
I am recently working on a BI project which is doing reconciliation between
repository and accounting. I'm using Drools 5.1.1 to maintain all these
matching rules. One scenario I have no clue to implement in Drools is that I
need to find x transactions from repository, to match y transactions from
accounting, while existing repository transactions and accounting
transactions are bigger than x and y. Does anybody have experience to do
similar thing in Drools?
Best Abe
14 years, 7 months
Store a Map in Country Enumeration
by srinivasasanda
Hi,
I have a declarative model with a fact named Person with
field*(country,state)*
I have seen in guvnor documentation that
'Board.type':['short','long','NN=MIn Mal']
Min Mal will be displayed in GUI where as NN will be used backend
In the sameway,I need to use country ids instead of countrynames in backend
where countryname should displayed at GUI.How I can do this?please suggest
me..
'Person.country':(new com.sample.DropDownList()).loadCountriesList()-----
Countries are succesfully loaded---US,UK,JAPAN....etc....in dropdown list
Now I should use different IDs for these different countries in backend.
In the above enumeration I should use different Ids for different countries
in backend(rule)..How can I do this
Please suggest me.Please How can I achieve
--
View this message in context: http://drools.46999.n3.nabble.com/Store-a-Map-in-Country-Enumeration-tp35...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 7 months
Sliding window behavior in stream mode and realtime clock
by MarcoMojana
Hi,
The situation is the following: we need to process a stream of delayed
events. This means that the event timestamp is provided for each one
of them and that it doesn't generally correspond to the system time when
we insert them in the entry-point. The events delay may vary, but they
are always inserted in chronological order. My questions refer to the
enclosed implementation and are:
1) Given my source code, would the timestamps correctly read and used?
2) I would like that the "time window" behaves as if it is initially
placed at t = -inf and, when a new event is inserted in the
entry-point, it would slide to the time of the last event timestamp.
In my code I have used the stream mode and a realtime clock: is it
correct?
3) When I run the given application, I expect it to print only:
Found TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
because it is the only event of type TriggerEvent for which there
exists a window of size 1h that contains no InhibitEvent. Instead,
sometimes it prints nothing and sometimes:
Found TriggerEvent [timestamp=Tue Dec 06 14:10:00 CET 2011]
Found TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
How is this possible? How can I achieve my goal?
(I'm currently using Drools 5.3.0 final.)
Cheers
Marco Mojana
------------------------------------------------------------------------
package com.sample;
import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.conf.EventProcessingOption;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
final KnowledgeSessionConfiguration sessionConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get("realtime"));
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession(sessionConfig, null);
WorkingMemoryEntryPoint eventStream =
ksession.getWorkingMemoryEntryPoint("EventStream");
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// Insert events
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 12, 0, 0).getTime()));
eventStream.insert(new TriggerEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 13, 0, 0).getTime()));
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 0, 0).getTime()));
eventStream.insert(new TriggerEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 10, 0).getTime()));
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 20, 0).getTime()));
ksession.fireAllRules();
ksession.dispose();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Rules.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
final KnowledgeBaseConfiguration kbConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbConfig.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConfig);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
------------------------------------------------------------------------
package com.sample;
import java.util.Date;
public class TriggerEvent {
private final Date timestamp;
public TriggerEvent(final Date timestamp) {
this.timestamp = timestamp;
}
public Date getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return "TriggerEvent [timestamp=" + timestamp + "]";
}
}
------------------------------------------------------------------------
package com.sample;
import java.util.Date;
public class InhibitEvent {
private final Date timestamp;
public InhibitEvent(final Date timestamp) {
this.timestamp = timestamp;
}
public Date getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return "InhibitEvent [timestamp=" + timestamp + "]";
}
}
------------------------------------------------------------------------
package com.sample
declare InhibitEvent
@role(event)
@timestamp(timestamp)
end
declare TriggerEvent
@role(event)
@timestamp(timestamp)
end
rule "EventNotInhibited"
dialect "mvel"
when
not( InhibitEvent() over window:time(1h) from entry-point EventStream )
$e0 : TriggerEvent() over window:time(1h) from entry-point EventStream
then
System.err.println("Found " + $e0);
end
------------------------------------------------------------------------
--
View this message in context: http://drools.46999.n3.nabble.com/Sliding-window-behavior-in-stream-mode-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 7 months
[MVEL] the data converter does not work
by kapokfly
Can someone tell why the data converter does not work at all and what is the
reason we make the data converter to value assignment statement only?
public void testDataConverter() throws Exception {
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
DataConversion.addConversionHandler(Date.class, new MyDateConverter());
Locale.setDefault(Locale.US);
Cheese cheese = new Cheese();
cheese.setUseBy(new
SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("cheese", cheese);
Serializable compiledExpression = MVEL.compileExpression("cheese.useBy
== '10-Jul-1974'");
boolean result = MVEL.executeExpression(compiledExpression, variables,
Boolean.class);
assertTrue(result);
}
Here is what I can see from the code, at the end this method will be called,
would it be nice to allow the data converter here?
private static Boolean safeEquals(final Object val1, final Object val2)
{
if (val1 != null) {
return val1.equals(val2) ? Boolean.TRUE : Boolean.FALSE;
}
else return val2 == null || (val2.equals(val1) ? Boolean.TRUE :
Boolean.FALSE);
}
-----
Ivan, your Panda, forever
--
View this message in context: http://drools.46999.n3.nabble.com/MVEL-the-data-converter-does-not-work-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 7 months