/* * Generate the candidate items */ private void candidateFrequentItems(AttributeItem attrItem) { AttributeItemSet attrItemSet = new AttributeItemSet(); attrItemSet.addCandidateItemSet(attrItem); if (_itemSet.contains(attrItemSet)) { AttributeItemSet orgItemSet = _itemSet.get(_itemSet.indexOf(attrItemSet)); orgItemSet.increaseCoverage(); } else { _itemSet.add(attrItemSet); } }
/* * Combine two item sets of size k into an item set of size k+1 * The maximum k is set to 5 at the moment */ private void combineItemSet() { ArrayList<AttributeItemSet> tempItemSet = new ArrayList<AttributeItemSet>(); for (int k = 1; k < this.ITEMSET_SIZE; k++) { for (int i = 0; i < this._itemSet.size() - 1; i++) { for (int j = i + 1; j < this._itemSet.size(); j++) { if (this._itemSet.get(i).differentInLastAttribute(this._itemSet.get(j))) { AttributeItemSet tempAttrItemSet1 = (AttributeItemSet) this._itemSet.get(i).clone(); System.out.println(tempAttrItemSet1.toString()); AttributeItemSet tempAttrItemSet2 = (AttributeItemSet) this._itemSet.get(j).clone(); System.out.println(tempAttrItemSet2.toString()); tempAttrItemSet1.addCandidateItemSet( tempAttrItemSet2 .getCandidateItemSet() .get(tempAttrItemSet2.getCandidateItemSet().size() - 1)); tempAttrItemSet1.resetCoverage(); tempItemSet.add((AttributeItemSet) tempAttrItemSet1); } else { // do nothing when all the attributes are similar or when there // are more than one difference (not only the last) in the two sets ; } } } this.findFrequentItemSets(tempItemSet); this._itemSet = (ArrayList<AttributeItemSet>) tempItemSet.clone(); tempItemSet.clear(); } }
/* * Count the number of occurrences of attributes combination from the item sets in the ActionDetail * list */ private void countOccurences( ArrayList<AttributeItemSet> tempItemSet, ArrayList<ActionDetail> details) { for (int i = 0; i < details.size(); i++) { ActionDetail ad = details.get(i); for (int j = 0; j < tempItemSet.size(); j++) { AttributeItemSet tempAttrItemSet = tempItemSet.get(j); boolean match = true; for (int k = 0; k < tempAttrItemSet.getCandidateItemSet().size() && match == true; k++) { AttributeItem attrItem = tempAttrItemSet.getCandidateItemSet().get(k); if (attrItem.getAttrName() == "subject") match = attrItem.getAttrValue().equals(ad.getSubject()); else if (attrItem.getAttrName() == "action") match = attrItem.getAttrValue().equals(ad.getAction()); else if (attrItem.getAttrName() == "target") match = attrItem.getAttrValue().equals(ad.getTarget()); else if (attrItem.getAttrName() == "desirability") match = attrItem.getAttrValue().equals(ad.getDesirability() >= 0 ? "positive" : "negative"); else if (attrItem.getAttrName() == "praiseworthiness") match = attrItem .getAttrValue() .equals(ad.getPraiseworthiness() >= 0 ? "positive" : "negative"); else if (attrItem.getAttrName() == "time") match = attrItem.getAttrValue().equals(ad.getTime().getStrRealTime()); } // if all attributes and values in the item set match the values in the action detail, // increase // the coverage for the item set if (match) { tempAttrItemSet.increaseCoverage(); } } } }