From: <sk...@us...> - 2008-01-30 11:47:31
|
Revision: 466 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=466&view=rev Author: sknappe Date: 2008-01-30 03:47:27 -0800 (Wed, 30 Jan 2008) Log Message: ----------- first exception handling (not final) Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/ajaxfunctions.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-30 11:21:13 UTC (rev 465) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-30 11:47:27 UTC (rev 466) @@ -108,31 +108,27 @@ function getSparqlResult($query) { - try { - $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "defaultGraphURIs", array("http://dbpedia.org")); - $queryID=$this->client->sparqlQueryThreaded($this->id,$this->ksID,$query); - $running=true; - $i = 1; - $sleeptime = 1; + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "defaultGraphURIs", array("http://dbpedia.org")); + $queryID=$this->client->sparqlQueryThreaded($this->id,$this->ksID,$query); + $running=true; + $i = 1; + $sleeptime = 1; - do { - // sleep a while - sleep($sleeptime); + do { + // sleep a while + sleep($sleeptime); - $running=$this->client->isSparqlQueryRunning($this->id,$queryID); - if (!$running){ - $result=$this->client->getAsStringArray($this->id,$queryID); - return $result; - } + $running=$this->client->isSparqlQueryRunning($this->id,$queryID); + if (!$running){ + $result=$this->client->getAsStringArray($this->id,$queryID); + return $result; + } - $seconds = $i * $sleeptime; - $i++; - } while($seconds<$this->ttl); - $this->client->stopSparqlQuery($id,$queryID); - } catch (Exception $e){ - echo $e->getMessage(); - } + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$this->ttl); + $this->client->stopSparqlQuery($id,$queryID); } function getSubjects($label) Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-30 11:21:13 UTC (rev 465) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-30 11:47:27 UTC (rev 466) @@ -58,86 +58,97 @@ if ($fromCache<0) { require_once("DLLearnerConnection.php"); $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); - $triples=$sc->getTriples($subject); $content=""; $searchResult=""; - $objResponse = new xajaxResponse(); - if (count($triples)==1) - { - // ToDo: find out why this was treated in a special way by Sebastian - $content.=substr($triples,7); - } - else if (count($triples)==0) { - $content.="Did not find an article with that name. Similar Articles are shown under 'Search Results'."; - } else { - - // goal: display the data in a nice (DBpedia specific way), maybe similar to - // dbpedia.org/search - - $content=""; - - // replace by label(?) - //$subject_nice = str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1))); + $lastArticles=""; + $artTitle=""; + try{ + $triples=$sc->getTriples($subject); + $objResponse = new xajaxResponse(); + if (count($triples)==1) + { + // ToDo: find out why this was treated in a special way by Sebastian + $content.=substr($triples,7); + } + else if (count($triples)==0) { + $content.="Did not find an article with that name. Similar Articles are shown under 'Search Results'."; + } else { - // 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_nice.'" style="float:right; max-width:200px;" \>'; + // goal: display the data in a nice (DBpedia specific way), maybe similar to + // dbpedia.org/search + + $content=""; + + // replace by label(?) + //$subject_nice = str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1))); - // 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="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>'; + // 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_nice.'" style="float:right; max-width:200px;" \>'; + + // 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="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>'; + + // display a list of classes + if(isset($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'])) + $content .= '<p>classes: '.formatClassArray($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).'</p>'; + + if(isset($triples['http://dbpedia.org/property/reference'])) { + $content .= '<p>references: <ul>'; + foreach($triples['http://dbpedia.org/property/reference'] as $reference) + $content .= '<li><a href="'.$reference.'">'.$reference.'</a></li>'; + $content .= '</ul></p>'; + } - // display a list of classes - if(isset($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'])) - $content .= '<p>classes: '.formatClassArray($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).'</p>'; - - if(isset($triples['http://dbpedia.org/property/reference'])) { - $content .= '<p>references: <ul>'; - foreach($triples['http://dbpedia.org/property/reference'] as $reference) - $content .= '<li><a href="'.$reference.'">'.$reference.'</a></li>'; - $content .= '</ul></p>'; - } + $artTitle=$triples['http://www.w3.org/2000/01/rdf-schema#label']; - // filter out uninteresting properties and properties which - // have already been displayed - unset($triples['http://xmlns.com/foaf/0.1/page']); - unset($triples['http://xmlns.com/foaf/0.1/depiction']); - unset($triples['http://dbpedia.org/property/abstract']); - unset($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']); - - // display the remaining properties as list which can be used for further navigation - - $content .= '<br/><br/><br/><br/><br/><br/>'.get_triple_table($triples); - - //store article in session, to navigate between last 5 articles quickly - $contentArray=array('content' => $content,'subject' => $subject); - if (!isset($_SESSION['nextArticle'])){ - $_SESSION['nextArticle']=0; - $_SESSION['articles']=array(); + + // filter out uninteresting properties and properties which + // have already been displayed + unset($triples['http://xmlns.com/foaf/0.1/page']); + unset($triples['http://xmlns.com/foaf/0.1/depiction']); + unset($triples['http://dbpedia.org/property/abstract']); + unset($triples['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']); + + // display the remaining properties as list which can be used for further navigation + + $content .= '<br/><br/><br/><br/><br/><br/>'.get_triple_table($triples); + + //store article in session, to navigate between last 5 articles quickly + $contentArray=array('content' => $content,'subject' => $subject); + if (!isset($_SESSION['nextArticle'])){ + $_SESSION['nextArticle']=0; + $_SESSION['articles']=array(); + } + if ($_SESSION['nextArticle']==5) $_SESSION['nextArticle']=0; + $_SESSION['articles'][$_SESSION['nextArticle']]=$contentArray; + $_SESSION['currentArticle']=$_SESSION['nextArticle']; + $_SESSION['nextArticle']++; + + //Add Positives to Session + if (!isset($_SESSION['positive'])){ + $array=array("http://dbpedia.org/resource/".str_replace(" ","_",$subject) => "http://dbpedia.org/resource/".str_replace(" ","_",$subject)); + $_SESSION['positive']=$array; + } + else{ + $array=$_SESSION['positive']; + $array["http://dbpedia.org/resource/".str_replace(" ","_",$subject)]="http://dbpedia.org/resource/".str_replace(" ","_",$subject); + $_SESSION['positive']=$array; + } + + //build Subject and Searchresults + if ($fromCache==-1) + $searchResult.="<a href=\"\" onclick=\"xajax_getAndShowSubjects('".$subject."');return false;\">Show more Results</a>"; } - if ($_SESSION['nextArticle']==5) $_SESSION['nextArticle']=0; - $_SESSION['articles'][$_SESSION['nextArticle']]=$contentArray; - $_SESSION['currentArticle']=$_SESSION['nextArticle']; - $_SESSION['nextArticle']++; - - //Add Positives to Session - if (!isset($_SESSION['positive'])){ - $array=array("http://dbpedia.org/resource/".str_replace(" ","_",$subject) => "http://dbpedia.org/resource/".str_replace(" ","_",$subject)); - $_SESSION['positive']=$array; - } - else{ - $array=$_SESSION['positive']; - $array["http://dbpedia.org/resource/".str_replace(" ","_",$subject)]="http://dbpedia.org/resource/".str_replace(" ","_",$subject); - $_SESSION['positive']=$array; - } - - //build Subject and Searchresults - if ($fromCache==-1) - $searchResult.="<a href=\"\" onclick=\"xajax_getAndShowSubjects('".$subject."');return false;\">Show more Results</a>"; + } catch (Exception $e) + { + $content=$e->getMessage(); + $artTitle="Fehler"; } } else { @@ -145,7 +156,6 @@ $subject=$_SESSION['articles'][$fromCache]['subject']; } - $lastArticles=""; if (isset($_SESSION['articles'])) foreach ($_SESSION['articles'] as $key => $value) { @@ -154,7 +164,7 @@ //put whole site content into session $_SESSION['artContent']=$content; - $_SESSION['artTitle']=$triples['http://www.w3.org/2000/01/rdf-schema#label']; + $_SESSION['artTitle']=$artTitle; $_SESSION['artLast']=$lastArticles; $_SESSION['artSubjects']=$searchResult; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |