private static PMML createPMMLDocument( final ScoreCardModel model ) {
final Scorecard pmmlScorecard = ScorecardPMMLUtils.createScorecard();
final Output output = new Output();
final Characteristics characteristics = new Characteristics();
final MiningSchema miningSchema = new MiningSchema();
Extension extension = new Extension();
extension.setName( PMMLExtensionNames.SCORECARD_RESULTANT_SCORE_CLASS );
extension.setValue( model.getFactName() );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
extension = new Extension();
extension.setName( PMMLExtensionNames.SCORECARD_IMPORTS );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
List<String> imports = new ArrayList<String>();
imports.add( model.getFactName() );
StringBuilder importBuilder = new StringBuilder();
importBuilder.append( model.getFactName() );
for ( final org.drools.guvnor.models.guided.scorecard.shared.Characteristic characteristic : model.getCharacteristics() ) {
if ( !imports.contains( characteristic.getFact() ) ) {
imports.add( characteristic.getFact() );
importBuilder.append( "," ).append( characteristic.getFact() );
}
}
imports.clear();
extension.setValue( importBuilder.toString() );
extension = new Extension();
extension.setName( PMMLExtensionNames.SCORECARD_RESULTANT_SCORE_FIELD );
extension.setValue( model.getFieldName() );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
extension = new Extension();
extension.setName( PMMLExtensionNames.SCORECARD_PACKAGE );
extension.setValue( model.getPackageName() );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
final String modelName = convertToJavaIdentifier( model.getName() );
pmmlScorecard.setModelName( modelName );
pmmlScorecard.setInitialScore( model.getInitialScore() );
pmmlScorecard.setUseReasonCodes( model.isUseReasonCodes() );
if ( model.isUseReasonCodes() ) {
pmmlScorecard.setBaselineScore( model.getBaselineScore() );
pmmlScorecard.setReasonCodeAlgorithm( model.getReasonCodesAlgorithm() );
}
for ( final org.drools.guvnor.models.guided.scorecard.shared.Characteristic characteristic : model.getCharacteristics() ) {
final Characteristic _characteristic = new Characteristic();
characteristics.getCharacteristics().add( _characteristic );
extension = new Extension();
extension.setName( PMMLExtensionNames.CHARACTERTISTIC_EXTERNAL_CLASS );
extension.setValue( characteristic.getFact() );
_characteristic.getExtensions().add( extension );
extension = new Extension();
extension.setName( PMMLExtensionNames.CHARACTERTISTIC_DATATYPE );
if ( "string".equalsIgnoreCase( characteristic.getDataType() ) ) {
extension.setValue( XLSKeywords.DATATYPE_TEXT );
} else if ( "int".equalsIgnoreCase( characteristic.getDataType() ) || "double".equalsIgnoreCase( characteristic.getDataType() ) ) {
extension.setValue( XLSKeywords.DATATYPE_NUMBER );
} else if ( "boolean".equalsIgnoreCase( characteristic.getDataType() ) ) {
extension.setValue( XLSKeywords.DATATYPE_BOOLEAN );
} else {
System.out.println( ">>>> Found unknown data type :: " + characteristic.getDataType() );
}
_characteristic.getExtensions().add( extension );
if ( model.isUseReasonCodes() ) {
_characteristic.setBaselineScore( characteristic.getBaselineScore() );
_characteristic.setReasonCode( characteristic.getReasonCode() );
}
_characteristic.setName( characteristic.getName() );
final MiningField miningField = new MiningField();
miningField.setName( characteristic.getField() );
miningField.setUsageType( FIELDUSAGETYPE.ACTIVE );
miningField.setInvalidValueTreatment( INVALIDVALUETREATMENTMETHOD.RETURN_INVALID );
miningSchema.getMiningFields().add( miningField );
extension = new Extension();
extension.setName( PMMLExtensionNames.CHARACTERTISTIC_EXTERNAL_CLASS );
extension.setValue( characteristic.getFact() );
miningField.getExtensions().add( extension );