Пример #1
0
 /**
  *
  * @method Returns a serialized tree of relevant nodes
  * @param string $article - unique name of Wikipedia entry
  * @param array $numNodes - maximum number of child nodes at given depth
  * (the first depth has numNodes[0] children, the second numNodes[1], etc.)
  * If there's a greater depth than the length of the array,
  *      then it repeats the last element.
  * This can also be sent as a string: "10,5,3" will automatically
  *      be converted to [10, 5, 3]
  * You can also just pass a single int instead of an array.
  * @param int $maxDepth - the maximum degrees of separation
  * @return String - a representation of our graph. Empty string if not found in DB.
  *
  */
 public function getRelevancyTree($article, $numNodes, $maxDepth, $enableCaching = true)
 {
     if (is_string($numNodes)) {
         // do a bit of conversion to make $numNodes more flexible
         $numNodes = explode(",", $numNodes);
     } else {
         if (is_int($numNodes)) {
             // ensure that this is an array
             $numNodes = array($numNodes);
         } else {
             if (!is_array($numNodes)) {
                 die("Invalid parameter for numNodes");
             }
         }
     }
     $numNodesString = implode(",", $numNodes);
     $inCache = false;
     if ($enableCaching) {
         $inCache = $this->isCached($article, $maxDepth, $numNodesString);
         // looks for the tree in the cache
         $db_cache = new DatabaseCacher($this->server, $this->db);
     }
     if ($inCache) {
         $db_cache->updateTreeTS($article, $maxDepth, $numNodesString);
         // update timestamp
         return $inCache;
     } else {
         $root = $this->generateRelevancyTree($article, $numNodes, $maxDepth);
         $serializedTree = $this->serializeTree($root, $numNodes, $maxDepth);
         if ($enableCaching && $serializedTree != "") {
             // don't cache if not found
             $db_cache->insertTree($article, $maxDepth, $numNodesString, $serializedTree);
         }
         // inserts tree into cache
         return $serializedTree;
     }
 }
Пример #2
0
<?php

// This API is used by the front-end to store image URLs and preview texts of articles that
// are retrieved later. It is also used by the database retriever to cache relevancy trees and
// for removing expired relevancy trees.
include "cacher.php";
$db_cache = new DatabaseCacher();
$debug = false;
if ($debug) {
    $function = $_GET['function'];
    $article = $_GET['article'];
    $maxDepth = $_GET['maxDepth'];
    $numNodes = $_GET['numNodes'];
    $data = $_GET['data'];
} else {
    $function = $_POST['function'];
    $article = $_POST['article'];
    $maxDepth = $_POST['maxDepth'];
    $numNodes = $_POST['numNodes'];
    $data = $_POST['data'];
}
// next line is a temporary hack just for the alpha
//$foundarticle = $db_ret->getPreviewText($article) != null
if ($function == 'insertImageURL') {
    $db_cache->insertImageURL($article, $data);
} else {
    if ($function == 'insertPreviewText') {
        $db_cache->insertPreviewText($article, $data);
    } else {
        if ($function == 'insertTree') {
            $db_cache->insertTree($article, $maxDepth, $numNodes, $data);