From: <sk...@us...> - 2008-01-30 15:27:25
|
Revision: 467 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=467&view=rev Author: sknappe Date: 2008-01-30 07:27:18 -0800 (Wed, 30 Jan 2008) Log Message: ----------- more error handling Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/rebuild.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-30 11:47:27 UTC (rev 466) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-30 15:27:18 UTC (rev 467) @@ -28,7 +28,7 @@ $this->ttl=$settings->sparqlttl; $this->lang=$settings->language; $this->DBPediaUrl=$settings->dbpediauri; - $this->client=new SoapClient("main.wsdl"); + $this->client=new SoapClient("main.wsdl",array('features' => SOAP_SINGLE_ELEMENT_ARRAYS)); $this->id=$id; $this->ksID=$ksID; } @@ -97,12 +97,14 @@ $query="SELECT ?pred ?obj ". "WHERE {<http://dbpedia.org/resource/".str_replace(' ','_',$label)."> ?pred ?obj}"; $result=$this->getSparqlResult($query); + if (!$result->item) throw new Exception("Your query brought no result."); $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; + $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; } + return $ret; } @@ -137,6 +139,7 @@ "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."); $ret=array(); foreach ($result->item as $results){ $ret[]=$results->item; @@ -234,5 +237,5 @@ $sc=new DLLearnerConnection(); $ids=$sc->getIDs(); $sc=new DLLearnerConnection($ids[0],$ids[1]); -$triples=$sc->getTriples("Leipzig");*/ +$triples=$sc->getTriples("tgzt");*/ ?> Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-30 11:47:27 UTC (rev 466) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-30 15:27:18 UTC (rev 467) @@ -10,22 +10,21 @@ function getsubjects($label) { require_once("DLLearnerConnection.php"); - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); + //initialise content $content=""; - $subjects=$sc->getSubjects($label); - - if (count($subjects)==1) - { - if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); - else $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".str_replace("_"," ",substr (strrchr ($subjects, "/"), 1))."',-2);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; - } - else if (count($subjects)==0) $content.="No search result found in time."; - else{ + try{ + $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); + + + $subjects=$sc->getSubjects($label); + foreach ($subjects as $subject) { $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."',-2);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } + } catch (Exception $e){ + $content=$e->getMessage(); } $_SESSION['subjects']=$content; @@ -47,7 +46,8 @@ function getarticle($subject,$fromCache) { - if (isset($_SESSION['articles'])) + //if article is in session, get it out of the session + if (isset($_SESSION['articles'])){ foreach ($_SESSION['articles'] as $key => $value) { if ($value['subject']==$subject){ @@ -55,96 +55,95 @@ break; } } + } + + //initialize the content variables + $content=""; + $searchResult=""; + $lastArticles=""; + $artTitle=""; + + //get the article + //if $fromCache is -2, no new SearchResults should be processed + //if $fromCache is -1, everything is normal + //if $fromCache is >=0, the article is taken out of the cache if ($fromCache<0) { - require_once("DLLearnerConnection.php"); - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); - $content=""; - $searchResult=""; - $lastArticles=""; - $artTitle=""; + //if there are errors see catch block try{ + require_once("DLLearnerConnection.php"); + $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); $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 { - // goal: display the data in a nice (DBpedia specific way), maybe similar to - // dbpedia.org/search + //BUILD ARTICLE + // 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))); - - // 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;" \>'; + // 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>"; + // 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>'; + // 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>'; + // 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']; + 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>'; + } + + + // 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); + + + + //BUILD ARTICLE TITLE + $artTitle=$triples['http://www.w3.org/2000/01/rdf-schema#label']; + + //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']++; - // 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 + //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; + } - $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>"; - } + + //BUILD SEARCHRESULT + if ($fromCache==-1) + $searchResult.="<a href=\"\" onclick=\"xajax_getAndShowSubjects('".$subject."');return false;\">Show more Results</a>"; } catch (Exception $e) { $content=$e->getMessage(); @@ -152,15 +151,18 @@ } } else { + //Article is in session $content=$_SESSION['articles'][$fromCache]['content']; $subject=$_SESSION['articles'][$fromCache]['subject']; } - if (isset($_SESSION['articles'])) + //Build lastArticles + if (isset($_SESSION['articles'])){ foreach ($_SESSION['articles'] as $key => $value) { $lastArticles.="<a href=\"\" onclick=\"xajax_getAndShowArticle('',".$key.");return false;\">".$value['subject']."</a><br/>"; } + } //put whole site content into session $_SESSION['artContent']=$content; @@ -168,6 +170,7 @@ $_SESSION['artLast']=$lastArticles; $_SESSION['artSubjects']=$searchResult; + $objResponse = new xajaxResponse(); return $objResponse; } Modified: trunk/src/dbpedia-navigator/rebuild.php =================================================================== --- trunk/src/dbpedia-navigator/rebuild.php 2008-01-30 11:47:27 UTC (rev 466) +++ trunk/src/dbpedia-navigator/rebuild.php 2008-01-30 15:27:18 UTC (rev 467) @@ -6,7 +6,7 @@ require_once 'pear/HTTP_Request.php'; require_once 'DLLearnerConnection.php'; require_once 'Settings.php'; -$settings=new Settings(); +$settings=new Settings(); // download new WSDL file DLLearnerConnection::loadWSDLfiles($settings->wsdluri); @@ -14,7 +14,6 @@ // we need to make sure that PHP really uses the new WSDL file // and does not cache, so we disable the cache and load it ini_set("soap.wsdl_cache_enabled","0"); - // redirect to index page $index_uri = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']).'/index.php'; header('Location: ' . $index_uri); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |