use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class PMML4Compiler method precompile.
public List<PMMLResource> precompile(InputStream stream, ClassLoader classLoader, KieBaseModel rootKieBaseModel) {
List<PMMLResource> resources = new ArrayList<>();
KieServices services = KieServices.Factory.get();
KieModuleModel module = services.newKieModuleModel();
this.results = new ArrayList<KnowledgeBuilderResult>();
PMML pmml = loadModel(PMML, stream);
helper.setResolver(classLoader);
PMML4Unit unit = new PMML4UnitImpl(pmml);
if (unit.containsMiningModel()) {
Miningmodel rootModel = unit.getRootMiningModel();
resources = buildResourcesFromModel(pmml, rootModel, null, classLoader, module);
} else {
PMML4Model rootModel = unit.getRootModel();
if (rootModel != null) {
helper.setPack(rootModel.getModelPackageName());
KieBaseModel kbm = module.newKieBaseModel(rootModel.getModelId());
kbm.addPackage(helper.getPack()).setDefault(true).setEventProcessingMode(EventProcessingOption.CLOUD);
PMMLResource resource = new PMMLResource(helper.getPack());
resource.setKieBaseModel(kbm);
resource.addRules(rootModel.getModelId(), this.compile(pmml, classLoader));
resources.add(resource);
}
}
return resources;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class PMML4Compiler method buildResourceFromSegment.
protected PMMLResource buildResourceFromSegment(PMML pmml_origin, MiningSegment segment, ClassLoader classLoader, KieModuleModel module) {
PMML pmml = new PMML();
DataDictionary dd = pmml_origin.getDataDictionary();
pmml.setDataDictionary(dd);
pmml.setHeader(pmml_origin.getHeader());
pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(segment.getModel().getRawModel());
addMissingFieldDefinition(pmml, segment.getOwner(), segment);
// PMML4Helper.pmmlDefaultPackageName()+".mining.segment_"+segment.getSegmentId());
helper.setPack(segment.getModel().getModelPackageName());
String rules = this.compile(pmml, classLoader);
KieBaseModel kbModel = module.newKieBaseModel(segment.getOwner().getOwner().getModelId() + "_" + segment.getOwner().getSegmentationId() + "_SEGMENT_" + segment.getSegmentId());
kbModel.addPackage(helper.getPack()).setDefault(false).setEventProcessingMode(EventProcessingOption.CLOUD);
KieSessionModel ksm = kbModel.newKieSessionModel("SEGMENT_" + segment.getSegmentId());
ksm.setDefault(true);
PMMLResource resource = new PMMLResource(helper.getPack());
resource.setKieBaseModel(kbModel);
resource.addRules(segment.getModel().getModelId(), rules);
return resource;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class AbstractKieCiTest method createKieFileSystemWithKProject.
protected KieFileSystem createKieFileSystemWithKProject(KieServices ks, boolean isdefault, String kbaseName, String ksessionName) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(kbaseName).setDefault(isdefault).setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel(ksessionName).setDefault(isdefault).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("realtime"));
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
return kfs;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieModuleDeploymentHelperTest method testFluentDeploymentHelper.
@Test
public void testFluentDeploymentHelper() throws Exception {
int numFiles = 0;
int numDirs = 0;
String content = "test file created by " + this.getClass().getSimpleName();
File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".tst");
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(content.getBytes());
fos.close();
FluentKieModuleDeploymentHelper deploymentHelper = KieModuleDeploymentHelper.newFluentInstance();
String groupId = "org.kie.api.builder.fluent";
String artifactId = "test-kjar";
String version = "0.1-SNAPSHOT";
deploymentHelper = deploymentHelper.setGroupId(groupId).setArtifactId(artifactId).setVersion(version).addResourceFilePath("builder/test/", "builder/simple_query_test.drl").addResourceFilePath(tempFile.getAbsolutePath()).addResourceFilePath(// from the drools-core jar
"/META-INF/WorkDefinitions.conf").addClass(KieModuleDeploymentHelperTest.class).addClass(KieModule.class).addClass(org.drools.compiler.Cheese.class);
// class dirs
// org.kie.api.builder.helper
numDirs += 5;
// (org.)drools.compiler
numDirs += 2;
// pom.xml, pom.properties
numFiles += 3;
// kmodule.xml, kmodule.info
numFiles += 2;
// kbase.cache x 2
numFiles += 2;
// drl files
numFiles += 3;
// WorkDefinitions
++numFiles;
// classes
numFiles += 3;
// META-INF/maven/org.kie.api.builder/test-kjar
numDirs += 4;
// defaultKiebase, META-INF/defaultKieBase
numDirs += 2;
KieBaseModel kbaseModel = deploymentHelper.getKieModuleModel().newKieBaseModel("otherKieBase");
kbaseModel.setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
kbaseModel.newKieSessionModel("otherKieSession").setClockType(ClockTypeOption.get("realtime"));
// META-INF/otherKieBase
++numDirs;
deploymentHelper.getKieModuleModel().getKieBaseModels().get("defaultKieBase").newKieSessionModel("secondKieSession");
deploymentHelper.createKieJarAndDeployToMaven();
File artifactFile = MavenRepository.getMavenRepository().resolveArtifact(groupId + ":" + artifactId + ":" + version).getFile();
zip = new ZipInputStream(new FileInputStream(artifactFile));
Set<String> jarFiles = new HashSet<String>();
Set<String> jarDirs = new HashSet<String>();
ZipEntry ze = zip.getNextEntry();
logger.debug("Getting files form deployed jar: ");
while (ze != null) {
String fileName = ze.getName();
if (fileName.endsWith("drl") || fileName.endsWith("class") || fileName.endsWith("tst") || fileName.endsWith("conf") || fileName.endsWith("xml") || fileName.endsWith("info") || fileName.endsWith("properties") || fileName.endsWith("cache")) {
jarFiles.add(fileName);
logger.debug("> " + fileName);
} else {
jarDirs.add(fileName);
logger.debug("] " + fileName);
}
ze = zip.getNextEntry();
}
assertEquals("Num files in kjar", numFiles, jarFiles.size());
assertEquals("Num dirs in kjar", numDirs, jarDirs.size());
}
Aggregations