//************ MAIN ************// if(strstr($HTTP_USER_AGENT, 'MSIE')) $MSIE = true; if(isset($clickedConcept)) $concept = $clickedConcept; if(isset($concept) && $concept != "") { session_start(); global $map_String; global $conceptFound; if(isset($cOldID) && $cOldID != "") $cID = $cOldID; $requestString = "&upFactor=" . $upFactor . "&downFactor=" . $downFactor; $requestString .= "&minWeight=" . $minWeight . "&view=" . $view; if(!isset($font)) $font = "9"; if(!isset($go) && !isset($clickedConcept) && $concept != $oldConcept) $links = fetchAlternatives($concept); else new Relatives($concept, $cID, $requestString, $font); } //************ MAIN ************// function fetchAlternatives(&$concept) { $sql = "SELECT naming, cid " . "FROM concept " . "WHERE naming LIKE '" . $concept . "%'"; $conn = ocilogon("prototype", "prototype_", "isl"); $stmt = ociparse($conn, $sql); $stmt = ociparse($conn, $sql); OCIExecute($stmt); while(OCIFetchinto($stmt, &$result)) { $links .= " " . $result[0] . " "; } OCIFreeStatement($stmt); return $links; } function getConceptID($concept, &$conn) { $sql = "SELECT cid " . "FROM concept " . "WHERE naming = '" . $concept . "'"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); if(OCIFetchinto($stmt, &$result)) { $conceptID = $result[0]; } else { $conceptID = -1; } OCIFreeStatement($stmt); return $conceptID; } function getParentInfo($cID, &$conn) { $sql = "SELECT concept2.cid, concept2.naming " . "FROM concept concept1, concept concept2, hasrelation " . "WHERE concept1.cid=" . $cID . " AND concept1.cid=hasrelation.conceptid1 AND hasrelation.conceptid2 = concept2.cid and relationid = 107678 and concept1.cid <> concept2.cid"; //print "getParentInfo: $sql
"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); $cnt = OCIFetchStatement($stmt, $results); OCIFreeStatement($stmt); if($cnt == 0) return 0; else return array($cnt, $results); } function getChildrenInfo($ID, &$conn) { $results; $sql = "SELECT concept1.cid, concept1.naming FROM concept concept1, concept concept2, hasrelation WHERE concept2.cid=" . $ID . " AND concept2.cid=hasrelation.conceptid2 AND hasrelation.conceptid1 = concept1.cid and relationid = 107678"; //print "getChildrenInfo: $sql
"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); $cnt = OCIFetchStatement($stmt, $results); OCIFreeStatement($stmt); return array($cnt, $results); } function getSiblingsInfo($parentID, $concept, &$conn) { $sql = "SELECT concept1.cid, concept1.naming " . "FROM concept concept1, concept concept2, hasrelation " . //"WHERE concept2.cid=" . $parentID . " AND concept2.cid=hasrelation.conceptid2 AND hasrelation.conceptid1 = concept1.cid"; "WHERE concept2.cid=" . $parentID . " AND relationid = 107678 AND concept2.cid=hasrelation.conceptid2 AND hasrelation.conceptid1 = concept1.cid AND NOT concept1.naming='" . $concept . "'"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); $cnt = OCIFetchStatement($stmt, $results); OCIFreeStatement($stmt); return array($cnt, $results); } function fetchSiblings($concept, &$dotString, &$cParents, &$conn, &$requestString) { while(list($ID, $parentName) = each($cParents)) { $siblingsInfo = getSiblingsInfo($ID, $concept, $conn); $j = $siblingsInfo[0]; $siblings = $siblingsInfo[1]; for($i = 0; $i < $j; $i++) { reset($siblings); for($p = 0; $column = each($siblings); $p++) { $data = $column['value']; if($p == 0) $siblingID = $data[$i]; else { $sibling = $data[$i]; $dotString .= "\"" . $parentName . "\" -> \"" . $sibling . "\"; "; $dotString .= "\"" . $sibling . "\" [URL=\"graphs_new3.php?clickedConcept=" . $sibling . $requestString . "&cID=" . $siblingID . "\"]; "; } } } } } function fetchChildren(&$dot, $cID, &$conn, $requestString, $concept) { $childrenInfo = getChildrenInfo($cID, $conn); $j = $childrenInfo[0]; $children = $childrenInfo[1]; for($i = 0; $i < $j; $i++) { reset($children); for($p = 0; $column = each($children); $p++) { $data = $column['value']; if($p == 0) $childID = $data[$i]; else { $child = $data[$i]; $dot .= "\"" . $concept . "\" -> \"" . $child . "\"; "; $dot .= "\"" . $child . "\" [URL=\"graphs_new3.php?clickedConcept=" . $child . $requestString . "&cID=" . $childID . "\"]; "; } } } } function fetchParents(&$dot, $ID, $prev, &$conn, &$requestString, $iteration, &$ancestors, &$cParents) { ++$iteration; if(($parentInfo = getParentInfo($ID, $conn)) > 0) { $j = $parentInfo[0]; $parents = $parentInfo[1]; for($i = 0; $i < $j; $i++) { reset($parents); for($p = 0; $column = each($parents); $p++) { $data = $column['value']; if($p == 0) $paID = $data[$i]; else { $parentName = $data[$i]; if(!containsKey($ancestors, $paID)) { if($iteration == 1) $cParents[$paID] = $parentName; $ancestors[$paID] = $parentName; fetchParents($dot, $paID, $parentName, $conn, $requestString, $iteration, $ancestors, $cParents); } $dot .= "\"" . $parentName . "\" -> \"" . $prev . "\"; "; $dot .= "\"" . $parentName . "\" [URL=\"graphs_new3.php?clickedConcept=" . $parentName . $requestString . "&cID=" . $paID . "\"]; "; } } } } } function containsKey(&$theArray, $var) { $keys = array_keys($theArray); $p = count($keys); for($q = 0; $q < $p; $q++) { if($keys[$q] == $var) return true; } return false; } function createImgMap($dotString) { error_reporting(E_ALL); $dotFile = tempnam("./", "dot"); //$dotFile = "$dotFile.dot"; $dotFileHandle = fopen($dotFile, "w"); fwrite($dotFileHandle, $dotString); fclose($dotFileHandle); $cmd = "/usr/bin/dot -Tcmap $dotFile"; $fd = popen($cmd, "r"); $mapString = ""; unlink($dotFile); $GLOBALS['map_String'] = $mapString; } // ***************************************************************** // *** The class which makes the 'RELATIVES' view of the ontoDB. *** // ***************************************************************** class Relatives { function Relatives($concept, $conceptID, $requestString, $font) { $conn = ocilogon("prototype", "prototype_", "isl"); if(isset($conceptID)) $cID = $conceptID; else $cID = getConceptID($concept, $conn); if($cID > -1) { $GLOBALS['conceptFound'] = true; $ancestors = array(); $cParents = array(); $dotString = "digraph onto { nodesep=\".10\"; node [height=\".001\", width=\".002\", fontsize=\"" . $font . "\"]; "; $dotString .= "edge [dir=back]; "; fetchParents($dotString, $cID, $concept, $conn, $requestString, 0, $ancestors, $cParents); $parentID = $parents[1]; $dotString .= "\"" . $concept . "\" [color=\"gray84\", style=\"filled\"]; "; fetchChildren($dotString, $cID, $conn, $requestString, $concept); fetchSiblings($concept, $dotString, $cParents, $conn, $requestString); OCILogoff($conn); $dotString .= " }"; session_register("sess_dotString"); $GLOBALS['sess_dotString'] = $dotString; session_register("sess_dotString"); createImgMap($dotString); } else { $GLOBALS['conceptFound'] = false; echo ""; } } } ?>
|
|
|