You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <sk...@us...> - 2008-07-06 12:34:40
|
Revision: 1000 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1000&view=rev Author: sknappe Date: 2008-07-06 05:34:38 -0700 (Sun, 06 Jul 2008) Log Message: ----------- Changed some things to work with the Maipulator and fixed some bugs (the SparqlQueryMaker didn't produce queries without failures at all filter combinations, I changed that) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java 2008-07-06 12:28:50 UTC (rev 999) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java 2008-07-06 12:34:38 UTC (rev 1000) @@ -71,10 +71,26 @@ public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { Set<StringTuple> toRemove = new HashSet<StringTuple>(); Iterator<StringTuple> it = tuples.iterator(); + float lat=0; + float lng=0; + String clas=""; + StringTuple typeTupel=null; + if (node.uri.toString().equals("http://dbpedia.org/class/custom/City_in_Saxony")) + tuples.add(new StringTuple("http://www.w3.org/2000/01/rdf-schema#subClassOf","http://dbpedia.org/class/yago/City108524735")); while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); + + if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ + clas=t.b; + typeTupel=t; + } - replacePredicate(t); + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) + lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) + lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + + /*replacePredicate(t); replaceObject(t); @@ -94,10 +110,16 @@ if (t.a.equals(type) && t.b.equals(thing) && node instanceof InstanceNode) { toRemove.add(t); - } + }*/ } - tuples.removeAll(toRemove); + if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ + if (lat>50&&lat<52&&lng>12&&lng<13){ + tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type","http://dbpedia.org/class/custom/City_in_Saxony")); + tuples.remove(typeTupel); + } + } + //tuples.removeAll(toRemove); return tuples; } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-07-06 12:28:50 UTC (rev 999) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-07-06 12:34:38 UTC (rev 1000) @@ -51,7 +51,7 @@ Set<StringTuple> s = tsq.getTupelForResource(uri); // see Manipulator - m.check(s, this); + s=m.check(s, this); // System.out.println("fffffff"+m); Vector<Node> Nodes = new Vector<Node>(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-07-06 12:28:50 UTC (rev 999) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-07-06 12:34:38 UTC (rev 1000) @@ -40,10 +40,13 @@ public String makeSubjectQueryUsingFilters(String subject) { String Filter = internalFilterAssemblySubject(); - String ret = "SELECT * WHERE { " + lineend + "<" + subject + String ret=""; + if (Filter.length()>0) ret = "SELECT * WHERE { " + lineend + "<" + subject + "> ?predicate ?object. " + lineend + "FILTER( " + lineend - + "(" + Filter + ").}"; - // System.out.println(ret); + + Filter + ").}"; + else ret="SELECT * WHERE { " + lineend + "<" + subject + + "> ?predicate ?object}"; + // System.out.println("Query: "+ret); // System.out.println(sparqlQueryType.getPredicatefilterlist().length); return ret; } @@ -89,14 +92,51 @@ private String internalFilterAssemblySubject() { String Filter = ""; - if (!this.sparqlQueryType.isLiterals()) - Filter += "!isLiteral(?object))"; + if (!this.sparqlQueryType.isLiterals()){ + Filter += "(!isLiteral(?object))"; + if (sparqlQueryType.getPredicatefilterlist().size()>0) + Filter += "&&("; + } + else if (sparqlQueryType.getPredicatefilterlist().size()>0) + Filter += "("; + int i=1; for (String p : sparqlQueryType.getPredicatefilterlist()) { - Filter += lineend + filterPredicate(p); + if (this.sparqlQueryType.getMode()=="forbid") + if (!this.sparqlQueryType.isLiterals()||i!=1) + Filter += lineend + filterPredicate(p); + else + Filter += lineend + filterPredicate(p).substring(2); + else if (this.sparqlQueryType.getMode()=="allow") + if (!this.sparqlQueryType.isLiterals()||i!=1) + Filter += lineend + allowPredicate(p); + else + Filter += lineend + allowPredicate(p).substring(2); + i++; } + if (sparqlQueryType.getPredicatefilterlist().size()>0) + Filter += ")"; + + if ((sparqlQueryType.getPredicatefilterlist().size()>0||!this.sparqlQueryType.isLiterals())&&sparqlQueryType.getObjectfilterlist().size()>0) + Filter += "&&("; + else if (sparqlQueryType.getObjectfilterlist().size()>0) + Filter += "("; + i=1; for (String o : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterObject(o); + if (this.sparqlQueryType.getMode()=="forbid") + if (!this.sparqlQueryType.isLiterals()||i!=1) + Filter += lineend + filterObject(o); + else + Filter += lineend + filterObject(o).substring(2); + else if (this.sparqlQueryType.getMode()=="allow") + if (!this.sparqlQueryType.isLiterals()||i!=1) + Filter += lineend + allowObject(o); + else + Filter += lineend + allowObject(o).substring(2); + i++; } + if (sparqlQueryType.getObjectfilterlist().size()>0) + Filter += ")"; + return Filter; } @@ -125,7 +165,15 @@ private static String filterObject(String ns) { return "&&( !regex(str(?object), '" + ns + "') )"; } + + private static String allowPredicate(String ns) { + return "||( regex(str(?predicate), '" + ns + "') )"; + } + private static String allowObject(String ns) { + return "||( regex(str(?object), '" + ns + "') )"; + } + /*private void p(String str) { if (print_flag) { System.out.println(str); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-07-06 12:28:50 UTC (rev 999) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-07-06 12:34:38 UTC (rev 1000) @@ -78,6 +78,8 @@ return YagoSpecialHierarchy(); if (name.equals("TEST")) return test(); + if (name.equals("DBPEDIA-NAVIGATOR")) + return DBpediaNavigatorFilter(); return null; } @@ -111,6 +113,24 @@ return new SparqlQueryType("forbid", obj, pred, false); } + + public static SparqlQueryType DBpediaNavigatorFilter(){ + Set<String> pred = new HashSet<String>(); + pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf"); + pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); + pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long"); + //pred.add("http://dbpedia.org/property/wikipage"); + //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + //pred.add("http://dbpedia.org/property/relatedInstance"); + //pred.add("http://dbpedia.org/property/owner"); + //pred.add("http://dbpedia.org/property/standard"); + + Set<String> obj = new HashSet<String>(); + + return new SparqlQueryType("allow", obj, pred, true); + } + public static SparqlQueryType YagoSpecialHierarchy(){ Set<String> pred = new HashSet<String>(); pred.add("http://www.w3.org/2004/02/skos/core"); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-06 12:28:50 UTC (rev 999) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-06 12:34:38 UTC (rev 1000) @@ -675,8 +675,8 @@ SparqlKnowledgeSource ks=(SparqlKnowledgeSource)component; SPARQLTasks task=ks.getSparqlTask(); AutomaticNegativeExampleFinderSPARQL finder=new AutomaticNegativeExampleFinderSPARQL(set,task); - finder.makeNegativeExamplesFromRelatedInstances(set, namespace); - finder.makeNegativeExamplesFromParallelClasses(set, 2); + //finder.makeNegativeExamplesFromRelatedInstances(set, namespace); + finder.makeNegativeExamplesFromParallelClasses(set, 5); SortedSet<String> negExamples=finder.getNegativeExamples(results); return negExamples.toArray(new String[negExamples.size()]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-07-06 12:28:56
|
Revision: 999 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=999&view=rev Author: sknappe Date: 2008-07-06 05:28:50 -0700 (Sun, 06 Jul 2008) Log Message: ----------- Changed to work with new Manipulator Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-07-05 14:21:07 UTC (rev 998) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-07-06 12:28:50 UTC (rev 999) @@ -46,19 +46,23 @@ $settings=new Settings(); $this->client->applyConfigEntryInt($this->id, $this->ksID, "recursionDepth",1); - $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "instances", array_merge($posExamples,$negExamples)); - $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedFilter", "YAGO"); + $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedFilter", "DBPEDIA-NAVIGATOR"); + //$this->client->applyConfigEntryBoolean($this->id, $this->ksID, "useLits", true); $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedEndpoint", "DBPEDIA"); + $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedManipulator", "DBPEDIA-NAVIGATOR"); $this->client->applyConfigEntryBoolean($this->id, $this->ksID, "useCache", $settings->useCache); + if(empty($negExamples)){ + $negExamples=$this->client->getNegativeExamples($this->id,$this->ksID,$posExamples,count($posExamples),"http://dbpedia.org/resource/"); + $negExamples=$negExamples->item; + + var_dump($negExamples); + } + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "instances", array_merge($posExamples,$negExamples)); $this->client->setReasoner($this->id, "fastInstanceChecker"); - /*if(empty($negExamples)) + if(empty($negExamples)) $this->client->setLearningProblem($this->id, "posOnlyDefinition"); else - $this->client->setLearningProblem($this->id, "posNegDefinition");*/ - $this->client->setLearningProblem($this->id, "posNegDefinition"); - if(empty($negExamples)){ - $negExamples=$this->client->getNegativeExamples($this->id,$this->ksID,$posExamples,count($posExamples),"http://dbpedia.org/resource/"); - } + $this->client->setLearningProblem($this->id, "posNegDefinition"); $this->client->setPositiveExamples($this->id, $posExamples); if(!empty($negExamples)) $this->client->setNegativeExamples($this->id, $negExamples); @@ -334,11 +338,11 @@ } } -/* + ini_set('default_socket_timeout',200); $sc=new DLLearnerConnection(); $ids=$sc->getIDs(); $sc=new DLLearnerConnection($ids[0],$ids[1]); -$triples=$sc->getSubjects("Leipzig"); -var_dump($triples);*/ +$triples=$sc->getConceptFromExamples(array('http://dbpedia.org/resource/Leipzig'),array()); +var_dump($triples); ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-07-05 14:21:14
|
Revision: 998 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=998&view=rev Author: sknappe Date: 2008-07-05 07:21:07 -0700 (Sat, 05 Jul 2008) Log Message: ----------- modified to work with changes in the ws 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-07-05 14:20:26 UTC (rev 997) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-07-05 14:21:07 UTC (rev 998) @@ -51,10 +51,14 @@ $this->client->applyConfigEntryString($this->id, $this->ksID, "predefinedEndpoint", "DBPEDIA"); $this->client->applyConfigEntryBoolean($this->id, $this->ksID, "useCache", $settings->useCache); $this->client->setReasoner($this->id, "fastInstanceChecker"); - if(empty($negExamples)) + /*if(empty($negExamples)) $this->client->setLearningProblem($this->id, "posOnlyDefinition"); else - $this->client->setLearningProblem($this->id, "posNegDefinition"); + $this->client->setLearningProblem($this->id, "posNegDefinition");*/ + $this->client->setLearningProblem($this->id, "posNegDefinition"); + if(empty($negExamples)){ + $negExamples=$this->client->getNegativeExamples($this->id,$this->ksID,$posExamples,count($posExamples),"http://dbpedia.org/resource/"); + } $this->client->setPositiveExamples($this->id, $posExamples); if(!empty($negExamples)) $this->client->setNegativeExamples($this->id, $negExamples); @@ -82,7 +86,7 @@ sleep($sleeptime); // see what we have learned so far - $concepts=$this->client->getCurrentlyBestConcepts($this->id,3); + $concepts=$this->client->getCurrentlyBestConcepts($this->id,3,"kb"); $running=$this->client->isAlgorithmRunning($this->id); $seconds = $i * $sleeptime; @@ -122,7 +126,7 @@ function getTriples($uri) { $query="SELECT ?pred ?obj ". - "WHERE {{<".$uri."> ?pred ?obj}UNION{<".$uri."> <http://dbpedia.org/property/redirect> ?Conc.?Conc ?pred ?obj}}"; + "WHERE {{<".$uri."> ?pred ?obj.Filter(!regex(str(?pred),'http://dbpedia.org/property/reference'))}UNION{<".$uri."> <http://dbpedia.org/property/redirect> ?Conc.?Conc ?pred ?obj.Filter(!regex(str(?pred),'http://dbpedia.org/property/reference'))}}"; $result=json_decode($this->getSparqlResultThreaded($query),true); if (count($result['results']['bindings'])==0) throw new Exception("Your query brought no result. The Label-Search is started."); $ret=array(); Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-07-05 14:20:26 UTC (rev 997) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-07-05 14:21:07 UTC (rev 998) @@ -220,7 +220,7 @@ $objResponse->assign("lastarticles","innerHTML",$lastArticles); $objResponse->assign('Positives','innerHTML',$posInterests); $objResponse->assign('Negatives','innerHTML',$negInterests); - //$objResponse->call('xajax_learnConcept'); + $objResponse->call('xajax_learnConcept'); return $objResponse; } @@ -392,7 +392,7 @@ $concept.="<table border=0>\n"; $i=1; foreach ($concepts as $con){ - $concept.="<tr><td><a href=\"\" onclick=\"xajax_getSubjectsFromConcept('".urlencode($con)."');return false;\" onMouseOver=\"showdiv('div".$i."');showdiv('ConceptBox');\" onMouseOut=\"hidediv('div".$i."');hidediv('ConceptBox');\" />".$con."</a></td></tr>"; + $concept.="<tr><td><a href=\"\" onclick=\"xajax_getSubjectsFromConcept('".htmlentities($con)."');return false;\" onMouseOver=\"showdiv('div".$i."');showdiv('ConceptBox');\" onMouseOut=\"hidediv('div".$i."');hidediv('ConceptBox');\" />".$con."</a></td></tr>"; //put information about concepts in divs //$conceptinformation.="<div id=\"div".$i."\" style=\"display:none\">Concept Depth: ".$conceptDepth[$i-1]."<br/>Concept Arity: ".$conceptArity[$i-1]."<br/>Concept Length: ".$sc->getConceptLength($con)."</div>"; $i++; @@ -421,7 +421,7 @@ setRunning($id,"true"); - $concept=urldecode($concept); + $concept=html_entity_decode($concept); $content=""; try{ require_once("DLLearnerConnection.php"); @@ -462,7 +462,7 @@ //delete whitespaces at beginning and end $subject=trim($subject); //get first letters big - $subject=ucwords($subject); + $subject=ucfirst($subject); //replace spaces with _ $subject=str_replace(' ','_',$subject); //add the uri @@ -486,7 +486,8 @@ else if ($count>($min+$distribution)) $style="font-size:medium;"; else $style="font-size:small;"; - $ret.='<a style="'.$style.'" href="#" onclick="xajax_getSubjectsFromConcept(\''.$tag.'\');">'.$label[$tag].'</a>'; + $tag_with_entities=htmlentities("\"".$tag."\""); + $ret.='<a style="'.$style.'" href="#" onclick="xajax_getSubjectsFromConcept(\''.$tag_with_entities.'\');">'.$label[$tag].'</a>'; } $ret.="</p>"; return $ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-07-05 14:20:37
|
Revision: 997 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=997&view=rev Author: sknappe Date: 2008-07-05 07:20:26 -0700 (Sat, 05 Jul 2008) Log Message: ----------- Several changes to make everything working Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-03 12:01:50 UTC (rev 996) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-05 14:20:26 UTC (rev 997) @@ -264,7 +264,7 @@ addToCache(query.getQueryString(), json); SparqlQuery.writeToSparqlLog("result added to cache: "+json); result=json; - query.setJson(result); + //query.setJson(result); } else { json=""; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-03 12:01:50 UTC (rev 996) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-05 14:20:26 UTC (rev 997) @@ -418,6 +418,15 @@ return new SparqlQuery(query, endpoint); } + public SPARQLTasks getSparqlTask() + { + if (this.useCache) + return new SPARQLTasks(new Cache(this.cacheDir),new SparqlEndpoint(url, defaultGraphURIs, + namedGraphURIs)); + else + return new SPARQLTasks(new SparqlEndpoint(url, defaultGraphURIs, + namedGraphURIs)); + } /* (non-Javadoc) * @see org.dllearner.core.KnowledgeSource#toKB() Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-03 12:01:50 UTC (rev 996) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-05 14:20:26 UTC (rev 997) @@ -100,6 +100,11 @@ HttpQuery.urlLimit = 3 * 1024; JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime") .start(); + //TODO correct Bug: when there is a & in the result like in the + //URL: http://www.discusmedia.com/catalog.php?catID=5.2.2&profile=map + //the XML Parser throws an error, because he thinks &profile is an html entitie + //but it doesn't end with an ; + //the & must be masked to an & but I am not sure at the moment how to do that rs = queryExecution.execSelect(); JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop(); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-03 12:01:50 UTC (rev 996) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-05 14:20:26 UTC (rev 997) @@ -58,6 +58,8 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; @@ -72,6 +74,7 @@ import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; /** * DL-Learner web service interface. @@ -664,6 +667,22 @@ } @WebMethod + public String[] getNegativeExamples(int sessionID, int componentID,String[] positives, int results, String namespace) throws ClientNotKnownException + { + SortedSet<String> set = new TreeSet<String>(Arrays.asList(positives)); + ClientState state = getState(sessionID); + Component component = state.getComponent(componentID); + SparqlKnowledgeSource ks=(SparqlKnowledgeSource)component; + SPARQLTasks task=ks.getSparqlTask(); + AutomaticNegativeExampleFinderSPARQL finder=new AutomaticNegativeExampleFinderSPARQL(set,task); + finder.makeNegativeExamplesFromRelatedInstances(set, namespace); + finder.makeNegativeExamplesFromParallelClasses(set, 2); + SortedSet<String> negExamples=finder.getNegativeExamples(results); + + return negExamples.toArray(new String[negExamples.size()]); + } + + @WebMethod public void debug(String deb) { System.out.println(deb); Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-03 12:01:50 UTC (rev 996) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-05 14:20:26 UTC (rev 997) @@ -1,11 +1,14 @@ package org.dllearner.utilities.examples; +import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.core.ComponentManager; +import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.datastructures.SetManipulation; public class AutomaticNegativeExampleFinderSPARQL { @@ -175,6 +178,4 @@ this.fromRange.removeAll(this.fullPositiveSet); logger.debug("|-neg Example size from Range: "+this.fromRange.size()); } - - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hee...@us...> - 2008-07-03 12:01:56
|
Revision: 996 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=996&view=rev Author: heeroyuy Date: 2008-07-03 05:01:50 -0700 (Thu, 03 Jul 2008) Log Message: ----------- -started a panel for more infos for the concept Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-06-30 14:37:58 UTC (rev 995) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-07-03 12:01:50 UTC (rev 996) @@ -9,13 +9,15 @@ import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; +import javax.swing.JDialog; + import org.dllearner.core.owl.Description; /** * * @author Heero Yuy * */ -public class ActionHandler implements ActionListener, ItemListener, MouseListener, ListSelectionListener{ +public class ActionHandler implements ActionListener, ItemListener, MouseListener, ListSelectionListener{ /** * This is the DLLearnerModel. */ @@ -37,6 +39,7 @@ * This is the view of the DL-Learner tab. */ private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; + private JDialog detailDialog; /** * This is the constructor for the action handler * @param a ActionHandler @@ -132,6 +135,10 @@ view.setExamplePanelVisible(toggled); } } + if(z.getActionCommand().equals("Why")) + { + view.getMoreDetailForSuggestedConceptsPanel().renderDetailPanel(model.getEvaluatedDescription()); + } } /** @@ -226,6 +233,7 @@ { if(!view.getAddButton().isEnabled()) { + view.getWhyButton().setEnabled(true); view.getAddButton().setEnabled(true); } } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-30 14:37:58 UTC (rev 995) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-07-03 12:01:50 UTC (rev 996) @@ -1,8 +1,8 @@ package org.dllearner.tools.protege; -import java.util.Observable; import java.util.Set; import java.util.TreeSet; +//import java.util.List; import java.util.Vector; import java.util.HashSet; import java.util.Iterator; @@ -16,6 +16,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ComponentManager; @@ -51,12 +52,12 @@ -/** +/**2 * This Class provides the necessary methods to learn Concepts from the DL-Learner. * @author Heero Yuy * */ -public class DLLearnerModel extends Observable implements Runnable{ +public class DLLearnerModel implements Runnable{ /** * The Sting is for components that are available in the DL-Learner */ @@ -175,7 +176,7 @@ * */ private OWLAxiom axiomOWLAPI; - + private EvaluatedDescription evalDescription; /** * This is the constructor for DL-Learner model * @param editorKit @@ -224,9 +225,10 @@ */ private void addToListModel() { + evalDescription = la.getCurrentlyBestEvaluatedDescription(); for(int j = 0;j<la.getCurrentlyBestEvaluatedDescriptions(anzahl).size();j++) { - suggestModel.add(j,la.getCurrentlyBestEvaluatedDescriptions(anzahl).get(j)); + suggestModel.add(j,la.getCurrentlyBestEvaluatedDescriptions(anzahl).get(j).getDescription()); } } @@ -356,7 +358,6 @@ addToListModel(); view.renderErrorMessage(error); view.getRunButton().setEnabled(true); - //view.getPosAndNegSelectPanel().unsetCheckBoxes(); view.getCancelButton().setEnabled(false); view.getSuggestClassPanel().setSuggestList(suggestModel); } @@ -426,6 +427,10 @@ } } + public EvaluatedDescription getEvaluatedDescription() + { + return evalDescription; + } /** * This method resets the Concepts that are learned. */ Deleted: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java 2008-06-30 14:37:58 UTC (rev 995) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java 2008-07-03 12:01:50 UTC (rev 996) @@ -1,43 +0,0 @@ -package org.dllearner.tools.protege; - -import org.protege.editor.core.ui.view.ViewComponent; -import org.protege.editor.core.ui.view.ViewComponentPlugin; -import org.protege.editor.core.ui.view.ViewComponentPluginAdapter; -import org.protege.editor.core.ui.workspace.Workspace; -import org.protege.editor.owl.ui.clshierarchy.ToldOWLClassHierarchyViewComponent; -import org.protege.editor.owl.ui.selector.AbstractSelectorPanel; -import org.protege.editor.owl.OWLEditorKit; - -public class DLLearnerViewPanel extends AbstractSelectorPanel { - - - private ToldOWLClassHierarchyViewComponent viewComponent; - private final static long serialVersionUID = 3546352435L; - public DLLearnerViewPanel(OWLEditorKit editor) - { - super(editor); - } - - @Override - protected ViewComponentPlugin getViewComponentPlugin() { - - return new ViewComponentPluginAdapter() { - public String getLabel() { - return "OWL Asserted Class Hierarchy"; - } - - - public Workspace getWorkspace() { - return getOWLEditorKit().getOWLWorkspace(); - } - - - public ViewComponent newInstance() throws ClassNotFoundException, IllegalAccessException, - InstantiationException { - viewComponent = new ToldOWLClassHierarchyViewComponent(); - viewComponent.setup(this); - return viewComponent; - } - -}; - }} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-06-30 14:37:58 UTC (rev 995) +++ trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-07-03 12:01:50 UTC (rev 996) @@ -6,7 +6,7 @@ Bundle-Description: blablabla Bundle-Vendor: blablabla Bundle-DocURL: blablabla -Bundle-ClassPath: .,lib/junit-4.4.jar,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.jar +Bundle-ClassPath: .,lib/junit-4.4.jar,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/jena/json.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.jar Import-Package: org.osgi.framework,org.apache.log4j Export-Package: lib Bundle-Version: 1.0.0 Added: trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2008-07-03 12:01:50 UTC (rev 996) @@ -0,0 +1,72 @@ +package org.dllearner.tools.protege; +import java.util.Iterator; +import java.util.Set; + +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JDialog; + +import java.awt.GridLayout; + +import org.dllearner.core.EvaluatedDescription; + +import org.dllearner.core.owl.Individual; +public class MoreDetailForSuggestedConceptsPanel extends JPanel{ + + private static final long serialVersionUID = 785272797932584581L; + + private DLLearnerModel model; + + private JLabel accuracy; + private JPanel accuracyPanel; + private JPanel coveredExamplesPanel; + + private JLabel coveredExamples; + + private JDialog detailPopup; + + private JScrollPane detailScroll; + + private JPanel detailPanel; + private EvaluatedDescription evalDescription; + public MoreDetailForSuggestedConceptsPanel(DLLearnerModel model) + { + this.model = model; + } + + public JDialog getMoreDialog() + { + return detailPopup; + } + + public JScrollPane getDetailScrollPane() + { + return detailScroll; + } + + public void renderDetailPanel(EvaluatedDescription eval) + { + this.evalDescription = eval; + accuracy = new JLabel("Accuracy:"); + coveredExamples = new JLabel("Covered Examples:"); + detailPopup = new JDialog(); + detailPopup.setSize(300, 300); + accuracyPanel = new JPanel(new GridLayout(0,1)); + coveredExamplesPanel = new JPanel(new GridLayout(0,1)); + detailScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + detailPanel = new JPanel(new GridLayout(0,2)); + accuracyPanel.add(new JLabel(String.valueOf(evalDescription.getAccuracy()))); + Set<Individual> posCovered = evalDescription.getCoveredPositives(); + for(Iterator<Individual> i = posCovered.iterator(); i.hasNext();) + { + coveredExamplesPanel.add(new JLabel(i.next().toString())); + } + detailPanel.add(accuracy); + detailPanel.add(accuracyPanel); + detailPanel.add(coveredExamples); + detailPanel.add(coveredExamplesPanel); + detailScroll.setViewportView(detailPanel); + detailPopup.add(detailScroll); + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2008-06-30 14:37:58 UTC (rev 995) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2008-07-03 12:01:50 UTC (rev 996) @@ -261,10 +261,6 @@ * */ private final static long serialVersionUID = 624829578325729385L; - /** - * - */ - private DLLearnerViewPanel panel; /** * */ @@ -280,7 +276,7 @@ /** * */ - private OWLEditorKit editor; + /** * */ @@ -312,26 +308,31 @@ /** * */ - private SuggestClassPanel sugPanel; + /** + * + */ private PosAndNegSelectPanel posPanel; + /** + * + */ private ImageIcon icon; + /** + * + */ private ImageIcon toggledIcon; /** * - * @return */ - public DLLearnerViewPanel getDLLearnerViewPanel() - { - return panel; - } + private JButton why; + private MoreDetailForSuggestedConceptsPanel detail; /** * The constructor for the DL-Learner tab in the class description editor * @param aktuell * @param label */ - public DLLearnerView(OWLFrame<OWLClass> aktuell,String label){ - editor = editorKit; + public DLLearnerView(OWLFrame<OWLClass> aktuell,String label) + { classSelectorPanel = new OWLClassSelectorPanel(editorKit); classSelectorPanel.firePropertyChange("test", false, true); URL iconUrl = this.getClass().getResource("pfeil.gif"); @@ -339,7 +340,6 @@ URL toggledIconUrl = this.getClass().getResource("pfeil2.gif"); toggledIcon = new ImageIcon(toggledIconUrl); model = new DLLearnerModel(editorKit,aktuell, label,this); - panel = new DLLearnerViewPanel(editor); sugPanel = new SuggestClassPanel(); action = new ActionHandler(this.action, model,this,label); adv = new JLabel("Advanced"); @@ -348,6 +348,7 @@ run = new JButton("Suggest "+label); cancel = new JButton("Cancel"); accept = new JButton("ADD"); + why = new JButton("Why"); sugPanel.addSuggestPanelMouseListener(action); errorMessage = new JLabel(); learner = new JPanel(); @@ -361,6 +362,7 @@ addRunButtonListener(this.action); addCancelButtonListener(this.action); addAdvancedButtonListener(this.action); + addWhyButtonListener(this.action); } @@ -379,6 +381,7 @@ */ public void makeView() { + why.setEnabled(false); advanced.setIcon(icon); model.clearVector(); model.unsetListModel(); @@ -390,6 +393,7 @@ action.resetToggled(); sugPanel.setSuggestList(model.getSuggestList()); sugPanel = sugPanel.updateSuggestClassList(); + why.setBounds(10,160,200,30); advanced.setSelected(false); sugPanel.setBounds(10,40,490,110); adv.setBounds(40,200,200,20); @@ -400,9 +404,10 @@ posPanel.setBounds(10, 230, 490, 250); cancel.setBounds(260,0,200,30); accept.setBounds(510,40,80,110); - errorMessage.setBounds(10,160,590,20); + errorMessage.setBounds(220,160,300,20); learner.add(run); learner.add(adv); + learner.add(why); learner.add(advanced); learner.add(cancel); learner.add(sugPanel); @@ -410,6 +415,7 @@ learner.add(errorMessage); learner.add(posPanel); posPanel.addHelpButtonListener(action); + detail = new MoreDetailForSuggestedConceptsPanel(model); add(learner); } public void setIconToggled(boolean toggled) @@ -423,10 +429,7 @@ advanced.setIcon(icon); } } - public void setArrowForToggleButton() - { - - } + /** * * @return @@ -435,6 +438,11 @@ { return learner; } + + public JButton getWhyButton() + { + return why; + } /** * * @param visible @@ -500,6 +508,10 @@ errorMessage.setText(s); } + public MoreDetailForSuggestedConceptsPanel getMoreDetailForSuggestedConceptsPanel() + { + return detail; + } /** * * @return @@ -522,7 +534,11 @@ public void dispose() { } - + + public void addWhyButtonListener(ActionListener a) + { + why.addActionListener(a); + } /** * * @param a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-30 14:38:12
|
Revision: 995 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=995&view=rev Author: jenslehmann Date: 2008-06-30 07:37:58 -0700 (Mon, 30 Jun 2008) Log Message: ----------- descriptions can now be converted to OWL/XML making it easier for clients to use their structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 14:12:50 UTC (rev 994) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 14:37:58 UTC (rev 995) @@ -25,9 +25,12 @@ import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.ScoreTwoValued; +import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIRenderers; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.semanticweb.owl.model.OWLDescription; /** * This represents a class description, which has been @@ -151,6 +154,8 @@ JSONObject object = new JSONObject(); try { object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null)); + OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description); + object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d)); object.put("accuracy", score.getAccuracy()); object.put("coveredPositives", getJSONArray(score.getCoveredPositives())); object.put("coveredNegatives", getJSONArray(score.getCoveredNegatives())); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java 2008-06-30 14:12:50 UTC (rev 994) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java 2008-06-30 14:37:58 UTC (rev 995) @@ -22,9 +22,13 @@ import java.io.StringWriter; import java.net.URI; +import org.coode.owlapi.owlxml.renderer.OWLXMLObjectRenderer; +import org.coode.owlapi.owlxml.renderer.OWLXMLWriter; +import org.coode.xml.XMLWriterNamespaceManager; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.model.OWLDataFactory; import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLOntologyManager; import uk.ac.manchester.cs.owl.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; @@ -51,11 +55,32 @@ return sw.toString(); } + /** + * Converts an OWL API description to an OWL/XML syntax string. + * + * @param description Input OWLDescription. + * @return OWL/XML syntax string. + */ + public static String toOWLXMLSyntax(OWLDescription description) { + StringWriter sw = new StringWriter(); + // set up default namespace and prefixes + XMLWriterNamespaceManager ns = new XMLWriterNamespaceManager("http://example.com"); + ns.setPrefix("owl2", "http://www.w3.org/2006/12/owl2-xml#"); + OWLXMLWriter oxw = new OWLXMLWriter(sw, ns); + OWLXMLObjectRenderer renderer = new OWLXMLObjectRenderer(oxw); + description.accept(renderer); + return sw.toString(); + } + public static void main(String args[]) { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = manager.getOWLDataFactory(); - OWLDescription d = factory.getOWLClass(URI.create("http://example.com/test")); - String s = toManchesterOWLSyntax(d); + OWLDescription a1 = factory.getOWLClass(URI.create("http://example.com/test#a1")); + OWLDescription a2 = factory.getOWLClass(URI.create("http://example.com/test#a2")); + OWLObjectProperty r = factory.getOWLObjectProperty(URI.create("http://example.com/test#r")); + OWLDescription d3 = factory.getOWLObjectSomeRestriction(r, a2); + OWLDescription d = factory.getOWLObjectIntersectionOf(a1,d3); + String s = toOWLXMLSyntax(d); System.out.println(s); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-30 14:12:52
|
Revision: 994 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=994&view=rev Author: jenslehmann Date: 2008-06-30 07:12:50 -0700 (Mon, 30 Jun 2008) Log Message: ----------- added converter of evaluated descriptions to a JSON format to simplify exchanging solutions Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/php-examples/LearningSimple.php Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-30 14:12:50 UTC (rev 994) @@ -1071,9 +1071,9 @@ @Override public Score getSolutionScore() { if(posOnly) - return posOnlyLearningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); + return posOnlyLearningProblem.computeScore(getCurrentlyBestDescription()); else - return learningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); + return learningProblem.computeScore(getCurrentlyBestDescription()); } Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 14:12:50 UTC (rev 994) @@ -25,6 +25,9 @@ import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.ScoreTwoValued; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; /** * This represents a class description, which has been @@ -138,4 +141,35 @@ public String getSparqlQuery(int limit) { return SparqlQueryDescriptionConvertVisitor.getSparqlQuery(description, limit); } + + /** + * This convenience method can be used to store and exchange evaluated + * descriptions by transforming them to a JSON string. + * @return A JSON representation of an evaluated description. + */ + public String asJSON() { + JSONObject object = new JSONObject(); + try { + object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null)); + object.put("accuracy", score.getAccuracy()); + object.put("coveredPositives", getJSONArray(score.getCoveredPositives())); + object.put("coveredNegatives", getJSONArray(score.getCoveredNegatives())); + object.put("notCoveredPositives", getJSONArray(score.getNotCoveredPositives())); + object.put("notCoveredNegatives", getJSONArray(score.getNotCoveredNegatives())); + return object.toString(3); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } + + // we need to use this method instead of the standard JSON array constructor, + // otherwise we'll get unexpected results (JSONArray does not take Individuals + // as arguments and does not use toString) + private static JSONArray getJSONArray(Set<Individual> individuals) { + JSONArray j = new JSONArray(); + for(Individual i : individuals) + j.put(i.getName()); + return j; + } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-30 14:12:50 UTC (rev 994) @@ -45,6 +45,7 @@ import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; @@ -317,6 +318,20 @@ return solution.toString(); } + @WebMethod + public String learnDescriptionsEvaluated(int id, int limit) throws ClientNotKnownException { + ClientState state = getState(id); + state.getLearningAlgorithm().start(); + List<EvaluatedDescription> descriptions = state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(limit); + String json = "{"; + int count = 1; + for(EvaluatedDescription description : descriptions) { + json += "\"solution" + count + "\" : " + description.asJSON(); + count++; + } + return json; + } + /** * Starts the learning algorithm and returns immediately. The learning * algorithm is executed in its own thread and can be queried and Modified: trunk/src/php-examples/LearningSimple.php =================================================================== --- trunk/src/php-examples/LearningSimple.php 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/php-examples/LearningSimple.php 2008-06-30 14:12:50 UTC (rev 994) @@ -62,8 +62,11 @@ // learn concept echo 'start learning ... '; -$concept = $client->learn($id, "manchester"); +// get only concept +// $concept = $client->learn($id, "manchester"); +// get concept and additional information in JSON syntax +$concept = $client->learnDescriptionsEvaluated($id, 5); echo 'OK <br />'; -echo 'solution: ' . $concept; +echo 'solution: <pre>' . $concept . '</pre>'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-30 11:26:45
|
Revision: 993 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=993&view=rev Author: jenslehmann Date: 2008-06-30 04:26:39 -0700 (Mon, 30 Jun 2008) Log Message: ----------- OWL API description to Manchester syntax converter Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java Added: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIRenderers.java 2008-06-30 11:26:39 UTC (rev 993) @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities.owl; + +import java.io.StringWriter; +import java.net.URI; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLOntologyManager; + +import uk.ac.manchester.cs.owl.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; + +/** + * A collection of various render methods provided by + * OWL API. + * + * @author Jens Lehmann + * + */ +public class OWLAPIRenderers { + + /** + * Converts an OWL API description to a Manchester OWL syntax string. + * + * @param description Input OWLDescription. + * @return Manchester OWL syntax string. + */ + public static String toManchesterOWLSyntax(OWLDescription description) { + StringWriter sw = new StringWriter(); + ManchesterOWLSyntaxObjectRenderer renderer = new ManchesterOWLSyntaxObjectRenderer(sw); + description.accept(renderer); + return sw.toString(); + } + + public static void main(String args[]) { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLDescription d = factory.getOWLClass(URI.create("http://example.com/test")); + String s = toManchesterOWLSyntax(d); + System.out.println(s); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-30 08:56:15
|
Revision: 992 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=992&view=rev Author: jenslehmann Date: 2008-06-30 01:56:11 -0700 (Mon, 30 Jun 2008) Log Message: ----------- - added convenience method to get SPARQL query for evaluated description - fixed all warnings (you should now have zero errors, zero warnings, zero notices) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/kb/OWLAPIOntology.java trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-30 08:56:11 UTC (rev 992) @@ -53,12 +53,12 @@ */ public class DBpediaNavigationSuggestor extends LearningAlgorithm { - private ReasoningService rs; +// private ReasoningService rs; private ExampleBasedROLComponent learner; private static String defaultSearchTreeFile = "log/searchTree.txt"; public DBpediaNavigationSuggestor(LearningProblem learningProblem, ReasoningService rs) { - this.rs=rs; +// this.rs=rs; if(learningProblem instanceof PosNegLP) { PosNegLP lp = (PosNegLP) learningProblem; this.learner=new ExampleBasedROLComponent(lp, rs); Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-30 08:56:11 UTC (rev 992) @@ -38,7 +38,7 @@ */ public class SimpleSuggestionLearningAlgorithm extends LearningAlgorithm implements Runnable { - private boolean stop = false; +// private boolean stop = false; private Score solutionScore; private Description bestSollution; private Set<Description> simpleSuggestions; @@ -59,7 +59,7 @@ @Override public void stop() { - stop = true; +// stop = true; } @Override Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 08:56:11 UTC (rev 992) @@ -23,6 +23,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.ScoreTwoValued; /** @@ -41,11 +42,24 @@ private Description description; private Score score; + /** + * Constructs an evaluated description using its score. + * @param description The description, which was evaluated. + * @param score The score of the description. + */ public EvaluatedDescription(Description description, Score score) { this.description = description; this.score = score; } + /** + * Constructs an evaluated description using example coverage. + * @param description The description, which was evaluated. + * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description. + * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description. + * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description. + * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description. + */ public EvaluatedDescription(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { this.description = description; // usually core methods should not depend on methods outside of the core package (except utilities) @@ -53,20 +67,29 @@ score = new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg); } + /** + * Gets the description, which was evaluated. + * @return The underlying description. + */ public Description getDescription() { return description; } + /** + * @see org.dllearner.core.owl.Description#getLength() + */ public int getDescriptionLength() { return description.getLength(); } + /** + * @see org.dllearner.core.owl.Description#getDepth() + */ public int getDescriptionDepth() { return description.getDepth(); } /** - * @return * @see org.dllearner.core.Score#getAccuracy() */ public double getAccuracy() { @@ -74,7 +97,6 @@ } /** - * @return * @see org.dllearner.core.Score#getCoveredNegatives() */ public Set<Individual> getCoveredNegatives() { @@ -82,7 +104,6 @@ } /** - * @return * @see org.dllearner.core.Score#getCoveredPositives() */ public Set<Individual> getCoveredPositives() { @@ -90,7 +111,6 @@ } /** - * @return * @see org.dllearner.core.Score#getNotCoveredNegatives() */ public Set<Individual> getNotCoveredNegatives() { @@ -98,11 +118,24 @@ } /** - * @return * @see org.dllearner.core.Score#getNotCoveredPositives() */ public Set<Individual> getNotCoveredPositives() { return score.getNotCoveredPositives(); } + /** + * Returns a SPARQL query to get instances of this description + * from a SPARQL endpoint. Of course, results may be incomplete, + * because no inference is done. The SPARQL query is a straightforward + * translation without any attempts to perform e.g. subclass + * inferencing. + * + * @param limit The maximum number of results. Corresponds to LIMIT + * in SPARQL. + * @return A SPARQL query of the underlying description. + */ + public String getSparqlQuery(int limit) { + return SparqlQueryDescriptionConvertVisitor.getSparqlQuery(description, limit); + } } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-06-30 08:56:11 UTC (rev 992) @@ -38,7 +38,6 @@ import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.SubsumptionHierarchy; import org.dllearner.utilities.datastructures.SortedSetTuple; -import org.semanticweb.owl.model.OWLClass; /** * @author Jens Lehmann Modified: trunk/src/dl-learner/org/dllearner/kb/OWLAPIOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLAPIOntology.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/OWLAPIOntology.java 2008-06-30 08:56:11 UTC (rev 992) @@ -20,6 +20,7 @@ this.ontology = onto; } + @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { @@ -30,21 +31,25 @@ return ontology; } + @Override public KB toKB() { throw new Error("OWL -> KB conversion not implemented yet."); } + @Override public void init() { } + @Override public void export(File file, OntologyFormat format) { } + @Override public String toDIG(URI kbURI) { return null; Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-06-30 08:56:11 UTC (rev 992) @@ -52,9 +52,9 @@ StringTuple t = (StringTuple) it.next(); try { // substitute rdf:type with owl:subclassof - if (t.a.equals(m.type) || t.a.equals(m.subclass)) { + if (t.a.equals(Manipulators.type) || t.a.equals(Manipulators.subclass)) { ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(m.subclass), this, + properties.add(new PropertyNode(new URI(Manipulators.subclass), this, tmp)); Nodes.add(tmp); } else { @@ -67,9 +67,9 @@ // if o is a blank node expand further // TODO this needs a lot more work - if (t.b.startsWith(m.blankNodeIdentifier)) { + if (t.b.startsWith(Manipulators.blankNodeIdentifier)) { tmp.expand(tsq, m); - System.out.println(m.blankNodeIdentifier); + System.out.println(Manipulators.blankNodeIdentifier); System.out.println("XXXXX" + t.b); } // Nodes.add(tmp); Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-06-30 08:56:11 UTC (rev 992) @@ -131,7 +131,7 @@ Node next = instances.remove(0); logger.trace("Getting classes for: " + next); classes.addAll(next.expand(tsqc, manipulator)); - if (classes.size() >= manipulator.breakSuperClassRetrievalAfter) { + if (classes.size() >= Manipulators.breakSuperClassRetrievalAfter) { break; } } @@ -155,7 +155,7 @@ // if(i % 50==0)System.out.println("got "+i+" extra classes, // max: "+manipulator.breakSuperClassRetrievalAfter); i++; - if (i >= manipulator.breakSuperClassRetrievalAfter) { + if (i >= Manipulators.breakSuperClassRetrievalAfter) { break; } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-06-30 08:56:11 UTC (rev 992) @@ -64,7 +64,7 @@ // basically : if p is rdf:type then o is a class // else it is an instance try { - if (t.a.equals(m.type)) { + if (t.a.equals(Manipulators.type)) { ClassNode tmp = new ClassNode(new URI(t.b)); classes.add(tmp); Nodes.add(tmp); Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-06-30 08:56:11 UTC (rev 992) @@ -67,7 +67,7 @@ while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); try { - if (t.a.equals(m.type)) { + if (t.a.equals(Manipulators.type)) { specialTypes.add(t.b); } } catch (Exception e) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-06-30 08:56:11 UTC (rev 992) @@ -1,6 +1,24 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.kb.sparql; - import java.util.HashMap; import java.util.SortedSet; import java.util.Stack; @@ -34,7 +52,9 @@ /** * Converter from DL-Learner descriptions to a corresponding SPARQL query * to get all instances that are described by this description. + * * @author Sebastian Knappe + * @author Sebastian Hellmann * */ public class SparqlQueryDescriptionConvertVisitor implements DescriptionVisitor{ Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-30 08:56:11 UTC (rev 992) @@ -83,7 +83,7 @@ String prim="http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; - String award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"); +// String award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"); SKOS7030 s= new SKOS7030(); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-28 07:28:11 UTC (rev 991) +++ trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-30 08:56:11 UTC (rev 992) @@ -22,7 +22,6 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; -import org.dllearner.reasoning.OWLAPIReasoner; import org.semanticweb.owl.model.OWLOntologyChange; import org.semanticweb.owl.model.RemoveAxiom; @@ -49,17 +48,17 @@ private ORE ore; private Individual ind; - private OWLAPIReasoner reasoner; +// private OWLAPIReasoner reasoner; private Description actualDesc; private Description newDesc; - private Individual object; +// private Individual object; public NegExampleRepairDialog(Individual ind, JDialog dialog, ORE ore){ super(dialog, "Repair negative example", true); this.ind = ind; this.ore = ore; - this.reasoner = ore.reasoner2; +// this.reasoner = ore.reasoner2; init(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-28 07:28:20
|
Revision: 991 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=991&view=rev Author: jenslehmann Date: 2008-06-28 00:28:11 -0700 (Sat, 28 Jun 2008) Log Message: ----------- - comparator for evaluated descriptions - fixed some warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.algorithms; import java.util.*; @@ -4,79 +23,80 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.Score; import org.dllearner.core.owl.*; -public class SimpleSuggestionLearningAlgorithm extends LearningAlgorithm implements Runnable{ +/** + * TODO: Javadoc + * TODO: Extend such that it can really be used as learning algorithm. + * + * @author Christian Kötteritzsch + * + */ +public class SimpleSuggestionLearningAlgorithm extends LearningAlgorithm implements Runnable { -private Score solutionScore; -private boolean stop = false; -private Description bestSollution; -private Set<Description> simpleSuggestions; -private LearningProblem learningProblem; + private boolean stop = false; + private Score solutionScore; + private Description bestSollution; + private Set<Description> simpleSuggestions; - public SimpleSuggestionLearningAlgorithm() - { - //this.learningProblem = learningProblem; + public SimpleSuggestionLearningAlgorithm() { + // this.learningProblem = learningProblem; } - - public Description getCurrentlyBestDescription() - { + + @Override + public Description getCurrentlyBestDescription() { return bestSollution; - } - - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() - { + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { return new EvaluatedDescription(bestSollution, solutionScore); } - - - public void stop() - { + + @Override + public void stop() { stop = true; } - - public void start() - { - + + @Override + public void start() { + } - - public <T> void applyConfigEntry(ConfigEntry<T> entry) - { - + + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) { + } - - public void init() - { - + + @Override + public void init() { + } - - public Score getSolutionScore() - { + + @Override + public Score getSolutionScore() { return solutionScore; } - - public void run() - { - + + public void run() { + } - - public Set<Description> getSimpleSuggestions(ReasoningService rs,Set<Individual> indi) { + + public Set<Description> getSimpleSuggestions(ReasoningService rs, Set<Individual> indi) { // EXISTS property.TOP // ESISTS hasChild // EXISTS hasChild.male - simpleSuggestions= new HashSet<Description>(); - List<ObjectProperty> test=rs.getAtomicRolesList(); - while(test.iterator().hasNext()) - { - test.iterator().next(); - Description d1 = new ObjectSomeRestriction(test.iterator().next(), new Thing()); - test.remove(rs.getAtomicRolesList().iterator().next()); - simpleSuggestions.add(d1); + simpleSuggestions = new HashSet<Description>(); + List<ObjectProperty> test = rs.getAtomicRolesList(); + while (test.iterator().hasNext()) { + test.iterator().next(); + Description d1 = new ObjectSomeRestriction(test.iterator().next(), new Thing()); + test.remove(rs.getAtomicRolesList().iterator().next()); + simpleSuggestions.add(d1); } return simpleSuggestions; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-28 07:28:11 UTC (rev 991) @@ -398,7 +398,7 @@ } @Override - public synchronized SortedSet<Description> getCurrentlyBestDescriptions() { + public synchronized List<Description> getCurrentlyBestDescriptions() { return algorithm.getCurrentlyBestDescriptions(); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-28 07:28:11 UTC (rev 991) @@ -50,6 +50,7 @@ import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; /** * Implements the example based refinement operator learning @@ -167,6 +168,8 @@ // comparator used to create ordered sets of concepts private ConceptComparator conceptComparator = new ConceptComparator(); + // comparator for evaluated descriptions + private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator(); // utility variables private DecimalFormat df = new DecimalFormat(); @@ -1059,8 +1062,8 @@ return candidatesStable.last().getConcept(); } - public SortedSet<Description> getCurrentlyBestDescriptions() { - SortedSet<Description> best = new TreeSet<Description>(); + public List<Description> getCurrentlyBestDescriptions() { + List<Description> best = new LinkedList<Description>(); int i=0; int nrOfSolutions = 200; for(ExampleBasedNode n : candidatesStable.descendingSet()) { @@ -1075,7 +1078,7 @@ public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { int count = 0; SortedSet<ExampleBasedNode> rev = candidatesStable.descendingSet(); - SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(); + SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator); for(ExampleBasedNode eb : rev) { cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); // return a maximum of 200 elements (we need a maximum, because the Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) @@ -88,8 +88,8 @@ /** * @see #getCurrentlyBestEvaluatedDescriptions() */ - public SortedSet<Description> getCurrentlyBestDescriptions() { - TreeSet<Description> ds = new TreeSet<Description>(); + public List<Description> getCurrentlyBestDescriptions() { + List<Description> ds = new LinkedList<Description>(); ds.add(getCurrentlyBestDescription()); return ds; } @@ -105,7 +105,7 @@ * @see #getCurrentlyBestEvaluatedDescriptions(int,double,boolean) */ public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions, boolean filterNonMinimalDescriptions) { - SortedSet<Description> currentlyBest = getCurrentlyBestDescriptions(); + List<Description> currentlyBest = getCurrentlyBestDescriptions(); List<Description> returnList = new LinkedList<Description>(); int count = 0; for(Description ed : currentlyBest) { Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-06-28 07:28:11 UTC (rev 991) @@ -34,7 +34,6 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DataRange; Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-28 07:28:11 UTC (rev 991) @@ -89,7 +89,7 @@ s.makeExamples(prim, percentOfSKOSSet, negfactor, sparqlResultSize); - SortedSet<Description> conceptresults = s.learn(); + List<Description> conceptresults = s.learn(); logger.debug("found nr of concepts: "+conceptresults.size()); System.out.println(conceptresults); @@ -249,7 +249,7 @@ logger.debug(fullPosSetWithoutPosExamples); } - public SortedSet<Description> learn(){ + public List<Description> learn(){ SortedSet<String> instances = new TreeSet<String>(); instances.addAll(this.posExamples); Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-28 07:28:11 UTC (rev 991) @@ -24,7 +24,6 @@ import java.util.TreeSet; import org.dllearner.algorithms.DBpediaNavigationSuggestor; -import org.dllearner.algorithms.RandomGuesser; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; @@ -35,7 +34,6 @@ import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.OWLAPIReasoner; /** Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java 2008-06-28 07:28:11 UTC (rev 991) @@ -2,8 +2,7 @@ import java.util.SortedSet; -import org.dllearner.core.owl.Description; - +// class is not used anywhere and is not documented - delete? public class ResultConceptSorter implements Comparable<ResultConceptSorter> { String concept; SortedSet<String> instances; Added: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2008-06-28 07:28:11 UTC (rev 991) @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities.owl; + +import java.util.Comparator; + +import org.dllearner.core.EvaluatedDescription; + +/** + * Comparator for evaluated descriptions, which orders them by + * accuracy as first criterion, length as second criterion, and + * syntactic structure as third criterion. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescriptionComparator implements Comparator<EvaluatedDescription> { + + ConceptComparator cc = new ConceptComparator(); + + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(EvaluatedDescription ed1, EvaluatedDescription ed2) { + double acc1 = ed1.getAccuracy(); + double acc2 = ed2.getAccuracy(); + if(acc1 > acc2) + return 1; + else if(acc1 < acc2) + return -1; + else { + int length1 = ed1.getDescriptionLength(); + int length2 = ed2.getDescriptionLength(); + if(length1 < length2) + return 1; + else if(length1 > length2) + return -1; + else + return cc.compare(ed1.getDescription(), ed2.getDescription()); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-27 16:49:49
|
Revision: 990 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=990&view=rev Author: jenslehmann Date: 2008-06-27 09:49:46 -0700 (Fri, 27 Jun 2008) Log Message: ----------- updated WSDL Modified Paths: -------------- trunk/src/music-recommender/main.wsdl Modified: trunk/src/music-recommender/main.wsdl =================================================================== --- trunk/src/music-recommender/main.wsdl 2008-06-27 16:08:01 UTC (rev 989) +++ trunk/src/music-recommender/main.wsdl 2008-06-27 16:49:46 UTC (rev 990) @@ -125,6 +125,7 @@ <message name="getCurrentlyBestConcepts"> <part name="arg0" type="xsd:int"></part> <part name="arg1" type="xsd:int"></part> + <part name="arg2" type="xsd:string"></part> </message> <message name="getCurrentlyBestConceptsResponse"> <part xmlns:ns7="http://jaxb.dev.java.net/array" name="return" type="ns7:stringArray"></part> @@ -429,7 +430,7 @@ <output message="tns:getCurrentlyBestConceptResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> - <operation name="getCurrentlyBestConcepts" parameterOrder="arg0 arg1"> + <operation name="getCurrentlyBestConcepts" parameterOrder="arg0 arg1 arg2"> <input message="tns:getCurrentlyBestConcepts"></input> <output message="tns:getCurrentlyBestConceptsResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -554,6 +555,7 @@ <input message="tns:getAsXMLString"></input> <output message="tns:getAsXMLStringResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> + <fault message="tns:SparqlQueryException" name="SparqlQueryException"></fault> </operation> <operation name="sparqlQueryThreaded" parameterOrder="arg0 arg1 arg2"> <input message="tns:sparqlQueryThreaded"></input> @@ -1144,6 +1146,9 @@ <fault name="ClientNotKnownException"> <soap:fault name="ClientNotKnownException" use="literal"></soap:fault> </fault> + <fault name="SparqlQueryException"> + <soap:fault name="SparqlQueryException" use="literal"></soap:fault> + </fault> </operation> <operation name="sparqlQueryThreaded"> <soap:operation soapAction=""></soap:operation> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <min...@us...> - 2008-06-27 16:08:16
|
Revision: 989 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=989&view=rev Author: minime219 Date: 2008-06-27 09:08:01 -0700 (Fri, 27 Jun 2008) Log Message: ----------- added String format Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 15:37:09 UTC (rev 988) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 16:08:01 UTC (rev 989) @@ -346,13 +346,18 @@ } @WebMethod - public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts) throws ClientNotKnownException { + public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts, String format) throws ClientNotKnownException { ClientState state = getState(id); List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); List<String> conc=new LinkedList<String>(); Iterator<Description> iter=bestConcepts.iterator(); while (iter.hasNext()) - conc.add(iter.next().toString()); + if (format.equals("manchester")) + conc.add(iter.next().toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>())); + else if(format.equals("kb")) + conc.add(iter.next().toKBSyntaxString()); + else + conc.add(iter.next().toString()); return conc.toArray(new String[conc.size()]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <min...@us...> - 2008-06-27 15:44:39
|
Revision: 988 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=988&view=rev Author: minime219 Date: 2008-06-27 08:37:09 -0700 (Fri, 27 Jun 2008) Log Message: ----------- return to old version, will make a new method. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 15:01:58 UTC (rev 987) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 15:37:09 UTC (rev 988) @@ -308,24 +308,13 @@ public String learn(int id, String format) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); - List<Description> concepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(4); - String solutions = "<br>"; - int it=1; - for(int i=0;i<concepts.size();i++){ - Description d = concepts.get(i); - - String s = null; - if(format.equals("manchester")) - s = d.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); - else if (format.equals("kb")) - s= d.toKBSyntaxString(); - else - s= d.toString(); - - solutions+="<b>"+it+"</b>: "+s+"<br>"; - it++; - } - return solutions; + Description solution = state.getLearningAlgorithm().getCurrentlyBestDescription(); + if(format.equals("manchester")) + return solution.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); + else if(format.equals("kb")) + return solution.toKBSyntaxString(); + else + return solution.toString(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <min...@us...> - 2008-06-27 15:02:14
|
Revision: 987 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=987&view=rev Author: minime219 Date: 2008-06-27 08:01:58 -0700 (Fri, 27 Jun 2008) Log Message: ----------- method learn returns a list of concepts instead of only one best concept Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 14:28:48 UTC (rev 986) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 15:01:58 UTC (rev 987) @@ -308,13 +308,24 @@ public String learn(int id, String format) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); - Description solution = state.getLearningAlgorithm().getCurrentlyBestDescription(); - if(format.equals("manchester")) - return solution.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); - else if(format.equals("kb")) - return solution.toKBSyntaxString(); - else - return solution.toString(); + List<Description> concepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(4); + String solutions = "<br>"; + int it=1; + for(int i=0;i<concepts.size();i++){ + Description d = concepts.get(i); + + String s = null; + if(format.equals("manchester")) + s = d.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); + else if (format.equals("kb")) + s= d.toKBSyntaxString(); + else + s= d.toString(); + + solutions+="<b>"+it+"</b>: "+s+"<br>"; + it++; + } + return solutions; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-27 14:28:52
|
Revision: 986 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=986&view=rev Author: jenslehmann Date: 2008-06-27 07:28:48 -0700 (Fri, 27 Jun 2008) Log Message: ----------- extension of abstract LearningAlgorithm class and many subsequent (possibly code-breaking) changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/Score.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -277,8 +278,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return bestDefinition; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(bestDefinition,bestScore); } @Override @@ -286,4 +292,22 @@ stop = true; } + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#pause() + */ + @Override + public void pause() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#resume() + */ + @Override + public void resume() { + // TODO Auto-generated method stub + + } + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-27 14:28:48 UTC (rev 986) @@ -24,6 +24,7 @@ import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -145,12 +146,35 @@ } @Override - public Description getBestSolution() { - return learner.getBestSolution(); + public Description getCurrentlyBestDescription() { + return learner.getCurrentlyBestDescription(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return learner.getCurrentlyBestEvaluatedDescription(); } @Override public Score getSolutionScore() { return learner.getSolutionScore(); } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#pause() + */ + @Override + public void pause() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#resume() + */ + @Override + public void resume() { + // TODO Auto-generated method stub + + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-06-27 14:28:48 UTC (rev 986) @@ -25,6 +25,7 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -117,8 +118,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return bestDefinition; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(bestDefinition,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,9 +1,8 @@ package org.dllearner.algorithms; -import java.util.Set; -import java.util.List; import java.util.*; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -25,9 +24,14 @@ //this.learningProblem = learningProblem; } - public Description getBestSolution() + public Description getCurrentlyBestDescription() { return bestSollution; + } + + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() + { + return new EvaluatedDescription(bestSollution, solutionScore); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-06-27 14:28:48 UTC (rev 986) @@ -30,6 +30,7 @@ import java.util.Map.Entry; import org.dllearner.algorithms.hybridgp.Psi; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -948,9 +949,14 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { + return bestConcept; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { // return fittestIndividual.getTree(); - return bestConcept; + return new EvaluatedDescription(bestConcept,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 14:28:48 UTC (rev 986) @@ -25,9 +25,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.SortedSet; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -391,21 +393,24 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return algorithm.getBestSolution(); } @Override - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - return algorithm.getBestSolutions(nrOfSolutions); + public synchronized SortedSet<Description> getCurrentlyBestDescriptions() { + return algorithm.getCurrentlyBestDescriptions(); } @Override - public synchronized List<Description> getGoodSolutions() { - return algorithm.getGoodSolutions(); + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(algorithm.getBestSolution(),algorithm.getSolutionScore()); } - + @Override + public synchronized SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + return algorithm.getCurrentlyBestEvaluatedDescriptions(); + } @Override public void stop() { @@ -415,14 +420,15 @@ public ExampleBasedNode getStartNode() { return algorithm.getStartNode(); } + + @Override + public void pause() { + // TODO: not implemented + } + + @Override + public void resume() { + // TODO: not implemented + } - - /*public void printBestSolutions(int nrOfSolutions){ - - algorithm.printBestSolutions(nrOfSolutions); - }*/ - - - - } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -33,6 +33,7 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -455,8 +456,7 @@ String KBSyntax="KBSyntax:\n"; for(Description c : solutions) { logger.info(show+": " + c.toString(baseURI,null) + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); - // watch for String.replace Quick hack - manchester+=show+": "+c.toManchesterSyntaxString(baseURI, new HashMap<String,String>()).replace("\"", "")+"\n"; + manchester+=show+": "+c.toManchesterSyntaxString(baseURI, new HashMap<String,String>())+"\n"; KBSyntax+=show+": " + c.toKBSyntaxString()+"\n"; if(show>=5){break;} show++; } @@ -1059,43 +1059,34 @@ return candidatesStable.last().getConcept(); } - - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - List<Description> best = new LinkedList<Description>(); + public SortedSet<Description> getCurrentlyBestDescriptions() { + SortedSet<Description> best = new TreeSet<Description>(); int i=0; + int nrOfSolutions = 200; for(ExampleBasedNode n : candidatesStable.descendingSet()) { - - best.add(n.getConcept()); - if(i==nrOfSolutions) - return best; + best.add(n.getConcept()); + if(i==nrOfSolutions) + return best; i++; } return best; } - - /** - * returns the solutions, that have at least a certain quality - * either accuracy = 100% full solutions - * or accuracy > 100% - noise; - * @return - */ - public synchronized List<Description> getGoodSolutions() { - List<Description> best = new LinkedList<Description>(); - - for(ExampleBasedNode n : candidatesStable.descendingSet()) { - if(n.getAccuracy(nrOfPositiveExamples, nrOfNegativeExamples)<(1-noise)) - return best; - best.add(n.getConcept()); - + public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + int count = 0; + SortedSet<ExampleBasedNode> rev = candidatesStable.descendingSet(); + SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(); + for(ExampleBasedNode eb : rev) { + cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); + // return a maximum of 200 elements (we need a maximum, because the + // candidate set can be very large) + if(count > 200) + return cbd; + count++; } - return best; + return cbd; } - - - - public void printBestSolutions(int nrOfSolutions, boolean showOrderedSolutions){ //QUALITY: could be optimized if(!logger.isTraceEnabled()) @@ -1136,6 +1127,13 @@ return learningProblem.computeScore(getBestSolution()); } + private Score getScore(Description d) { + if(posOnly) + return posOnlyLearningProblem.computeScore(d); + else + return learningProblem.computeScore(d); + } + public ExampleBasedNode getStartNode() { return startNode; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -14,6 +14,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -1033,8 +1034,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return candidatesStable.last().getConcept(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore()); } public void printBestSolutions(int nrOfSolutions){ @@ -1050,7 +1056,7 @@ } @Override - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfSolutions) { List<Description> best = new LinkedList<Description>(); int i=0; for(Node n : candidatesStable.descendingSet()) { @@ -1065,9 +1071,9 @@ @Override public Score getSolutionScore() { if(posOnly) - return posOnlyLearningProblem.computeScore(getBestSolution()); + return posOnlyLearningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); else - return learningProblem.computeScore(getBestSolution()); + return learningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); } Added: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-27 14:28:48 UTC (rev 986) @@ -0,0 +1,108 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Set; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.ScoreTwoValued; + +/** + * This represents a class description, which has been + * evaluated by the learning algorithm, i.e. it has been checked + * which examples it covers. It can be used as return value for + * learning algorithms to make it easier for applications to + * assess how good an offered class description is and how it + * classifies particular examples. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescription { + + private Description description; + private Score score; + + public EvaluatedDescription(Description description, Score score) { + this.description = description; + this.score = score; + } + + public EvaluatedDescription(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + this.description = description; + // usually core methods should not depend on methods outside of the core package (except utilities) + // in this case, this is just a convenience constructor + score = new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg); + } + + public Description getDescription() { + return description; + } + + public int getDescriptionLength() { + return description.getLength(); + } + + public int getDescriptionDepth() { + return description.getDepth(); + } + + /** + * @return + * @see org.dllearner.core.Score#getAccuracy() + */ + public double getAccuracy() { + return score.getAccuracy(); + } + + /** + * @return + * @see org.dllearner.core.Score#getCoveredNegatives() + */ + public Set<Individual> getCoveredNegatives() { + return score.getCoveredNegatives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getCoveredPositives() + */ + public Set<Individual> getCoveredPositives() { + return score.getCoveredPositives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getNotCoveredNegatives() + */ + public Set<Individual> getNotCoveredNegatives() { + return score.getNotCoveredNegatives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getNotCoveredPositives() + */ + public Set<Individual> getNotCoveredPositives() { + return score.getNotCoveredPositives(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -22,73 +22,188 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.owl.Description; +import org.dllearner.utilities.owl.ConceptTransformation; /** + * Abstract superclass of all learning algorithm implementations. + * Includes support for anytime learning algorithms and resumable + * learning algorithms. Provides methods for filtering the best + * descriptions found by the algorithm. As results of the algorithm, + * you can either get only descriptions or evaluated descriptions. + * Evaluated descriptions have information about accuracy and + * example coverage associated with them. However, retrieving those + * may require addition reasoner queries, because the learning + * algorithms usually use but do not necessarily store this information. + * * @author Jens Lehmann * */ public abstract class LearningAlgorithm extends Component { /** - * Starts the algorithm. - * + * Starts the algorithm. It runs until paused, stopped, or + * a termination criterion has been reached. */ public abstract void start(); - /** - * Stops the algorithm gracefully. - * + * Pauses the algorithm (not all algorithms need to implement + * this operation). */ + public void pause() { }; + + /** + * Resumes the algorithm (not all algorithms need to implement + * this operation). You can use this method to continue + * an algorithm run even after a termination criterion has been + * reached. It will run until paused, stopped, or terminated + * again. + */ + public void resume() { }; + + /** + * Stops the algorithm gracefully. A stopped algorithm cannot be resumed anymore. + * Use this method for cleanup and freeing memory. + */ public abstract void stop(); - + /** * Every algorithm must be able to return the score of the * best solution found. + * * @return Best score. */ + @Deprecated public abstract Score getSolutionScore(); /** - * Returns the best solutions obtained so far. - * @return Best solution. + * @see #getCurrentlyBestEvaluatedDescription() */ - public abstract Description getBestSolution(); + public abstract Description getCurrentlyBestDescription(); + /** + * @see #getCurrentlyBestEvaluatedDescriptions() + */ + public SortedSet<Description> getCurrentlyBestDescriptions() { + TreeSet<Description> ds = new TreeSet<Description>(); + ds.add(getCurrentlyBestDescription()); + return ds; + } + /** + * @see #getCurrentlyBestEvaluatedDescriptions(int) + */ + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { + return getCurrentlyBestDescriptions(nrOfDescriptions, false); + } /** - * returns the best nrOfSolutions solutions - * regardless of quality, just depends on input int - * @param nrOfSolutions - * @return List<Description> + * @see #getCurrentlyBestEvaluatedDescriptions(int,double,boolean) */ - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - List<Description> single = new LinkedList<Description>(); - single.add(getBestSolution()); - return single; + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions, boolean filterNonMinimalDescriptions) { + SortedSet<Description> currentlyBest = getCurrentlyBestDescriptions(); + List<Description> returnList = new LinkedList<Description>(); + int count = 0; + for(Description ed : currentlyBest) { + // return if we have sufficiently many descriptions + if(count >= nrOfDescriptions) + return returnList; + + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed)) + returnList.add(ed); + + count++; + } + return returnList; + } + + /** + * Returns the best descriptions obtained so far. + * @return Best class description found so far. + */ + public abstract EvaluatedDescription getCurrentlyBestEvaluatedDescription(); + + /** + * Returns a sorted set of the best descriptions found so far. We + * assume that they are ordered such that the best ones come in + * first. + * @return Best class descriptions found so far. + */ + public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + TreeSet<EvaluatedDescription> ds = new TreeSet<EvaluatedDescription>(); + ds.add(getCurrentlyBestEvaluatedDescription()); + return ds; } /** - * returns the solutions, that have at least a certain quality - * either accuracy = 100%, i.e. full solutions - * or accuracy > 100% - noise; - * @return + * Returns a filtered list of currently best class descriptions. + * + * @param nrOfDescriptions Maximum number of restrictions. Use Integer.MAX_VALUE + * if you do not want this filter to be active. + * + * @param accuracyThreshold Minimum accuracy. All class descriptions with lower + * accuracy are disregarded. Specify a value between 0.0 and 1.0. Use 0.0 if + * you do not want this filter to be active. + * + * @param filterNonMinimalDescriptions If true, non-minimal descriptions are + * filtered, e.g. ALL r.TOP (being equivalent to TOP), male AND male (can be + * shortened to male). Currently, non-minimal descriptions are just skipped, + * i.e. they are completely omitted from the return list. Later, implementation + * might be changed to return shortened versions of those descriptions. + * + * @return A list of currently best class descriptions. */ - public synchronized List<Description> getGoodSolutions() { - List<Description> single = new LinkedList<Description>(); - single.add(getBestSolution()); - return single; + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) { + SortedSet<EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions(); + List<EvaluatedDescription> returnList = new LinkedList<EvaluatedDescription>(); + int count = 0; + for(EvaluatedDescription ed : currentlyBest) { + // once we hit a description with a below threshold accuracy, we simply return + // because learning algorithms are advised to order descriptions by accuracy, + // so we won't find any concept with higher accuracy in the remaining list + if(ed.getAccuracy() < accuracyThreshold) + return returnList; + + // return if we have sufficiently many descriptions + if(count >= nrOfDescriptions) + return returnList; + + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed.getDescription())) + returnList.add(ed); + + count++; + } + return returnList; } + /** + * Return the best currently found concepts up to some maximum + * count (no minimality filter used). + * @param nrOfDescriptions Maximum number of descriptions returned. + * @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false). + */ + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) { + return getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, 0.0, false); + } /** + * Returns a fraction of class descriptions with sufficiently high accuracy. + * @param accuracyThreshold Only return solutions with this accuracy or higher. + * @return Return value is getCurrentlyBestDescriptions(Integer.MAX_VALUE, accuracyThreshold, false). + */ + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) { + return getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, accuracyThreshold, false); + } + + /** * Returns all learning problems supported by this component. */ public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { return new LinkedList<Class<? extends LearningProblem>>(); } - + } Modified: trunk/src/dl-learner/org/dllearner/core/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Score.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/core/Score.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.core; import java.util.Set; @@ -4,9 +24,26 @@ import org.dllearner.core.owl.Individual; +/** + * The score class is used to store how well a class description did + * on a learning problem. + * + * @author Jens Lehmann + * + */ public abstract class Score { + + // accuracy + public abstract double getAccuracy(); + + // example coverage + public abstract Set<Individual> getCoveredPositives(); + public abstract Set<Individual> getCoveredNegatives(); + public abstract Set<Individual> getNotCoveredPositives(); + public abstract Set<Individual> getNotCoveredNegatives(); + + // older methods (not frequently used anymore) public abstract double getScore(); - /** * The score of a concept depends on how good it classifies the * examples of a learning problem and the length of the concept @@ -20,9 +57,4 @@ */ public abstract Score getModifiedLengthScore(int newLength); - public abstract Set<Individual> getCoveredPositives(); - public abstract Set<Individual> getCoveredNegatives(); - public abstract Set<Individual> getNotCoveredPositives(); - - // public abstract int getNrOfMiss } Modified: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-06-27 14:28:48 UTC (rev 986) @@ -284,7 +284,7 @@ //System.out.println("best"+la.getBestSolution()); }catch (Exception e) {e.printStackTrace();} - return la.getBestSolution(); + return la.getCurrentlyBestDescription(); } static KB getKB(SortedSet<Integer> lines){ Modified: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-06-27 14:28:48 UTC (rev 986) @@ -198,7 +198,7 @@ // wait for a solution (note that not all learning problems have a // solution (100% accuracy), so one usually has to run the algorithm in its own // thread, such that it can be aborted after some time - Description solution = la.getBestSolution(); + Description solution = la.getCurrentlyBestDescription(); solutionDisplay.setText(solution.toString()); } } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-06-27 14:28:48 UTC (rev 986) @@ -172,9 +172,9 @@ infoArea.setText(""); // best solutions - if (config.getLearningAlgorithm().getBestSolutions(5) != null) { + if (config.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(5) != null) { infoArea.append("Best solutions: \n\n" - + listToString(config.getLearningAlgorithm().getBestSolutions(10)) + "\n"); + + listToString(config.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(10)) + "\n"); } // solution score // if (config.getLearningAlgorithm().getSolutionScore() != null) @@ -257,7 +257,7 @@ if (millis > 0) time += millis + "ms "; if (false) - time += mikros + "\xB5s "; + time += mikros + "�s "; if (false) time += nanos + "ns "; return time; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-06-27 14:28:48 UTC (rev 986) @@ -233,6 +233,22 @@ @Override public Score getModifiedLengthScore(int newLength) { return new ScoreThreeValued(newLength, accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Score#getAccuracy() + */ + @Override + public double getAccuracy() { + return accuracy; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Score#getNotCoveredNegatives() + */ + @Override + public Set<Individual> getNotCoveredNegatives() { + return negAsNeg; } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.learningproblems; import java.util.Set; @@ -6,10 +26,15 @@ import org.dllearner.core.owl.Individual; /** + * Calculates accuracy and score (with respect to some length penalty) of + * a class description. * - * TODO: accuracy-Berechnung (positive+negative Beispiele muessen dafuer bekannt sein) + * TODO: In fact, a score value influencing a learning algorithm + * should not be calculated here, but rather in a separate heuristic + * as there are many methods to calculate such a value. This class + * should only be used for computing example coverage, accuracy etc. * - * @author jl + * @author Jens Lehmann * */ public class ScoreTwoValued extends Score { @@ -19,11 +44,15 @@ private Set<Individual> negAsPos; private Set<Individual> negAsNeg; private double score; - private double classificationScore; + private double accuracy; private int nrOfExamples; private int conceptLength; private double percentPerLengthUnit; + public ScoreTwoValued(Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + this(0,0,posAsPos,posAsNeg,negAsPos,posAsPos); + } + public ScoreTwoValued(int conceptLength, double percentPerLengthUnit, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { this.conceptLength = conceptLength; this.percentPerLengthUnit = percentPerLengthUnit; @@ -36,15 +65,22 @@ } private void computeScore() { - // - Anzahl falscher Klassifikationen - classificationScore = - posAsNeg.size() - negAsPos.size(); - // Anteil falscher Klassifikationen (Zahl zwischen -1 und 0) - classificationScore = classificationScore / (double) nrOfExamples; - // Berücksichtigung des Längenfaktors - score = classificationScore - percentPerLengthUnit * conceptLength; + // compute accuracy + accuracy = posAsPos.size() + negAsNeg.size(); + accuracy = accuracy / (double) nrOfExamples; + // compute score + score = accuracy - 1 - percentPerLengthUnit * conceptLength; } @Override + public double getAccuracy() { + return accuracy; + } + + /** + * score = accuracy - 1 - length * length penalty + */ + @Override public double getScore() { return score; } @@ -53,7 +89,7 @@ public String toString() { String str = ""; str += "score: " + score + "\n"; - str += "accuracy: " + (1 + classificationScore) + "\n"; + str += "accuracy: " + accuracy + "\n"; str += "posAsPos (" + posAsPos.size() + "): " + posAsPos + "\n"; str += "positive examples classified as negative (" + posAsNeg.size() + "): " + posAsNeg + "\n"; str += "negative examples classified as positive (" + negAsPos.size() + "): " + negAsPos + "\n"; @@ -74,16 +110,15 @@ public Set<Individual> getNotCoveredPositives() { return posAsNeg; } - - /* + @Override - public double getModifiedLengthScore(int newLength) { - return classificationScore - Config.percentPerLengthUnit * newLength; - } - */ + public Set<Individual> getNotCoveredNegatives() { + return negAsNeg; + } @Override public Score getModifiedLengthScore(int newLength) { return new ScoreTwoValued(newLength, percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); - } + } + } Modified: trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -222,7 +222,7 @@ long algorithmDuration = System.nanoTime() - algorithmStartTime; runtime.addNumber(algorithmDuration/(double)1000000000); - Description concept = la.getBestSolution(); + Description concept = la.getCurrentlyBestDescription(); ReasoningService rs = start.getReasoningService(); Set<Individual> tmp = rs.instanceCheck(concept, testSetsPos.get(currFold)); Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 14:28:48 UTC (rev 986) @@ -89,7 +89,7 @@ s.makeExamples(prim, percentOfSKOSSet, negfactor, sparqlResultSize); - List<Description> conceptresults = s.learn(); + SortedSet<Description> conceptresults = s.learn(); logger.debug("found nr of concepts: "+conceptresults.size()); System.out.println(conceptresults); @@ -249,7 +249,7 @@ logger.debug(fullPosSetWithoutPosExamples); } - public List<Description> learn(){ + public SortedSet<Description> learn(){ SortedSet<String> instances = new TreeSet<String>(); instances.addAll(this.posExamples); @@ -330,7 +330,7 @@ //Statistics.addTimeLearning(sc.getTime()); - return la.getGoodSolutions(); + return la.getCurrentlyBestDescriptions(); }catch (Exception e) {e.printStackTrace();} return null; Modified: trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -57,7 +57,7 @@ Start start = new Start(new File(filenameTrain)); start.start(false); - Description solution = start.getLearningAlgorithm().getBestSolution(); + Description solution = start.getLearningAlgorithm().getCurrentlyBestDescription(); logger.setLevel(Level.WARN); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 14:28:48 UTC (rev 986) @@ -308,7 +308,7 @@ public String learn(int id, String format) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); - Description solution = state.getLearningAlgorithm().getBestSolution(); + Description solution = state.getLearningAlgorithm().getCurrentlyBestDescription(); if(format.equals("manchester")) return solution.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); else if(format.equals("kb")) @@ -342,13 +342,13 @@ @WebMethod public String getCurrentlyBestConcept(int id) throws ClientNotKnownException { ClientState state = getState(id); - return state.getLearningAlgorithm().getBestSolution().toString(); + return state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescription().toString(); } @WebMethod public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); List<String> conc=new LinkedList<String>(); Iterator<Description> iter=bestConcepts.iterator(); while (iter.hasNext()) @@ -612,7 +612,7 @@ @WebMethod public int[] getConceptDepth(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); Iterator<Description> iter=bestConcepts.iterator(); int[] length=new int[bestConcepts.size()]; int i=0; @@ -626,7 +626,7 @@ @WebMethod public int[] getConceptArity(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); Iterator<Description> iter=bestConcepts.iterator(); int[] arity=new int[bestConcepts.size()]; int i=0; Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 14:28:48 UTC (rev 986) @@ -97,7 +97,7 @@ // start the algorithm and print the best concept found la.start(); - System.out.println(la.getBestSolution()); + System.out.println(la.getCurrentlyBestEvaluatedDescription()); } } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-27 14:28:48 UTC (rev 986) @@ -69,7 +69,7 @@ la = getWizardModel().getOre().start();//started endlosen Algorithmus - publish(la.getBestSolutions(10)); + publish(la.getCurrentlyBestDescriptions(10)); List<Description> result = getWizardModel().getOre().getLearningResults(100); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-27 14:28:48 UTC (rev 986) @@ -177,15 +177,15 @@ } public Description getLearningResult(){ - return la.getBestSolution(); + return la.getCurrentlyBestDescription(); } - public List<Description> getSolutions(){ - return la.getGoodSolutions(); - } +// public List<Description> getSolutions(){ +// return la.getCurrentlyBestDescriptions(); +// } public List<Description> getLearningResults(int anzahl){ - return la.getBestSolutions(anzahl); + return la.getCurrentlyBestDescriptions(anzahl); } /** Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-27 14:28:48 UTC (rev 986) @@ -224,9 +224,9 @@ */ private void addToListModel() { - for(int j = 0;j<la.getBestSolutions(anzahl).size();j++) + for(int j = 0;j<la.getCurrentlyBestEvaluatedDescriptions(anzahl).size();j++) { - suggestModel.add(j,la.getBestSolutions(anzahl).get(j)); + suggestModel.add(j,la.getCurrentlyBestEvaluatedDescriptions(anzahl).get(j)); } } @@ -352,7 +352,7 @@ error = "Learning succesful"; // start the algorithm and print the best concept found la.start(); - description = new Description[la.getBestSolutions(anzahl).size()]; + description = new Description[la.getCurrentlyBestEvaluatedDescriptions(anzahl).size()]; addToListModel(); view.renderErrorMessage(error); view.getRunButton().setEnabled(true); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.utilities.owl; import java.util.Collections; @@ -21,8 +40,11 @@ import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.Thing; -// ev. kann man diese Klasse später in ein anderes Paket ziehen, da sie nicht direkt mit -// refinement zu tun hat +/** + * Concept transformation and concept checking methods. + * + * @author Jens Lehmann + */ public class ConceptTransformation { public static long cleaningTimeNs = 0; @@ -386,4 +408,39 @@ return concept; } + /** + * Method to determine, whether a class description is minimal, + * e.g. \forall r.\top (\equiv \top) or male \sqcup male are not + * minimal. This method performs heuristic sanity checks (it will + * not try to find semantically equivalent shorter descriptions). + * @param description Input description. + * @return True if a superfluous construct has been found. + */ + public static boolean isDescriptionMinimal(Description description) { + ConceptComparator cc = new ConceptComparator(); + int length = description.getLength(); + int length2 = ConceptTransformation.getShortConcept(description, cc).getLength(); + if(length2 < length) + return false; + if(ConceptTransformation.findEquivalences(description)) + return false; + return true; + } + + private static boolean findEquivalences(Description description) { + // \exists r.\bot \equiv \bot + if(description instanceof ObjectSomeRestriction && description.getChild(0) instanceof Nothing) + return true; + // \forall r.\top \equiv \top + if(description instanceof ObjectAllRestriction && description.getChild(0) instanceof Thing) + return true; + // check children + for(Description child : description.getChildren()) { + if(findEquivalences(child)) + return true; + } + // false if none of the checks was successful + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-06-27 13:45:54
|
Revision: 985 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=985&view=rev Author: kurzum Date: 2008-06-27 06:44:33 -0700 (Fri, 27 Jun 2008) Log Message: ----------- comments and formatting Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-26 15:21:53 UTC (rev 984) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-27 13:44:33 UTC (rev 985) @@ -44,16 +44,18 @@ public class SparqlQuery { private static Logger logger = Logger.getLogger(SparqlQuery.class); - private boolean isRunning = false; + private boolean wasExecuted = false; + private String queryString; + private QueryEngineHTTP queryExecution; + private SparqlEndpoint endpoint; - //private ResultSet rs; + private String json = null; -// private SparqlQueryException sendException=null; /** * Standard constructor. @@ -62,32 +64,29 @@ * @param endpoint */ public SparqlQuery(String queryString, SparqlEndpoint endpoint) { - // QUALITY there seems to be a bug in ontowiki - this.queryString = queryString.replaceAll("\n", " "); + // QUALITY there seems to be a bug in ontowiki + this.queryString = queryString.replaceAll("\n", " "); this.endpoint = endpoint; } - - - - /** - * Sends a SPARQL query using the Jena library. - * main format is JSON use method getasjson + * Sends a SPARQL query using the Jena library. main format is JSON, use + * method getasjson * * @return nothing */ - + public void send() { - wasExecuted = true; + wasExecuted = true; + // isRunning = true; ResultSet rs; - //isRunning = true; + writeToSparqlLog("***********\nNew Query:"); writeToSparqlLog(queryString); writeToSparqlLog(endpoint.getURL().toString()); - + String service = endpoint.getURL().toString(); - + // Jena access to SPARQL endpoint queryExecution = new QueryEngineHTTP(service, queryString); for (String dgu : endpoint.getDefaultGraphURIs()) { @@ -96,26 +95,25 @@ for (String ngu : endpoint.getNamedGraphURIs()) { queryExecution.addNamedGraph(ngu); } - - - //TODO remove after overnext Jena release - HttpQuery.urlLimit = 3*1024 ; - JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").start(); + + // TODO remove after overnext Jena release + HttpQuery.urlLimit = 3 * 1024; + JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime") + .start(); rs = queryExecution.execSelect(); JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop(); - - - logger.debug("query length: "+queryString.length()+" | ENDPOINT: "+endpoint.getURL().toString()); - //writeToSparqlLog("query: "+queryString+ " | ENDPOINT: "+endpoint.getURL().toString()); - - - + + logger.debug("query length: " + queryString.length() + " | ENDPOINT: " + + endpoint.getURL().toString()); + // writeToSparqlLog("query: "+queryString+ " | ENDPOINT: + // "+endpoint.getURL().toString()); + json = SparqlQuery.getAsJSON(rs); - - writeToSparqlLog("JSON: "+json); - + + writeToSparqlLog("JSON: " + json); + isRunning = false; - + } public void stop() { @@ -126,43 +124,97 @@ public String getQueryString() { return queryString; } - + public SparqlEndpoint getEndpoint() { - return endpoint; + return endpoint; } - + public boolean isRunning() { return isRunning; } - - public QueryEngineHTTP getExecution(){ + + public QueryEngineHTTP getExecution() { return queryExecution; } - -// public SparqlQueryException getException(){ -// return sendException; -// } + public void setJson(String json) { + this.wasExecuted = true; + this.json = json; + } + + public void setRunning(boolean running) { + this.isRunning = running; + } + /** + * returns the Result of the query as JSON string executes the query if it + * wasn't executed before + * + * @return + */ + public String getJson() { + if (wasExecuted == false) { + this.send(); + } + return json; + } + + /** + * makes a ResultSet from the Json String, depends on getJSON + * + * @return + */ + public ResultSet getResultSet() { + if (getJson() == null) { + return null; + } else + return JSONtoResultSet(json); + } + + /** + * makes an XML String from the Json String, depends on getJSON + * + * @return + */ + public String getXMLString() { + if (getJson() == null) { + return null; + } else + return JSONtoXML(json); + } + + public static void writeToSparqlLog(String s) { + try { + FileWriter fw = new FileWriter("log/sparql.txt", true); + fw.write(s + "\n"); + fw.flush(); + fw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** * Converts Jena result set to XML. * * @return String xml */ public static String getAsXMLString(ResultSet resultSet) { - //if (rs == null) - // this.send(); + // if (rs == null) + // this.send(); return ResultSetFormatter.asXMLString(resultSet); } /** * Converts Jena result set to JSON. * - * @param resultSet The result set to transform. + * @param resultSet + * The result set to transform. * @return JSON representation of the result set. */ public static String getAsJSON(ResultSet resultSet) { // if (rs == null) - // this.send(); + // this.send(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ResultSetFormatter.outputAsJSON(baos, resultSet); // possible Jena bug: Jena modifies the result set during @@ -186,10 +238,10 @@ public static ResultSet JSONtoResultSet(String json) { ByteArrayInputStream bais = new ByteArrayInputStream(json .getBytes(Charset.forName("UTF-8"))); - //System.out.println("JSON " + json); + // System.out.println("JSON " + json); return ResultSetFactory.fromJSON(bais); } - + /** * Converts from JSON to xml format. * @@ -200,39 +252,4 @@ public static String JSONtoXML(String json) { return getAsXMLString(JSONtoResultSet(json)); } - - public String getJson() { - if(wasExecuted == false){this.send();} - return json; - } - - public void setJson(String json) { - this.wasExecuted=true; - this.json = json; - } - - public void setRunning(boolean running){ - this.isRunning=running; - } - - public static void writeToSparqlLog(String s){ - try{ - FileWriter fw = new FileWriter("log/sparql.txt",true); - fw.write(s+"\n"); - fw.flush(); - fw.close(); - }catch (Exception e) { - e.printStackTrace(); - } - } - - public ResultSet getResultSet(){ - if(getJson() == null) {return null;} - else return JSONtoResultSet(json) ; - } - - public String getXMLString(){ - if(getJson() == null) {return null;} - else return JSONtoXML(json) ; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-06-26 15:22:06
|
Revision: 984 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=984&view=rev Author: kurzum Date: 2008-06-26 08:21:53 -0700 (Thu, 26 Jun 2008) Log Message: ----------- main format for sparqlquery is json now hope it doesn't produce so much errors now anymore Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-06-26 15:21:53 UTC (rev 984) @@ -246,12 +246,13 @@ JamonMonitorLogger.getTimeMonitor(Cache.class, "ReadTime").stop(); if (result != null) { - //query.setJson(result); + query.setJson(result); query.setRunning(false); - SparqlQuery.writeToSpecialLog("***********\nJSON retrieved from cache"); - SparqlQuery.writeToSpecialLog(query.getQueryString()); - SparqlQuery.writeToSpecialLog(query.getEndpoint().getURL().toString()); + SparqlQuery.writeToSparqlLog("***********\nJSON retrieved from cache"); + SparqlQuery.writeToSparqlLog(query.getQueryString()); + SparqlQuery.writeToSparqlLog(query.getEndpoint().getURL().toString()); + SparqlQuery.writeToSparqlLog("JSON: "+result); JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits"); } else { @@ -261,7 +262,7 @@ String json = query.getJson(); if (json!=null){ addToCache(query.getQueryString(), json); - SparqlQuery.writeToSpecialLog("result added to cache: "+json); + SparqlQuery.writeToSparqlLog("result added to cache: "+json); result=json; query.setJson(result); } @@ -269,7 +270,7 @@ json=""; result=""; logger.warn(Cache.class.getSimpleName()+"empty result: "+query.getQueryString()); - SparqlQuery.writeToSpecialLog("empty result for : "+query.getQueryString()); + SparqlQuery.writeToSparqlLog("empty result for : "+query.getQueryString()); } //return json; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-06-26 15:21:53 UTC (rev 984) @@ -354,8 +354,8 @@ if(c==null){ SparqlQuery sq = new SparqlQuery(SPARQLquery,se); // sq.extraDebugInfo+=se.getURL(); - ResultSet rs=sq.send(); - String JSON = SparqlQuery.getAsJSON(rs); + sq.send(); + String JSON = sq.getJson(); return JSON; }else{ return c.executeSparqlQuery(new SparqlQuery(SPARQLquery,se)); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-06-26 15:21:53 UTC (rev 984) @@ -45,7 +45,6 @@ import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.owl.KB; import org.dllearner.kb.extraction.Manager; -import org.dllearner.kb.extraction.Manipulator; import org.dllearner.kb.extraction.ManipulatorType; import org.dllearner.kb.extraction.Manipulators; import org.dllearner.parser.KBParser; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-26 15:21:53 UTC (rev 984) @@ -47,11 +47,12 @@ private boolean isRunning = false; + private boolean wasExecuted = false; private String queryString; private QueryEngineHTTP queryExecution; private SparqlEndpoint endpoint; //private ResultSet rs; - private String json; + private String json = null; // private SparqlQueryException sendException=null; /** @@ -61,7 +62,8 @@ * @param endpoint */ public SparqlQuery(String queryString, SparqlEndpoint endpoint) { - this.queryString = queryString; + // QUALITY there seems to be a bug in ontowiki + this.queryString = queryString.replaceAll("\n", " "); this.endpoint = endpoint; } @@ -71,17 +73,18 @@ /** * Sends a SPARQL query using the Jena library. - * should return JSON String - * needs refactoring - * @return ResultSet + * main format is JSON use method getasjson + * + * @return nothing */ - @Deprecated - public ResultSet send() { + + public void send() { + wasExecuted = true; ResultSet rs; //isRunning = true; - writeToSpecialLog("***********\nNew Query:"); - writeToSpecialLog(queryString); - writeToSpecialLog(endpoint.getURL().toString()); + writeToSparqlLog("***********\nNew Query:"); + writeToSparqlLog(queryString); + writeToSparqlLog(endpoint.getURL().toString()); String service = endpoint.getURL().toString(); @@ -94,6 +97,7 @@ queryExecution.addNamedGraph(ngu); } + //TODO remove after overnext Jena release HttpQuery.urlLimit = 3*1024 ; JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").start(); @@ -101,20 +105,17 @@ JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop(); - logger.debug("query SPARQL server, retrieved: "+rs.getResultVars()); - writeToSpecialLog("query SPARQL server, retrieved: "+rs.getResultVars()); - writeToSpecialLog("Results from ResultSet"); + logger.debug("query length: "+queryString.length()+" | ENDPOINT: "+endpoint.getURL().toString()); + //writeToSparqlLog("query: "+queryString+ " | ENDPOINT: "+endpoint.getURL().toString()); + + json = SparqlQuery.getAsJSON(rs); - writeToSpecialLog(json); - rs = SparqlQuery.JSONtoResultSet(json); - while (rs.hasNext()){ - writeToSpecialLog("Result: "+rs.nextBinding()); - } + writeToSparqlLog("JSON: "+json); + isRunning = false; - rs = SparqlQuery.JSONtoResultSet(json); - return rs; + } public void stop() { @@ -143,7 +144,7 @@ // } /** - * sends a query and returns XML + * Converts Jena result set to XML. * * @return String xml */ @@ -188,12 +189,25 @@ //System.out.println("JSON " + json); return ResultSetFactory.fromJSON(bais); } + + /** + * Converts from JSON to xml format. + * + * @param json + * A JSON representation if a SPARQL query result. + * @return A Jena ResultSet. + */ + public static String JSONtoXML(String json) { + return getAsXMLString(JSONtoResultSet(json)); + } public String getJson() { + if(wasExecuted == false){this.send();} return json; } public void setJson(String json) { + this.wasExecuted=true; this.json = json; } @@ -201,7 +215,7 @@ this.isRunning=running; } - public static void writeToSpecialLog(String s){ + public static void writeToSparqlLog(String s){ try{ FileWriter fw = new FileWriter("log/sparql.txt",true); fw.write(s+"\n"); @@ -212,7 +226,13 @@ } } - /*public ResultSet getResultSet(){ - return rs; - }*/ + public ResultSet getResultSet(){ + if(getJson() == null) {return null;} + else return JSONtoResultSet(json) ; + } + + public String getXMLString(){ + if(getJson() == null) {return null;} + else return JSONtoXML(json) ; + } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-26 15:21:53 UTC (rev 984) @@ -519,21 +519,39 @@ { ClientState state = getState(sessionID); //ResultSet resultSet=null; - String json=null; - if ((json=state.getQuery(queryID).getJson())!=null) return json; + String json = null; + try { + json = state.getQuery(queryID).getJson(); + }catch (Exception e) { + e.printStackTrace(); + throw new SparqlQueryException("SparqlQuery failed"+e.toString()); + } + + if(json == null) { throw new SparqlQueryException("SparqlQuery failed JSON was null");} + return json; + //if ((json=state.getQuery(queryID).getJson())!=null) return json; //else if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsJSON(resultSet); - else return SparqlQuery.getAsJSON(state.getQuery(queryID).send()); + //else return SparqlQuery.getAsJSON(state.getQuery(queryID).send()); } @WebMethod - public String getAsXMLString(int sessionID, int queryID) throws ClientNotKnownException + public String getAsXMLString(int sessionID, int queryID) throws ClientNotKnownException, SparqlQueryException { ClientState state = getState(sessionID); - //ResultSet resultSet=null; - String json=null; + + String xml = null; + try{ + xml = state.getQuery(queryID).getXMLString(); + }catch (Exception e) { + e.printStackTrace(); + throw new SparqlQueryException("SparqlQuery failed"+e.toString()); + } + + if(xml == null) throw new SparqlQueryException("SparqlQuery failed xml was null"); + return xml; //if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsXMLString(resultSet); - if ((json=state.getQuery(queryID).getJson())!=null) return SparqlQuery.getAsXMLString(SparqlQuery.JSONtoResultSet(json)); - else return SparqlQuery.getAsXMLString(state.getQuery(queryID).send()); + //if ((json=state.getQuery(queryID).getJson())!=null) return SparqlQuery.getAsXMLString(SparqlQuery.JSONtoResultSet(json)); + //else return SparqlQuery.getAsXMLString(state.getQuery(queryID).send()); } @WebMethod @@ -574,7 +592,7 @@ Cache cache=new Cache(ks.getCacheDir()); return cache.executeSparqlQuery(sparql); } - else return SparqlQuery.getAsJSON(sparql.send()); + else return sparql.getJson(); } @WebMethod Modified: trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-06-26 10:44:36 UTC (rev 983) +++ trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-06-26 15:21:53 UTC (rev 984) @@ -22,7 +22,6 @@ import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; -import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFormatter; @@ -54,14 +53,14 @@ SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); // first query is not counted - ResultSet rs = sqJena.send(); - SparqlQuery.getAsXMLString(rs); + sqJena.send(); + sqJena.getXMLString(); long now = System.currentTimeMillis(); long tmp = now; for (int i = 0; i < howOften; i++) { - rs = sqJena.send(); - SparqlQuery.getAsXMLString(rs); + sqJena.send(); + sqJena.getXMLString(); p("Jena as XML needed: " + (System.currentTimeMillis() - tmp)); tmp = System.currentTimeMillis(); @@ -83,8 +82,8 @@ for (int i = 0; i < howOften; i++) { // sqJena.getAsList(); - ResultSet rs = sqJena.send(); - ResultSetFormatter.toList(rs); + sqJena.send(); + ResultSetFormatter.toList(sqJena.getResultSet()); p("Jena as List needed: " + (System.currentTimeMillis() - tmp)); tmp = System.currentTimeMillis(); @@ -100,14 +99,14 @@ SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); // first query is not counted - ResultSet rs = sqJena.send(); - SparqlQuery.getAsJSON(rs); + sqJena.send(); + sqJena.getJson(); long now = System.currentTimeMillis(); long tmp = now; for (int i = 0; i < howOften; i++) { - rs = sqJena.send(); - SparqlQuery.getAsJSON(rs); + sqJena.send(); + sqJena.getJson(); p("Jena as JSON needed: " + (System.currentTimeMillis() - tmp)); tmp = System.currentTimeMillis(); @@ -123,15 +122,15 @@ SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); // first query is not counted - ResultSet rs = sqJena.send(); - SparqlQuery.getAsJSON(rs); + sqJena.send(); + sqJena.getJson(); long now = System.currentTimeMillis(); long tmp = now; for (int i = 0; i < howOften; i++) { // System.out.println(sqJena.getAsJSON()); - rs = sqJena.send(); - String json = SparqlQuery.getAsJSON(rs); + sqJena.send(); + String json = sqJena.getJson(); SparqlQuery.JSONtoResultSet(json); p("Jena as JSON and back needed: " + (System.currentTimeMillis() - tmp)); @@ -150,8 +149,8 @@ SparqlQuery sqJena = new SparqlQuery(queryString, sse); // SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); - ResultSet rs = sqJena.send(); - System.out.println(SparqlQuery.getAsXMLString(rs)); + sqJena.send(); + System.out.println(sqJena.getJson()); // System.out.println(sqConv.getAsXMLString("")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-06-26 10:44:41
|
Revision: 983 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=983&view=rev Author: JensLehmann Date: 2008-06-26 03:44:36 -0700 (Thu, 26 Jun 2008) Log Message: ----------- - ComponentInitException thrown when loading inconsistent ontologies into OWL API reasoner - OWL API bug test file Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/php-examples/LearningSimple.php Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/OWLAPIConsistency.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-26 10:44:36 UTC (rev 983) @@ -36,6 +36,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.ConfigEntry; @@ -162,7 +163,7 @@ } @Override - public void init() { + public void init() throws ComponentInitException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // it is a bit cumbersome to obtain all classes, because there @@ -294,10 +295,19 @@ // compute class hierarchy and types of individuals // (done here to speed up later reasoner calls) + boolean inconsistentOntology = false; try { reasoner.loadOntologies(allImports); - reasoner.classify(); - reasoner.realise(); + for(OWLOntology ont : owlAPIOntologies) { + if(!reasoner.isConsistent(ont)) { + inconsistentOntology = true; + throw new ComponentInitException("Inconsistent ontologies."); + } + } + if(!inconsistentOntology) { + reasoner.classify(); + reasoner.realise(); + } } catch (OWLReasonerException e) { e.printStackTrace(); } Modified: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-06-26 10:44:36 UTC (rev 983) @@ -17,7 +17,9 @@ OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); URI ontologyURI = URI.create("http://www.examples.com/test"); - File f = new File("test.owl"); +// File f = new File("test.owl"); + + File f = new File("src/dl-learner/org/dllearner/tools/ore/inconsistent.owl"); URI physicalURI = f.toURI(); SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); manager.addURIMapper(mapper); Added: trunk/src/dl-learner/org/dllearner/test/OWLAPIConsistency.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIConsistency.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIConsistency.java 2008-06-26 10:44:36 UTC (rev 983) @@ -0,0 +1,45 @@ +package org.dllearner.test; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.model.*; + +import java.io.File; +import java.net.URI; +import java.util.Set; + +public class OWLAPIConsistency { + public static void main(String[] args) { + + try { + File f = new File("src/dl-learner/org/dllearner/tools/ore/inconsistent.owl"); + URI physicalURI = f.toURI(); + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + OWLOntology ont = manager.loadOntologyFromPhysicalURI(physicalURI); + System.out.println("Loaded " + ont.getURI()); + + OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + + Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); + reasoner.loadOntologies(importsClosure); +// reasoner.classify(); + + boolean consistent = reasoner.isConsistent(ont); + System.out.println("Consistent: " + consistent); + System.out.println("\n"); + + } + catch(UnsupportedOperationException exception) { + System.out.println("Unsupported reasoner operation."); + } + catch(OWLReasonerException ex) { + System.out.println("Reasoner error: " + ex.getMessage()); + } + catch (OWLOntologyCreationException e) { + System.out.println("Could not load the pizza ontology: " + e.getMessage()); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-26 10:44:36 UTC (rev 983) @@ -94,9 +94,14 @@ } - rs = cm.reasoningService(reasoner); +// rs = cm.reasoningService(reasoner); reasoner2 = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner2.init(); + try { + reasoner2.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } modi = new OntologyModifierOWLAPI(reasoner2); } @@ -475,12 +480,12 @@ final ORE test = new ORE(); - File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl"); + File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/inconsistent.owl"); test.setKnowledgeSource(owlFile); test.detectReasoner(); - System.out.println(test.reasoner2.getInconsistentClasses()); +// System.out.println(test.reasoner2.getInconsistentClasses()); // System.err.println("Concepts :" + rs.getAtomicConcepts()); Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-26 10:44:36 UTC (rev 983) @@ -286,7 +286,12 @@ public void setReasoner() { this.reasoner =cm.reasoner(OWLAPIReasoner.class,source); - reasoner.init(); + try { + reasoner.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } rs = cm.reasoningService(reasoner); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-06-26 10:44:36 UTC (rev 983) @@ -8,6 +8,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.ClassAssertionAxiom; @@ -47,7 +48,12 @@ Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(this.kbFile); OWLAPIReasoner owlapi = new OWLAPIReasoner(ks); - owlapi.init(); + try { + owlapi.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } this.indToRestr = new HashMap<Individual, Set<ObjectExactCardinalityRestriction>>(); this.classes = new HashSet<Description>(); this.rs = new ReasoningService(owlapi); @@ -64,7 +70,12 @@ sc.printAndSet("updating reasoner"); OWLAPIReasoner owlapi = new OWLAPIReasoner(ks); sc.printAndSet("init"); - owlapi.init(); + try { + owlapi.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } sc.printAndSet(); this.rs = new ReasoningService(owlapi); Modified: trunk/src/php-examples/LearningSimple.php =================================================================== --- trunk/src/php-examples/LearningSimple.php 2008-06-26 06:52:48 UTC (rev 982) +++ trunk/src/php-examples/LearningSimple.php 2008-06-26 10:44:36 UTC (rev 983) @@ -62,7 +62,7 @@ // learn concept echo 'start learning ... '; -$concept = $client->learn($id); +$concept = $client->learn($id, "manchester"); echo 'OK <br />'; echo 'solution: ' . $concept; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2008-06-26 06:52:51
|
Revision: 982 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=982&view=rev Author: lorenz_b Date: 2008-06-25 23:52:48 -0700 (Wed, 25 Jun 2008) Log Message: ----------- test cases for inconsistency Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/inconsistent.owl trunk/src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-25 20:34:43 UTC (rev 981) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-26 06:52:48 UTC (rev 982) @@ -85,16 +85,16 @@ public void detectReasoner(){ -// reasoner = cm.reasoner(FastInstanceChecker.class, ks); -// try { -// reasoner.init(); -// } catch (ComponentInitException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// -// -// rs = cm.reasoningService(reasoner); + reasoner = cm.reasoner(FastInstanceChecker.class, ks); + try { + reasoner.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + rs = cm.reasoningService(reasoner); reasoner2 = cm.reasoner(OWLAPIReasoner.class, ks); reasoner2.init(); Added: trunk/src/dl-learner/org/dllearner/tools/ore/inconsistent.owl =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/inconsistent.owl (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/inconsistent.owl 2008-06-26 06:52:48 UTC (rev 982) @@ -0,0 +1,95 @@ +<?xml version="1.0"?> + + +<!DOCTYPE rdf:RDF [ + <!ENTITY www "http://www.test.owl#" > + <!ENTITY owl "http://www.w3.org/2002/07/owl#" > + <!ENTITY owl2 "http://www.w3.org/2006/12/owl2#" > + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > + <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" > + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > +]> + + +<rdf:RDF xmlns="http://www.test.owl#" + xml:base="http://www.test.owl" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#" + xmlns:www="http://www.test.owl#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:owl2="http://www.w3.org/2006/12/owl2#"> + <owl:Ontology rdf:about=""/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.test.owl#A --> + + <owl:Class rdf:about="#A"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.test.owl#B --> + + <owl:Class rdf:about="#B"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + <owl:disjointWith rdf:resource="#C"/> + </owl:Class> + + + + <!-- http://www.test.owl#C --> + + <owl:Class rdf:about="#C"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.test.owl#D --> + + <owl:Class rdf:about="#D"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.w3.org/2002/07/owl#Thing --> + + <owl:Class rdf:about="&owl;Thing"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Individuals + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.test.owl#lorenz --> + + <C rdf:about="#lorenz"> + <rdf:type rdf:resource="#A"/> + <rdf:type rdf:resource="#B"/> + </C> +</rdf:RDF> Added: trunk/src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl 2008-06-26 06:52:48 UTC (rev 982) @@ -0,0 +1,101 @@ +<?xml version="1.0"?> + + +<!DOCTYPE rdf:RDF [ + <!ENTITY www "http://www.test.owl#" > + <!ENTITY owl "http://www.w3.org/2002/07/owl#" > + <!ENTITY owl2 "http://www.w3.org/2006/12/owl2#" > + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > + <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" > + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > +]> + + +<rdf:RDF xmlns="http://www.test.owl#" + xml:base="http://www.test.owl" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#" + xmlns:www="http://www.test.owl#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:owl2="http://www.w3.org/2006/12/owl2#"> + <owl:Ontology rdf:about=""/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.test.owl#A --> + + <owl:Class rdf:about="#A"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.test.owl#B --> + + <owl:Class rdf:about="#B"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + <owl:disjointWith rdf:resource="#C"/> + </owl:Class> + + + + <!-- http://www.test.owl#C --> + + <owl:Class rdf:about="#C"> + <rdfs:subClassOf rdf:resource="&owl;Thing"/> + </owl:Class> + + + + <!-- http://www.test.owl#D --> + + <owl:Class rdf:about="#D"> + <rdfs:subClassOf rdf:resource="#B"/> + <rdfs:subClassOf rdf:resource="#C"/> + </owl:Class> + + + + <!-- http://www.w3.org/2002/07/owl#Thing --> + + <owl:Class rdf:about="&owl;Thing"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Individuals + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.test.owl#frank --> + + <B rdf:about="#frank"/> + + + + <!-- http://www.test.owl#lorenz --> + + <C rdf:about="#lorenz"> + <rdf:type rdf:resource="#A"/> + </C> +</rdf:RDF> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2008-06-25 20:34:47
|
Revision: 981 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=981&view=rev Author: lorenz_b Date: 2008-06-25 13:34:43 -0700 (Wed, 25 Jun 2008) Log Message: ----------- changed some repair options Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/ChangesPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/ChooseDialog.java trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/ChangePanel.java trunk/src/dl-learner/org/dllearner/tools/ore/UndoLabel.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/tools/ore/ActionsPanel.java Deleted: trunk/src/dl-learner/org/dllearner/tools/ore/ActionsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ActionsPanel.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ActionsPanel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,120 +0,0 @@ -package org.dllearner.tools.ore; - -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import javax.swing.border.TitledBorder; - -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.reasoning.OWLAPIReasoner; - -public class ActionsPanel extends JPanel{ - /** - * - */ - private static final long serialVersionUID = -3761077097231343915L; - ORE ore; - Individual ind; - OWLAPIReasoner reasoner; - ActionListener al; - - - public ActionsPanel(ORE ore, Individual ind, ActionListener al){ - super(new GridLayout(0, 1)); - this.ore = ore; - this.ind = ind; - this.reasoner = ore.modi.reasoner; - this.al = al; - } - - public void init(){ - setBorder(new TitledBorder("actions")); - JButton delete = new JButton("delete instance"); - add(delete); - updatePanel(); - -// for(Description d :ore.getCriticalDescriptions(ind, ore.getConceptToAdd())){ -// -// if(!(d instanceof Negation)){ -// if(d instanceof NamedClass){ -// add(new DescriptionButton("remove class assertion to " + d.toString(), d )); -// add(new DescriptionButton("move class assertion " + d.toString() + " to ...", d)); -// } -// else if(d instanceof ObjectSomeRestriction) -// add(new DescriptionButton("remove property assertion " + d.toString(), d)); -// } -// else if(d instanceof Negation){ -// if(d.getChild(0) instanceof NamedClass) -// add(new DescriptionButton("add class assertion to " + d.getChild(0).toString(), d)); -// else if(d.getChild(0) instanceof ObjectSomeRestriction) -// add(new DescriptionButton("add property " + d.toString(), d)); -// } -// } - } - - - public void addActionListeners(ActionListener al){ - for(Component c : getComponents()) - if(c instanceof JButton) - ((JButton)c).addActionListener(al); - } - - public void updatePanel(){//DescriptionButton descBut, Description desc){ - for(Component c : getComponents()) - if(c instanceof DescriptionButton) - remove(c); - - ore.modi.refreshReasoner(); - for(Description d :ore.getCriticalDescriptions(ind, ore.getConceptToAdd())){ - System.out.println(d + " " + ore.modi.reasoner.instanceCheck(d, ind)); - if(ore.modi.reasoner.instanceCheck(d, ind)){ - if(!(d instanceof Negation)){ - if(d instanceof NamedClass){ - add(new DescriptionButton("remove class assertion to " + d.toString(), d )); - add(new DescriptionButton("move class assertion " + d.toString() + " to ...", d)); - } - else if(d instanceof ObjectSomeRestriction) - add(new DescriptionButton("remove property assertion " + d.toString(), d)); - } - else if(d instanceof Negation){ - if(d.getChild(0) instanceof NamedClass) - add(new DescriptionButton("add class assertion to " + d.getChild(0).toString(), d.getChild(0))); - else if(d.getChild(0) instanceof ObjectSomeRestriction) - add(new DescriptionButton("add property " + d.toString(), d)); - } - } - } - addActionListeners(al); - - - - - -// String command = descBut.getActionCommand(); -// if(command.startsWith("remove class")){ -// for(Component c : getComponents()) -// if(c instanceof DescriptionButton && ((DescriptionButton)c).getDescription().equals(desc) && ((DescriptionButton)c).getActionCommand().startsWith("move class")) -// remove(c); -// } -// else if(command.startsWith("move class")){ -// for(Component c : getComponents()) -// if(c instanceof DescriptionButton && ((DescriptionButton)c).getDescription().equals(desc) && ((DescriptionButton)c).getActionCommand().startsWith("remove class")) -// remove(c); -// } -// -// remove(descBut); -// - SwingUtilities.updateComponentTreeUI(this); - - } - - -} Added: trunk/src/dl-learner/org/dllearner/tools/ore/ChangePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ChangePanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ChangePanel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -0,0 +1,29 @@ +package org.dllearner.tools.ore; + + +import java.awt.Color; +import java.awt.event.MouseListener; +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.semanticweb.owl.model.OWLOntologyChange; + +public class ChangePanel extends JPanel{ + + /** + * + */ + private static final long serialVersionUID = -934113184795465461L; + + + public ChangePanel(String label, List<OWLOntologyChange> changes, MouseListener mL){ + super(); + add(new JLabel(label)); + add(new UndoLabel(changes, mL)); + setBackground(Color.WHITE); + + } + +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ChangesPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ChangesPanel.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ChangesPanel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,9 +1,13 @@ package org.dllearner.tools.ore; +import java.awt.Color; +import java.awt.Container; import java.awt.GridLayout; +import javax.swing.BorderFactory; import javax.swing.JPanel; -import javax.swing.border.TitledBorder; +import javax.swing.SwingUtilities; +import javax.swing.border.BevelBorder; public class ChangesPanel extends JPanel{ @@ -14,12 +18,19 @@ public ChangesPanel(){ super(new GridLayout(0, 1)); + setBackground(Color.WHITE); + setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); } public void init(){ - setBorder(new TitledBorder("changes")); +// setBorder(new TitledBorder("changes")); } + public void updatePanel(Container cont){ + remove(cont); + SwingUtilities.updateComponentTreeUI(this); + } + } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ChooseDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ChooseDialog.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ChooseDialog.java 2008-06-25 20:34:43 UTC (rev 981) @@ -99,7 +99,7 @@ return selectedElement; } - @Override + public void actionPerformed(ActionEvent e) { if(e.getSource().equals(okButton)){ selectedElement = list.getSelectedValue(); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -7,9 +7,11 @@ import java.awt.event.MouseListener; import javax.swing.JLabel; +import javax.swing.JMenu; import javax.swing.JPopupMenu; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; import org.dllearner.core.owl.ObjectSomeRestriction; @@ -20,6 +22,8 @@ */ private static final long serialVersionUID = 1L; private final Description desc; + private Individual ind; + private ORE ore; private JPopupMenu menu; public DescriptionLabel(Description d){ @@ -27,24 +31,56 @@ this.desc = d; setForeground(Color.red); addMouseListener(this); +// menu = new JPopupMenu(); +// if(!(desc instanceof Negation)){ +// if(desc instanceof NamedClass){ +// menu.add(new DescriptionMenuItem("remove class assertion " + desc.toString(), desc) ); +// DescriptionMenuItem dme = new DescriptionMenuItem("move class assertion " + desc.toString() + " to ...", desc); +// for(NamedClass nc : ore.getpossibleMoveClasses(ind)) +// dme.add(new JMenuItem(nc.getName())); +// menu.add(dme); +//// menu.add(new DescriptionMenuItem("move class assertion " + desc.toString() + " to ...", desc)); +// } +// else if(desc instanceof ObjectSomeRestriction) +// menu.add(new DescriptionMenuItem("remove property assertion " + desc.toString(), desc)); +// } +// else if(desc instanceof Negation){ +// if(desc.getChild(0) instanceof NamedClass) +// menu.add(new DescriptionMenuItem("add class assertion to " + desc.getChild(0).toString(), desc.getChild(0))); +// else if(desc.getChild(0) instanceof ObjectSomeRestriction) +// menu.add(new DescriptionMenuItem("add property " + d.toString(), desc.getChild(0))); +// } + + + + } + + public void init(){ menu = new JPopupMenu(); if(!(desc instanceof Negation)){ if(desc instanceof NamedClass){ menu.add(new DescriptionMenuItem("remove class assertion " + desc.toString(), desc) ); - menu.add(new DescriptionMenuItem("move class assertion " + desc.toString() + " to ...", desc)); + JMenu dme = new JMenu("move class assertion " + desc.toString() + " to ..."); + for(NamedClass nc : ore.getpossibleMoveClasses(ind)) + dme.add(new DescriptionMenuItem(nc.getName(), desc)); + menu.add(dme); +// menu.add(new DescriptionMenuItem("move class assertion " + desc.toString() + " to ...", desc)); } else if(desc instanceof ObjectSomeRestriction) menu.add(new DescriptionMenuItem("remove property assertion " + desc.toString(), desc)); } else if(desc instanceof Negation){ - if(desc.getChild(0) instanceof NamedClass) - menu.add(new DescriptionMenuItem("add class assertion to " + desc.getChild(0).toString(), desc.getChild(0))); + if(desc.getChild(0) instanceof NamedClass){ + DescriptionMenuItem item = new DescriptionMenuItem("add class assertion to " + desc.getChild(0).toString(), desc.getChild(0)); + menu.add(item); + if(ore.hasComplement(desc, ind)){ + item.setEnabled(false); + item.setToolTipText("class assertion not possible because individual is still asserted to its complement"); + } + } else if(desc.getChild(0) instanceof ObjectSomeRestriction) - menu.add(new DescriptionMenuItem("add property " + d.toString(), desc.getChild(0))); + menu.add(new DescriptionMenuItem("add property " + desc.toString(), desc.getChild(0))); } - - - } public Description getDescription(){ @@ -52,37 +88,49 @@ } public void addActionListeners(ActionListener aL){ - for(Component c : menu.getComponents()) - ((DescriptionMenuItem)c).addActionListener(aL); + for(Component c : menu.getComponents()){ + if(c instanceof DescriptionMenuItem) + ((DescriptionMenuItem)c).addActionListener(aL); + else if(c instanceof JMenu) + for( int i = 0; i < ((JMenu)c).getItemCount(); i++) + ((JMenu)c).getItem(i).addActionListener(aL); + + + } } + + public void setIndOre(ORE ore, Individual ind){ + this.ore = ore; + this.ind = ind; + } - @Override + public void mouseClicked(MouseEvent e) { menu.show(this.getParent(),getLocation().x ,getLocation().y+50); } - @Override + public void mouseEntered(MouseEvent e) { setText("<html><u>" + desc.toString() + "</u></html>"); } - @Override + public void mouseExited(MouseEvent e) { setText(desc.toString()); } - @Override + public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } - @Override + public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub Modified: trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionPanel.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionPanel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,11 +1,14 @@ package org.dllearner.tools.ore; +import java.awt.Color; import java.awt.Component; import java.awt.event.ActionListener; +import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.border.BevelBorder; import org.dllearner.core.owl.Individual; @@ -22,13 +25,19 @@ public DescriptionPanel(ORE ore, Individual ind, ActionListener aL){ super(); + setBackground(Color.WHITE); + setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); this.ore = ore; this.ind = ind; this.aL = aL; for(JLabel jL : ore.DescriptionToJLabel(ind, ore.conceptToAdd)){ add(jL); - if(jL instanceof DescriptionLabel) + if(jL instanceof DescriptionLabel){ + + ((DescriptionLabel)jL).setIndOre(ore, ind); + ((DescriptionLabel)jL).init(); ((DescriptionLabel)jL).addActionListeners(aL); + } } } @@ -40,8 +49,13 @@ ore.updateReasoner(); for(JLabel jL : ore.DescriptionToJLabel(ind, ore.conceptToAdd)){ add(jL); - if(jL instanceof DescriptionLabel) + if(jL instanceof DescriptionLabel){ + ((DescriptionLabel)jL).setIndOre(ore, ind); + ((DescriptionLabel)jL).init(); ((DescriptionLabel)jL).addActionListeners(aL); + + + } } SwingUtilities.updateComponentTreeUI(this); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-25 20:34:43 UTC (rev 981) @@ -60,17 +60,19 @@ @SuppressWarnings("unchecked") @Override public List<Description> doInBackground() { + panel4.getResultList().setCellRenderer(new ColumnListCellRenderer(getWizardModel().getOre())); panel4.getLoadingLabel().setBusy(true); panel4.getStatusLabel().setText("Learning"); getWizardModel().getOre().setNoise(panel4.getNoise()); - la = getWizardModel().getOre().start();//started endlosen Algorithmus + la = getWizardModel().getOre().start();//started endlosen Algorithmus publish(la.getBestSolutions(10)); + - List<Description> result = getWizardModel().getOre().getLearningResults(10); + List<Description> result = getWizardModel().getOre().getLearningResults(100); return result; } @@ -97,6 +99,7 @@ @Override protected void process(List<List<Description>> resultLists) { + panel4.getModel().clear(); for (List<Description> list : resultLists) { Modified: trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,18 +1,20 @@ package org.dllearner.tools.ore; import java.awt.BorderLayout; -import java.awt.GridLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.border.EmptyBorder; @@ -20,11 +22,11 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.reasoning.OWLAPIReasoner; +import org.semanticweb.owl.model.OWLOntologyChange; +import org.semanticweb.owl.model.RemoveAxiom; -public class NegExampleRepairDialog extends JDialog implements ActionListener{ +public class NegExampleRepairDialog extends JDialog implements ActionListener, MouseListener{ /** * @@ -76,18 +78,25 @@ changesPanel = new ChangesPanel(); changesPanel.init(); + JButton deleteButton = new JButton("delete"); + deleteButton.addActionListener(this); + changesPanel.add(deleteButton); - action_stats_Panel = new JPanel(); - action_stats_Panel.setLayout(new GridLayout(4,0)); - + GridBagLayout gbl = new GridBagLayout(); + gbl.rowWeights = new double[] {0.0, 0.1, 0.1}; + gbl.rowHeights = new int[] {34, 7, 7}; + gbl.columnWeights = new double[] {0.1}; + gbl.columnWidths = new int[] {7}; + action_stats_Panel.setLayout(gbl); - action_stats_Panel.add(descPanel); - action_stats_Panel.add(scroll); - action_stats_Panel.add(changesPanel); + action_stats_Panel.add(descPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); + action_stats_Panel.add(scroll, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 0, 5), 0, 0)); + action_stats_Panel.add(changesPanel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 0, 5), 0, 0)); + JSeparator separator = new JSeparator(); Box buttonBox = new Box(BoxLayout.X_AXIS); @@ -117,38 +126,44 @@ } public void actionPerformed(ActionEvent e) { - System.out.println(e.getSource()); + if(e.getSource() instanceof DescriptionMenuItem){ actualDesc = ((DescriptionMenuItem)e.getSource()).getDescription(); - + if(e.getActionCommand().startsWith("remove class")){ //remove class - System.err.println("vorher: " + ore.modi.checkInstanceNewOntology(ore.getConceptToAdd() ,ind)); - System.err.println("vorher: " + ore.modi.getCriticalDescriptions(ind, ore.conceptToAdd)); - ore.modi.removeClassAssertion(ind, actualDesc); + List<OWLOntologyChange> changes = ore.modi.removeClassAssertion(ind, actualDesc); descPanel.updatePanel(); - changesPanel.add(new JLabel("removed class assertion to " + actualDesc)); - changesPanel.add(new JButton("Undo")); - System.err.println("nachher: " + ore.modi.checkInstanceNewOntology(ore.conceptToAdd, ind)); - System.err.println("nachher: " + ore.modi.getCriticalDescriptions(ind, ore.conceptToAdd)); + changesPanel.add(new ChangePanel("removed class assertion to " + actualDesc, changes, this)); + + } -// else if(e.getActionCommand().startsWith("add class")){ //add class -// System.err.println(actualDesc); -// ore.modi.addClassAssertion(ind, actualDesc); -// actionsPanel.updatePanel(); -// changes.add(new JLabel("added class assertion to " + actualDesc)); -// -// } -// else if(e.getActionCommand().startsWith("move class")){ //move class -// -// newDesc = (Description)new ChooseDialog(this, ore, ind).getSelectedElement(); -// System.err.println(newDesc); -// if(newDesc != null){ -// System.out.print(ind + " from " + actualDesc + " to " + newDesc); -// ore.modi.moveIndividual(ind, actualDesc, newDesc); -// } -// -// } + else if(e.getActionCommand().startsWith("add class")){ //add class + List<OWLOntologyChange> changes = ore.modi.addClassAssertion(ind, actualDesc); + descPanel.updatePanel(); + changesPanel.add(new ChangePanel("added class assertion to " + actualDesc, changes, this)); + + + } + else{ //move class + + newDesc = new NamedClass(e.getActionCommand()); + List<OWLOntologyChange> changes = ore.modi.moveIndividual(ind, actualDesc, newDesc); + + descPanel.updatePanel(); + changesPanel.add(new ChangePanel("moved class assertion from " + actualDesc + " to " + newDesc, changes, this)); + + } + + } + else if(e.getActionCommand().equals("delete")){ + List<OWLOntologyChange> changes = ore.modi.deleteIndividual(ind); + for(OWLOntologyChange ol : changes) + System.out.println(((RemoveAxiom)ol).getAxiom()); + } + + + } // else if(e.getActionCommand().equals("add property")){ //add property // object = (Individual)new ChooseDialog(this, ore, actualDesc).getSelectedElement(); // if(object != null) @@ -158,7 +173,36 @@ // ore.modi.deleteObjectProperty(ind, (ObjectSomeRestriction)actualDesc); // } // } + + public void mouseClicked(MouseEvent e) { + if(e.getSource() instanceof UndoLabel){ + List<OWLOntologyChange> changes = ((UndoLabel)e.getSource()).getChanges(); + ore.modi.undoChanges(changes); + descPanel.updatePanel(); + changesPanel.updatePanel(((UndoLabel)e.getSource()).getParent()); + } + } + + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + } + + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + // if(e.getActionCommand().equals("delete instance")){ // ore.modi.deleteIndividual(ind); // @@ -202,13 +246,12 @@ // ore.modi.deleteObjectProperty(ind, (ObjectSomeRestriction)actualDesc); // } // } - } - } + Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,6 +1,5 @@ package org.dllearner.tools.ore; -import java.awt.Dimension; import java.io.File; import java.math.BigDecimal; import java.util.ArrayList; @@ -12,9 +11,7 @@ import java.util.TreeSet; import java.util.Vector; -import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JPanel; import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.ComponentInitException; @@ -28,6 +25,7 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.Union; import org.dllearner.kb.OWLAPIOntology; @@ -50,7 +48,7 @@ OWLAPIReasoner reasoner2; SortedSet<Individual> posExamples; SortedSet<Individual> negExamples; - NamedClass concept; + NamedClass ignoredConcept; Description conceptToAdd; OntologyModifierOWLAPI modi; Set<NamedClass> allAtomicConcepts; @@ -87,16 +85,16 @@ public void detectReasoner(){ - reasoner = cm.reasoner(FastInstanceChecker.class, ks); - try { - reasoner.init(); - } catch (ComponentInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - rs = cm.reasoningService(reasoner); +// reasoner = cm.reasoner(FastInstanceChecker.class, ks); +// try { +// reasoner.init(); +// } catch (ComponentInitException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// +// rs = cm.reasoningService(reasoner); reasoner2 = cm.reasoner(OWLAPIReasoner.class, ks); reasoner2.init(); @@ -112,7 +110,7 @@ } public void setPosNegExamples(){ - posExamples = rs.retrieval(concept); + posExamples = rs.retrieval(ignoredConcept); negExamples = rs.getIndividuals(); for (Individual rem_pos : posExamples) @@ -143,7 +141,7 @@ //la = new ROLearner(lp, rs); Set<String> t = new TreeSet<String>(); - t.add(concept.getName()); + t.add(ignoredConcept.getName()); cm.applyConfigEntry(la, "ignoredConcepts", t ); cm.applyConfigEntry(la, "noisePercentage", noise); cm.applyConfigEntry(la, "guaranteeXgoodDescriptions", 5); @@ -157,7 +155,7 @@ } public void setConcept(NamedClass concept){ - this.concept = concept; + this.ignoredConcept = concept; } @@ -185,6 +183,11 @@ return la.getBestSolutions(anzahl); } + /** + * + * @param d + * @return + */ public BigDecimal getCorrectness(Description d){ int numberPosExamples = 0; int numberNegExamples = 0; @@ -306,8 +309,8 @@ return modi; } - public NamedClass getConcept() { - return concept; + public NamedClass getIgnoredConcept() { + return ignoredConcept; } public void setAllAtomicConcepts(Set<NamedClass> allAtomicConcepts) { @@ -333,10 +336,11 @@ Set<Description> criticals = new HashSet<Description>(); List<Description> children = desc.getChildren(); - - + + if(reasoner2.instanceCheck(desc, ind)){ + if(children.size() >= 2){ - + if(desc instanceof Intersection){ for(Description d: children) criticals.addAll(getCriticalDescriptions(ind, d)); @@ -344,17 +348,13 @@ } else if(desc instanceof Union){ for(Description d: children) - try { - if(reasoner.instanceCheck(d, ind)) - criticals.addAll(getCriticalDescriptions(ind, d)); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + if(reasoner2.instanceCheck(d, ind)) + criticals.addAll(getCriticalDescriptions(ind, d)); } } else criticals.add(desc); + } return criticals; @@ -431,12 +431,21 @@ } public Set<NamedClass> getpossibleMoveClasses(Individual ind){ - Set<NamedClass> classes = rs.getAtomicConcepts(); - for(NamedClass nc : classes) - if(rs.instanceCheck(nc, ind)) - classes.remove(nc); + Set<NamedClass> moveClasses = rs.getAtomicConcepts(); + Set<NamedClass> indClasses = new HashSet<NamedClass>(); - return classes; + for(NamedClass moveNc : moveClasses) + if(rs.instanceCheck(moveNc, ind)){ + indClasses.add(moveNc); + } + moveClasses.removeAll(indClasses); + + for(NamedClass moveNc : moveClasses) + for(NamedClass indNc : indClasses ) + if(new Intersection(moveNc, indNc).equals(new Nothing())) + moveClasses.remove(moveNc); + + return moveClasses; } public void updateReasoner(){ @@ -449,19 +458,29 @@ } } + public boolean hasComplement(Description desc, Individual ind){ + for(NamedClass nc : reasoner2.getAtomicConcepts()) + if(reasoner2.instanceCheck(nc, ind)) + if(modi.isComplement(desc, nc)) + return true; + + return false; + } + + public static void main(String[] args){ final ORE test = new ORE(); - File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/test.owl"); + File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/inkohaerent.owl"); test.setKnowledgeSource(owlFile); test.detectReasoner(); - ReasoningService rs = test.getReasoningService(); + System.out.println(test.reasoner2.getInconsistentClasses()); // System.err.println("Concepts :" + rs.getAtomicConcepts()); @@ -470,21 +489,23 @@ // System.out.println(test.posExamples); // System.out.println(test.negExamples); // test.start(); - Individual ind = new Individual("http://www.test.owl#lorenz"); - System.out.println(rs.getIndividuals()); - Description d = new Intersection(new NamedClass("http://www.test.owl#A"), new Union(new NamedClass("http://www.test.owl#B"), - new NamedClass("http://www.test.owl#C"))); - System.out.println(d); - System.out.println(test.getCriticalDescriptions(ind, d)); - JFrame testFrame = new JFrame(); - JPanel j = new JPanel(); - testFrame.add(j); - testFrame.setSize(new Dimension(400, 400)); - for(JLabel jLab : test.DescriptionToJLabel(ind, d)) - j.add(jLab); - testFrame.setVisible(true); +// Individual ind = new Individual("http://www.test.owl#lorenz"); +// test.modi.addClassAssertion(ind, new NamedClass("http://www.test.owl#B")); +// System.out.println(test.reasoner2.getInconsistentClasses()); +// Description d = new Intersection(new NamedClass("http://www.test.owl#A"), new Union(new NamedClass("http://www.test.owl#B"), +// new NamedClass("http://www.test.owl#C"))); +// System.out.println(d); +// System.out.println(test.getCriticalDescriptions(ind, d)); +// JFrame testFrame = new JFrame(); +// JPanel j = new JPanel(); +// testFrame.add(j); +// testFrame.setSize(new Dimension(400, 400)); +// for(JLabel jLab : test.DescriptionToJLabel(ind, d)) +// j.add(jLab); +// testFrame.setVisible(true); + Modified: trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java 2008-06-25 20:34:43 UTC (rev 981) @@ -7,17 +7,12 @@ import java.util.List; import java.util.Set; -import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.Union; -import org.dllearner.kb.OWLAPIOntology; import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; import org.dllearner.reasoning.OWLAPIReasoner; import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.io.RDFXMLOntologyFormat; import org.semanticweb.owl.model.AddAxiom; import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLClassAssertionAxiom; @@ -29,6 +24,7 @@ import org.semanticweb.owl.model.OWLObjectPropertyAssertionAxiom; import org.semanticweb.owl.model.OWLObjectPropertyExpression; import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChange; import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyManager; import org.semanticweb.owl.model.OWLOntologyStorageException; @@ -51,7 +47,12 @@ this.ontology = reasoner.getOWLAPIOntologies().get(0); } - + /** + * Adds an axiom to the ontology, using an EquivalentClassesAxiom + * @param newDesc new axiom to add + * @param oldDesc old description + * @return + */ public void addAxiomToOWL(Description newDesc, Description oldDesc){ OWLDescription newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(newDesc); OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(oldDesc); @@ -74,11 +75,13 @@ } + /** + * saves the ontology as RDF-file + */ public void saveOntology(){ - URI physicalURI2 = URI.create("file:/tmp/MyOnt2.owl"); try { - manager.saveOntology(ontology, new RDFXMLOntologyFormat(), physicalURI2); + manager.saveOntology(ontology); } catch (UnknownOWLOntologyException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -86,61 +89,88 @@ // TODO Auto-generated catch block e.printStackTrace(); } + +// URI physicalURI2 = URI.create("file:/tmp/MyOnt2.owl"); +// +// try { +// manager.saveOntology(ontology, new RDFXMLOntologyFormat(), physicalURI2); +// } catch (UnknownOWLOntologyException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } catch (OWLOntologyStorageException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } } /** * Deletes the complete individual from the ontology - * @param ind + * @param ind the individual to delete */ - public void deleteIndividual(Individual ind){ + public List<OWLOntologyChange> deleteIndividual(Individual ind){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); OWLEntityRemover remover = new OWLEntityRemover(manager, Collections.singleton(ontology)); individualOWLAPI.accept(remover); - + changes.addAll(remover.getChanges()); try { - manager.applyChanges(remover.getChanges()); + manager.applyChanges(changes); + saveOntology(); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } - remover.reset(); + + return null; + } /** * Removes a classAssertion - * @param ind - * @param desc + * @param ind the individual which has to removed from class + * @param desc the class to which the individual is asserted + * @return changes that have been done */ - public void removeClassAssertion(Individual ind, Description desc){ + public List<OWLOntologyChange> removeClassAssertion(Individual ind, Description desc){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); OWLDescription owlDesc = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); OWLClassAssertionAxiom owlCl = factory.getOWLClassAssertionAxiom(individualOWLAPI, owlDesc); RemoveAxiom rm = new RemoveAxiom(ontology, owlCl); - + changes.add(rm); try { manager.applyChange(rm); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } + + return null; } /** * adds a classAssertion - * @param ind - * @param desc + * @param ind the individual which has to be asserted to class + * @param desc the class to which the individual has to be asserted + * @return changes that have been done */ - public void addClassAssertion(Individual ind, Description desc){ + public List<OWLOntologyChange> addClassAssertion(Individual ind, Description desc){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); OWLDescription owlDesc = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); @@ -148,13 +178,20 @@ AddAxiom am = new AddAxiom(ontology, owlCl); + + changes.add(am); try { manager.applyChange(am); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } + + + return null; + } /** @@ -162,33 +199,50 @@ * @param ind individual which has to be moved * @param oldClass class where individual is asserted before * @param newClass class where individual is moved to + * @return changes that have been done */ - public void moveIndividual(Individual ind, Description oldClass, Description newClass){ + public List<OWLOntologyChange> moveIndividual(Individual ind, Description oldClass, Description newClass){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); //Loeschen - removeClassAssertion(ind, oldClass); + OWLDescription oldDesc = OWLAPIDescriptionConvertVisitor.getOWLDescription(oldClass); + OWLClassAssertionAxiom owlCl = factory.getOWLClassAssertionAxiom(individualOWLAPI, oldDesc); + RemoveAxiom rem = new RemoveAxiom(ontology, owlCl); + changes.add(rem); //Hinzufuegen - OWLDescription newClassOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(newClass); - - OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(individualOWLAPI, newClassOWLAPI); + OWLDescription newDesc = OWLAPIDescriptionConvertVisitor.getOWLDescription(newClass); + OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(individualOWLAPI, newDesc); + AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); + changes.add(axiom); - AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); + try { - manager.applyChange(axiom); + manager.applyChanges(changes); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } - saveOntology(); + return null; + } - public void deleteObjectProperty(Individual ind, ObjectSomeRestriction objSome){ + /** + * + * @param ind the individual which property has to be removed + * @param objSome the property which has to be removed + * @return changes that have been done + */ + public List<OWLOntologyChange> deleteObjectProperty(Individual ind, ObjectSomeRestriction objSome){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); OWLObjectProperty propertyOWLAPI = factory.getOWLObjectProperty(URI.create(objSome.getRole().getName())); @@ -216,19 +270,31 @@ } + changes.addAll(removeList); try { manager.applyChanges(removeList); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } + return null; + } - - public void addObjectProperty(Individual subInd, ObjectSomeRestriction objSome, Individual objInd){ + /** + * + * @param subInd the individual which is subject in the objectProperty + * @param objSome the property which has to be added to subject + * @param objInd the individual which is object in the objectProperty + * @return changes that have been done + */ + public List<OWLOntologyChange> addObjectProperty(Individual subInd, ObjectSomeRestriction objSome, Individual objInd){ + List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>(); + OWLIndividual subIndividualOWLAPI = factory.getOWLIndividual( URI.create(subInd.getName())); OWLIndividual objIndividualOWLAPI = factory.getOWLIndividual( URI.create(objInd.getName())); OWLObjectProperty propertyOWLAPI = factory.getOWLObjectProperty(URI.create(objSome.getRole().getName())); @@ -236,66 +302,83 @@ OWLObjectPropertyAssertionAxiom objAssertion = factory.getOWLObjectPropertyAssertionAxiom(subIndividualOWLAPI, propertyOWLAPI, objIndividualOWLAPI); AddAxiom axiom = new AddAxiom(ontology, objAssertion); + changes.add(axiom); try { manager.applyChange(axiom); + return changes; } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } + + return null; } - public void refreshReasoner(){ - Set<KnowledgeSource> s = new HashSet<KnowledgeSource>(); - s.add(new OWLAPIOntology(ontology)); - this.reasoner = new OWLAPIReasoner(s); - reasoner.init(); - } - - public boolean checkInstanceNewOntology(Description desc, Individual ind){ - Set<KnowledgeSource> s = new HashSet<KnowledgeSource>(); - s.add(new OWLAPIOntology(ontology)); - OWLAPIReasoner r = new OWLAPIReasoner(s); - r.init(); - boolean check = r.instanceCheck(desc, ind); + + /** + * undo changes of type {@link OWLOntologyChange} + * @param changes + */ + public void undoChanges(List<OWLOntologyChange> changes){ - return check; - } - - public Set<Description> getCriticalDescriptions(Individual ind, Description desc){ - Set<KnowledgeSource> s = new HashSet<KnowledgeSource>(); - s.add(new OWLAPIOntology(ontology)); - OWLAPIReasoner r = new OWLAPIReasoner(s); - r.init(); - - Set<Description> criticals = new HashSet<Description>(); - List<Description> children = desc.getChildren(); - - if(r.instanceCheck(desc, ind)){ - System.out.println("wahr"); - if(children.size() >= 2){ - - if(desc instanceof Intersection){ - for(Description d: children) - criticals.addAll(getCriticalDescriptions(ind, d)); - + for(OWLOntologyChange change : changes){ + if(change instanceof RemoveAxiom){ + OWLAxiom axiom = ((RemoveAxiom)change).getAxiom(); + AddAxiom add = new AddAxiom(ontology, axiom); + try { + manager.applyChange(add); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - else if(desc instanceof Union){ - for(Description d: children) - if(reasoner.instanceCheck(d, ind)) - criticals.addAll(getCriticalDescriptions(ind, d)); + } + else if(change instanceof AddAxiom){ + OWLClassAssertionAxiom cl = (OWLClassAssertionAxiom)((AddAxiom)change).getAxiom(); + RemoveAxiom rem = new RemoveAxiom(ontology, cl); + try { + manager.applyChange(rem); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } - else - criticals.add(desc); + } + } - - return criticals; -} + public boolean isComplement(Description desc1, Description desc2){ + + OWLDescription d1 = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc1); + OWLDescription d2 = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc2); + OWLDescription d3 = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc1.getChild(0)); + + for(OWLAxiom ax : ontology.getAxioms()){ + if(ax.equals(factory.getOWLEquivalentClassesAxiom(d1, d2))) + return true; + if(ax.equals(factory.getOWLDisjointClassesAxiom(d3, d2))) + return true; + } + +// OWLClass owlClass1 = factory.getOWLClass(URI.create(desc1.toString())); +// OWLClass owlClass2 = factory.getOWLClass(URI.create(desc2.toString())); +// for(OWLEquivalentClassesAxiom eq :ontology.getEquivalentClassesAxioms(owlClass1)) +// for(OWLDescription d : eq.getDescriptions()) +// System.out.println(d.isAnonymous()); +// for(OWLEquivalentClassesAxiom eq :ontology.getEquivalentClassesAxioms(owlClass2)){ +// for(OWLDescription d : eq.getDescriptions()) +// System.out.println(d.getClass()); +// for(OWLEntity e : eq.getReferencedEntities()) +// System.out.println(e); +// } + + return false; + + } + // public OWLOntology copyOntology(){ Modified: trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -1,13 +1,17 @@ package org.dllearner.tools.ore; +import java.awt.Color; +import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; +import java.awt.Insets; import java.util.Set; +import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.border.TitledBorder; +import javax.swing.border.BevelBorder; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -28,107 +32,49 @@ public void init(){ - setBorder(new TitledBorder("stats")); + setBackground(Color.WHITE); + setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - - GridBagLayout gbl = new GridBagLayout(); + gbl.rowWeights = new double[] {0.0, 0.1, 0.1}; + gbl.rowHeights = new int[] {34, 7, 7}; + gbl.columnWeights = new double[] {0.1}; + gbl.columnWidths = new int[] {7}; setLayout(gbl); + + + - GridBagConstraints gbc = new GridBagConstraints(); - JLabel descLb = new JLabel("Description:"); - JLabel indLb = new JLabel("Individual:"); - JLabel classLb = new JLabel("Classes:"); - JLabel descLb1 = new JLabel(ore.conceptToAdd.toString()); + JPanel indPanel = new JPanel(); + indPanel.setBackground(new Color(224, 223, 227)); + indPanel.setLayout(new GridLayout(0, 1)); + JLabel indLb = new JLabel("Individual:"); + indLb.setFont(indLb.getFont().deriveFont(Font.BOLD)); JLabel indLb1 = new JLabel(ind.getName()); + indPanel.add(indLb); + indPanel.add(indLb1); + + JPanel classesPanel = new JPanel(); + classesPanel.setBackground(new Color(224, 223, 227)); + classesPanel.setLayout(new GridLayout(0, 1)); + JLabel classLb = new JLabel("Classes:"); + classLb.setFont(indLb.getFont().deriveFont(Font.BOLD)); + classesPanel.add(classLb); + Set<NamedClass> t = null; - - JPanel classesPanel = new JPanel(new GridLayout(0, 1)); - + t = ore.reasoner2.getConcepts(ind); - t.add(ore.getConcept()); + for(NamedClass nc : t) classesPanel.add(new JLabel(nc.getName())); - - gbc.gridx = 0; // first column - gbc.gridy = 0; // first row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 20; // relative horizontal size - first column - gbc.weighty = 10; // relative vertical size - first row - gbc.fill = GridBagConstraints.NONE; // stay as small as possible - // suite for labels - gbc.anchor = GridBagConstraints.CENTER; // center aligning - //inform the layout about the control to be added and its constraints: - gbl.setConstraints(descLb, gbc); - add(descLb); //add the JLabel to the JPanel object - - gbc.gridx = 0; // first column - gbc.gridy = 1; // second row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 0; // !!! horizontal size for the column is defined already! - gbc.weighty = 10; // relative vertical size - second row - gbc.fill = GridBagConstraints.NONE; // stay as small as possible, suites for labels - gbc.anchor = GridBagConstraints.CENTER; // center aligning - //inform the layout about the control to be added and its constraints: - gbl.setConstraints(indLb, gbc); - add(indLb); - - gbc.gridx = 0; // first column - gbc.gridy = 2; // third row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 0; // !!! horizontal size for the column is defined already! - gbc.weighty = 10; // relative vertical size - second row - gbc.fill = GridBagConstraints.NONE; // stay as small as possible, suites for labels - gbc.anchor = GridBagConstraints.CENTER; // center aligning - //inform the layout about the control to be added and its constraints: - gbl.setConstraints(classLb, gbc); - add(classLb); - - gbc.gridx = 1; // second column - gbc.gridy = 0; // first row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 100; // horizontal size - second column - gbc.weighty = 0; // !!! vertical size for the row is defined already! - gbc.fill = GridBagConstraints.HORIZONTAL; // fill horizontally entire cell - gbc.anchor = GridBagConstraints.CENTER; // center aligning - - gbl.setConstraints(descLb1, gbc); - add(descLb1); - - gbc.gridx = 1; // second column - gbc.gridy = 1; // second row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 0; // horizontal size for the column is defined already! - gbc.weighty = 0; // vertical size for the row is defined already! - gbc.fill = GridBagConstraints.HORIZONTAL; // fill horizontally entire cell - gbc.anchor = GridBagConstraints.CENTER; // center aligning - - gbl.setConstraints(indLb1, gbc); - add(indLb1); - - gbc.gridx = 1; // second column - gbc.gridy = 2; // third row - gbc.gridwidth = 1; // occupies only one column - gbc.gridheight = 1; // occupies only one row - gbc.weightx = 0; // horizontal size for the column is defined already! - gbc.weighty = 0; // vertical size for the row is defined already! - gbc.fill = GridBagConstraints.HORIZONTAL; // fill horizontally entire cell - gbc.anchor = GridBagConstraints.CENTER; // center aligning - -// gbl.setConstraints(scrollPane, gbc); -// statsPanel.add(scrollPane); - gbl.setConstraints(classesPanel, gbc); - add(classesPanel); + add(indPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); + + add(classesPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); } } Added: trunk/src/dl-learner/org/dllearner/tools/ore/UndoLabel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/UndoLabel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/UndoLabel.java 2008-06-25 20:34:43 UTC (rev 981) @@ -0,0 +1,30 @@ +package org.dllearner.tools.ore; + +import java.awt.Color; +import java.awt.event.MouseListener; +import java.util.List; + +import javax.swing.JLabel; + +import org.semanticweb.owl.model.OWLOntologyChange; + +public class UndoLabel extends JLabel { + + /** + * + */ + private static final long serialVersionUID = 2058081574518973309L; + + private List<OWLOntologyChange> owlChanges; + + public UndoLabel(List<OWLOntologyChange> changes, MouseListener mL){ + super("<html><u>Undo</u></html>"); + setForeground(Color.RED); + this.owlChanges = changes; + addMouseListener(mL); + } + + public List<OWLOntologyChange> getChanges(){ + return owlChanges; + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-06-25 20:33:25 UTC (rev 980) +++ trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-06-25 20:34:43 UTC (rev 981) @@ -76,16 +76,22 @@ if( nextPanelDescriptor.equals("REPAIR_PANEL")){ ((RepairPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getNegFailureModel().clear(); ((RepairPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getPosFailureModel().clear(); - wizard.getModel().getOre().getModi().addAxiomToOWL(wizard.getModel().getOre().getConceptToAdd(), wizard.getModel().getOre().getConcept()); + wizard.getModel().getOre().getModi().addAxiomToOWL(wizard.getModel().getOre().getConceptToAdd(), wizard.getModel().getOre().getIgnoredConcept()); new FailInstancesRetriever(nextPanelDescriptor).execute(); // for(Description desc : wizard.getModel().getOre().getConceptToAdd().getChildren()) // System.out.println(desc); + + } + if(nextPanelDescriptor.equals("LEARNING_PANEL")){ + ((LearningPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getStatusLabel().setText(""); + ((LearningPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getModel().clear(); - } + + if (nextPanelDescriptor instanceof WizardPanelDescriptor.FinishIdentifier) { wizard.close(Wizard.FINISH_RETURN_CODE); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2008-06-25 20:33:28
|
Revision: 980 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=980&view=rev Author: lorenz_b Date: 2008-06-25 13:33:25 -0700 (Wed, 25 Jun 2008) Log Message: ----------- changed return type of method getInconsistentClasses() to NamedClass Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-06-24 17:04:10 UTC (rev 979) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-06-25 20:33:25 UTC (rev 980) @@ -256,7 +256,7 @@ public abstract void releaseKB(); - public Set<OWLClass> getInconsistentClasses() throws ReasoningMethodUnsupportedException{ + public Set<NamedClass> getInconsistentClasses() throws ReasoningMethodUnsupportedException{ throw new ReasoningMethodUnsupportedException(); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-24 17:04:10 UTC (rev 979) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-25 20:33:25 UTC (rev 980) @@ -937,15 +937,18 @@ } @Override - public Set<OWLClass> getInconsistentClasses(){ + public Set<NamedClass> getInconsistentClasses(){ + Set<NamedClass> concepts = new HashSet<NamedClass>(); try { - return reasoner.getInconsistentClasses(); + for(OWLClass concept : reasoner.getInconsistentClasses()) + concepts.add(new NamedClass(concept.getURI().toString())); + } catch (OWLReasonerException e) { e.printStackTrace(); - throw new Error("Inconsistens classes check error in OWL API."); + throw new Error("Inconsistent classes check error in OWL API."); } - + return concepts; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-06-24 17:05:38
|
Revision: 979 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=979&view=rev Author: kurzum Date: 2008-06-24 10:04:10 -0700 (Tue, 24 Jun 2008) Log Message: ----------- made an extra log file just fo sparql in folder log/sparql.txt SparqlQuery method send should not return resultSet. Therefore I marked it deprecated. It is a possible source of errors, because it can only be used/traversed once. e.g. SparqlQuery.getAsXML(ResulSet); SparqlQuery.getAsXML(ResulSet); will produce an error on second call. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-06-24 12:08:34 UTC (rev 978) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-06-24 17:04:10 UTC (rev 979) @@ -64,9 +64,9 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.StringTupleListConfigOption; -import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; @@ -120,18 +120,24 @@ // create logger (a simple logger which outputs // its messages to the console and a log file) + SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); - FileAppender fileAppender = null; + FileAppender fileAppenderNormal = null; + File f = new File("log/sparql.txt"); try { - fileAppender = new FileAppender(layout, "log/log.txt", false); + fileAppenderNormal = new FileAppender(layout, "log/log.txt", false); + f.delete(); + f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } + logger.removeAllAppenders(); logger.addAppender(consoleAppender); - logger.addAppender(fileAppender); + logger.addAppender(fileAppenderNormal); logger.setLevel(Level.DEBUG); + // Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); // Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN); // Logger.getLogger(TypedSparqlQuery.class).setLevel(Level.WARN); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-06-24 12:08:34 UTC (rev 978) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-06-24 17:04:10 UTC (rev 979) @@ -31,11 +31,8 @@ import java.util.LinkedList; import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; import org.dllearner.utilities.JamonMonitorLogger; -import com.hp.hpl.jena.query.ResultSet; - /** * SPARQL query cache to avoid possibly expensive multiple queries. The queries * and their results are written to files. A cache has an associated cache @@ -61,7 +58,8 @@ */ public class Cache implements Serializable { - private static Logger logger = Logger.getLogger(KnowledgeSource.class); + private static Logger logger = Logger.getLogger(Cache.class); + private static final long serialVersionUID = 843308736471742205L; @@ -237,39 +235,41 @@ * * @param query * The SPARQL query. - * @return Jena result set. + * @return Jena result set in JSON format */ public String executeSparqlQuery(SparqlQuery query) { JamonMonitorLogger.getTimeMonitor(Cache.class, "TotalTimeExecuteSparqlQuery").start(); JamonMonitorLogger.increaseCount(Cache.class, "TotalQueries"); - - - //Statistics.increaseQuery(); - + JamonMonitorLogger.getTimeMonitor(Cache.class, "ReadTime").start(); String result = getCacheEntry(query.getQueryString()); JamonMonitorLogger.getTimeMonitor(Cache.class, "ReadTime").stop(); if (result != null) { - query.setJson(result); - query.setRunning(false); - logger.trace("got from cache"); + //query.setJson(result); + + query.setRunning(false); + SparqlQuery.writeToSpecialLog("***********\nJSON retrieved from cache"); + SparqlQuery.writeToSpecialLog(query.getQueryString()); + SparqlQuery.writeToSpecialLog(query.getEndpoint().getURL().toString()); JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits"); - //Statistics.increaseCachedQuery(); - //return result; + } else { - //SimpleClock sc = new SimpleClock(); - //sc.printAndSet("query"); - ResultSet rs= query.send(); - String json = SparqlQuery.getAsJSON(rs); + + //ResultSet rs= query.send(); + query.send(); + String json = query.getJson(); if (json!=null){ addToCache(query.getQueryString(), json); + SparqlQuery.writeToSpecialLog("result added to cache: "+json); result=json; query.setJson(result); } else { json=""; + result=""; logger.warn(Cache.class.getSimpleName()+"empty result: "+query.getQueryString()); + SparqlQuery.writeToSpecialLog("empty result for : "+query.getQueryString()); } //return json; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-24 12:08:34 UTC (rev 978) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-06-24 17:04:10 UTC (rev 979) @@ -21,15 +21,13 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileWriter; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -import java.util.Iterator; import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; import org.dllearner.utilities.JamonMonitorLogger; -import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetFormatter; @@ -45,13 +43,14 @@ */ public class SparqlQuery { - private static Logger logger = Logger.getLogger(KnowledgeSource.class); + private static Logger logger = Logger.getLogger(SparqlQuery.class); + private boolean isRunning = false; private String queryString; private QueryEngineHTTP queryExecution; private SparqlEndpoint endpoint; - private ResultSet rs; + //private ResultSet rs; private String json; // private SparqlQueryException sendException=null; @@ -66,16 +65,26 @@ this.endpoint = endpoint; } + + + + /** * Sends a SPARQL query using the Jena library. + * should return JSON String + * needs refactoring + * @return ResultSet */ + @Deprecated public ResultSet send() { - + ResultSet rs; //isRunning = true; - logger.trace(queryString); + writeToSpecialLog("***********\nNew Query:"); + writeToSpecialLog(queryString); + writeToSpecialLog(endpoint.getURL().toString()); String service = endpoint.getURL().toString(); - logger.trace(endpoint.getURL().toString()); + // Jena access to SPARQL endpoint queryExecution = new QueryEngineHTTP(service, queryString); for (String dgu : endpoint.getDefaultGraphURIs()) { @@ -91,17 +100,20 @@ rs = queryExecution.execSelect(); JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop(); + logger.debug("query SPARQL server, retrieved: "+rs.getResultVars()); - - logger.trace(rs.getResultVars().toString()); -// } catch (Exception e){ -// sendException=new SparqlQueryException(e.getMessage()); -// logger.debug(e.getMessage()); -// //e.printStackTrace(); -// logger.debug("Exception when querying Sparql Endpoint in " + this.getClass()); -// logger.debug(queryString); -// } - //isRunning = false; + writeToSpecialLog("query SPARQL server, retrieved: "+rs.getResultVars()); + writeToSpecialLog("Results from ResultSet"); + + json = SparqlQuery.getAsJSON(rs); + writeToSpecialLog(json); + rs = SparqlQuery.JSONtoResultSet(json); + while (rs.hasNext()){ + writeToSpecialLog("Result: "+rs.nextBinding()); + } + + isRunning = false; + rs = SparqlQuery.JSONtoResultSet(json); return rs; } @@ -114,6 +126,10 @@ return queryString; } + public SparqlEndpoint getEndpoint() { + return endpoint; + } + public boolean isRunning() { return isRunning; } @@ -185,7 +201,18 @@ this.isRunning=running; } - public ResultSet getResultSet(){ + public static void writeToSpecialLog(String s){ + try{ + FileWriter fw = new FileWriter("log/sparql.txt",true); + fw.write(s+"\n"); + fw.flush(); + fw.close(); + }catch (Exception e) { + e.printStackTrace(); + } + } + + /*public ResultSet getResultSet(){ return rs; - } + }*/ } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-24 12:08:34 UTC (rev 978) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-24 17:04:10 UTC (rev 979) @@ -51,16 +51,16 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.kb.sparql.SparqlQueryException; -import org.dllearner.kb.sparql.Cache; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -72,8 +72,6 @@ import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; -import com.hp.hpl.jena.query.ResultSet; - /** * DL-Learner web service interface. * @@ -520,10 +518,10 @@ public String getAsJSON(int sessionID, int queryID) throws ClientNotKnownException, SparqlQueryException { ClientState state = getState(sessionID); - ResultSet resultSet=null; + //ResultSet resultSet=null; String json=null; if ((json=state.getQuery(queryID).getJson())!=null) return json; - else if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsJSON(resultSet); + //else if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsJSON(resultSet); else return SparqlQuery.getAsJSON(state.getQuery(queryID).send()); } @@ -531,10 +529,10 @@ public String getAsXMLString(int sessionID, int queryID) throws ClientNotKnownException { ClientState state = getState(sessionID); - ResultSet resultSet=null; + //ResultSet resultSet=null; String json=null; - if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsXMLString(resultSet); - else if ((json=state.getQuery(queryID).getJson())!=null) return SparqlQuery.getAsXMLString(SparqlQuery.JSONtoResultSet(json)); + //if ((resultSet=state.getQuery(queryID).getResultSet())!=null) return SparqlQuery.getAsXMLString(resultSet); + if ((json=state.getQuery(queryID).getJson())!=null) return SparqlQuery.getAsXMLString(SparqlQuery.JSONtoResultSet(json)); else return SparqlQuery.getAsXMLString(state.getQuery(queryID).send()); } @@ -590,7 +588,6 @@ public void stopSparqlThread(int sessionID, int queryID) throws ClientNotKnownException { ClientState state = getState(sessionID); - state.getQuery(queryID).stop(); } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2008-06-24 12:08:34 UTC (rev 978) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2008-06-24 17:04:10 UTC (rev 979) @@ -20,6 +20,7 @@ package org.dllearner.server; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetSocketAddress; @@ -29,6 +30,7 @@ import javax.xml.ws.Endpoint; import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; @@ -46,14 +48,28 @@ public class DLLearnerWSStart { public static void main(String[] args) { - - // create web service logger - SimpleLayout layout = new SimpleLayout(); + + //create web service logger + SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); Logger logger = Logger.getRootLogger(); + + FileAppender fileAppenderNormal = null; + File f = new File("log/sparql.txt"); + try { + fileAppenderNormal = new FileAppender(layout, "log/log.txt", false); + f.delete(); + f.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + logger.removeAllAppenders(); logger.addAppender(consoleAppender); + logger.addAppender(fileAppenderNormal); logger.setLevel(Level.INFO); + InetSocketAddress isa = new InetSocketAddress("localhost", 8181); HttpServer server = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-06-24 12:09:51
|
Revision: 978 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=978&view=rev Author: JensLehmann Date: 2008-06-24 05:08:34 -0700 (Tue, 24 Jun 2008) Log Message: ----------- fixed string comparison bug Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-23 16:20:34 UTC (rev 977) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-24 12:08:34 UTC (rev 978) @@ -311,9 +311,9 @@ ClientState state = getState(id); state.getLearningAlgorithm().start(); Description solution = state.getLearningAlgorithm().getBestSolution(); - if(format == "manchester") + if(format.equals("manchester")) return solution.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); - else if(format == "kb") + else if(format.equals("kb")) return solution.toKBSyntaxString(); else return solution.toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-06-23 16:20:47
|
Revision: 977 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=977&view=rev Author: jenslehmann Date: 2008-06-23 09:20:34 -0700 (Mon, 23 Jun 2008) Log Message: ----------- Jamendo artist search Modified Paths: -------------- trunk/src/music-recommender/ajax.php trunk/src/music-recommender/index.php Modified: trunk/src/music-recommender/ajax.php =================================================================== --- trunk/src/music-recommender/ajax.php 2008-06-23 11:11:48 UTC (rev 976) +++ trunk/src/music-recommender/ajax.php 2008-06-23 16:20:34 UTC (rev 977) @@ -31,17 +31,19 @@ $xajax = new xajax(); +// set to debug during development if needed +$xajax->configureMany(array('debug'=>false)); + // register functions $xajax->registerFunction("doSearch"); - $xajax->processRequest(); // search for songs matching the search string function doSearch($searchString) { // ToDo: execute a SPARQL query (find labels matching search string) by contacting DL-Learner web service - $query = 'PREFIX geo:<http://www.geonames.org/ontology#> + /*$query = 'PREFIX geo:<http://www.geonames.org/ontology#> PREFIX wgs:<http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT ?a ?place ?lat ?long WHERE { @@ -52,7 +54,20 @@ wgs:lat ?lat; wgs:long ?long } - LIMIT 1'; + LIMIT 1';*/ + // unfortunately full text search does not work yet - I am in contact with Yves Raimond to find a solution + // currently, we look for exact matches + $query = ' + SELECT ?artist ?name ?image ?homepage + WHERE { + ?artist a mo:MusicArtist . + ?artist foaf:name "'.$searchString.'" . + ?artist foaf:name ?name . + ?artist foaf:img ?image . + ?artist foaf:homepage ?homepage . + } + LIMIT 10'; + /*PREFIX geo: <http://www.geonames.org/ontology#> PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT DISTINCT ?an ?lat ?long ?name ?population @@ -72,8 +87,29 @@ try { $connection = new DLLearnerConnection(); - $result = $connection->sparqlQuery($query); - $newContent = 'searching for '.$searchString.' ... not implemented '.$result; + $json = $connection->sparqlQuery($query); + $result = json_decode($json); + $bindings = $result->results->bindings; + + // preprocessing phase + // found artists (currently all results are artists) + /* + $artists = array(); + $count = 0; + foreach($bindings as $binding) { + $artists[$count]['image'] = $binding->image; + $count++; + }*/ + + // var_dump($bindings); + // $newContent = 'searching for '.$searchString.' ... not implemented <pre>test</pre>'; + $newContent = '<h3>Search Results</h3>'; + foreach($bindings as $binding) { + $newContent .= '<img style="float:right" src="'.$binding->image->value.'" />'; + $newContent .= '<b>'.$binding->name->value.'</b><br />'; + $newContent .= '<a href="'.$binding->homepage->value.'">'.$binding->homepage->value.'</a><br />'; + $newContent .= 'TODO: make author name clickable such that people can get tracks from this artist and listen to them'; + } } catch (Exception $e) { $newContent = '<b>Search aborted: '.$e->getMessage().'</b>'; } Modified: trunk/src/music-recommender/index.php =================================================================== --- trunk/src/music-recommender/index.php 2008-06-23 11:11:48 UTC (rev 976) +++ trunk/src/music-recommender/index.php 2008-06-23 16:20:34 UTC (rev 977) @@ -45,6 +45,8 @@ require_once 'ajax.php'; +// doSearch('Allison Crowe'); + echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <!DOCTYPE html @@ -64,9 +66,11 @@ <!-- search form --> <input type="text" id="label" /> <button onclick="xajax_doSearch(document.getElementById('label').value);">search</button> + <p>Enter an artist and click the search button. (TODO: Enable search also for tracks and tags. Enable hitting enter instead of clicking button.)</p> + <p>Example artist: Allison Crowe</p> <!-- search result display --> - <div id="searchElement"></div> + <div id="searchElement" style="max-width:500px;"></div> <h2>Song List</h2> <a href="http://mediaplayer.yahoo.com/example1.mp3">song 1</a> <br /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hee...@us...> - 2008-06-23 11:12:45
|
Revision: 976 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=976&view=rev Author: heeroyuy Date: 2008-06-23 04:11:48 -0700 (Mon, 23 Jun 2008) Log Message: ----------- -bug fixes -removed unnecessary outputs Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-22 11:09:36 UTC (rev 975) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-23 11:11:48 UTC (rev 976) @@ -72,7 +72,6 @@ test.iterator().next(); Description d1 = new ObjectSomeRestriction(test.iterator().next(), new Thing()); test.remove(rs.getAtomicRolesList().iterator().next()); - System.out.println("TADA: "+d1); simpleSuggestions.add(d1); } return simpleSuggestions; Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-22 11:09:36 UTC (rev 975) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-06-23 11:11:48 UTC (rev 976) @@ -195,8 +195,6 @@ try { if(source instanceof OWLAPIOntology) { - System.out.println(source instanceof OWLAPIOntology); - System.out.println("JUHU es geht"); OWLOntology ontology = ((OWLAPIOntology)source).getOWLOntolgy(); owlAPIOntologies.add(ontology); allImports.addAll(manager.getImportsClosure(ontology)); @@ -216,7 +214,6 @@ } else { - System.out.println(":'S"); OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); owlAPIOntologies.add(ontology); allImports.addAll(manager.getImportsClosure(ontology)); Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-22 11:09:36 UTC (rev 975) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-23 11:11:48 UTC (rev 976) @@ -438,20 +438,28 @@ public void setPositiveConcept() { SortedSet<Individual> individuals = null; - for(Iterator<NamedClass> i = rs.getAtomicConcepts().iterator(); i.hasNext();) + if(!aktuell.getRootObject().toString().equals("Thing")) { - if(individuals==null) + for(Iterator<NamedClass> i = rs.getAtomicConcepts().iterator(); i.hasNext();) { - NamedClass concept = i.next(); - if(concept.toString().endsWith("#"+aktuell.getRootObject().toString())) + if(individuals==null) { - if(rs.retrieval(concept)!=null){ - individual = rs.retrieval(concept); - break; + NamedClass concept = i.next(); + if(concept.toString().endsWith("#"+aktuell.getRootObject().toString())) + { + if(rs.retrieval(concept)!=null) + { + individual = rs.retrieval(concept); + break; + } } } } } + else + { + individual = rs.getIndividuals(); + } } /** @@ -463,9 +471,12 @@ public boolean setPositivExamplesChecked(String indi) { boolean isChecked = false; - if(individual.toString().contains(indi)) + if(individual != null) { - isChecked = true; + if(individual.toString().contains(indi)) + { + isChecked = true; + } } return isChecked; Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2008-06-22 11:09:36 UTC (rev 975) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2008-06-23 11:11:48 UTC (rev 976) @@ -177,7 +177,6 @@ public void clear() { - System.out.println("Und jetzt bin ich hier :-)"); dllearner.unsetEverything(); dllearner.makeView(); handleVerifyEditorContents(); @@ -194,8 +193,6 @@ return restrictionCreatorPanel.createRestrictions(); } else if(tabbedPane.getSelectedComponent() == dllearner){ - System.out.println("die loesungen:"+dllearner.getSollutions()); - return dllearner.getSollutions(); } return super.getEditedObjects(); @@ -478,7 +475,6 @@ */ public OWLDescription getSollution() { - System.out.println(model.getSolution()); return model.getSolution(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |