HeaderType header = _40Factory.eINSTANCE.createHeaderType();
header.setCopyright("www.admire-project.eu");
header.setDescription("Association rule model");
pmml.setHeader(header);
AssociationModelType ruleModel = _40Factory.eINSTANCE.createAssociationModelType();
pmml.getAssociationModel().add(ruleModel);
List<AssociationRule> rules = associator.getAssociationRules().getRules();
ruleModel.setNumberOfRules(BigInteger.valueOf(rules.size()));
List<MyItemSet> allItemsets = new ArrayList<MyItemSet>();
for(AssociationRule r:rules) {
MyItemSet myPremise = new MyItemSet(r.getPremiseSupport(), r.getPremise());
MyItemSet myConsequence = new MyItemSet(r.getConsequenceSupport(), r.getConsequence());
if(!allItemsets.contains(myPremise))
allItemsets.add(myPremise);
if(!allItemsets.contains(myConsequence))
allItemsets.add(myConsequence);
AssociationRuleType ruleType = _40Factory.eINSTANCE.createAssociationRuleType();
ruleType.setAntecedent(String.valueOf(allItemsets.indexOf(myPremise)));
ruleType.setConsequent(String.valueOf(allItemsets.indexOf(myConsequence)));
try {
//ruleType.setSupport(BigDecimal.valueOf(r.getTotalSupport()));
ruleType.setSupport(BigDecimal.valueOf(Math.random()));
ruleType.setConfidence(BigDecimal.valueOf(r.getNamedMetricValue("Confidence")));
ruleType.setLift(BigDecimal.valueOf(r.getNamedMetricValue("Lift")).floatValue());
}
catch(Exception exc) {
exc.printStackTrace();
}
ruleModel.getAssociationRule().add(ruleType);
}
List<Item> allItems = new ArrayList<Item>();
LOG.debug("AllItemSetsSize == " + allItemsets.size());
for(MyItemSet itemset:allItemsets) {
List<ItemRefType> itemrefs = new ArrayList<ItemRefType>();
for(Item i:itemset.getItems()) {
if(!allItems.contains(i)) {
allItems.add(i);
ItemType pmmlItem = _40Factory.eINSTANCE.createItemType();
pmmlItem.setId(String.valueOf(allItems.indexOf(i)));
pmmlItem.setValue(i.toString());
ruleModel.getItem().add(pmmlItem);
}
ItemRefType itemref = _40Factory.eINSTANCE.createItemRefType();
itemref.setItemRef(String.valueOf(allItems.indexOf(i)));
itemrefs.add(itemref);
}
ItemsetType pmmlItemset = _40Factory.eINSTANCE.createItemsetType();
pmmlItemset.setId(String.valueOf(allItemsets.indexOf(itemset)));
pmmlItemset.setSupport(BigDecimal.valueOf(itemset.getSupport()));
pmmlItemset.setNumberOfItems(BigInteger.valueOf(itemset.getItems().size()));
pmmlItemset.getItemRef().addAll(itemrefs);
ruleModel.getItemset().add(pmmlItemset);
ruleModel.setNumberOfItems(BigInteger.valueOf(allItems.size()));
ruleModel.setNumberOfItemsets(BigInteger.valueOf(allItemsets.size()));
if(rules.size() > 0)
ruleModel.setNumberOfTransactions(BigInteger.valueOf(rules.get(0).getTotalTransactions()));
if(associator instanceof OptionHandler) {
String[] options = ((OptionHandler)associator).getOptions();
ruleModel.setMinimumConfidence(BigDecimal.valueOf(getMinConfidence(options)));
ruleModel.setMinimumSupport(BigDecimal.valueOf(getMinSupport(options)));
}
}