/** * get all k-1 candidate sequences * * @param seq - parent sequence * @return a list of sequences */ public static ArrayList<ItemSet> getsubSequences(Sequence seq) { int n = seq.getAllItems().size(); int[] masks = new int[n]; ArrayList<ItemSet> subSequences = new ArrayList<ItemSet>(); for (int i = 0; i < n; i++) { masks[i] = (1 << i); } for (int i = 0; i < (1 << n); i++) { ArrayList<Integer> newList = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { if ((masks[j] & i) != 0) { newList.add(seq.getAllItems().get(j)); } } if (newList.size() == n - 1) { ItemSet is = new ItemSet(); is.setItems(newList); subSequences.add(is); } } return subSequences; }
/** * returns all sequences of a specific size * * @param frequentSequences - list of sequences * @param size specified size of the sequences * @return list of sequences */ public static ArrayList<Sequence> getOfSize(ArrayList<Sequence> frequentSequences, int size) { ArrayList<Sequence> setOfSize = new ArrayList<Sequence>(); for (Sequence seq : frequentSequences) { if (seq.getAllItems().size() == size) { setOfSize.add(seq); } } return setOfSize; }