/** find all the relations between the given words and expand them to include other words **/ function getContext($words) { $contexts = array(); $information; $word; foreach ($words as $word) { $information = array("synonyms" => synset($word['id'])); $information["context"] = array(); $information["word"] = $word['word']; array_push($contexts, $information); } return $contexts; }
/** once all the lin similarities have been calculated, calculate synsets for easy access**/ function makeSynsets() { echo "MAKING SYNSETS\n\t"; $query = "SELECT distinct word2_id, word \n\tfrom similarity join word ON word2_id = id \n\tWHERE word2_id >= 4625;"; $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>\n<br/> Query: " . $query . "\n<br/> Error: (" . mysql_errno() . ") " . mysql_error()); $row; $id; $synset; $result2; $s; while ($row = mysql_fetch_array($result)) { $id = $row['word2_id']; echo $row['word'], "\n\t\t"; $synset = synset($id, "", ""); foreach ($synset as $s) { $query = "INSERT IGNORE INTO synsets (word1_id, word1, word2_id, word2, similarity) \n\t\t\tVALUES (" . $id . ", '" . mysql_real_escape_string($row['word']) . "', " . $s['id'] . ", '" . mysql_real_escape_string($s['word']) . "', " . $s['similarity'] . ");"; $result2 = mysql_query($query) or die("<b>A fatal MySQL error occured</b>\n<br/> Query: " . $query . "\n<br/> Error: (" . mysql_errno() . ") " . mysql_error()); } } }