use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KiePMMLTreeModelFactoryTest method setConstructor.
@Test
public void setConstructor() {
final String targetField = "whatIdo";
final ClassOrInterfaceDeclaration modelTemplate = classOrInterfaceDeclaration.clone();
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, treeModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
final DroolsCompilationDTO<TreeModel> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, new HashMap<>());
KiePMMLTreeModelFactory.setConstructor(droolsCompilationDTO, modelTemplate);
Map<Integer, Expression> superInvocationExpressionsMap = new HashMap<>();
superInvocationExpressionsMap.put(0, new NameExpr(String.format("\"%s\"", treeModel.getModelName())));
superInvocationExpressionsMap.put(2, new NameExpr(String.format("\"%s\"", treeModel.getAlgorithmName())));
MINING_FUNCTION miningFunction = MINING_FUNCTION.byName(treeModel.getMiningFunction().value());
PMML_MODEL pmmlModel = PMML_MODEL.byName(treeModel.getClass().getSimpleName());
Map<String, Expression> assignExpressionMap = new HashMap<>();
assignExpressionMap.put("targetField", new StringLiteralExpr(targetField));
assignExpressionMap.put("miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name()));
assignExpressionMap.put("pmmlMODEL", new NameExpr(pmmlModel.getClass().getName() + "." + pmmlModel.name()));
ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().get();
assertTrue(commonEvaluateConstructor(constructorDeclaration, getSanitizedClassName(treeModel.getModelName()), superInvocationExpressionsMap, assignExpressionMap));
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class ScorecardModelImplementationProviderTest method getKiePMMLModel.
@Test
public void getKiePMMLModel() throws Exception {
final PMML pmml = getPMML(SOURCE_1);
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, (Scorecard) pmml.getModels().get(0), new HasKnowledgeBuilderMock(knowledgeBuilder));
final KiePMMLScorecardModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
assertNotNull(retrieved);
commonVerifyIsDeepCloneable(retrieved);
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class MiningModelImplementationProviderTest method commonGetKiePMMLModel.
private void commonGetKiePMMLModel(String source) throws Exception {
final PMML pmml = getPMML(source);
final KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final MiningModel miningmodel = (MiningModel) pmml.getModels().get(0);
final CommonCompilationDTO<MiningModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, miningmodel, new HasKnowledgeBuilderMock(knowledgeBuilder));
final KiePMMLMiningModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
assertNotNull(retrieved);
assertTrue(retrieved instanceof Serializable);
commonVerifyIsDeepCloneable(retrieved);
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class TreeModelImplementationProviderTest method getKiePMMLModel.
@Test
public void getKiePMMLModel() throws Exception {
final PMML pmml = getPMML(SOURCE_1);
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, (TreeModel) pmml.getModels().get(0), new HasKnowledgeBuilderMock(knowledgeBuilder));
final KiePMMLTreeModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
assertNotNull(retrieved);
commonVerifyIsDeepCloneable(retrieved);
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class DMNAssemblerService method addResourceAfterRules.
@Override
public void addResourceAfterRules(Object kbuilder, Resource resource, ResourceType type, ResourceConfiguration configuration) throws Exception {
logger.warn("invoked legacy addResourceAfterRules (no control on the order of the assembler compilation): {}", resource.getSourcePath());
KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
DMNCompiler dmnCompiler = kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
Collection<DMNModel> dmnModels = new ArrayList<>();
for (PackageRegistry pr : kbuilderImpl.getPackageRegistry().values()) {
ResourceTypePackage resourceTypePackage = pr.getPackage().getResourceTypePackages().get(ResourceType.DMN);
if (resourceTypePackage != null) {
DMNPackageImpl dmnpkg = (DMNPackageImpl) resourceTypePackage;
dmnModels.addAll(dmnpkg.getAllModels().values());
}
}
compileResourceToModel(kbuilderImpl, dmnCompiler, resource, null, dmnModels);
}
Aggregations