From: <sk...@us...> - 2007-10-30 16:30:32
|
Revision: 274 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=274&view=rev Author: sknappe Date: 2007-10-30 09:30:24 -0700 (Tue, 30 Oct 2007) Log Message: ----------- All calls of the dllearner from the application are now done with threads Modified Paths: -------------- trunk/src/dbpedia-navigator/Ajax-Test/Settings.php trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php trunk/src/dbpedia-navigator/Ajax-Test/index.php trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dbpedia-navigator/Ajax-Test/Settings.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/Settings.php 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dbpedia-navigator/Ajax-Test/Settings.php 2007-10-30 16:30:24 UTC (rev 274) @@ -2,6 +2,7 @@ class Settings{ public $wsdluri="http://localhost:8181/services?wsdl"; - public $dbpediauri="http://dbpedia.openlinksw.com:8890/sparql"; + public $dbpediauri="http://dbpedia.openlinksw.com:8890/sparql"; + public $sparqlttl=40; } ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php 2007-10-30 16:30:24 UTC (rev 274) @@ -16,7 +16,7 @@ $this->client=new SoapClient("main.wsdl"); } - function getConceptFromExamples($posExamples,$negExamples) + function getConceptFromExamples($ttl,$posExamples,$negExamples) { $id=$this->client->generateID(); @@ -64,13 +64,14 @@ $seconds = $i * $sleeptime; $i++; - } while($running); + } while($seconds<$ttl&&$running); + $this->client->stop($id); } return $concept; } - function getTriples($individual) + function getTriples($ttl,$individual) { $id=$this->client->generateID(); @@ -85,34 +86,93 @@ $this->client->applyConfigEntryBoolean($id, $ksID, "dumpToFile", false); $this->client->applyConfigEntryBoolean($id,$ksID,"useLits",true); - $object=$this->client->getTriples($id,$ksID); - $array=$object->item; - $ret=array(); - foreach ($array as $element) - { - $items=preg_split("[<]",$element,-1, PREG_SPLIT_NO_EMPTY); - $ret[$items[1]]=$items[2]; - } + $options=array("triples"); + $this->client->startThread($id,$ksID,$options); + $i = 1; + $sleeptime = 1; + + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($id,$ksID,"triples")) + { + $object=$this->client->getFromSparql($id,$ksID,"triples"); + $array=$object->item; + $ret=array(); + foreach ($array as $element) + { + $items=preg_split("[<]",$element,-1, PREG_SPLIT_NO_EMPTY); + $ret[$items[1]]=$items[2]; + } + return $ret; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); - return $ret; + $this->client->stopSparqlThread($id,$ksID,"triples"); + return array(); } - function getSubjects($label='Leipzig',$limit=5) + function getSubjects($ttl,$label='Leipzig',$limit=5) { $id=$this->client->generateID(); $ksID = $this->client->addKnowledgeSource($id, "sparql", $this->DBPediaUrl); - $object=$this->client->getSubjects($id,$ksID,$label,$limit); - return $object->item; + + $options=array("subjects",$label,$limit); + $this->client->startThread($id,$ksID,$options); + $i = 1; + $sleeptime = 1; + + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($id,$ksID,"subjects")) + { + $object=$this->client->getFromSparql($id,$ksID,"subjects"); + return $object->item; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); + + $this->client->stopSparqlThread($id,$ksID,"subjects"); + return array(); } - function getSubjectsFromConcept($concept) + function getSubjectsFromConcept($ttl,$concept) { $id=$this->client->generateID(); $ksID = $this->client->addKnowledgeSource($id, "sparql", $this->DBPediaUrl); - $object=$this->client->getSubjectsFromConcept($id,$ksID,$concept); - return $object->item; + $options=array("conceptSubjects",$concept); + $this->client->startThread($id,$ksID,$options); + $i = 1; + $sleeptime = 1; + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($id,$ksID,"conceptSubjects")) + { + $object=$this->client->getFromSparql($id,$ksID,"conceptSubjects"); + return $object->item; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); + + $this->client->stopSparqlThread($id,$ksID,"conceptSubjects"); + return array(); } public function loadWSDLfiles($wsdluri){ Modified: trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php 2007-10-30 16:30:24 UTC (rev 274) @@ -1,4 +1,5 @@ <?php +ini_set('max_execution_time',200); session_start(); function getsubjects($label, $limit) { @@ -8,10 +9,13 @@ $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); $content=""; - $subjects=$sc->getSubjects($label,$limit); - foreach ($subjects as $subject) - { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + $subjects=$sc->getSubjects($settings->sparqlttl,$label,$limit); + if (count($subjects)==0) $content.="No search result found in time."; + else{ + foreach ($subjects as $subject) + { + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + } } $objResponse = new xajaxResponse(); @@ -25,13 +29,16 @@ require_once("SparqlConnection.php"); $settings=new Settings(); $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); - $triples=$sc->getTriples($subject); - $content=""; - $content.="<img src=\"".$triples['http://xmlns.com/foaf/0.1/img']."\" alt=\"Picture of ".urldecode(substr (strrchr ($subject, "/"), 1))."\" width=\"50\"/ style=\"float:left\">"; - $content.="<div>".$triples['http://dbpedia.org/property/abstract']."</div>"; + $triples=$sc->getTriples($settings->sparqlttl,$subject); + if (count($triples)==0) $content.="Article not found."; + else { + $content=""; + $content.="<img src=\"".$triples['http://xmlns.com/foaf/0.1/img']."\" alt=\"Picture of ".urldecode(substr (strrchr ($subject, "/"), 1))."\" width=\"50\"/ style=\"float:left\">"; + $content.="<div>".$triples['http://dbpedia.org/property/abstract']."</div>"; + + $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="<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;\" />"; - $objResponse = new xajaxResponse(); $objResponse->assign("articlecontent", "innerHTML", $content); $objResponse->assign("contentbuttons", "innerHTML", $contentbuttons); @@ -103,9 +110,9 @@ $settings=new Settings(); $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); - $concept=$sc->getConceptFromExamples($_SESSION['positive'],$_SESSION['negative']); + $concept=$sc->getConceptFromExamples($settings->sparqlttl,$_SESSION['positive'],$_SESSION['negative']); $_SESSION['lastLearnedConcept']=$concept; - $concept=urldecode(substr (strrchr ($concept, "/"), 1)); + if (strlen(substr (strrchr ($concept, "/"), 1))>0) $concept=urldecode(substr (strrchr ($concept, "/"), 1)); } else $concept="You must choose at least one<br/> positive and one negative example."; @@ -124,10 +131,13 @@ $content=""; if (isset($_SESSION['lastLearnedConcept'])) { - $subjects=$sc->getSubjectsFromConcept($_SESSION['lastLearnedConcept']); - foreach ($subjects as $subject) - { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + $subjects=$sc->getSubjectsFromConcept($settings->sparqlttl,$_SESSION['lastLearnedConcept']); + if (count($subjects)==0) $content.="No examples for concept found in time."; + else { + foreach ($subjects as $subject) + { + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + } } } else $content.="No concept to get Subjects from."; Modified: trunk/src/dbpedia-navigator/Ajax-Test/index.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/index.php 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dbpedia-navigator/Ajax-Test/index.php 2007-10-30 16:30:24 UTC (rev 274) @@ -1,12 +1,13 @@ <?php +ini_set('error_reporting',E_ALL); +ini_set('max_execution_time',200); session_start(); echo "<a href='clearsession.php'>start from scratch</a>"; require("ajax.php"); - ini_set('error_reporting',E_ALL); - ini_set('max_execution_time',200); + echo '<?xml version="1.0" encoding="UTF-8"?>' ?> <html> @@ -14,7 +15,7 @@ <title>DL Learner</title> <meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\"/> <link rel="stylesheet" href="default.css"/> - <?php $xajax->printJavascript('xajax/'); ?> + <?php $xajax->printJavascript('xajax/'); ?> <script type="text/javascript"> showLoadingSubjects = function() { xajax.$('loadingSubject').style.display='block'; @@ -49,7 +50,7 @@ xajax.$('conceptsubjectcontent').style.display = 'block'; } </script> - </head> + </head> <body> <h3>DBPedia-Navigator-Test</h3> <div id="layer" style="display:none"><div id="layerContent" style="display:none"></div></div> @@ -59,7 +60,6 @@ <div class="box" id="search"> <div class="boxtitle">Search</div> <div class="boxcontent"> - <form action="index.php" method="GET" id="searchForm"> <table border="0"> <tr><tb>Search:<br/></tb></tr> <tr><tb><input type="textfield" name="label" id="label"> <select name="limit" size="1" id="limit"> @@ -68,9 +68,8 @@ <option>10</option> <option>15</option> </select><br/></tb></tr> - <tr><tb><input type="button" value="Search" class="button" onclick="xajax_getsubjects(document.getElementById('label').value,document.getElementById('limit').value);return false;" /></tb></tr> + <tr><tb><input type="button" value="Search" class="button" onclick="xajax_getsubjects(document.getElementById('label').value,document.getElementById('limit').value);return false;"/></tb></tr> </table> - </form> </div> <!-- boxcontent --> </div> <!-- box --> Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-30 16:30:24 UTC (rev 274) @@ -69,6 +69,39 @@ private boolean dumpToFile; private boolean useLits=false; + /** + * Holds the results of the calculateSubjects method + */ + private String[] subjects; + + /** + * Holds the results of the calculateTriples method + */ + private String[] triples; + + /** + * Holds the results of the calculateConceptSubjects method + */ + private String[] conceptSubjects; + + /** + * if a method is running this becomes true + */ + private boolean subjectThreadRunning=false; + + private boolean triplesThreadRunning=false; + + private boolean conceptThreadRunning=false; + + /** + * the Thread that is running a method + */ + private Thread subjectThread; + + private Thread triplesThread; + + private Thread conceptThread; + //received ontology as array, used if format=Array(an element of the //array consists of the subject, predicate and object separated by '<' private String[] ontArray; @@ -196,30 +229,96 @@ return ontArray; } - public String[] getSubjects(String label,int limit) + public void calculateSubjects(String label,int limit) { System.out.println("SparqlModul: Collecting Subjects"); SparqlOntologyCollector oc=new SparqlOntologyCollector(url); - String[] ret=oc.getSubjectsFromLabel(label,limit); + subjects=oc.getSubjectsFromLabel(label,limit); System.out.println("SparqlModul: ****Finished"); - return ret; } - public String[] getTriples(){ + public void calculateTriples(){ System.out.println("SparqlModul: Collecting Triples"); SparqlOntologyCollector oc=new SparqlOntologyCollector(Datastructures.setToArray(instances), numberOfRecursions, filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format,url,useLits); - String[] ret=oc.collectTriples(); + triples=oc.collectTriples(); System.out.println("SparqlModul: ****Finished"); - return ret; } - public String[] getSubjectsFromConcept(String concept) + public void calculateConceptSubjects(String concept) { System.out.println("SparqlModul: Collecting Subjects"); SparqlOntologyCollector oc=new SparqlOntologyCollector(url); - String[] ret=oc.getSubjectsFromConcept(concept); + conceptSubjects=oc.getSubjectsFromConcept(concept); System.out.println("SparqlModul: ****Finished"); - return ret; } + + public boolean subjectThreadIsRunning() + { + return subjectThreadRunning; + } + + public void setSubjectThreadRunning(boolean bool) + { + subjectThreadRunning=bool; + } + + public boolean triplesThreadIsRunning() + { + return triplesThreadRunning; + } + + public void setTriplesThreadRunning(boolean bool) + { + triplesThreadRunning=bool; + } + + public boolean conceptThreadIsRunning() + { + return conceptThreadRunning; + } + + public void setConceptThreadRunning(boolean bool) + { + conceptThreadRunning=bool; + } + + public String[] getSubjects() + { + return subjects; + } + + public Thread getSubjectThread() { + return subjectThread; + } + + public void setSubjectThread(Thread subjectThread) { + this.subjectThread = subjectThread; + } + + public Thread getTriplesThread() { + return triplesThread; + } + + public void setTriplesThread(Thread triplesThread) { + this.triplesThread = triplesThread; + } + + public Thread getConceptThread() { + return conceptThread; + } + + public void setConceptThread(Thread conceptThread) { + this.conceptThread = conceptThread; + } + + public String[] getTriples() + { + return triples; + } + + public String[] getConceptSubjects() + { + return conceptSubjects; + } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-10-29 13:15:28 UTC (rev 273) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-10-30 16:30:24 UTC (rev 274) @@ -449,27 +449,99 @@ return Datastructures.sortedSet2StringListIndividuals(individuals); } + //////////////////////////////////// + // sparql modul methods // + //////////////////////////////////// + + @WebMethod - public String[] getTriples(int id, int componentID) throws ClientNotKnownException + public void startThread(int id, int componentID, String[] options) throws ClientNotKnownException { - ClientState state=getState(id); + final ClientState state = getState(id); + final Component component = state.getComponent(componentID); + String method=options[0]; + Thread thread=null; + if (method.equals("subjects")){ + final String label=options[1]; + final int limit=Integer.parseInt(options[2]); + thread = new Thread() { + @Override + public void run() { + ((SparqlEndpoint)component).setSubjectThread(this); + ((SparqlEndpoint)component).setSubjectThreadRunning(true); + ((SparqlEndpoint)component).calculateSubjects(label,limit); + ((SparqlEndpoint)component).setSubjectThreadRunning(false); + } + }; + } else if (method.equals("triples")){ + thread = new Thread() { + @Override + public void run() { + ((SparqlEndpoint)component).setTriplesThread(this); + ((SparqlEndpoint)component).setTriplesThreadRunning(true); + ((SparqlEndpoint)component).calculateTriples(); + ((SparqlEndpoint)component).setTriplesThreadRunning(false); + } + }; + } else if (method.equals("conceptSubjects")){ + final String concept=options[1]; + thread = new Thread() { + @Override + public void run() { + ((SparqlEndpoint)component).setConceptThread(this); + ((SparqlEndpoint)component).setConceptThreadRunning(true); + ((SparqlEndpoint)component).calculateConceptSubjects(concept); + ((SparqlEndpoint)component).setConceptThreadRunning(false); + } + }; + } + thread.start(); + } + + @WebMethod + public boolean isThreadRunning(int id, int componentID, String option) throws ClientNotKnownException + { + ClientState state = getState(id); Component component = state.getComponent(componentID); - return ((SparqlEndpoint)component).getTriples(); + if (option.equals("subjects")) + return ((SparqlEndpoint)component).subjectThreadIsRunning(); + else if (option.equals("triples")) + return ((SparqlEndpoint)component).triplesThreadIsRunning(); + else if (option.equals("conceptSubjects")) + return ((SparqlEndpoint)component).conceptThreadIsRunning(); + return true; } @WebMethod - public String[] getSubjects(int id, int componentID, String label, int limit) throws ClientNotKnownException + public void stopSparqlThread(int id, int componentID, String option) throws ClientNotKnownException { - ClientState state=getState(id); + ClientState state = getState(id); Component component = state.getComponent(componentID); - return ((SparqlEndpoint)component).getSubjects(label,limit); + if (option.equals("subjects")) + ((SparqlEndpoint)component).getSubjectThread().stop(); + else if (option.equals("triples")) + ((SparqlEndpoint)component).getTriplesThread().stop(); + else if (option.equals("conceptSubjects")) + ((SparqlEndpoint)component).getConceptThread().stop(); } @WebMethod - public String[] getSubjectsFromConcept(int id, int componentID, String concept) throws ClientNotKnownException + public String[] getFromSparql(int id, int componentID, String option) throws ClientNotKnownException { - ClientState state=getState(id); + ClientState state = getState(id); Component component = state.getComponent(componentID); - return ((SparqlEndpoint)component).getSubjectsFromConcept(concept); + if (option.equals("subjects")) + return ((SparqlEndpoint)component).getSubjects(); + else if (option.equals("triples")) + return ((SparqlEndpoint)component).getTriples(); + else if (option.equals("conceptSubjects")) + return ((SparqlEndpoint)component).getConceptSubjects(); + return new String[0]; } + + @WebMethod + public void debug(String deb) + { + System.out.println(deb); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |