/** 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; }