Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
PMML : disable, enable and remove models from a session
Browse files Browse the repository at this point in the history
PMML : fixed questionnaire generation
  • Loading branch information
sotty committed Aug 25, 2012
1 parent 5fb4331 commit 2349bbb
Show file tree
Hide file tree
Showing 37 changed files with 1,785 additions and 703 deletions.
34 changes: 22 additions & 12 deletions drools-pmml/src/main/java/org/drools/pmml_4_0/ModelMarker.java
Expand Up @@ -28,8 +28,10 @@ public class ModelMarker {
private String modelClass;

@Position(2)
private String modelUrl;
private boolean enabled = true;

@Position(3)
private String modelUrl;


public ModelMarker() { }
Expand Down Expand Up @@ -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 + '\'' +
'}';
}
}
51 changes: 43 additions & 8 deletions drools-pmml/src/main/java/org/drools/pmml_4_0/PMML4Compiler.java
Expand Up @@ -62,6 +62,7 @@ public class PMML4Compiler implements org.drools.compiler.PMMLCompiler {
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",
Expand Down Expand Up @@ -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;

}
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit 2349bbb

Please sign in to comment.