@@ -20,14 +20,14 @@ class FPTree
2020 * Initialize the tree.
2121 * @param array $transactions
2222 * @param int $threshold
23- * @param $root_value
24- * @param int $root_count
23+ * @param $rootValue
24+ * @param int $rootCount
2525 */
26- public function __construct (array $ transactions , int $ threshold , $ root_value , int $ root_count )
26+ public function __construct (array $ transactions , int $ threshold , $ rootValue , int $ rootCount )
2727 {
2828 $ this ->frequent = $ this ->findFrequentItems ($ transactions , $ threshold );
2929 $ 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 );
3131 }
3232
3333 /**
@@ -75,29 +75,29 @@ protected function buildHeaderTable(): array
7575 /**
7676 * Build the FP tree and return the root node.
7777 * @param $transactions
78- * @param $root_value
79- * @param $root_count
78+ * @param $rootValue
79+ * @param $rootCount
8080 * @param $frequent
8181 * @return FPNode
8282 */
83- protected function buildFPTree ($ transactions , $ root_value , $ root_count , &$ frequent ): FPNode
83+ protected function buildFPTree ($ transactions , $ rootValue , $ rootCount , &$ frequent ): FPNode
8484 {
85- $ root = new FPNode ($ root_value , $ root_count , null );
85+ $ root = new FPNode ($ rootValue , $ rootCount , null );
8686 arsort ($ frequent );
8787 foreach ($ transactions as $ transaction ) {
88- $ sorted_items = [];
88+ $ sortedItems = [];
8989 foreach ($ transaction as $ item ) {
9090 if (isset ($ frequent [$ item ])) {
91- $ sorted_items [] = $ item ;
91+ $ sortedItems [] = $ item ;
9292 }
9393 }
9494
95- usort ($ sorted_items , function ($ a , $ b ) use ($ frequent ) {
95+ usort ($ sortedItems , function ($ a , $ b ) use ($ frequent ) {
9696 return $ frequent [$ b ] <=> $ frequent [$ a ];
9797 });
9898
99- if (count ($ sorted_items ) > 0 ) {
100- $ this ->insertTree ($ sorted_items , $ root );
99+ if (count ($ sortedItems ) > 0 ) {
100+ $ this ->insertTree ($ sortedItems , $ root );
101101 }
102102 }
103103 return $ root ;
@@ -131,10 +131,10 @@ protected function insertTree(array $items, FPNode $node): void
131131 }
132132
133133 // Call function recursively.
134- $ remaining_items = array_slice ($ items , 1 , null );
134+ $ remainingItems = array_slice ($ items , 1 , null );
135135
136- if (count ($ remaining_items ) > 0 ) {
137- $ this ->insertTree ($ remaining_items , $ child );
136+ if (count ($ remainingItems ) > 0 ) {
137+ $ this ->insertTree ($ remainingItems , $ child );
138138 }
139139 }
140140
@@ -146,17 +146,17 @@ protected function insertTree(array $items, FPNode $node): void
146146 */
147147 protected function treeHasSinglePath (FPNode $ node ): bool
148148 {
149- $ num_children = count ($ node ->children );
149+ $ childrenCount = count ($ node ->children );
150150
151- if ($ num_children > 1 ) {
151+ if ($ childrenCount > 1 ) {
152152 return false ;
153153 }
154154
155- if ($ num_children === 0 ) {
155+ if ($ childrenCount === 0 ) {
156156 return true ;
157157 }
158158
159- return $ this ->treeHasSinglePath ($ node -> children [ array_key_first ($ node ->children )] );
159+ return $ this ->treeHasSinglePath (current ($ node ->children ));
160160 }
161161
162162 /**
@@ -238,15 +238,15 @@ protected function generatePatternList(): array
238238 protected function mineSubTrees (int $ threshold ): array
239239 {
240240 $ 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 );
244244
245245 // Get items in tree in reverse order of occurrences.
246- foreach ($ mining_order as $ item ) {
246+ foreach ($ miningOrder as $ item ) {
247247 /** @var FPNode[] $suffixes */
248248 $ suffixes = [];
249- $ conditional_tree_input = [];
249+ $ conditionalTreeInput = [];
250250 $ node = $ this ->headers [$ item ];
251251
252252 // Follow node links to get a list of all occurrences of a certain item.
@@ -265,20 +265,20 @@ protected function mineSubTrees(int $threshold): array
265265 $ parent = $ parent ->parent ;
266266 }
267267 for ($ i = 0 ; $ i < $ frequency ; $ i ++) {
268- $ conditional_tree_input [] = $ path ;
268+ $ conditionalTreeInput [] = $ path ;
269269 }
270270 }
271271
272272 // 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 );
275275
276276 // Insert subtree patterns into main patterns dictionary.
277- foreach (array_keys ($ subtree_patterns ) as $ pattern ) {
277+ foreach (array_keys ($ subtreePatterns ) as $ pattern ) {
278278 if (in_array ($ pattern , $ patterns )) {
279- $ patterns [$ pattern ] += $ subtree_patterns [$ pattern ];
279+ $ patterns [$ pattern ] += $ subtreePatterns [$ pattern ];
280280 } else {
281- $ patterns [$ pattern ] = $ subtree_patterns [$ pattern ];
281+ $ patterns [$ pattern ] = $ subtreePatterns [$ pattern ];
282282 }
283283 }
284284 }
0 commit comments