function clusterConnection($first, $second) { $first = str_replace("__perc__", "%", $first); $second = str_replace("__perc__", "%", $second); $ignoredPredicates = array(); $ignoredObjects = array(); for ($t = 0; $t < 5; $t++) { if (isset($_REQUEST['ignoreObject_' . $t])) { $ignoredObjects[] = urlencode($_REQUEST['ignoreObject_' . $t]); } } for ($t = 0; $t < 5; $t++) { if (isset($_REQUEST['ignorePredicate_' . $t])) { $ignoredPredicates[] = $_REQUEST['ignorePredicate_' . $t]; } } echo '<table cellpadding="0" cellspacing="0"> <tr> <td> <table class="closeheader" style="background-color:white;"> <tr> <td>Quick Connection with Cluster Table</td><td align="right"><a href="javascript:toggle(\'clusterCon\',false);" alt="close" style="color:white;text-decoration:none;background-color:orange">x</a></td> </tr> </table> </td> </tr> <tr> <td> <table style="border: 1px solid #888;background-color:white;width:100%"> <tr> <td>'; $connectedfirst = searchClusterStart($GLOBALS['wikipediaBase'] . $first); $connectedsecond = searchClusterStart($GLOBALS['wikipediaBase'] . $second); $shortestPathFound = false; do { $popA = array_pop($connectedfirst); $popB = array_pop($connectedsecond); if ($popA == $popB) { continue; } else { $shortestPathFound = true; array_push($connectedfirst, strlen($popA) == 0 ? $GLOBALS['wikipediaBase'] . $first : $popA); array_push($connectedsecond, strlen($popB) == 0 ? $GLOBALS['wikipediaBase'] . $second : $popB); } } while ($shortestPathFound == false); echo '<table><tr>'; #print_r($ignoredObjects); #print_r($connectedsecond); for ($i = 0; $i < count($connectedfirst); $i++) { if ($i == 0) { echo '<td><a href="' . $GLOBALS['objectLinkingURL'] . cutBaseUri($connectedfirst[$i], 'wikiBase') . '">'; echo cutBaseUri($connectedfirst[$i], 'wikiBase') == $first ? '<span style="font-weight:bold">' . getLabel($connectedfirst[$i]) . '</span>' : getLabel($connectedfirst[$i]); echo '</a>'; echo '<a href="#e" onclick="ladeInfobox(\'ajax.php?f=4&actObject=' . $connectedfirst[$i] . '\',1000,\'' . str_replace('"', '', urldecode(cutBaseUri($connectedfirst[$i], 'wikiBase'))) . '\');"><img border="0" src="images/moreKnopf.png" title="show Details about this Object"></a>'; echo '</td>'; } else { $ignoretest[] = cutBaseUri(getClusterProperty($connectedfirst[$i]), 'predBase'); $ignoretest[] = cutBaseUri($connectedfirst[$i], 'wikiBase'); echo '<td><table><tr><td align="center">' . cutBaseUri(getClusterProperty($connectedfirst[$i]), 'predBase') . '</td></tr><tr><td>'; echo getClusterPropertyDirection($connectedfirst[$i], getClusterProperty($connectedfirst[$i])) == 'left' ? '<img src="images/nachlinksPfeil.png" width="90" height="10" />' : '<img src="images/nachrechtsPfeil.png" width="90" height="10" />'; echo '</td></tr></table></td>'; echo '<td><a href="' . $GLOBALS['objectLinkingURL'] . cutBaseUri($connectedfirst[$i], 'wikiBase') . '">' . getLabel($connectedfirst[$i]) . '</a>'; echo '<a href="#e" onclick="ladeInfobox(\'ajax.php?f=4&actObject=' . $connectedfirst[$i] . '\',1000,\'' . str_replace('"', '', urldecode(cutBaseUri($connectedfirst[$i], 'wikiBase'))) . '\');"><img border="0" src="images/moreKnopf.png" title="show Details about this Object"></a>'; echo '</td>'; } } for ($i = count($connectedsecond) - 1; $i >= 0; $i--) { $ignoretest[] = cutBaseUri(getClusterProperty($connectedsecond[$i]), 'predBase'); $ignoretest[] = cutBaseUri($connectedsecond[$i], 'wikiBase'); echo '<td><table><tr><td align="center">' . cutBaseUri(getClusterProperty($connectedsecond[$i]), 'predBase') . '</td></tr><tr><td>'; echo getClusterPropertyDirection($connectedsecond[$i], getClusterProperty($connectedsecond[$i])) == 'left' ? '<img src="images/nachlinksPfeil.png" width="90" height="10" />' : '<img src="images/nachrechtsPfeil.png" width="90" height="10" />'; echo '</td></tr></table></td><td><a href="' . $GLOBALS['objectLinkingURL'] . cutBaseUri($connectedsecond[$i], 'wikiBase') . '">'; echo cutBaseUri($connectedsecond[$i], 'wikiBase') == $second ? '<span style="font-weight:bold">' . getLabel($connectedsecond[$i]) . '</span>' : getLabel($connectedsecond[$i]); echo '</a>'; echo '<a href="#e" onclick="ladeInfobox(\'ajax.php?f=4&actObject=' . $connectedsecond[$i] . '\',1000,\'' . str_replace('"', '', urldecode(cutBaseUri($connectedsecond[$i], 'wikiBase'))) . '\');"><img border="0" src="images/moreKnopf.png" title="show Details about this Object"></a>'; echo '</td>'; } echo '</tr></table>'; echo ' </td> </tr>'; foreach ($ignoretest as $ignore) { if (in_array($ignore, $ignoredPredicates) || in_array($ignore, $ignoredObjects)) { echo '<tr><td><span style="color:red">Warning: The preview connection contains elements in your ignore list.</span></td></tr>'; } } echo '</table> </td> </tr>'; echo '</table>'; }
function calcConnectionCluster($first, $second, $maxdepth) { $res = mysql_query("SELECT t1.object, t1.depth, t1.referenced_by_property, t1.referenced_by_object, t1.cluster_id, t2.object, t2.depth, t2.referenced_by_property, t2.referenced_by_object,t2.cluster_id FROM " . $GLOBALS['clusterTableName'] . " AS t1, " . $GLOBALS['clusterTableName'] . " AS t2 WHERE t1.object='" . $GLOBALS['wikipediaBase'] . $first . "' AND t2.object='" . $GLOBALS['wikipediaBase'] . $second . "' AND t1.cluster_id=t2.cluster_id"); $row = mysql_fetch_array($res); if (mysql_num_rows($res) > 0) { $resCount = mysql_query("SELECT object_count, triple_count FROM " . $GLOBALS['countTableName'] . " WHERE id='" . $row[4] . "'"); $resRow = mysql_fetch_array($resCount); $mindepthcalc = abs($row[1] - $row[6]); #$maxdepthcalc=$row[1]+$row[6]; $connectedfirst = searchClusterStart($GLOBALS['wikipediaBase'] . $first); $connectedsecond = searchClusterStart($GLOBALS['wikipediaBase'] . $second); $shortestPathFound = false; do { $popA = array_pop($connectedfirst); $popB = array_pop($connectedsecond); if ($popA == $popB) { continue; } else { $shortestPathFound = true; array_push($connectedfirst, strlen($popA) == 0 ? $GLOBALS['wikipediaBase'] . $first : $popA); array_push($connectedsecond, strlen($popB) == 0 ? $GLOBALS['wikipediaBase'] . $second : $popB); } } while ($shortestPathFound == false); $maxdepthcalc = count($connectedfirst) + count($connectedsecond) - 1; if ($mindepthcalc <= $maxdepth) { $return = $mindepthcalc > 0 ? $mindepthcalc - 1 : $mindepthcalc; $isInMainCluster = $row[4] == 0; echo '"' . $first . '" and "' . $second . '" can be found in cluster ' . $row[4] . ' ' . ($isInMainCluster ? '(the main cluster)' : '(a minor cluster)') . ' containing ' . $resRow[0] . ' objects and ' . $resRow[1] . ' triples.<br>'; echo 'Using the paths stored in the cluster table, we determined that the shortest connection between them has a length between ' . $mindepthcalc . ' and ' . $maxdepthcalc . '. (You choosed ' . $maxdepth . ' as max. Distance.)<br><br>'; } else { $return = 'notenoughdistance'; echo 'There is no connection between these objects within the chosen distance. Using the paths stored in the cluster table, we determined that the shortest connection between them has a length between ' . $mindepthcalc . ' and ' . $maxdepthcalc . ''; } } else { echo '<a href="' . $GLOBALS['objectLinkingURL'] . $first . '">' . getLabel($GLOBALS['wikipediaBase'] . $first) . '</a> and <a href="' . $GLOBALS['objectLinkingURL'] . $second . '">' . getLabel($GLOBALS['wikipediaBase'] . $second) . '</a> are not in the same Cluster.<br> There exists no connection between these two objects in the DBpedia infobox data set.<br> The reason is that infoboxes in the corresponding Wikipedia articles do not exist or do not contain information<br>allowing to connect these two objects (note that this may have changed since the data was extracted). <br>'; $return = false; } return $return; }