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;
}
Aggregations