Search in sources :

Example 1 with ItemRef

use of org.dmg.pmml.association.ItemRef in project jpmml-sparkml by jpmml.

the class FPGrowthModelConverter method ensureItemset.

private static Itemset ensureItemset(Feature feature, List<String> values, Map<List<String>, Itemset> itemsets, Map<String, Item> items) {
    Itemset itemset = itemsets.get(values);
    if (itemset == null) {
        itemset = new Itemset(String.valueOf(itemsets.size() + 1));
        for (String value : values) {
            Item item = items.get(value);
            if (item == null) {
                item = new Item(String.valueOf(items.size() + 1), value).setField(feature.getName());
                items.put(value, item);
            }
            itemset.addItemRefs(new ItemRef(item.getId()));
        }
        List<ItemRef> itemRefs = itemset.getItemRefs();
        if (itemRefs.size() > 1) {
            Comparator<ItemRef> comparator = new Comparator<ItemRef>() {

                @Override
                public int compare(ItemRef left, ItemRef right) {
                    int leftId = Integer.parseInt(left.getItemRef());
                    int rightId = Integer.parseInt(right.getItemRef());
                    return Integer.compare(leftId, rightId);
                }
            };
            Collections.sort(itemRefs, comparator);
        }
        itemsets.put(values, itemset);
    }
    return itemset;
}
Also used : Item(org.dmg.pmml.association.Item) Itemset(org.dmg.pmml.association.Itemset) ItemRef(org.dmg.pmml.association.ItemRef) Comparator(java.util.Comparator)

Aggregations

Comparator (java.util.Comparator)1 Item (org.dmg.pmml.association.Item)1 ItemRef (org.dmg.pmml.association.ItemRef)1 Itemset (org.dmg.pmml.association.Itemset)1