}
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.EXTERNAL_CLASS );
extension.setValue( model.getFactName() );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
String agendaGroup = model.getAgendaGroup();
if (!StringUtils.isEmpty(agendaGroup)){
extension = new Extension();
extension.setName( PMMLExtensionNames.AGENDA_GROUP );
extension.setValue(agendaGroup);
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
}
String ruleFlowGroup = model.getRuleFlowGroup();
if (!StringUtils.isEmpty(ruleFlowGroup)){
extension = new Extension();
extension.setName( PMMLExtensionNames.RULEFLOW_GROUP );
extension.setValue(agendaGroup);
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
}
extension = new Extension();
extension.setName( PMMLExtensionNames.MODEL_IMPORTS );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
List<String> imports = new ArrayList<String>();
StringBuilder importBuilder = new StringBuilder();
for ( Import imp : model.getImports().getImports() ) {
if ( !imports.contains( imp.getType() ) ) {
imports.add( imp.getType() );
importBuilder.append( imp.getType() ).append( "," );
}
}
extension.setValue( importBuilder.toString() );
extension = new Extension();
extension.setName( ScorecardPMMLExtensionNames.SCORECARD_RESULTANT_SCORE_FIELD );
extension.setValue( model.getFieldName() );
pmmlScorecard.getExtensionsAndCharacteristicsAndMiningSchemas().add( extension );
extension = new Extension();
extension.setName( PMMLExtensionNames.MODEL_PACKAGE );
String pkgName = model.getPackageName();
extension.setValue( !( pkgName == null || pkgName.isEmpty() ) ? pkgName : null );
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.workbench.models.guided.scorecard.shared.Characteristic characteristic : model.getCharacteristics() ) {
final Characteristic _characteristic = new Characteristic();
characteristics.getCharacteristics().add( _characteristic );
extension = new Extension();
extension.setName( PMMLExtensionNames.EXTERNAL_CLASS );
extension.setValue( characteristic.getFact() );
_characteristic.getExtensions().add( extension );