" . $result[0] . " "; } OCIFreeStatement($stmt); return $links; } function getConceptName($cID, &$conn) { $sql = "SELECT naming " . "FROM tontoword " . "WHERE id = '" . $cID . "'"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); if(OCIFetchinto($stmt, &$result)) { $conceptName = $result[0]; } else { $conceptName = -1; } OCIFreeStatement($stmt); return $conceptName; } function getConceptID($concept, &$conn) { $sql = "SELECT id " . "FROM tontoword " . "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 tonto2.id, tonto2.naming " . "FROM tontoword, tontoword tonto2, tontorel " . "WHERE tontoword.id=" . $cID . " AND tontoword.id=tontorel.id AND tontorel.target = tonto2.id"; $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 tontoword.id, tontoword.naming FROM tontoword, tontoword tontoword2, tontorel WHERE tontoword2.id=" . $ID . " AND tontoword2.id=tontorel.target AND tontorel.id = tontoword.id"; $stmt = ociparse($conn, $sql); OCIExecute($stmt); $cnt = OCIFetchStatement($stmt, $results); OCIFreeStatement($stmt); return array($cnt, $results); } function getSiblingsInfo($parentID, $concept, &$conn) { $sql = "SELECT tontoword.id, tontoword.naming " . "FROM tontoword, tontoword tontoword2, tontorel " . "WHERE tontoword2.id=" . $parentID . " AND tontoword2.id=tontorel.target AND tontorel.id = tontoword.id AND NOT tontoword.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=\"ontonav.php?clickedConcept=" . $sibling . $requestString . "&cID=" . $siblingID . "&view=RE" . "\"]; "; } } } } } 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=\"ontonav.php?clickedConcept=" . $child . $requestString . "&cID=" . $childID . "&view=RE" . "\"]; "; } } } } 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(!array_key_exists($paID, $ancestors)) { if($iteration == 1) $cParents[$paID] = $parentName; $ancestors[$paID] = $parentName; fetchParents($dot, $paID, $parentName, $conn, $requestString, $iteration, $ancestors, $cParents); } $dot .= "\"" . $parentName . "\" -> \"" . $prev . "\"; "; $dot .= "\"" . $parentName . "\" [URL=\"ontonav.php?clickedConcept=" . $parentName . $requestString . "&cID=" . $paID . "&view=RE" . "\"]; "; } } } } } function createImgMap($dotString) { $dotFile = tempnam("./", "dot"); //$dotFile = "$dotFile"; $dotFileHandle = fopen($dotFile, "w"); //print "$dotString

"; fwrite($dotFileHandle, $dotString); fclose($dotFileHandle); $mapFile = tempnam("./", "map"); //$mapFile = "$mapFile"; $cmd = "/usr/local/bin/dot -Timap $dotFile -o $mapFile"; system($cmd); $fd = fopen($mapFile, "r"); $mapString = ""; while(!feof($fd)) { $buffer = fgets($fd, 2048); if($buffer[0] != '#') { $nn = explode(" ", $buffer); $k = sizeOf($nn); if(($k = sizeOf($nn)) == 4) $mapString .= "\n"; else if($k == 5) $mapString .= "\n"; else if($k == 6) $mapString .= "\n"; else if($k == 7) $mapString .= "\n"; } } //unlink($dotFile); unlink($mapFile); $mapString .= ""; $GLOBALS['map_String'] = $mapString; } function initDotString(&$dotString, &$font) { switch($font) { case 5 : $ranksep = ".50"; break; case 6 : $ranksep = ".55"; break; case 7 : $ranksep = ".60"; break; case 8 : $ranksep = ".70"; break; case 9 : $ranksep = ".80"; break; case 10 : $ranksep = ".85"; break; case 11 : $ranksep = ".90"; break; case 12 : $ranksep = ".95"; } $dotString = "digraph onto { ranksep=\"" . $ranksep . "\"; node [height=\".001\", width=\".002\", fontsize=\"" . $font . "\"]; " . "edge [dir=back]; "; } // ***************************************************************** // *** The class which makes the 'RELATIVES' view of the ontoDB. *** // ***************************************************************** class Relatives { function Relatives($concept, $conceptID, $requestString, $font) { putenv("ORACLE_HOME=/usr/local/oracle/OraHome"); putenv("ORACLE_SID=isl"); $conn = ocilogon("ordbog", "isl_ordbog", ""); if(isset($conceptID)) $cID = $conceptID; else $cID = getConceptID($concept, $conn); if($cID > -1) { $GLOBALS['conceptFound'] = true; $ancestors = array(); $cParents = array(); initDotString($dotString, $font); 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 ""; } } } // ********************************************************************* // *** The class that which makes the 'Weighted' view of the ontoDB. *** // ********************************************************************* class WeightedView { var $seenNodes; function WeightedView(&$concept, &$cID, &$requestString, &$upfactor, &$downfactor, &$minWeight, &$font) { if(isset($cID)) { $GLOBALS['conceptFound'] = true; $seenNodes = array(); $seenEdges = array(); $cmd = "/usr/local/bin/ontoexp -g -n -d " . $downfactor . " -u " . $upfactor . " -l " . $minWeight . " " . $cID; $fd = popen($cmd, "r"); initDotString($dotString, $font); while(!feof($fd)) { $buffer = fgets($fd, 1024); if($buffer != "") { $sides = explode(" -> ", $buffer); $childName = $parentName = $cLabel = $pLabel = $childID = $parentID = ""; if(strpos($sides[1], '-1') === false) { $s = $sides[0]; $i = 0; if(($cc = $s[$i]) == '{') { while(($cc = $s[++$i]) != ',') $childID .= $cc; $i++; while(($cc = $s[++$i]) != '|' && $cc != '"') $childName .= $cc; if($cc == '|') while(($cc = $s[++$i]) != '"') $cLabel .= $cc; } $s = $sides[1]; $i = 0; if(($cc = $s[$i]) == '{') { while(($cc = $s[++$i]) != ',') $parentID .= $cc; $i++; while(($cc = $s[++$i]) != '|' && $cc != '"') $parentName .= $cc; if($cc == '|') while(($cc = $s[++$i]) != '"') $pLabel .= $cc; } if($cLabel != "") { $childName = rtrim($childName); $dotString .= "\"" . $childName . "\" [label=\"" . $childName . "\\n" . $cLabel . "\"]; "; } if($pLabel != "") { $parentName = rtrim($parentName); $dotString .= "\"" . $parentName . "\" [label=\"" . $parentName . "\\n" . $pLabel . "\"]; "; } if(!array_key_exists($childID, $seenNodes)) { $dotString .= "\"" . $childName . "\" [URL=\"ontonav.php?clickedConcept=" . str_replace("\"", "", $childName) . $requestString . "&cID=" . $childID . "&view=WE" . "\"]; "; $seenNodes[$childID] = ""; } if(!array_key_exists($parentID, $seenNodes)) { $dotString .= "\"" . $parentName . "\" [URL=\"ontonav.php?clickedConcept=" . str_replace("\"", "", $parentName) . $requestString . "&cID=" . $parentID . "&view=WE" . "\"]; "; $seenNodes[$parentID] = ""; } $dotString .= "\"" . $childName . "\" -> \"" . $parentName . "\";\n "; } else { $s = $sides[0]; $i = 0; if(($cc = $s[$i]) == '{') { while(($cc = $s[++$i]) != ','){} $i++; while(($cc = $s[++$i]) != '|' && $cc != '"'){ $childName .= $cc; } } $dotString .= "\"" . rtrim($childName) . "\" [color=\"lightgray\", label=\"" . rtrim($childName) . "\\n1.0000\", style=\"filled\"]; "; } } } pclose($fd); $dotString .= " }"; session_register("sess_dotString"); $GLOBALS['sess_dotString'] = $dotString; session_register("sess_dotString"); createImgMap($dotString); } else { $GLOBALS['conceptFound'] = false; echo ""; } } } ?> Test page - www.ontoquery.dk - www.isl.ruc.dk




"; echo $GLOBALS['map_String']; echo "
Back"; } ?>





"?>