diff --git a/Business/Recommendation/ModelCF.php b/Business/Recommendation/ModelCF.php index 9f9cda6f2..ff1a6ce04 100644 --- a/Business/Recommendation/ModelCF.php +++ b/Business/Recommendation/ModelCF.php @@ -49,15 +49,29 @@ final class ModelCF * the multiplication gives a score of how much the user may like that movie. * A segnificant amount of attributes are required to calculate a good match * - * @param Matrix $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users - * @param Matrix $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type + * @param array> $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users + * @param array> $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type * * @return array * * @since 1.0.0 */ - public static function score(Matrix $users, Matrix $items) : array + public static function score(array $users, array $items) : array { - return $users->mult($items)->getMatrix(); + $matrix = []; + + foreach ($users as $uid => $userrow) { + foreach ($items as $iid => $itemrow) { + $matrix[$uid][$iid] = 0.0; + + foreach ($userrow as $user) { + foreach ($itemrow as $item) { + $matrix[$uid][$iid] += $user * $item; + } + } + } + } + + return $matrix; } } diff --git a/tests/Business/Recommendation/ModelCFTest.php b/tests/Business/Recommendation/ModelCFTest.php new file mode 100644 index 000000000..47418cb38 --- /dev/null +++ b/tests/Business/Recommendation/ModelCFTest.php @@ -0,0 +1,48 @@ +get()->con->prepare('DROP TABLE test_has_many_direct')->execute(); $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute(); $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute(); + + $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_directp')->execute(); + $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_relp')->execute(); + $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relationsp')->execute(); + $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_onep')->execute(); + $GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_onep')->execute(); } /**