Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[PMML] Prevent duplicate rules

  • Loading branch information...
commit a235481a7d5b108f9b28f74c85c30f875b9e89ea 1 parent 56885cf
@sotty sotty authored
View
4 drools-pmml/src/main/java/org/drools/pmml/pmml_4_1/PMML4Compiler.java
@@ -50,6 +50,7 @@
public static final String PMML = "org.dmg.pmml.pmml_4_1.descr";
public static final String SCHEMA_PATH = "xsd/org/dmg/pmml/pmml_4_1/pmml-4-1.xsd";
public static final String BASE_PACK = PMML4Compiler.class.getPackage().getName().replace('.','/');
+ public static final String BASE_TEST_PACK = "org.drools.pmml.pmml_4_1.test";
public static final String VISITOR_RULES = BASE_PACK + "/pmml_visitor.drl";
@@ -68,7 +69,6 @@
"global/pmml_header.drlt",
"global/pmml_import.drlt",
"global/modelMark.drlt",
- "global/commonQueries.drlt",
"global/dataDefinition/common.drlt",
"global/dataDefinition/rootDataField.drlt",
@@ -251,7 +251,7 @@ public PMML4Compiler() {
super();
results = new ArrayList<KnowledgeBuilderResult>();
helper = new PMML4Helper();
- helper.setPack( "org.drools.pmml.pmml_4_1.test" );
+ helper.setPack( BASE_TEST_PACK );
}
View
3  drools-pmml/src/main/resources/org/drools/pmml/pmml_4_1/pmml_compiler.drl
@@ -95,7 +95,6 @@ salience 9990
when
$h : Header( )
then
- applyTemplate( "commonQueries.drlt", $h, registry, Collections.emptyMap(), theory );
retract( $h );
end
@@ -1855,7 +1854,7 @@ then
applyTemplate( "neuralBeans.drlt", null, registry, null, theory );
- applyTemplate( "neuralLinkSynapses.drlt", null, registry, null, theory );
+ applyTemplate( "neuralLinkSynapses.drlt", null, registry, map, theory );
modify ( $stat ) {
setNeuralNetwork( true );
View
34 drools-pmml/src/main/resources/org/drools/pmml/pmml_4_1/templates/global/commonQueries.drlt
@@ -1,34 +0,0 @@
-@comment{
-
- Copyright 2011 JBoss Inc
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-}
-
-
-@comment{
-
-}
-
-@declare{'commonQueries'}
-
-
-query modelMarker( String $model, ModelMarker $mm )
- $mm := ModelMarker( $model ; )
-end
-
-
-@end{}
-
-
-@includeNamed{'commonQueries'}
View
2  drools-pmml/src/main/resources/org/drools/pmml/pmml_4_1/templates/global/modelMark.drlt
@@ -28,7 +28,7 @@ then
insertLogical( mark );
end
-rule "Enable/Disable Model"
+rule "Enable/Disable Model_@{name}"
when
$flag : Boolean() from entry-point "enable_@{name}"
$mark : ModelMarker( modelName == "@{name}", enabled != $flag )
View
2  ...c/main/resources/org/drools/pmml/pmml_4_1/templates/models/neural/neuralLinkSynapses.drlt
@@ -22,7 +22,7 @@
@declare{'neuralLinkSynapsesRule'}
-rule "LinkSynapses"
+rule "LinkSynapses_@{name}"
when
Stym( $ctx : context, $index : index, $val : value )
Synapse( context == $ctx, source == $index, $target : target, $w : weight )
View
56 drools-pmml/src/test/java/org/drools/pmml/pmml_4_1/predictive/models/CleanupTest.java
@@ -20,6 +20,7 @@
import junit.framework.Assert;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
+import org.drools.ObjectFilter;
import org.drools.agent.ChangeSetHelperImpl;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
@@ -32,13 +33,15 @@
import org.drools.io.ResourceFactory;
import org.drools.io.impl.ClassPathResource;
import org.drools.pmml.pmml_4_1.DroolsAbstractPMMLTest;
+import org.drools.pmml.pmml_4_1.ModelMarker;
import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.rule.QueryResults;
-import org.drools.runtime.rule.Variable;
-import org.junit.After;
import org.junit.Test;
-import static org.junit.Assert.*;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class CleanupTest extends DroolsAbstractPMMLTest {
@@ -62,12 +65,9 @@ public void testCleanupANN() {
StatefulKnowledgeSession kSession = loadModel( source1 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "Neuiris", Variable.v );
+ Collection qres = getModelMarker( kSession, "Neuiris" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_Neuiris" ).insert( Boolean.FALSE );
kSession.fireAllRules();
@@ -77,18 +77,23 @@ public void testCleanupANN() {
kSession.dispose();
}
+ private Collection getModelMarker( final StatefulKnowledgeSession kSession, final String modelName ) {
+ return kSession.getObjects( new ObjectFilter() {
+ public boolean accept( Object o ) {
+ return o instanceof ModelMarker && modelName.equals( ((ModelMarker) o).getModelName() );
+ }
+ } );
+ }
+
@Test
public void testReenableANN() {
setKSession( loadModel( source1 ) );
assertTrue( getKSession().getObjects().size() > 0 );
- QueryResults qres = getKSession().getQueryResults( "modelMarker", "Neuiris", Variable.v );
+ Collection qres = getModelMarker( getKSession(), "Neuiris" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
getKSession().getWorkingMemoryEntryPoint( "enable_Neuiris" ).insert( Boolean.FALSE );
getKSession().fireAllRules();
@@ -125,12 +130,9 @@ public void testCleanupDT() {
StatefulKnowledgeSession kSession = loadModel( source2 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "TreeTest", Variable.v );
+ Collection qres = getModelMarker( kSession, "TreeTest" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_TreeTest" ).insert(Boolean.FALSE);
kSession.fireAllRules();
@@ -146,12 +148,9 @@ public void testCleanupRegression() {
StatefulKnowledgeSession kSession = loadModel( source3 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "LinReg", Variable.v );
+ Collection qres = getModelMarker( kSession, "LinReg" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_LinReg" ).insert(Boolean.FALSE);
kSession.fireAllRules();
@@ -167,12 +166,9 @@ public void testCleanupClustering() {
StatefulKnowledgeSession kSession = loadModel( source4 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "CenterClustering", Variable.v );
+ Collection qres = getModelMarker( kSession, "CenterClustering" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_CenterClustering" ).insert(Boolean.FALSE);
kSession.fireAllRules();
@@ -188,12 +184,9 @@ public void testCleanupSVM() {
StatefulKnowledgeSession kSession = loadModel( source5 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "SVMXORModel", Variable.v );
+ Collection qres = getModelMarker( kSession, "SVMXORModel" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_SVMXORModel" ).insert(Boolean.FALSE);
kSession.fireAllRules();
@@ -209,12 +202,9 @@ public void testCleanupScorecard() {
StatefulKnowledgeSession kSession = loadModel( source6 );
assertTrue( kSession.getObjects().size() > 0 );
- QueryResults qres = kSession.getQueryResults( "modelMarker", "SampleScore", Variable.v );
+ Collection qres = getModelMarker( kSession, "SampleScore" );
assertEquals( 1, qres.size() );
- Object marker = qres.iterator().next().get( "$mm" );
- assertNotNull( marker );
-
kSession.getWorkingMemoryEntryPoint( "enable_SampleScore" ).insert(Boolean.FALSE);
kSession.fireAllRules();
@@ -261,7 +251,7 @@ public void testCleanupANNRulesWithIncrementalKA() {
kSession.fireAllRules();
- assertEquals( 41, kBase.getKnowledgePackage( packageName ).getRules().size() );
+ assertEquals( 40, kBase.getKnowledgePackage( packageName ).getRules().size() );
System.out.println( "************************ REMOVING resource 2 ");
View
1  drools-pmml/src/test/resources/org/drools/pmml/pmml_4_1/ann_rules.drl
@@ -3400,7 +3400,6 @@ when
$assoc : DomainModelAssociation( $id : questionId, object == $bean )
$quest : Question( id == $id )
then
- System.out.println("MOdel-driven invalid answer " + $bean);
insertLogical( new InvalidAnswer($id, "invalid", " Value of " + $bean.getClass().getSimpleName() + " not valid in model " + $ct + " >>> " + $bean) );
end
// fired template modelRevalidate.drlt
Please sign in to comment.
Something went wrong with that request. Please try again.