Trouble wrapping my head around window.length(1)
by Ladd
I'm new to Drools and have what I think should be a simple use case. But I'm
getting some puzzling results from my tests.
I have a simple class with just a key and value. What I want to detect is
when the last occurrence with key "X" has a value of "ALARM" and the last
occurrence with key "Y" has a value of "ALARM".
Could someone please either educate me or point me to the documentation that
explains how this would be done? Many thanks in advance!!
Here's my test code and results:
*The event class:*
public class MyEvent {
String key;
String value;
public MyEvent( String key, String value ) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
*The test runner:*
@Test
public void testWindowLen1() {
StringBuilder sb = new StringBuilder();
sb.append( "import drools.tests.MyEvent \n" );
sb.append( " \n" );
sb.append( "declare MyEvent @role(event) end \n" );
sb.append( " \n" );
sb.append( "rule \"Any event detected\" \n" );
sb.append( " \n" );
sb.append( "salience 10 \n" );
sb.append( "when \n" );
sb.append( " f : MyEvent() \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ fault seen with key \" +
f.getKey() + \" value \" + f.getValue() ); \n" );
sb.append( "end \n" );
sb.append( " \n" );
sb.append( "rule \"Faults coincide\" \n" );
sb.append( " \n" );
sb.append( "when \n" );
sb.append( " f1 : MyEvent( key == \"faultType1\", value == \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( " f2 : MyEvent( key == \"faultType2\", value == \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ both faults are active!
f1.key = \" + f1.getKey() + \" f2.key = \" + f2.getKey() ); \n" );
sb.append( "end \n" );
sb.append( " \n" );
sb.append( "rule \"Faults don't coincide\" \n" );
sb.append( " \n" );
sb.append( "when \n" );
sb.append( " f1 : MyEvent( key == \"faultType1\", value != \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( " or \n" );
sb.append( " f2 : MyEvent( key == \"faultType2\", value != \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ at least one fault isn't
active!\" ); \n" );
sb.append( "end \n" );
StatefulKnowledgeSession ksession = null;
KnowledgeBase kbase = null;
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption( EventProcessingOption.STREAM );
kbase = KnowledgeBaseFactory.newKnowledgeBase( config );
ksession = kbase.newStatefulKnowledgeSession();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource(
sb.toString().getBytes() ), ResourceType.DRL );
if( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
} else {
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
}
// Inject the first fault = ALARM
MyEvent faultType1Alarm = new MyEvent( "faultType1", "ALARM" );
System.out.println( "Firing fault1 = ALARM" );
ksession.insert( faultType1Alarm );
ksession.fireAllRules();
// Inject the second fault = ALARM
// Want this to trigger the "Faults concide" rule
MyEvent faultType2Alarm = new MyEvent( "faultType2", "ALARM" );
System.out.println( "Firing fault2 = ALARM" );
ksession.insert( faultType2Alarm );
ksession.fireAllRules();
// Inject the first fault = OK
// Want this to trigger the "Faults don't concide" rule
MyEvent faultType1OK = new MyEvent( "faultType1", "OK" );
System.out.println( "Firing fault1 = OK" );
ksession.insert( faultType1OK );
ksession.fireAllRules();
ksession.dispose();
System.out.println( "Done!" );
assert( true );
}
*And the results that have me scratching my head:*
Firing fault1 = ALARM
************ fault seen with key faultType1 value ALARM
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType1 f2.key = faultType1
Firing fault2 = ALARM
************ fault seen with key faultType2 value ALARM
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType2 f2.key = faultType2
************ both faults are active! f1.key = faultType2 f2.key = faultType1
Firing fault1 = OK
************ fault seen with key faultType1 value OK
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType1 f2.key = faultType1
************ both faults are active! f1.key = faultType1 f2.key = faultType2
Done!
--
View this message in context: http://drools.46999.n3.nabble.com/Trouble-wrapping-my-head-around-window-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 6 months
Error deploying drools-spring (5.4.0.Final) on ServiceMix 4.4.1
by Nicholas Hemley
Hello,
I have deployed drools-spring on ServiceMix 4.4.1 and suffer the following error:
java.lang.NullPointerException
at org.apache.felix.framework.resolver.ResolverImpl.toStringBlame(ResolverImpl.java:1521)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.resolver.ResolverImpl.checkPackageSpaceConsistency(ResolverImpl.java:943)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.resolver.ResolverImpl.resolve(ResolverImpl.java:130)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix$StatefulResolver.resolve(Felix.java:4129)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3459)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
Nothing further in the log, so I am a bit stumped as to what the actual problem is.
Has anyone successfully deployed drools 5.4.0.Final to ServiceMix 4.4.x, please?
Cheerio,
Nic
Nicholas Hemley
Direct: +44 (0) 117 231 0003
Scott Logic | 10 Victoria Street, Bristol, BS1 6BN
Reception: +44 (0) 117 231 0000
12 years, 6 months
Drools verifier
by FrankVhh
Hi all,
Triggered by a post on this forum, I decided to try a testcase
implementation of Drool Verifiier.
I manage to write some code that does not produce any errors at runtime,
which is good. Unfortunately, it doesn't produce any errors/warnings/notes
on my rulefile either, which isn't good.
The drl file consists of some duplicate rules, and since the file is only
part of a ruleset, there might be some gaps as well.
I pasted the java-code below. Does anyone see where I am going wrong?
Thanks in advance!
Regards,
Frank
VerifierBuilder vBuilder =
VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
String ruleText =
"C:\\Users\\Frank\\Documents\\DroolsWorkSpaces\\EmpiricalExperiments\\Financial
Rules\\src\\main\\rules\\clearancerules.drl";
verifier.addResourcesToVerify( ResourceFactory.newReaderResource(
new StringReader( ruleText ) ), ResourceType.DRL );
verifier.fireAnalysis();
VerifierReport result = verifier.getResult();
for(VerifierMessageBase base: result.getBySeverity(
Severity.ERROR ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity(
Severity.WARNING ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity( Severity.NOTE )
){
System.out.println( base );
}
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-verifier-tp268...
Sent from the Drools - User mailing list archive at Nabble.com.
12 years, 6 months
simple subtraction in drools 5.3 fires rules
by oranoh
I have a simple class
public class Dummy {
private int x1, x2, y1, y2;
public Dummy(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public int getX1() {
return x1;
}
public int getX2() {
return x2;
}
public int getX2M150() {
return x2-150;
}
public int getY1() {
return y1;
}
public int getY2() {
return y2;
}
}
And a the following Rule:
rule "DummyRule"
ruleflow-group "DummyTest"
when
d1 : Dummy()
d2 : Dummy(y2 == d1.y1, (x1 == (d1.x2 -150) || x2 == (d1.x2 -150)))
then
System.out.println("Rule DummyTest fired");
end
Executing the rule with the following Data - The Rule fires !!! - WRONG
Dummy d1 = new Dummy(-1050, -900, -750, -600);
Dummy d2 = new Dummy(-1050, -1200, -750, -900);
When I modify the Rule the follow way
rule "DummyRule"
ruleflow-group "DummyTest"
when
d1 : Dummy()
d2 : Dummy(y2 == d1.y1, (x1 == d1.x2M150 || x2 == d1.x2M150))
then
System.out.println("Rule DummyTest fired");
end
with the same Data - The Rule fires not !!!! - What is CORRECT
This problem comes up, when I move from drools 5.01 to 5.3
Can anybody help ?
--
View this message in context: http://drools.46999.n3.nabble.com/simple-subtraction-in-drools-5-3-fires-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 6 months
Re: [rules-users] Planner and domain modeling
by ge0ffrey
Garf wrote
>
> Ah, I see.
> It would be handy to update the docs to clarify such (is there a community
> wiki around?)
>
Not sure. Normally, I'd like to document as much as possible, but I 'd
rather leave this one undefined for now and see how people solve, instead of
pushing people into a certain direction which I haven't tried out decently
in any of the examples yet (or any of the alternative directions).
Try it out, let me know what works best for you. Also, a pull request for
the docs is welcome, if you've verified the changes :)
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-and-domain-modeling-tp4018117p4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 6 months
Re: [rules-users] simple subtraction in drools 5.3 fires rules
by George
Your first rule did not fire for me as expected using drools 5.3. Please ignore my previous post.
oranoh <olaf.raether(a)emerson.com> wrote:
>I have a simple class
>
>public class Dummy {
>
> private int x1, x2, y1, y2;
> public Dummy(int x1, int y1, int x2, int y2) {
> this.x1 = x1;
> this.y1 = y1;
> this.x2 = x2;
> this.y2 = y2;
> }
> public int getX1() {
> return x1;
> }
> public int getX2() {
> return x2;
> }
> public int getX2M150() {
> return x2-150;
> }
> public int getY1() {
> return y1;
> }
> public int getY2() {
> return y2;
> }
>}
>
>And a the following Rule:
>
>rule "DummyRule"
>ruleflow-group "DummyTest"
> when
> d1 : Dummy()
> d2 : Dummy(y2 == d1.y1, (x1 == (d1.x2 -150) || x2 == (d1.x2 -150)))
> then
> System.out.println("Rule DummyTest fired");
>end
>
>Executing the rule with the following Data - The Rule fires !!! - WRONG
>
>Dummy d1 = new Dummy(-1050, -900, -750, -600);
>Dummy d2 = new Dummy(-1050, -1200, -750, -900);
>
>When I modify the Rule the follow way
>
>rule "DummyRule"
>ruleflow-group "DummyTest"
> when
> d1 : Dummy()
> d2 : Dummy(y2 == d1.y1, (x1 == d1.x2M150 || x2 == d1.x2M150))
> then
> System.out.println("Rule DummyTest fired");
>end
>
>
>with the same Data - The Rule fires not !!!! - What is CORRECT
>
>
>This problem comes up, when I move from drools 5.01 to 5.3
>
>Can anybody help ?
>
>
>
>
>
>--
>View this message in context: http://drools.46999.n3.nabble.com/simple-subtraction-in-drools-5-3-fires-...
>Sent from the Drools: User forum mailing list archive at Nabble.com.
>_______________________________________________
>rules-users mailing list
>rules-users(a)lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
12 years, 6 months
drools-planner drl file help
by Ricardo
Hi, My use case is 2 rooms and multiple table in various size, I want planner
to organize the table in the available rooms in our case 2 rooms.
room1 - 10x10 (length x width)
room2 - 5x5
table1 - 5x5 (length X width)
table2 - 2x3
table4 - 2x3
table5 - 7x4
table6 - 4x2
*my drl file as follows...*
rule "requiredRoomSpace"
when
$room : Room($length : length, $width : width, $size : size)
$requiredSizeTotal : Number(intValue > $size) from accumulate(
Table(
room == $room, length < $length, width < $width,
$requiredSize : requiredSize),
sum($requiredSize)
)
then
insertLogical(new IntConstraintOccurrence("requiredRoomSpace",
ConstraintType.NEGATIVE_HARD,
$requiredSizeTotal.intValue() - $size, $room));
end
//
############################################################################
// Calculate score
//
############################################################################
// Accumulate hard constraints
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight) // Vote for
http://jira.jboss.com/jira/browse/JBRULES-1075
)
then
scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
end
*/when i run the program...it assign all the tables into room1 only...I am
not sure what went to wrong...help will be appriciated....if need more info
..I will provide.../*
warm regards,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/drools-planner-drl-file-help-tp4018104....
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 6 months