Search in sources :

Example 1 with MissingValueWeights

use of org.dmg.pmml.clustering.MissingValueWeights in project drools by kiegroup.

the class KiePMMLClusteringModelFactory method setConstructor.

static void setConstructor(final CompilationDTO<ClusteringModel> compilationDTO, final ClassOrInterfaceDeclaration modelTemplate) {
    KiePMMLModelFactoryUtils.init(compilationDTO, modelTemplate);
    final ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName())));
    final BlockStmt body = constructorDeclaration.getBody();
    ClusteringModel clusteringModel = compilationDTO.getModel();
    body.addStatement(assignExprFrom("modelClass", modelClassFrom(clusteringModel.getModelClass())));
    clusteringModel.getClusters().stream().map(KiePMMLClusteringModelFactory::clusterCreationExprFrom).map(expr -> methodCallExprFrom("clusters", "add", expr)).forEach(body::addStatement);
    clusteringModel.getClusteringFields().stream().map(KiePMMLClusteringModelFactory::clusteringFieldCreationExprFrom).map(expr -> methodCallExprFrom("clusteringFields", "add", expr)).forEach(body::addStatement);
    body.addStatement(assignExprFrom("comparisonMeasure", comparisonMeasureCreationExprFrom(clusteringModel.getComparisonMeasure())));
    if (clusteringModel.getMissingValueWeights() != null) {
        body.addStatement(assignExprFrom("missingValueWeights", missingValueWeightsCreationExprFrom(clusteringModel.getMissingValueWeights())));
    }
}
Also used : KiePMMLCluster(org.kie.pmml.models.clustering.model.KiePMMLCluster) Arrays(java.util.Arrays) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) CommonCodegenUtils.methodCallExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.methodCallExprFrom) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CommonCodegenUtils.assignExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.assignExprFrom) CommonCodegenUtils.literalExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.literalExprFrom) MAIN_CLASS_NOT_FOUND(org.kie.pmml.compiler.commons.utils.JavaParserUtils.MAIN_CLASS_NOT_FOUND) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) MissingValueWeights(org.dmg.pmml.clustering.MissingValueWeights) KiePMMLComparisonMeasure(org.kie.pmml.models.clustering.model.KiePMMLComparisonMeasure) DoubleLiteralExpr(com.github.javaparser.ast.expr.DoubleLiteralExpr) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) ComparisonMeasure(org.dmg.pmml.ComparisonMeasure) CompilationUnit(com.github.javaparser.ast.CompilationUnit) KiePMMLClusteringModel(org.kie.pmml.models.clustering.model.KiePMMLClusteringModel) KiePMMLMissingValueWeights(org.kie.pmml.models.clustering.model.KiePMMLMissingValueWeights) NodeList(com.github.javaparser.ast.NodeList) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) KiePMMLClusteringField(org.kie.pmml.models.clustering.model.KiePMMLClusteringField) ClusteringField(org.dmg.pmml.clustering.ClusteringField) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) Logger(org.slf4j.Logger) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) KiePMMLModelFactoryUtils(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils) JavaParserUtils.getFullClassName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFullClassName) KiePMMLClusteringConversionUtils.aggregateFunctionFrom(org.kie.pmml.models.clustering.compiler.factories.KiePMMLClusteringConversionUtils.aggregateFunctionFrom) KiePMMLClusteringConversionUtils.compareFunctionFrom(org.kie.pmml.models.clustering.compiler.factories.KiePMMLClusteringConversionUtils.compareFunctionFrom) Array(org.dmg.pmml.Array) KiePMMLClusteringConversionUtils.modelClassFrom(org.kie.pmml.models.clustering.compiler.factories.KiePMMLClusteringConversionUtils.modelClassFrom) Cluster(org.dmg.pmml.clustering.Cluster) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) MISSING_DEFAULT_CONSTRUCTOR(org.kie.pmml.commons.Constants.MISSING_DEFAULT_CONSTRUCTOR) KiePMMLClusteringConversionUtils.comparisonMeasureKindFrom(org.kie.pmml.models.clustering.compiler.factories.KiePMMLClusteringConversionUtils.comparisonMeasureKindFrom) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) ClusteringModel(org.dmg.pmml.clustering.ClusteringModel) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLClusteringModel(org.kie.pmml.models.clustering.model.KiePMMLClusteringModel) ClusteringModel(org.dmg.pmml.clustering.ClusteringModel)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList (com.github.javaparser.ast.NodeList)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1 DoubleLiteralExpr (com.github.javaparser.ast.expr.DoubleLiteralExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Array (org.dmg.pmml.Array)1 ComparisonMeasure (org.dmg.pmml.ComparisonMeasure)1 Cluster (org.dmg.pmml.clustering.Cluster)1 ClusteringField (org.dmg.pmml.clustering.ClusteringField)1 ClusteringModel (org.dmg.pmml.clustering.ClusteringModel)1 MissingValueWeights (org.dmg.pmml.clustering.MissingValueWeights)1