Example #1
0
 private function setAssocProperties(AssocRule $inputRule)
 {
     $leftCount = 0;
     $rightCount = 0;
     $leftRightCount = 0;
     foreach ($this->assocRules as $rule) {
         $leftInput = $inputRule->getFullLeftTerms();
         $leftCompare = $rule->getFullLeftTerms();
         $rightInput = $inputRule->getFullRightTerms();
         $rightCompare = $rule->getFullRightTerms();
         Util::translateArr($leftInput);
         Util::translateArr($leftCompare);
         Util::translateArr($rightInput);
         Util::translateArr($rightCompare);
         if (count(array_intersect($leftInput, $leftCompare)) === count($leftInput)) {
             $leftCount++;
             if (count(array_intersect($rightInput, $rightCompare)) === count($rightInput)) {
                 $leftRightCount++;
             }
         }
         if (count(array_intersect($rightInput, $rightCompare)) === count($rightInput)) {
             $rightCount++;
         }
     }
     $total = count($this->assocRules);
     $inputRule->setP2000Support($leftCount / $total);
     $inputRule->setNewsSupport($rightCount / $total);
     $inputRule->setTotalSupport($leftRightCount / $total);
     $inputRule->setConfidenceLeft($inputRule->getTotalSupport() / $inputRule->getP2000Support());
     $inputRule->setConfidenceRight($inputRule->getTotalSupport() / $inputRule->getNewsSupport());
     $inputRule->setLift($inputRule->getTotalSupport() / ($inputRule->getP2000Support() * $inputRule->getNewsSupport()));
 }
Example #2
0
 private static function storeAssociation(AssocRule $rule)
 {
     $mysqli = self::connect();
     $query = "INSERT INTO p2000_news_assoc (p2000Id, newsId, date, score, " . "supportP2000, supportNews, supportTotal, confP2000, confNews, lift) " . "VALUES(?,?,?,?,?,?,?,?,?,?)";
     $statement = $mysqli->prepare($query);
     $p2000id = $rule->getP2000id();
     $newsId = $rule->getNewsId();
     $date = "";
     if ($rule->getDate()) {
         $date = $rule->getDate()->format("Y-m-d");
     }
     $score = $rule->getScore();
     $supportP2000 = $rule->getP2000Support();
     $supportNews = $rule->getNewsSupport();
     $supportTotal = $rule->getTotalSupport();
     $confP2000 = $rule->getConfidenceLeft();
     $confNews = $rule->getConfidenceRight();
     $lift = $rule->getLift();
     $statement->bind_param('iisddddddd', $p2000id, $newsId, $date, $score, $supportP2000, $supportNews, $supportTotal, $confP2000, $confNews, $lift);
     $statement->execute();
     $mysqli->close();
 }