@@ -94,28 +94,65 @@ private void readDataFile() {
9494 * @return
9595 */
9696 private ArrayList <Sequence > generateOneFrequencyItem () {
97+ int count = 0 ;
98+ int currentTransanctionID = 0 ;
9799 Sequence tempSeq ;
98100 ItemSet tempItemSet ;
101+ HashMap <Integer , Integer > itemNumMap = new HashMap <>();
99102 ArrayList <Sequence > seqList = new ArrayList <>();
100- ArrayList <Integer > itemNumArray = new ArrayList <>();
101103
102104 for (Sequence seq : totalSequences ) {
103105 for (ItemSet itemSet : seq .getItemSetList ()) {
104106 for (int num : itemSet .getItems ()) {
105107 // 如果没有此种类型项,则进行添加操作
106- if (!itemNumArray . contains (num )) {
107- itemNumArray . add (num );
108+ if (!itemNumMap . containsKey (num )) {
109+ itemNumMap . put (num , 1 );
108110 }
109111 }
110112 }
111113 }
114+
115+ boolean isContain = false ;
116+ int number = 0 ;
117+ for (Map .Entry entry : itemNumMap .entrySet ()) {
118+ count = 0 ;
119+ number = (int ) entry .getKey ();
120+ for (Sequence seq : totalSequences ) {
121+ isContain = false ;
122+
123+ for (ItemSet itemSet : seq .getItemSetList ()) {
124+ for (int num : itemSet .getItems ()) {
125+ // 如果没有此种类型项,则进行添加操作
126+ if (num == number ) {
127+ isContain = true ;
128+ break ;
129+ }
130+ }
131+
132+ if (isContain ){
133+ break ;
134+ }
135+ }
136+
137+ if (isContain ){
138+ count ++;
139+ }
140+ }
141+
142+ itemNumMap .put (number , count );
143+ }
144+
145+
146+ for (Map .Entry entry : itemNumMap .entrySet ()) {
147+ count = (int ) entry .getValue ();
148+ if (count >= minSupportCount ) {
149+ tempSeq = new Sequence ();
150+ tempItemSet = new ItemSet (new int [] { (int ) entry .getKey () });
112151
113- for ( int num : itemNumArray ) {
114- tempSeq = new Sequence ( );
115- tempItemSet = new ItemSet ( new int [] { num });
152+ tempSeq . getItemSetList (). add ( tempItemSet );
153+ seqList . add ( tempSeq );
154+ }
116155
117- tempSeq .getItemSetList ().add (tempItemSet );
118- seqList .add (tempSeq );
119156 }
120157 // 将序列升序排列
121158 Collections .sort (seqList );
0 commit comments