Ejemplo n.º 1
0
/** get the group of words most similar to this word **/
function old_synset($id, $word, $pos)
{
    $query = "SELECT * from word where word = '" . $word . "' and pos = '" . $pos . "';";
    if ($id) {
        $query = "SELECT * from word where id = " . $id . ";";
    }
    $result = mysql_query($query);
    $row = array();
    $friends = array();
    $similarities = array();
    $ids = array();
    $poss = array();
    $best = new PriorityQueue();
    $best->clear();
    $row;
    $word;
    $pos;
    $friend;
    $friends_of_friends;
    while ($row = mysql_fetch_array($result)) {
        $id = $row['id'];
        $word = $row['word'];
        $_GET['word'] = $word;
        $pos = $row['pos'];
        $_GET['pos'] = $pos;
        $friends = getMostSimilar($id);
        foreach ($friends as $friend) {
            if ($friend['word'] != $word) {
                if (!array_key_exists($friend['id'], $similarities)) {
                    $similarities[$friend['id']] = 0;
                    $ids[$friend['id']] = $friend['word'];
                    $poss[$friend['id']] = $friend['pos'];
                }
                $similarities[$friend['id']] += $friend['similarity'];
                $friends_of_friends = getMostSimilar($friend['id']);
                foreach ($friends_of_friends as $ff) {
                    if ($ff['word'] != $word) {
                        if (!array_key_exists($ff['id'], $similarities)) {
                            $similarities[$ff['id']] = 0;
                            $ids[$ff['id']] = $ff['word'];
                            $poss[$ff['id']] = $ff['pos'];
                        }
                        $similarities[$ff['id']] += $ff['similarity'] * $friend['similarity'];
                    }
                }
            }
        }
    }
    foreach (array_keys($similarities) as $id) {
        $best->push($id, $similarities[$id]);
    }
    $answer = array();
    $max = 0;
    $next;
    $w;
    $pos;
    $sim;
    while (!$best->IsEmpty()) {
        $next = $best->pop();
        $w = $ids[$next];
        $pos = $poss[$next];
        $sim = $similarities[$next];
        if ($sim > $max) {
            $max = $sim;
        }
        if ($sim >= $max / 2) {
            array_push($answer, array("word" => $w, "id" => $next, "similarity" => $sim, "pos" => $pos));
        }
    }
    return $answer;
}
Ejemplo n.º 2
0
echo "Insert (2, 'two') into pq, ";
$pq->insert(2, 'two');
echo "done.";
$pq->renderInternalRepresentation();
echo "<br>";
echo "Insert (0, 'zero') into pq, ";
$pq->insert(0, 'zero');
echo "done.";
$pq->renderInternalRepresentation();
echo "<br>";
echo "Top of pq: ";
var_dump($pq->top());
$pq->renderInternalRepresentation();
echo "<br>";
echo "Pop pq: ";
var_dump($pq->pop());
$pq->renderInternalRepresentation();
echo "<br>";
echo "Pop pq: ";
var_dump($pq->pop());
$pq->renderInternalRepresentation();
echo "<br>";
echo "Pop pq: ";
var_dump($pq->pop());
$pq->renderInternalRepresentation();
echo "<br>";
echo "Pop pq: ";
var_dump($pq->pop());
$pq->renderInternalRepresentation();
echo "<br>";
echo "Stable and FIFO? ";
Ejemplo n.º 3
0
         }
     }
     $md5top = md5($top);
     $text = curl_multi_getcontent($ch);
     Error::disableLogging();
     db_query("REPLACE INTO primitive_cache (url, content) VALUES ('%s', '%s')", $md5top, $text);
     Error::enableLogging();
     db_end_transaction('primitive_cache', $md5top);
     curl_multi_remove_handle($mch, $ch);
     curl_close($ch);
     $n_reqs_procd++;
     fputs($fp, "Daemon {$GLOBALS['client']} processed {$top}\r\n");
     Error::generate('debug', "Processed {$top}");
 } else {
     if (count($in_progress) < $max_simult_queries && $curl_stack->size() > 0) {
         $ch = $curl_stack->pop();
         $top = $completed->pop();
         $md5top = md5($top);
         db_query("INSERT IGNORE INTO primitive_cache_lock (id,locked) VALUES ('%s','0')", $md5top);
         $exists = db_affected_rows() == 0;
         // TODO: CURLOPT_TIMEVALUE and CURLOPT_TIMECONDITION on cache timestamp for Last-Modified if exists
         if (!$exists) {
             $locked = db_start_transaction('primitive_cache', $md5top, $blocking);
         } else {
             $locked = false;
         }
         if ($locked) {
             // we've got a lock, we can either start or finish
             $in_progress[] = array('ch' => $ch, 'top' => $top);
             curl_multi_add_handle($mch, $ch);
             $mcr = curl_multi_exec($mch, $active);