Permalink
Browse files

PMML : disable, enable and remove models from a session

PMML : fixed questionnaire generation
  • Loading branch information...
1 parent 5fb4331 commit 2349bbb5b608e70c81fc9591fddb2810d929538b @sotty sotty committed Aug 15, 2012
Showing with 1,785 additions and 703 deletions.
  1. +22 −12 drools-pmml/src/main/java/org/drools/pmml_4_0/ModelMarker.java
  2. +43 −8 drools-pmml/src/main/java/org/drools/pmml_4_0/PMML4Compiler.java
  3. +10 −6 drools-pmml/src/main/resources/org/drools/pmml_4_0/pmml_compiler.drl
  4. +144 −32 drools-pmml/src/main/resources/org/drools/pmml_4_0/pmml_informer.drl
  5. +34 −0 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/global/commonQueries.drlt
  6. +5 −5 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/global/dataDefinition/inputFromEP.drlt
  7. +14 −5 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/global/modelMark.drlt
  8. +7 −6 ...l/src/main/resources/org/drools/pmml_4_0/templates/informer/modelAddQuestionsToQuestionnaire.drlt
  9. +6 −6 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelCreateByBinding.drlt
  10. +0 −2 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelInvalidAnswer.drlt
  11. +23 −8 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelMultiQuestion.drlt
  12. +6 −6 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelOutputBinding.drlt
  13. +19 −6 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelQuestion.drlt
  14. +17 −11 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelQuestionBinding.drlt
  15. +7 −4 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelQuestionRebinding.drlt
  16. +29 −9 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelQuestionnaire.drlt
  17. +7 −6 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/informer/modelRevalidate.drlt
  18. +2 −2 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/clustering/clusteringInit.drlt
  19. +2 −1 ...l/src/main/resources/org/drools/pmml_4_0/templates/models/clustering/clusteringMatrixCompare.drlt
  20. +1 −1 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/neural/neuralBuildSynapses.drlt
  21. +5 −5 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/regression/regDeclare.drlt
  22. +10 −10 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/regression/regParams.drlt
  23. +1 −1 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/svm/svmBuild.drlt
  24. +3 −1 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/svm/svmInitSupportVector.drlt
  25. +1 −1 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/svm/svmParams.drlt
  26. +1 −1 drools-pmml/src/main/resources/org/drools/pmml_4_0/templates/models/tree/treeInit.drlt
  27. +181 −55 drools-pmml/src/test/java/org/drools/pmml_4_0/informer/QuestionnaireTest.java
  28. +445 −0 drools-pmml/src/test/java/org/drools/pmml_4_0/predictive/models/CleanupTest.java
  29. +238 −5 drools-pmml/src/test/java/org/drools/pmml_4_0/predictive/models/MultipleModelTest.java
  30. +7 −4 drools-pmml/src/test/java/org/drools/pmml_4_0/predictive/models/NeuralNetworkTest.java
  31. +3 −1 drools-pmml/src/test/java/org/drools/pmml_4_0/predictive/models/SimpleRegressionTest.java
  32. +134 −132 drools-pmml/src/test/resources/org/drools/pmml_4_0/mock_breastcancer.pmml
  33. +42 −42 drools-pmml/src/test/resources/org/drools/pmml_4_0/mock_cold.pmml
  34. +122 −120 drools-pmml/src/test/resources/org/drools/pmml_4_0/mock_ptsd.pmml
  35. +114 −113 drools-pmml/src/test/resources/org/drools/pmml_4_0/test_ann_iris_prediction.xml
  36. +4 −2 drools-pmml/src/test/resources/org/drools/pmml_4_0/test_ann_mixed_inputs.xml
  37. +76 −74 drools-pmml/src/test/resources/org/drools/pmml_4_0/test_miningSchema.xml
@@ -28,8 +28,10 @@
private String modelClass;
@Position(2)
- private String modelUrl;
+ private boolean enabled = true;
+ @Position(3)
+ private String modelUrl;
public ModelMarker() { }
@@ -63,31 +65,39 @@ public void setModelUrl(String modelUrl) {
this.modelUrl = modelUrl;
}
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public String toString() {
+ return "ModelMarker{" +
+ "modelName='" + modelName + '\'' +
+ ", modelClass='" + modelClass + '\'' +
+ ", enabled=" + enabled +
+ ", modelUrl='" + modelUrl + '\'' +
+ '}';
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ModelMarker that = (ModelMarker) o;
- if (modelClass != null ? !modelClass.equals(that.modelClass) : that.modelClass != null) return false;
if (modelName != null ? !modelName.equals(that.modelName) : that.modelName != null) return false;
return true;
}
@Override
public int hashCode() {
- int result = modelName != null ? modelName.hashCode() : 0;
- result = 31 * result + (modelClass != null ? modelClass.hashCode() : 0);
- return result;
+ return modelName != null ? modelName.hashCode() : 0;
}
- public String toString() {
- return "ModelMarker{" +
- ", modelName=" + modelName +
- ", modelClass='" + modelClass + '\'' +
- ", modelUrl='" + modelUrl + '\'' +
- '}';
- }
}
@@ -62,6 +62,7 @@
protected static final String[] GLOBAL_TEMPLATES = new String[] {
"global/pmml_header.drlt",
"global/modelMark.drlt",
+ "global/commonQueries.drlt",
"global/dataDefinition/common.drlt",
"global/dataDefinition/rootDataField.drlt",
@@ -356,15 +357,49 @@ private static void checkBuildingResources( PMML pmml ) {
}
}
-
- for ( Extension x : pmml.getExtensions() ) {
- for ( Object c : x.getContent() ) {
- if ( ! informerLoaded && c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
- for ( String ntempl : INFORMER_TEMPLATES ) {
- prepareTemplate( ntempl );
+ for ( Object o : pmml.getAssociationModelsAndClusteringModelsAndGeneralRegressionModels() ) {
+ List inner;
+ if ( o instanceof NeuralNetwork ) {
+ inner = ((NeuralNetwork) o).getExtensionsAndNeuralLayersAndNeuralInputs();
+ } else if ( o instanceof MiningModel ) {
+ inner = ((MiningModel) o).getExtensionsAndMiningSchemasAndOutputs();
+ } else if ( o instanceof ClusteringModel ) {
+ inner = ((ClusteringModel) o).getExtensionsAndClustersAndComparisonMeasures();
+ } else if ( o instanceof AssociationModel ) {
+ inner = ((AssociationModel) o).getExtensionsAndMiningSchemasAndOutputs();
+ } else if ( o instanceof SupportVectorMachineModel ) {
+ inner = ((SupportVectorMachineModel) o).getExtensionsAndSupportVectorMachinesAndVectorDictionaries();
+ } else if ( o instanceof RegressionModel ) {
+ inner = ((RegressionModel) o).getExtensionsAndRegressionTablesAndMiningSchemas();
+ } else if ( o instanceof NaiveBayesModel ) {
+ inner = ((NaiveBayesModel) o).getExtensionsAndBayesOutputsAndBayesInputs();
+ } else if ( o instanceof TextModel ) {
+ inner = ((TextModel) o).getExtensionsAndDocumentTermMatrixesAndTextCorpuses();
+ } else if ( o instanceof SequenceModel ) {
+ inner = ((SequenceModel) o).getExtensionsAndSequencesAndMiningSchemas();
+ } else if ( o instanceof GeneralRegressionModel ) {
+ inner = ((GeneralRegressionModel) o).getExtensionsAndParamMatrixesAndPPMatrixes();
+ } else if ( o instanceof RuleSetModel ) {
+ inner = ((RuleSetModel) o).getExtensionsAndRuleSetsAndMiningSchemas();
+ } else if ( o instanceof TimeSeriesModel ) {
+ inner = ((TimeSeriesModel) o).getExtensionsAndMiningSchemasAndOutputs();
+ } else if ( o instanceof TreeModel ) {
+ inner = ((TreeModel) o).getExtensionsAndNodesAndMiningSchemas();
+ } else {
+ //should not happen
+ inner = Collections.emptyList();
+ }
+ for ( Object p : inner ) {
+ if ( p instanceof Extension ) {
+ Extension x = (Extension) p;
+ for ( Object c : x.getContent() ) {
+ if ( ! informerLoaded && c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
+ for ( String ntempl : INFORMER_TEMPLATES ) {
+ prepareTemplate( ntempl );
+ }
+ informerLoaded = true;
+ }
}
- informerLoaded = true;
-
}
}
}
@@ -18,6 +18,7 @@ package org.drools.pmml_4_0.compiler;
import org.drools.pmml_4_0.descr.*;
import org.drools.pmml_4_0.ModelMarker;
import org.mvel2.templates.*;
+import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
@@ -96,10 +97,13 @@ salience 9999
when
$h : Header()
then
- HashMap map = new HashMap(7);
- map.put("pack",utils.getPack());
- applyTemplate("pmml_header.drlt", $h, registry, map, theory);
- retract($h);
+ HashMap map = new HashMap( 3 );
+ map.put( "pack", utils.getPack() );
+ applyTemplate( "pmml_header.drlt", $h, registry, map, theory );
+
+ applyTemplate( "commonQueries.drlt", $h, registry, map, theory );
+
+ retract( $h );
end
@@ -133,7 +137,7 @@ when
eval( ! utils.isModelBeanDefined("DataField") )
then
utils.addModelBeanDefinition("DataField");
- applyTemplate("rootDataField.drlt", utils, registry, new HashMap(), theory);
+ applyTemplate("rootDataField.drlt", utils, registry, Collections.emptyMap(), theory);
end
@@ -183,7 +187,7 @@ when
Value( property != "invalid", property != "missing" ) from $vals
)
then
- HashMap map = new HashMap( 7 );
+ HashMap map = new HashMap( 11 );
map.put( "context", utils.context );
map.put( "fullName", $fld.displayName );
map.put( "name", utils.compactUpperCase( $fld.name ) );
Oops, something went wrong.

0 comments on commit 2349bbb

Please sign in to comment.