@@ -20,14 +20,14 @@ class FPTree
20
20
* Initialize the tree.
21
21
* @param array $transactions
22
22
* @param int $threshold
23
- * @param $root_value
24
- * @param int $root_count
23
+ * @param $rootValue
24
+ * @param int $rootCount
25
25
*/
26
- public function __construct (array $ transactions , int $ threshold , $ root_value , int $ root_count )
26
+ public function __construct (array $ transactions , int $ threshold , $ rootValue , int $ rootCount )
27
27
{
28
28
$ this ->frequent = $ this ->findFrequentItems ($ transactions , $ threshold );
29
29
$ this ->headers = $ this ->buildHeaderTable ();
30
- $ this ->root = $ this ->buildFPTree ($ transactions , $ root_value , $ root_count , $ this ->frequent );
30
+ $ this ->root = $ this ->buildFPTree ($ transactions , $ rootValue , $ rootCount , $ this ->frequent );
31
31
}
32
32
33
33
/**
@@ -75,29 +75,29 @@ protected function buildHeaderTable(): array
75
75
/**
76
76
* Build the FP tree and return the root node.
77
77
* @param $transactions
78
- * @param $root_value
79
- * @param $root_count
78
+ * @param $rootValue
79
+ * @param $rootCount
80
80
* @param $frequent
81
81
* @return FPNode
82
82
*/
83
- protected function buildFPTree ($ transactions , $ root_value , $ root_count , &$ frequent ): FPNode
83
+ protected function buildFPTree ($ transactions , $ rootValue , $ rootCount , &$ frequent ): FPNode
84
84
{
85
- $ root = new FPNode ($ root_value , $ root_count , null );
85
+ $ root = new FPNode ($ rootValue , $ rootCount , null );
86
86
arsort ($ frequent );
87
87
foreach ($ transactions as $ transaction ) {
88
- $ sorted_items = [];
88
+ $ sortedItems = [];
89
89
foreach ($ transaction as $ item ) {
90
90
if (isset ($ frequent [$ item ])) {
91
- $ sorted_items [] = $ item ;
91
+ $ sortedItems [] = $ item ;
92
92
}
93
93
}
94
94
95
- usort ($ sorted_items , function ($ a , $ b ) use ($ frequent ) {
95
+ usort ($ sortedItems , function ($ a , $ b ) use ($ frequent ) {
96
96
return $ frequent [$ b ] <=> $ frequent [$ a ];
97
97
});
98
98
99
- if (count ($ sorted_items ) > 0 ) {
100
- $ this ->insertTree ($ sorted_items , $ root );
99
+ if (count ($ sortedItems ) > 0 ) {
100
+ $ this ->insertTree ($ sortedItems , $ root );
101
101
}
102
102
}
103
103
return $ root ;
@@ -131,10 +131,10 @@ protected function insertTree(array $items, FPNode $node): void
131
131
}
132
132
133
133
// Call function recursively.
134
- $ remaining_items = array_slice ($ items , 1 , null );
134
+ $ remainingItems = array_slice ($ items , 1 , null );
135
135
136
- if (count ($ remaining_items ) > 0 ) {
137
- $ this ->insertTree ($ remaining_items , $ child );
136
+ if (count ($ remainingItems ) > 0 ) {
137
+ $ this ->insertTree ($ remainingItems , $ child );
138
138
}
139
139
}
140
140
@@ -146,17 +146,17 @@ protected function insertTree(array $items, FPNode $node): void
146
146
*/
147
147
protected function treeHasSinglePath (FPNode $ node ): bool
148
148
{
149
- $ num_children = count ($ node ->children );
149
+ $ childrenCount = count ($ node ->children );
150
150
151
- if ($ num_children > 1 ) {
151
+ if ($ childrenCount > 1 ) {
152
152
return false ;
153
153
}
154
154
155
- if ($ num_children === 0 ) {
155
+ if ($ childrenCount === 0 ) {
156
156
return true ;
157
157
}
158
158
159
- return $ this ->treeHasSinglePath ($ node -> children [ array_key_first ($ node ->children )] );
159
+ return $ this ->treeHasSinglePath (current ($ node ->children ));
160
160
}
161
161
162
162
/**
@@ -238,15 +238,15 @@ protected function generatePatternList(): array
238
238
protected function mineSubTrees (int $ threshold ): array
239
239
{
240
240
$ patterns = [];
241
- $ mining_order = $ this ->frequent ;
242
- asort ($ mining_order );
243
- $ mining_order = array_keys ($ mining_order );
241
+ $ miningOrder = $ this ->frequent ;
242
+ asort ($ miningOrder );
243
+ $ miningOrder = array_keys ($ miningOrder );
244
244
245
245
// Get items in tree in reverse order of occurrences.
246
- foreach ($ mining_order as $ item ) {
246
+ foreach ($ miningOrder as $ item ) {
247
247
/** @var FPNode[] $suffixes */
248
248
$ suffixes = [];
249
- $ conditional_tree_input = [];
249
+ $ conditionalTreeInput = [];
250
250
$ node = $ this ->headers [$ item ];
251
251
252
252
// Follow node links to get a list of all occurrences of a certain item.
@@ -265,20 +265,20 @@ protected function mineSubTrees(int $threshold): array
265
265
$ parent = $ parent ->parent ;
266
266
}
267
267
for ($ i = 0 ; $ i < $ frequency ; $ i ++) {
268
- $ conditional_tree_input [] = $ path ;
268
+ $ conditionalTreeInput [] = $ path ;
269
269
}
270
270
}
271
271
272
272
// Now we have the input for a subtree, so construct it and grab the patterns.
273
- $ subtree = new FPTree ($ conditional_tree_input , $ threshold , $ item , $ this ->frequent [$ item ]);
274
- $ subtree_patterns = $ subtree ->minePatterns ($ threshold );
273
+ $ subtree = new FPTree ($ conditionalTreeInput , $ threshold , $ item , $ this ->frequent [$ item ]);
274
+ $ subtreePatterns = $ subtree ->minePatterns ($ threshold );
275
275
276
276
// Insert subtree patterns into main patterns dictionary.
277
- foreach (array_keys ($ subtree_patterns ) as $ pattern ) {
277
+ foreach (array_keys ($ subtreePatterns ) as $ pattern ) {
278
278
if (in_array ($ pattern , $ patterns )) {
279
- $ patterns [$ pattern ] += $ subtree_patterns [$ pattern ];
279
+ $ patterns [$ pattern ] += $ subtreePatterns [$ pattern ];
280
280
} else {
281
- $ patterns [$ pattern ] = $ subtree_patterns [$ pattern ];
281
+ $ patterns [$ pattern ] = $ subtreePatterns [$ pattern ];
282
282
}
283
283
}
284
284
}
0 commit comments