From: <sk...@us...> - 2008-02-16 12:41:35
|
Revision: 580 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=580&view=rev Author: sknappe Date: 2008-02-16 04:41:30 -0800 (Sat, 16 Feb 2008) Log Message: ----------- JSON is now used Google Maps added redirection is shown Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/Settings.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/default.css trunk/src/dbpedia-navigator/index.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-02-15 16:56:37 UTC (rev 579) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-02-16 12:41:30 UTC (rev 580) @@ -120,13 +120,12 @@ { $query="SELECT ?pred ?obj ". "WHERE {{<http://dbpedia.org/resource/".str_replace(' ','_',$label)."> ?pred ?obj}UNION{<http://dbpedia.org/resource/".str_replace(' ','_',$label)."> <http://dbpedia.org/property/redirect> ?Conc.?Conc ?pred ?obj}}"; - $result=$this->getSparqlResult($query); - if (!isset($result->item)) throw new Exception("Your query brought no result. The Label-Search is started."); + $result=json_decode($this->getSparqlResult($query),true); + if (count($result['results']['bindings'])==0) throw new Exception("Your query brought no result. The Label-Search is started."); $ret=array(); - foreach ($result->item as $results){ - $value=$results->item[1]; - if (strpos($value,"@".$this->lang)==(strlen($value)-strlen("@".$this->lang))) $ret[$results->item[0]][]=substr($value,0,strlen($value)-strlen("@".$this->lang)); - if (strpos($value,"@")!=(strlen($value)-strlen($this->lang)-1)) $ret[$results->item[0]][]=$value; + foreach ($result['results']['bindings'] as $results){ + $value=$results['obj']; + if (!(isset($value['xml:lang'])&&($value['xml:lang']!=$this->lang))) $ret[$results['pred']['value']][]=$value['value']; } return $ret; @@ -146,7 +145,7 @@ $running=$this->client->isSparqlQueryRunning($this->id,$queryID); if (!$running){ - $result=$this->client->getAsStringArray($this->id,$queryID); + $result=$this->client->getAsJSON($this->id,$queryID); return $result; } @@ -163,17 +162,17 @@ } while($seconds<$this->ttl); $this->client->stopSparqlQuery($id,$queryID); } - + function getSubjects($label) { $query="SELECT DISTINCT ?subject\n". "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object. ?object bif:contains '\"".$label."\"'@en}\n". "LIMIT 10"; - $result=$this->getSparqlResult($query); - if (!$result->item) throw new Exception("Your query brought no result."); + $result=json_decode($this->getSparqlResult($query),true); + if (count($result['results']['bindings'])==0) throw new Exception("Your query brought no result."); $ret=array(); - foreach ($result->item as $results){ - $ret[]=$results->item[0]; + foreach ($result['results']['bindings'] as $results){ + $ret[]=$results['subject']['value']; } return $ret; } @@ -183,11 +182,11 @@ $query="SELECT DISTINCT ?subject\n". "WHERE { ?subject a <".$concept.">}\n". "LIMIT 10"; - $result=$this->getSparqlResult($query); - if (!$result->item) throw new Exception("Your query brought no result."); + $result=json_decode($this->getSparqlResult($query),true); + if (count($result['results']['bindings'])==0) throw new Exception("Your query brought no result."); $ret=array(); - foreach ($result->item as $results){ - $ret[]=$results->item[0]; + foreach ($result['results']['bindings'] as $results){ + $ret[]=$results['subject']['value']; } return $ret; } @@ -265,9 +264,9 @@ } } /* -require_once("DLLearnerConnection.php"); $sc=new DLLearnerConnection(); $ids=$sc->getIDs(); $sc=new DLLearnerConnection($ids[0],$ids[1]); -$triples=$sc->getConceptFromExamples(array("http://dbpedia.org/resource/Angela_Merkel"),array("http://dbpedia.org/resource/Joschka_Fischer"));*/ +$triples=$sc->getSubjects("Angela Merkel"); +var_dump($triples);*/ ?> Modified: trunk/src/dbpedia-navigator/Settings.php =================================================================== --- trunk/src/dbpedia-navigator/Settings.php 2008-02-15 16:56:37 UTC (rev 579) +++ trunk/src/dbpedia-navigator/Settings.php 2008-02-16 12:41:30 UTC (rev 580) @@ -37,8 +37,10 @@ // public $dbpediauri='http://dbpedia2.openlinksw.com:8890/isparql'; public $sparqlttl=60; - //not yet used + public $language="en"; + + public $googleMapsKey="ABQIAAAAWwHG9WuZ8hxFSPjRX2-D-hSOxlJeL3USfakgDtFzmQkGhQTW0xTFM1Yr38ho8qREnjt-6oLs37o4xg"; } ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-15 16:56:37 UTC (rev 579) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-16 12:41:30 UTC (rev 580) @@ -49,6 +49,7 @@ //get first Letter of label big $subject=ucfirst($subject); + $uri="http://dbpedia.org/resource/".str_replace(' ','_',$subject); //if article is in session, get it out of the session if (isset($articles)){ @@ -87,14 +88,17 @@ // display a picture if there is one if(isset($triples['http://xmlns.com/foaf/0.1/depiction'])) $content.='<img src="'.$triples['http://xmlns.com/foaf/0.1/depiction'][0].'" alt="Picture of '.$subject.'" style="float:right; max-width:200px;" \>'; - + + //display where it was redirected from, if it was redirected + if (isset($triples['http://dbpedia.org/property/redirect'])) $content.="<span id=\"redirectedFrom\">redirected from '$subject'</span>"; + // add short description in english $content.="<h4>Short Description</h4><p>".urldecode($triples['http://dbpedia.org/property/abstract'][0])."</p>"; // give the link to the corresponding Wikipedia article if(isset($triples['http://xmlns.com/foaf/0.1/page'])) $content .= '<p><img src="'.$_GET['path'].'images/wikipedia_favicon.png" alt"Wikipedia" /> <a href="'.$triples['http://xmlns.com/foaf/0.1/page'][0].'">view Wikipedia article</a>, '; - $content .= '<a href="'.$subject.'">view DBpedia resource description</a></p>'; + $content .= '<a href="'.$uri.'">view DBpedia resource description</a></p>'; // display a list of classes if(isset($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'])) @@ -107,7 +111,11 @@ $content .= '</ul></p>'; } + if (isset($triples['http://www.w3.org/2003/01/geo/wgs84_pos#long'])&&isset($triples['http://www.w3.org/2003/01/geo/wgs84_pos#lat'])){ + $content.="<br/><a href=\"\" onClick=\"loadGoogleMap(".$triples['http://www.w3.org/2003/01/geo/wgs84_pos#lat'][0].",".$triples['http://www.w3.org/2003/01/geo/wgs84_pos#long'][0].");return false;\">a map of the location</a><div id=\"map\" style=\"width: 500px; height: 300px;display:none;\"></div>"; + } + // filter out uninteresting properties and properties which // have already been displayed unset($triples['http://xmlns.com/foaf/0.1/page']); @@ -190,7 +198,7 @@ $objResponse->assign("articlecontent", "innerHTML", $content); $objResponse->assign("ArticleTitle","innerHTML",$artTitle); $objResponse->assign("lastarticles","innerHTML",$lastArticles); - $objResponse->assign("searchcontent", "innerHTML", $searchResult); + if ($searchResult!="") $objResponse->assign("searchcontent", "innerHTML", $searchResult); $objResponse->assign('Positives','innerHTML',$posInterests); $objResponse->assign('Negatives','innerHTML',$negInterests); return $objResponse; Modified: trunk/src/dbpedia-navigator/default.css =================================================================== --- trunk/src/dbpedia-navigator/default.css 2008-02-15 16:56:37 UTC (rev 579) +++ trunk/src/dbpedia-navigator/default.css 2008-02-16 12:41:30 UTC (rev 580) @@ -80,14 +80,6 @@ right: 15px;*/ } -#clear { - clear: both; -} - -#validation { - padding: 0.5em; -} - /* * sidebar content (boxes) */ @@ -384,4 +376,9 @@ #todo { padding: 15px; margin: 10px; +} + +#redirectedFrom { + color: #666; + font-size: 85%; } \ No newline at end of file Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-02-15 16:56:37 UTC (rev 579) +++ trunk/src/dbpedia-navigator/index.php 2008-02-16 12:41:30 UTC (rev 580) @@ -13,13 +13,10 @@ if (isset($_GET['path'])) $path=$_GET['path']; else $path=""; - -// debugging code -// echo '<pre>'; -// $sc=new DLLearnerConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); -// print_r($sc->getTriples($settings->sparqlttl,'http://dbpedia.org/resource/Dog')); -// echo '</pre>'; +require_once 'Settings.php'; +$settings=new Settings(); + require("ajax.php"); echo '<?xml version="1.0" encoding="UTF-8"?>'; @@ -33,6 +30,8 @@ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" href="<?php print $path;?>default.css"/> <?php $xajax->printJavascript($path.'xajax/'); ?> + <script src="http://maps.google.com/maps?file=api&v=2&key=<?php print $settings->googleMapsKey;?>" + type="text/javascript"></script> <script type="text/javascript"> showLoading = function() { xajax.$('Loading').style.display='inline'; @@ -49,7 +48,18 @@ function hidediv(id) { document.getElementById(id).style.display='none'; - } + } + + function loadGoogleMap(Lat,Lng) { + document.getElementById("map").style.display='block'; + if (GBrowserIsCompatible()) { + // Create and Center a Map + var map = new GMap2(document.getElementById("map")); + map.setCenter(new GLatLng(Lat, Lng), 10); + map.addControl(new GLargeMapControl()); + map.addControl(new GMapTypeControl()); + } + } </script> </head> <body <?php if (isset($_GET['resource'])) print "onLoad=\"xajax_getarticle('".$_GET['resource']."',-1);return false;\"";unset($_GET['resource']);?>> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |