From: <sk...@us...> - 2008-01-15 09:29:21
|
Revision: 371 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=371&view=rev Author: sknappe Date: 2008-01-15 01:29:18 -0800 (Tue, 15 Jan 2008) Log Message: ----------- Articles are now automatically added to relevant interests but can be swapped to unrelevant or removed changed the way xajax is used to get better performance Modified Paths: -------------- trunk/src/dbpedia-navigator/ajax.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/index.php Added Paths: ----------- trunk/src/dbpedia-navigator/images/minus.jpg trunk/src/dbpedia-navigator/images/plus.jpg Modified: trunk/src/dbpedia-navigator/ajax.php =================================================================== --- trunk/src/dbpedia-navigator/ajax.php 2008-01-14 11:54:55 UTC (rev 370) +++ trunk/src/dbpedia-navigator/ajax.php 2008-01-15 09:29:18 UTC (rev 371) @@ -3,15 +3,18 @@ $sid = session_id(); $xajax = new xajax("ajaxfunctions.php?sid=$sid"); -$xajax->register(XAJAX_FUNCTION, 'getsubjects', array( +$xajax->configureMany(array('debug'=>true)); +$xajax->register(XAJAX_FUNCTION, 'showSubjects', array( 'onResponseDelay' => 'showLoadingSubjects', 'beforeResponseProcessing' => 'hideLoadingSubjects' )); $xajax->registerFunction('getarticle'); -$xajax->registerFunction('addPositive'); -$xajax->registerFunction('addNegative'); +$xajax->registerFunction('toPositive'); +$xajax->registerFunction('toNegative'); $xajax->registerFunction('clearPositives'); $xajax->registerFunction('clearNegatives'); +$xajax->registerFunction('showInterests'); +$xajax->registerFunction('getAndShowArticle'); $xajax->register(XAJAX_FUNCTION, 'learnConcept', array( 'onResponseDelay' => 'showLoadingConcept', 'beforeResponseProcessing' => 'hideLoadingConcept' @@ -20,5 +23,9 @@ 'onResponseDelay' => 'showLoadingConceptSubjects', 'beforeResponseProcessing' => 'hideLoadingConceptSubjects' )); -$xajax->registerFunction('searchAndShowArticle'); +$xajax->registerFunction('getAndShowSubjects'); +$xajax->registerFunction('getsubjects'); +$xajax->registerFunction('showArticle'); +$xajax->registerFunction('removePosInterest'); +$xajax->registerFunction('removeNegInterest'); ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-14 11:54:55 UTC (rev 370) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-15 09:29:18 UTC (rev 371) @@ -16,24 +16,37 @@ $content=""; $subjects=$sc->getSubjects($settings->sparqlttl,$label); + if (count($subjects)==1) { if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); - else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; + else $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".str_replace("_"," ",substr (strrchr ($subjects, "/"), 1))."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; } else if (count($subjects)==0) $content.="No search result found in time."; else{ foreach ($subjects as $subject) { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".str_replace("_"," ",substr (strrchr ($subject, "/"), 1))."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } } + $_SESSION['subjects']=$content; + $objResponse = new xajaxResponse(); - $objResponse->assign("searchcontent", "innerHTML", $content); return $objResponse; } +function showSubjects() +{ + while (!isset($_SESSION['subjects'])){ + sleep(0.5); + } + $objResponse = new xajaxResponse(); + $objResponse->assign("searchcontent", "innerHTML", $_SESSION['subjects']); + unset($_SESSION['subjects']); + return $objResponse; +} + function getarticle($subject,$fromCache) { if (isset($_SESSION['articles'])) @@ -50,7 +63,7 @@ $settings=new Settings(); $sc=new DLLearnerConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); $triples=$sc->getTriples($settings->sparqlttl,$subject); - $content="";$contentbuttons=""; + $content=""; if (count($triples)==1) { // ToDo: find out why this was treated in a special way by Sebastian @@ -99,14 +112,11 @@ // display the remaining properties as list which can be used for further navigation - $content .= '<br/><br/><br/><br/><br/><br/>'.get_triple_table($triples); - - // $contentbuttons="<input type=\"button\" value=\"Positive\" class=\"button\" onclick=\"xajax_addPositive('".$subject."');return false;\" /> <input type=\"button\" value=\"Negative\" class=\"button\" onclick=\"xajax_addNegative('".$subject."');return false;\" />"; - $contentbuttons='<img src="images/green-plus.png" alt="positive example" onclick="xajax_addPositive(\''.$subject.'\')" /> <img src="images/red-minus.png" alt="negative example" onclick="xajax_addNegative(\''.$subject.'\') />'; + $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,'contentbuttons' => $contentbuttons, 'subject' => $subject); + $contentArray=array('content' => $content,'subject' => $subject); if (!isset($_SESSION['nextArticle'])){ $_SESSION['nextArticle']=0; $_SESSION['articles']=array(); @@ -118,60 +128,101 @@ } else { $content=$_SESSION['articles'][$fromCache]['content']; - $contentbuttons=$_SESSION['articles'][$fromCache]['contentbuttons']; $subject=$_SESSION['articles'][$fromCache]['subject']; } $lastArticles=""; foreach ($_SESSION['articles'] as $key => $value) { - $lastArticles.="<a href=\"\" onclick=\"xajax_getarticle('',".$key.");return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($value['subject'], "/"), 1)))."</a><br/>"; + $lastArticles.="<a href=\"\" onclick=\"xajax_getAndShowArticle('',".$key.");return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($value['subject'], "/"), 1)))."</a><br/>"; } + //Add Positives to Session + if (!isset($_SESSION['positive'])){ + $array=array($subject => $subject); + $_SESSION['positive']=$array; + } + else{ + $array=$_SESSION['positive']; + $array[$subject]=$subject; + $_SESSION['positive']=$array; + } + + //build Subject and Searchresults + $searchResult="<a href=\"\" onclick=\"xajax_getAndShowArticle('".$subject."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + $searchResult.="<a href=\"\" onclick=\"xajax_getAndShowSubjects('".str_replace("_"," ",substr (strrchr ($subject, "/"), 1))."');return false;\">Show more Results</a>"; + + //put whole site content into session + $_SESSION['artContent']=$content; + $_SESSION['artTitle']=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1))); + $_SESSION['artLast']=$lastArticles; + $_SESSION['artSubjects']=$searchResult; + //build the response $objResponse = new xajaxResponse(); - $objResponse->assign("articlecontent", "innerHTML", $content); - $objResponse->assign("contentbuttons", "innerHTML", $contentbuttons); - $objResponse->assign("ArticleTitle","innerHTML",str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))); - $objResponse->assign("lastarticles","innerHTML",$lastArticles); return $objResponse; } -function addPositive($subject) +function showArticle() { + while (!isset($_SESSION['artLast'])){ + sleep(0.5); + } + $objResponse = new xajaxResponse(); + $objResponse->assign("articlecontent", "innerHTML", $_SESSION['artContent']); + $objResponse->assign("ArticleTitle","innerHTML",$_SESSION['artTitle']); + $objResponse->assign("lastarticles","innerHTML",$_SESSION['artLast']); + $objResponse->assign("searchcontent", "innerHTML", $_SESSION['artSubjects']); + unset($_SESSION['artContent']); + unset($_SESSION['artTitle']); + unset($_SESSION['artLast']); + unset($_SESSION['artSubjects']); + + $objResponse->call('xajax_showInterests'); + return $objResponse; +} + +function getAndShowArticle($subject,$fromCache) +{ + $objResponse = new xajaxResponse(); + $objResponse->call('xajax_getarticle',"http://dbpedia.org/resource/".str_replace(" ","_",$subject),$fromCache); + $objResponse->call('xajax_showArticle'); + return $objResponse; +} + +function toPositive($subject) +{ + unset($_SESSION['negative'][$subject]); if (!isset($_SESSION['positive'])){ - $array=array($subject); + $array=array($subject => $subject); $_SESSION['positive']=$array; } else{ $array=$_SESSION['positive']; - $array[]=$subject; + $array[$subject]=$subject; $_SESSION['positive']=$array; } - $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; - $objResponse = new xajaxResponse(); - $objResponse->append("Positives", "innerHTML", $content); + $objResponse->call('xajax_showInterests'); return $objResponse; } -function addNegative($subject) +function toNegative($subject) { + unset($_SESSION['positive'][$subject]); if (!isset($_SESSION['negative'])){ - $array=array($subject); + $array=array($subject => $subject); $_SESSION['negative']=$array; } else{ $array=$_SESSION['negative']; - $array[]=$subject; + $array[$subject]=$subject; $_SESSION['negative']=$array; } - $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; - $objResponse = new xajaxResponse(); - $objResponse->append("Negatives", "innerHTML", $content); + $objResponse->call('xajax_showInterests'); return $objResponse; } @@ -193,6 +244,42 @@ return $objResponse; } +function showInterests() +{ + //add Positives and Negatives to Interests + $posInterests=""; + if (isset($_SESSION['positive'])) foreach($_SESSION['positive'] as $pos){ + $posInterests=$posInterests.str_replace("_"," ",urldecode(substr (strrchr ($pos, "/"), 1)))." <a href=\"\" onclick=\"xajax_toNegative('".$pos."');return false;\"><img src=\"images/minus.jpg\" alt=\"Minus\"/></a> <a href=\"\" onclick=\"xajax_removePosInterest('".$pos."');return false;\"><img src=\"images/remove.png\" alt=\"Minus\"/></a><br/>"; + } + $negInterests=""; + if (isset($_SESSION['negative'])) foreach($_SESSION['negative'] as $neg){ + $negInterests=$negInterests.str_replace("_"," ",urldecode(substr (strrchr ($neg, "/"), 1)))." <a href=\"\" onclick=\"xajax_toPositive('".$neg."');return false;\"><img src=\"images/plus.jpg\" alt=\"Plus\"/></a> <a href=\"\" onclick=\"xajax_removeNegInterest('".$pos."');return false;\"><img src=\"images/remove.png\" alt=\"Minus\"/></a><br/>"; + } + + $objResponse=new xajaxResponse(); + $objResponse->assign('Positives','innerHTML',$posInterests); + $objResponse->assign('Negatives','innerHTML',$negInterests); + return $objResponse; +} + +function removePosInterest($subject) +{ + unset($_SESSION['positive'][$subject]); + + $objResponse = new xajaxResponse(); + $objResponse->call('xajax_showInterests'); + return $objResponse; +} + +function removeNegInterest($subject) +{ + unset($_SESSION['negative'][$subject]); + + $objResponse = new xajaxResponse(); + $objResponse->call('xajax_showInterests'); + return $objResponse; +} + function learnConcept() { if (isset($_SESSION['positive'])) @@ -247,19 +334,11 @@ return $objResponse; } -function searchAndShowArticle($keyword) +function getAndShowSubjects($keyword) { - require_once("Settings.php"); - require_once("DLLearnerConnection.php"); - $settings=new Settings(); - - $sc=new DLLearnerConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); - - $content=""; - $objResponse = new xajaxResponse(); - $objResponse->call('xajax_getarticle', "http://dbpedia.org/resource/".str_replace(" ","_",$keyword),-1); $objResponse->call('xajax_getsubjects',$keyword); + $objResponse->call('xajax_showSubjects'); return $objResponse; } Added: trunk/src/dbpedia-navigator/images/minus.jpg =================================================================== (Binary files differ) Property changes on: trunk/src/dbpedia-navigator/images/minus.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/src/dbpedia-navigator/images/plus.jpg =================================================================== (Binary files differ) Property changes on: trunk/src/dbpedia-navigator/images/plus.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-01-14 11:54:55 UTC (rev 370) +++ trunk/src/dbpedia-navigator/index.php 2008-01-15 09:29:18 UTC (rev 371) @@ -81,9 +81,9 @@ <div class="boxtitle">Search DBpedia</div> <div class="boxcontent" id="search"> <!-- Search:<br/> --> - <form onSubmit="xajax_searchAndShowArticle(document.getElementById('label').value);return false;"> + <form onSubmit="xajax_getAndShowArticle(document.getElementById('label').value,-1);return false;"> <input type="text" name="label" id="label" /><br/> - <input type="button" value="Search" class="button" onclick="xajax_searchAndShowArticle(document.getElementById('label').value);return false;" /> + <input type="button" value="Search" class="button" onclick="xajax_getAndShowArticle(document.getElementById('label').value,-1);return false;" /> <!-- <input type="button" value="Fulltext" class="button" onclick=""/> --> </form> </div> <!-- boxcontent --> @@ -131,7 +131,7 @@ <div id="content"> <div class="box"> - <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left" id="ArticleTitle">Welcome</td><td class="right"><span id="contentbuttons"></span></td></tr></table></div> + <div class="boxtitle" id="ArticleTitle">Welcome</div> <div class="boxcontent" id="article"> <div id="articlecontent" style="display:block"> <br /><br /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |