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: <jen...@us...> - 2007-10-09 09:26:35
|
Revision: 202 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=202&view=rev Author: jenslehmann Date: 2007-10-09 02:26:31 -0700 (Tue, 09 Oct 2007) Log Message: ----------- web service interface started (intermediate commit) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/ClientNotKnownException.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java trunk/src/php-client/LearnerClient.php Added Paths: ----------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java trunk/src/dl-learner/org/dllearner/server/State.java trunk/src/php-client/testnew.php Modified: trunk/src/dl-learner/org/dllearner/server/ClientNotKnownException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientNotKnownException.java 2007-10-09 08:47:11 UTC (rev 201) +++ trunk/src/dl-learner/org/dllearner/server/ClientNotKnownException.java 2007-10-09 09:26:31 UTC (rev 202) @@ -1,15 +1,11 @@ package org.dllearner.server; public class ClientNotKnownException extends Exception { + static final long serialVersionUID=100; - String detail; - public ClientNotKnownException (String message, String detail) { - super (message); - this.detail = detail; + public ClientNotKnownException (long id) { + super ("Client with id " + id + " is not known."); } - public String getDetail () { - return detail; - } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-10-09 08:47:11 UTC (rev 201) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-10-09 09:26:31 UTC (rev 202) @@ -212,7 +212,8 @@ ClientState c=this.clients.get(new Integer(id)); if(c==null){ //System.out.println(clients.keySet().toString()); - throw new ClientNotKnownException("Client with id: "+id+" is not known","ClientNotKnownException");}; + // throw new ClientNotKnownException("Client with id: "+id+" is not known","ClientNotKnownException"); + }; return c; } Added: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java 2007-10-09 09:26:31 UTC (rev 202) @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2007, 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.server; + +import java.util.HashMap; +import java.util.Random; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.SparqlEndpoint; + +/** + * DL-Learner web service interface. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ +@WebService(name = "DLLearnerWebService") +@SOAPBinding(style = SOAPBinding.Style.RPC) +public class DLLearnerWSNew { + + private HashMap<Long, State> clients; + private Random rand=new Random(); + private ComponentManager cm = ComponentManager.getInstance(); + + /** + * Generates a unique ID for the client and initialises a session. + * Using the ID the client can call the other web service methods. + * Two calls to this method are guaranteed to return different results. + * + * @return A session ID. + */ + @WebMethod + public long generateID() { + long id; + do { + id = rand.nextLong(); + } while(clients.containsKey(id)); + return id; + } + + // returns session state or throws client not known exception + private State getState(long id) throws ClientNotKnownException { + State state = clients.get(id); + if(state==null) + throw new ClientNotKnownException(id); + return state; + } + + @WebMethod + public void addKnowledgeSource(long id, String type, String url) throws ClientNotKnownException { + State state = getState(id); + Class<? extends KnowledgeSource> ksClass; + if(type.equals("sparql")) + ksClass = SparqlEndpoint.class; + else + ksClass = OWLFile.class; + KnowledgeSource ks = cm.knowledgeSource(ksClass); + cm.applyConfigEntry(ks, "url", url); + state.addKnowledgeSource(ks); + } + + @WebMethod + public void setLearningAlgorithm(long id, String algorithm) throws ClientNotKnownException { + State state = getState(id); + // ... + } + +} Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2007-10-09 08:47:11 UTC (rev 201) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2007-10-09 09:26:31 UTC (rev 202) @@ -32,7 +32,7 @@ System.out.print("Starting DL-Learner web service at http://" + isa.getHostName()+":"+isa.getPort()+ "/services ... "); - Endpoint endpoint = Endpoint.create(new DLLearnerWS()); + Endpoint endpoint = Endpoint.create(new DLLearnerWSNew()); //Endpoint endpoint = Endpoint.create(new CustomDataClass()); HttpContext context = server.createContext("/services"); endpoint.publish(context); Added: trunk/src/dl-learner/org/dllearner/server/State.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/State.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/State.java 2007-10-09 09:26:31 UTC (rev 202) @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2007, 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.server; + +import java.util.Set; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; + +/** + * Stores the state of a DL-Learner client session. + * + * @author Jens Lehmann + * + */ +public class State { + + private Set<KnowledgeSource> knowledgeSource; + + private LearningProblem learningProblem; + + private ReasonerComponent reasonerComponent; + + private LearningAlgorithm learningAlgorithm; + + /** + * @return the knowledgeSource + */ + public Set<KnowledgeSource> getKnowledgeSource() { + return knowledgeSource; + } + + /** + * @param knowledgeSource the knowledgeSource to set + */ + public void setKnowledgeSource(Set<KnowledgeSource> knowledgeSource) { + this.knowledgeSource = knowledgeSource; + } + + /** + * @param e + * @return + * @see java.util.Set#add(java.lang.Object) + */ + public boolean addKnowledgeSource(KnowledgeSource ks) { + return knowledgeSource.add(ks); + } + + /** + * @param o + * @return + * @see java.util.Set#remove(java.lang.Object) + */ + public boolean removeKnowledgeSource(KnowledgeSource ks) { + return knowledgeSource.remove(ks); + } + + /** + * @return the learningProblem + */ + public LearningProblem getLearningProblem() { + return learningProblem; + } + + /** + * @param learningProblem the learningProblem to set + */ + public void setLearningProblem(LearningProblem learningProblem) { + this.learningProblem = learningProblem; + } + + /** + * @return the reasonerComponent + */ + public ReasonerComponent getReasonerComponent() { + return reasonerComponent; + } + + /** + * @param reasonerComponent the reasonerComponent to set + */ + public void setReasonerComponent(ReasonerComponent reasonerComponent) { + this.reasonerComponent = reasonerComponent; + } + + /** + * @return the learningAlgorithm + */ + public LearningAlgorithm getLearningAlgorithm() { + return learningAlgorithm; + } + + /** + * @param learningAlgorithm the learningAlgorithm to set + */ + public void setLearningAlgorithm(LearningAlgorithm learningAlgorithm) { + this.learningAlgorithm = learningAlgorithm; + } + +} Modified: trunk/src/php-client/LearnerClient.php =================================================================== --- trunk/src/php-client/LearnerClient.php 2007-10-09 08:47:11 UTC (rev 201) +++ trunk/src/php-client/LearnerClient.php 2007-10-09 09:26:31 UTC (rev 202) @@ -194,7 +194,7 @@ public function getInfo(){ $functions = $this->soapclient->__getFunctions(); - echo '<b>Verf\xFCgbare Methoden:</b>'; + echo '<b>Verf�gbare Methoden:</b>'; echo '<pre>'; print_r($functions); echo '</pre>'; @@ -203,19 +203,19 @@ } - public function loadWSDLfiles($wsdluri){ - $main=$this->getwsdl($wsdluri); - $other=$this->getOtherWSDL($main); - $newMain=$this->changeWSDL($main); - $this->writeToFile("main.wsdl",$newMain); + public static function loadWSDLfiles($wsdluri){ + $main=self::getwsdl($wsdluri); + $other=self::getOtherWSDL($main); + $newMain=self::changeWSDL($main); + self::writeToFile("main.wsdl",$newMain); $x=0; foreach ($other as $o){ - $this->writeToFile("def".($x++).".xsd",$this->getwsdl($o)); + self::writeToFile("def".($x++).".xsd",self::getwsdl($o)); } } - public function changeWSDL($wsdl){ + public static function changeWSDL($wsdl){ $before="<xsd:import schemaLocation=\""; $after="\" namespace=\""; $newWSDL=""; @@ -236,7 +236,7 @@ } - public function getOtherWSDL($wsdl){ + public static function getOtherWSDL($wsdl){ $before="<xsd:import schemaLocation=\""; $after="\" namespace=\""; $ret=array(); @@ -254,7 +254,7 @@ - public function getwsdl($wsdluri){ + public static function getwsdl($wsdluri){ // this is copied from the Pear example // please don't ask me how it works $req = &new HTTP_Request($wsdluri); @@ -267,7 +267,7 @@ - public function writeToFile($filename,$content){ + public static function writeToFile($filename,$content){ $fp=fopen($filename,"w"); fwrite($fp,$content); Added: trunk/src/php-client/testnew.php =================================================================== --- trunk/src/php-client/testnew.php (rev 0) +++ trunk/src/php-client/testnew.php 2007-10-09 09:26:31 UTC (rev 202) @@ -0,0 +1,22 @@ +<?php + +include_once("LearnerClient.php"); + +ini_set("soap.wsdl_cache_enabled","0"); + +$wsdluri="http://localhost:8181/services?wsdl"; + +// always update WSDL +LearnerClient::loadWSDLfiles($wsdluri); + +// test web service +$client = new SoapClient("main.wsdl"); + +$test = $client->hello(); +echo $test; + +$stringar = array('blub','blab'); +$ret = $client->test($stringar); +print_r($ret); + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-09 08:47:12
|
Revision: 201 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=201&view=rev Author: sknappe Date: 2007-10-09 01:47:11 -0700 (Tue, 09 Oct 2007) Log Message: ----------- added new options(format, dumpToFile) to choose wether the ontology from DBPedia is stored in a file (in a specific format), adjustet example accordingly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java Modified: trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java 2007-10-09 08:46:58 UTC (rev 200) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java 2007-10-09 08:47:11 UTC (rev 201) @@ -46,6 +46,7 @@ HashSet<String> classes; HashSet<String> instances; HashSet<String> triples; + String format; // some namespaces String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; @@ -74,10 +75,10 @@ * @param defClasses */ public OntologyCollector(String[] subjectList,int numberOfRecursions, - int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses){ + int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses, String format){ this.subjectList=subjectList; this.numberOfRecursions=numberOfRecursions; - + this.format=format; this.s=new SimpleHTTPRequest(); this.q=new QueryMaker(); this.c=new Cache("cache"); @@ -282,11 +283,12 @@ * @return triple in the n triple notation */ public String makeTriples(String s,String p, String o){ - //s=replaceNamespace(s); - //p=replaceNamespace(p); - //o=replaceNamespace(o); String ret=""; - ret="<"+s+"> <"+p+"> <"+o+">.\n"; + if (format.equals("N-TRIPLES")) ret="<"+s+"> <"+p+"> <"+o+">.\n"; + else if (format.equals("KB")){ + if (p.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) ret="\""+o+"\"(\""+s+"\").\n"; + else ret="\""+p+"\"(\""+s+"\",\""+o+"\").\n"; + } return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-09 08:46:59
|
Revision: 200 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=200&view=rev Author: sknappe Date: 2007-10-09 01:46:58 -0700 (Tue, 09 Oct 2007) Log Message: ----------- added new options(format, dumpToFile) to choose wether the ontology from DBPedia is stored in a file (in a specific format), adjustet example accordingly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/KBParser.java Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-09 08:46:35 UTC (rev 199) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-09 08:46:58 UTC (rev 200) @@ -32,6 +32,11 @@ KBParser parser = new KBParser(new FileInputStream(file)); return parser.KB(); } + + public static KB parseKBFile(StringReader read) throws ParseException{ + KBParser parser = new KBParser(read); + return parser.KB(); + } final public KB KB() throws ParseException { ConceptAssertion conceptAssertion; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-09 08:46:39
|
Revision: 199 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=199&view=rev Author: sknappe Date: 2007-10-09 01:46:35 -0700 (Tue, 09 Oct 2007) Log Message: ----------- added new options(format, dumpToFile) to choose wether the ontology from DBPedia is stored in a file (in a specific format), adjustet example accordingly Modified Paths: -------------- trunk/examples/dbpedia/sparql.conf Modified: trunk/examples/dbpedia/sparql.conf =================================================================== --- trunk/examples/dbpedia/sparql.conf 2007-10-09 08:46:07 UTC (rev 198) +++ trunk/examples/dbpedia/sparql.conf 2007-10-09 08:46:35 UTC (rev 199) @@ -32,14 +32,20 @@ // SPARQL options sparql.numberOfRecursions = 2; -sparql.instances = {"http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; +sparql.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Philolaus","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; sparql.filterMode = 0; sparql.predList = {}; sparql.objList = {}; sparql.classList = {}; +sparql.format = "KB"; +sparql.dumpToFile = false; import("http://dbpedia.openlinksw.com","SPARQL"); /** examples **/ +"http://dbpedia.org/resource/Pythagoras" ++"http://dbpedia.org/resource/Philolaus" ++"http://dbpedia.org/resource/Archytas" -"http://dbpedia.org/resource/Socrates" +-"http://dbpedia.org/resource/Zeno_of_Elea" +-"http://dbpedia.org/resource/Plato" \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-09 08:46:09
|
Revision: 198 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=198&view=rev Author: sknappe Date: 2007-10-09 01:46:07 -0700 (Tue, 09 Oct 2007) Log Message: ----------- added new options(format, dumpToFile) to choose wether the ontology from DBPedia is stored in a file (in a specific format), adjustet example accordingly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 16:33:30 UTC (rev 197) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-09 08:46:07 UTC (rev 198) @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileWriter; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -28,6 +29,7 @@ import java.util.LinkedList; import java.util.Set; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.IntegerConfigOption; @@ -35,6 +37,9 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.KB; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; import org.dllearner.utilities.Datastructures; @@ -57,6 +62,9 @@ private Set<String> predList; private Set<String> objList; private Set<String> classList; + private KB kb; + private String format; + private boolean dumpToFile; public static String getName() { return "SPARQL Endpoint"; @@ -71,6 +79,8 @@ options.add(new StringSetConfigOption("predList","a predicate list")); options.add(new StringSetConfigOption("objList","an object list")); options.add(new StringSetConfigOption("classList","a class list")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format")); + options.add(new BooleanConfigOption("dumpToFile", "wether Ontology from DBPedia is written to a file or not")); return options; } @@ -100,6 +110,10 @@ classList = (Set<String>) entry.getValue(); } else if(option.equals("filterMode")){ filterMode=(Integer)entry.getValue(); + } else if(option.equals("format")){ + format=(String)entry.getValue(); + } else if(option.equals("dumpToFile")){ + dumpToFile=(Boolean)entry.getValue(); } } @@ -108,29 +122,34 @@ */ @Override public void init() { - // TODO add code for downloading data from SPARQL endpoint - String filename=System.currentTimeMillis()+".nt"; + System.out.println("SparqlModul: Collecting Ontology"); + String[] a=new String[0]; + OntologyCollector oc=new OntologyCollector(instances.toArray(a), numberOfRecursions, + filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format); + String ont=oc.collectOntology(); - try{ + if (format.equals("N-TRIPLES")||dumpToFile){ + String filename=System.currentTimeMillis()+".nt"; String basedir="cache"+File.separator; - if(!new File(basedir).exists()) - new File(basedir).mkdir(); - FileWriter fw=new FileWriter(new File(basedir+filename),true); - System.out.println("SparqlModul: Collecting Ontology"); - String[] a=new String[0]; - OntologyCollector oc=new OntologyCollector(instances.toArray(a), numberOfRecursions, - filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList)); - - String ont=oc.collectOntology(); - fw.write(ont); - fw.flush(); - - System.out.println("SparqlModul: ****Finished"); - - fw.close(); - this.ntFile=(new File(basedir+filename)).toURI().toURL(); - //System.exit(0); - }catch (Exception e) {e.printStackTrace();} + try{ + if(!new File(basedir).exists()) + new File(basedir).mkdir(); + + FileWriter fw=new FileWriter(new File(basedir+filename),true); + fw.write(ont); + fw.flush(); + fw.close(); + + ntFile=(new File(basedir+filename)).toURI().toURL(); + }catch (Exception e) {e.printStackTrace();} + } + if (format.equals("KB")) { + try{ + kb=KBParser.parseKBFile(new StringReader(ont)); + } catch(Exception e) {e.printStackTrace();} + } + + System.out.println("SparqlModul: ****Finished"); } /* @@ -140,7 +159,8 @@ */ @Override public String toDIG(URI kbURI) { - return JenaOWLDIGConverter.getTellsString(ntFile, OntologyFileFormat.N_TRIPLES, kbURI); + if (format.equals("N-TRIPLES")) return JenaOWLDIGConverter.getTellsString(ntFile, OntologyFileFormat.N_TRIPLES, kbURI); + else return DIGConverter.getDIGString(kb, kbURI).toString(); } public URL getURL() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 16:44:17
|
Revision: 196 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=196&view=rev Author: jenslehmann Date: 2007-10-08 09:25:29 -0700 (Mon, 08 Oct 2007) Log Message: ----------- another configuration option (penaliseNeutralExamples) adapted to new structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 15:48:00 UTC (rev 195) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 16:25:29 UTC (rev 196) @@ -32,7 +32,7 @@ // public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; - public static boolean penalizeNeutralExamples = false; + // public static boolean penalizeNeutralExamples = false; public static boolean showCorrectClassifications = false; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 15:48:00 UTC (rev 195) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 16:25:29 UTC (rev 196) @@ -421,7 +421,7 @@ private void applyStringOptions(String option, String value) { if (option.equals("penalizeNeutralExamples")) - Config.penalizeNeutralExamples = Datastructures.strToBool(value); + ; // Config.penalizeNeutralExamples = Datastructures.strToBool(value); else if (option.equals("showCorrectClassifications")) Config.showCorrectClassifications = Datastructures.strToBool(value); else if (option.equals("statMode")) Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 15:48:00 UTC (rev 195) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 16:25:29 UTC (rev 196) @@ -459,7 +459,7 @@ // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); PosNegDefinitionLPStrict lp = (PosNegDefinitionLPStrict)learningProblem; - return new ScoreThreeValued(conceptLength, lp.getAccuracyPenalty(), lp.getErrorPenalty(), posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); + return new ScoreThreeValued(conceptLength, lp.getAccuracyPenalty(), lp.getErrorPenalty(), lp.isPenaliseNeutralExamples(), posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); } // aktualisiert die besten Knoten Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-08 15:48:00 UTC (rev 195) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-08 16:25:29 UTC (rev 196) @@ -82,7 +82,10 @@ String name = entry.getOptionName(); if(name.equals("penaliseNeutralExamples")) penaliseNeutralExamples = (Boolean) entry.getValue(); - // else if + else if(name.equals("accuracyPenalty")) + accuracyPenalty = (Double) entry.getValue(); + else if(name.equals("errorPenalty")) + errorPenalty = (Double) entry.getValue(); } /* (non-Javadoc) @@ -109,13 +112,13 @@ // this.defPosSet = tuple.getPosSet(); // this.defNegSet = tuple.getNegSet(); SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, penaliseNeutralExamples, tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); } else if(reasoningService.getReasonerType() == ReasonerType.KAON2) { SortedSet<Individual> posClassified = reasoningService.retrieval(concept); SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } else { @@ -155,7 +158,7 @@ SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } @@ -186,4 +189,11 @@ public double getErrorPenalty() { return errorPenalty; } + + /** + * @return the penaliseNeutralExamples + */ + public boolean isPenaliseNeutralExamples() { + return penaliseNeutralExamples; + } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 15:48:00 UTC (rev 195) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 16:25:29 UTC (rev 196) @@ -27,6 +27,7 @@ private double accuracyPenalty; private double errorPenalty; + private boolean penaliseNeutralExamples; private SortedSet<Individual> posClassified; private SortedSet<Individual> neutClassified; @@ -57,6 +58,7 @@ public ScoreThreeValued(int conceptLength, double accuracyPenalty, double errorPenalty, + boolean penaliseNeutralExamples, SortedSet<Individual> posClassified, SortedSet<Individual> neutClassified, SortedSet<Individual> negClassified, @@ -99,7 +101,7 @@ if(Config.scoreMethod==ScoreMethod.FULL) score -= negAsNeut.size()*accuracyPenalty; - if(Config.penalizeNeutralExamples) + if(penaliseNeutralExamples) score -= (neutAsPos.size()*accuracyPenalty + neutAsNeg.size()*accuracyPenalty); @@ -147,7 +149,7 @@ str += "full"; else str += "positive"; - if(!Config.penalizeNeutralExamples) + if(!penaliseNeutralExamples) str += " (neutral examples not penalized)"; str += "\n"; if(Config.showCorrectClassifications) { @@ -158,7 +160,7 @@ } str += "Inaccurately classified (penalty of " + df.format(accuracyPenalty) + " per instance):\n"; str += " positive --> neutral: " + posAsNeut + "\n"; - if(Config.penalizeNeutralExamples) { + if(penaliseNeutralExamples) { str += " neutral --> positive: " + neutAsPos + "\n"; str += " neutral --> negative: " + neutAsNeg + "\n"; } @@ -201,7 +203,7 @@ @Override public Score getModifiedLengthScore(int newLength) { - return new ScoreThreeValued(newLength, accuracyPenalty, errorPenalty, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); + return new ScoreThreeValued(newLength, accuracyPenalty, errorPenalty, penaliseNeutralExamples, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 16:33:35
|
Revision: 197 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=197&view=rev Author: jenslehmann Date: 2007-10-08 09:33:30 -0700 (Mon, 08 Oct 2007) Log Message: ----------- more config options integrated Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 16:25:29 UTC (rev 196) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 16:33:30 UTC (rev 197) @@ -11,7 +11,6 @@ import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; -import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.reasoning.ReasonerType; public class Config { @@ -28,13 +27,13 @@ // und negativ als positiv // public static double errorPenalty = 3; - public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; + // public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; // public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; // public static boolean penalizeNeutralExamples = false; - public static boolean showCorrectClassifications = false; + // public static boolean showCorrectClassifications = false; // wieviel Prozent darf ein um eine Einheit längeres Konzept schlechter // sein (aktuell: 5% sind eine Verlängerung um 1 wert) Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 16:25:29 UTC (rev 196) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 16:33:30 UTC (rev 197) @@ -17,7 +17,6 @@ import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; -import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; @@ -423,7 +422,7 @@ if (option.equals("penalizeNeutralExamples")) ; // Config.penalizeNeutralExamples = Datastructures.strToBool(value); else if (option.equals("showCorrectClassifications")) - Config.showCorrectClassifications = Datastructures.strToBool(value); + ; // Config.showCorrectClassifications = Datastructures.strToBool(value); else if (option.equals("statMode")) Config.statisticMode = Datastructures.strToBool(value); else if (option.equals("una")) @@ -433,10 +432,10 @@ else if (option.equals("gp.useFixedNumberOfGenerations")) Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); else if (option.equals("scoreMethod")) { - if (value.equals("full")) - Config.scoreMethod = ScoreMethod.FULL; - else - Config.scoreMethod = ScoreMethod.POSITIVE; +// if (value.equals("full")) +// Config.scoreMethod = ScoreMethod.FULL; +// else +// Config.scoreMethod = ScoreMethod.POSITIVE; } else if (option.equals("returnType")) Config.returnType = value; else if (option.equals("algorithm")) { Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 16:25:29 UTC (rev 196) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 16:33:30 UTC (rev 197) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, 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.text.DecimalFormat; @@ -10,13 +30,13 @@ import org.dllearner.utilities.Helper; /** - * Berechnet die Punktzahl (negativ), indem es die Ergebnisse einer Definition - * mit den Soll-Ergebnissen vergleicht. + * Computes the score (a negative value) by comparing the classification results + * with ideal results. * - * TODO: die Implementierung ist momentan dahingehend unguenstig, dass viele Sachen - * nur fuer die optische Aufbereitung berechnet werden; effizienter waere es - * nur die Klassifikationsfehler zu beruecksichtigen und andere statistische Werte nur - * dann wenn sie benoetigt werden + * @todo: The implementation is not very efficient, because some things are + * only computed to be able to present the score results. This means that + * it would be better to compute only the necessary computations and do + * the other ones only when they are needed to calculate statistical values. * * @author Jens Lehmann * @@ -25,10 +45,16 @@ public enum ScoreMethod {POSITIVE, FULL}; + // configuration options private double accuracyPenalty; private double errorPenalty; private boolean penaliseNeutralExamples; + // potential configuration options (not implemented as such, but one + // could so) + private boolean showCorrectClassifications = false; + private static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; + private SortedSet<Individual> posClassified; private SortedSet<Individual> neutClassified; private SortedSet<Individual> negClassified; @@ -98,7 +124,7 @@ - negAsPos.size()*errorPenalty - posAsNeut.size()*accuracyPenalty; - if(Config.scoreMethod==ScoreMethod.FULL) + if(scoreMethod==ScoreMethod.FULL) score -= negAsNeut.size()*accuracyPenalty; if(penaliseNeutralExamples) @@ -145,14 +171,14 @@ DecimalFormat df = new DecimalFormat("0.00"); String str = ""; str += "score method "; - if(Config.scoreMethod == ScoreMethod.FULL) + if(scoreMethod == ScoreMethod.FULL) str += "full"; else str += "positive"; if(!penaliseNeutralExamples) str += " (neutral examples not penalized)"; str += "\n"; - if(Config.showCorrectClassifications) { + if(showCorrectClassifications) { str += "Correctly classified:\n"; str += " positive --> positive: " + posAsPos + "\n"; str += " neutral --> neutral: " + neutAsNeut + "\n"; @@ -164,7 +190,7 @@ str += " neutral --> positive: " + neutAsPos + "\n"; str += " neutral --> negative: " + neutAsNeg + "\n"; } - if(Config.scoreMethod == ScoreMethod.FULL) + if(scoreMethod == ScoreMethod.FULL) str += " negative --> neutral: " + negAsNeut + "\n"; str += "Classification errors (penalty of " + df.format(errorPenalty) + " per instance):\n"; str += " positive --> negative: " + posAsNeg + "\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 15:48:05
|
Revision: 195 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=195&view=rev Author: jenslehmann Date: 2007-10-08 08:48:00 -0700 (Mon, 08 Oct 2007) Log Message: ----------- readded search tree support for refinement operator based learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 15:23:41 UTC (rev 194) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 15:48:00 UTC (rev 195) @@ -1,6 +1,5 @@ package org.dllearner; -import java.io.File; import java.lang.reflect.Field; import java.net.URL; import java.util.LinkedList; @@ -139,9 +138,9 @@ public static boolean quiet = false; - public static boolean writeSearchTree = false; + // public static boolean writeSearchTree = false; - public static File searchTreeFile = new File("searchTree.txt"); + // public static File searchTreeFile = new File("searchTree.txt"); public enum Heuristic { LEXICOGRAPHIC, FLEXIBLE Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 15:23:41 UTC (rev 194) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 15:48:00 UTC (rev 195) @@ -1,6 +1,5 @@ package org.dllearner; -import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; @@ -497,9 +496,9 @@ } else if (option.equals("refinement.quiet")) Config.Refinement.quiet = Datastructures.strToBool(value); else if (option.equals("refinement.writeSearchTree")) - Config.Refinement.writeSearchTree = Datastructures.strToBool(value); + ; //Config.Refinement.writeSearchTree = Datastructures.strToBool(value); else if (option.equals("refinement.searchTreeFile")) { - Config.Refinement.searchTreeFile = new File(value); + ; // Config.Refinement.searchTreeFile = new File(value); } else if (option.equals("refinement.applyAllFilter")) Config.Refinement.applyAllFilter = Datastructures.strToBool(value); else if (option.equals("refinement.applyExistsFilter")) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 15:23:41 UTC (rev 194) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 15:48:00 UTC (rev 195) @@ -1,5 +1,6 @@ package org.dllearner.algorithms.refinement; +import java.io.File; import java.text.DecimalFormat; import java.util.Collection; import java.util.Comparator; @@ -11,6 +12,7 @@ import java.util.TreeSet; import org.dllearner.Config; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; @@ -18,6 +20,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; +import org.dllearner.core.StringConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; @@ -30,6 +33,11 @@ public class ROLearner extends LearningAlgorithm { + // configuration options + private boolean writeSearchTree; + private File searchTreeFile; + private static String defaultSearchTreeFile = "log/searchTree.txt"; + private boolean stop = false; private ReasoningService rs; @@ -224,6 +232,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new BooleanConfigOption("writeSearchTree", "specifies whether to write a search tree", false)); + options.add(new StringConfigOption("searchTreeFile","file to use for the search tree", defaultSearchTreeFile)); return options; } @@ -232,8 +242,11 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - + String name = entry.getOptionName(); + if(name.equals("writeSearchTree")) + writeSearchTree = (Boolean) entry.getValue(); + else if(name.equals("searchTreeFile")) + searchTreeFile = new File((String)entry.getValue()); } /* (non-Javadoc) @@ -241,6 +254,9 @@ */ @Override public void init() { + if(searchTreeFile == null) + searchTreeFile = new File(defaultSearchTreeFile); + // TODO: this needs to be changed Helper.autoDetectConceptsAndRoles(rs); // prepare subsumption and role hierarchies, because they are needed @@ -365,7 +381,7 @@ // System.out.println(n); //} - if(Config.Refinement.writeSearchTree) { + if(writeSearchTree) { // String treeString = ""; String treeString = "best expanded node: " + bestNode+ "\n"; if(expandedNodes.size()>1) { @@ -381,7 +397,7 @@ searchTree += treeString + "\n"; // TODO: ev. immer nur einen search tree speichern und den an die // Datei anhängen => spart Speicher - Files.createFile(Config.Refinement.searchTreeFile, searchTree); + Files.createFile(searchTreeFile, searchTree); } // Anzahl Schleifendurchläufe @@ -393,8 +409,8 @@ } // Suchbaum in Datei schreiben - if(Config.Refinement.writeSearchTree) - Files.createFile(Config.Refinement.searchTreeFile, searchTree); + if(writeSearchTree) + Files.createFile(searchTreeFile, searchTree); // Ergebnisausgabe /* @@ -440,7 +456,7 @@ // gefunden wurden long propCalcNsStart = System.nanoTime(); - if(Config.Refinement.writeSearchTree) + if(writeSearchTree) expandedNodes.add(node); if(node.getChildren().size()>maxNrOfChildren) Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 15:23:41 UTC (rev 194) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 15:48:00 UTC (rev 195) @@ -24,16 +24,9 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; -import java.util.Map; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; @@ -42,10 +35,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.Individual; import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.reasoning.OWLAPIDIGConverter; import org.dllearner.utilities.Datastructures; /** Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 15:23:41 UTC (rev 194) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 15:48:00 UTC (rev 195) @@ -102,7 +102,7 @@ private boolean writeDIGProtocol; private File digProtocolFile; - private static String defaultDIGProtocolFile = "log/digProtocol"; + private static String defaultDIGProtocolFile = "log/digProtocol.txt"; public DIGReasoner(Set<KnowledgeSource> sources) { this.sources = sources; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 15:23:43
|
Revision: 194 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=194&view=rev Author: sknappe Date: 2007-10-08 08:23:41 -0700 (Mon, 08 Oct 2007) Log Message: ----------- filterMode=0 Modified Paths: -------------- trunk/examples/dbpedia/SilentBobWorking1.conf Modified: trunk/examples/dbpedia/SilentBobWorking1.conf =================================================================== --- trunk/examples/dbpedia/SilentBobWorking1.conf 2007-10-08 15:11:34 UTC (rev 193) +++ trunk/examples/dbpedia/SilentBobWorking1.conf 2007-10-08 15:23:41 UTC (rev 194) @@ -24,7 +24,7 @@ // SPARQL options sparql.numberOfRecursions = 2; sparql.instances = {"http://dbpedia.org/resource/Matt_Stone","http://dbpedia.org/resource/Sarah_Silverman","http://dbpedia.org/resource/Jim_Carrey","http://dbpedia.org/resource/Jason_Mewes","http://dbpedia.org/resource/Kevin_Smith","http://dbpedia.org/resource/Trey_Parker","http://dbpedia.org/resource/Adam_Sandler"}; -sparql.filterMode = 2; +sparql.filterMode = 0; sparql.predList = {}; sparql.objList = {}; sparql.classList = {}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 15:11:38
|
Revision: 193 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=193&view=rev Author: sknappe Date: 2007-10-08 08:11:34 -0700 (Mon, 08 Oct 2007) Log Message: ----------- examples modified to work with new Sparql module Modified Paths: -------------- trunk/examples/dbpedia/SilentBobWorking1.conf Added Paths: ----------- trunk/examples/dbpedia/Aristotle.conf trunk/examples/dbpedia/sparql.conf Removed Paths: ------------- trunk/examples/dbpedia/AristotleWorking1.conf Copied: trunk/examples/dbpedia/Aristotle.conf (from rev 176, trunk/examples/dbpedia/AristotleWorking1.conf) =================================================================== --- trunk/examples/dbpedia/Aristotle.conf (rev 0) +++ trunk/examples/dbpedia/Aristotle.conf 2007-10-08 15:11:34 UTC (rev 193) @@ -0,0 +1,55 @@ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = false; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.6; +//refinement.quiet = false; +//refinement.useTooWeakList = true; + +// search tree protocol +//refinement.writeSearchTree = false; +//refinement.searchTreeFile = "Aristotle_searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +/*sparqlModule.sparqlPredicateFilterList={"http://www.w3.org/2004/02/skos/core", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/wikipage-", + "http://www.w3.org/2002/07/owl#sameAs", + "http://dbpedia.org/property/reference"}; +sparqlModule.sparqlObjectFilterList={"http://dbpedia.org/resource/Category:Articles_", + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/resource/Category", + "http://dbpedia.org/resource/Template", + "http://upload.wikimedia.org/wikipedia/commons"};*/ +//sparqlModule.classList={}; +//sparqlModule.useLiterals = false; + +// SPARQL options +sparql.numberOfRecursions = 2; +sparql.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Socrates","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Philolaus"}; +sparql.filterMode = 0; +sparql.predList = {}; +sparql.objList = {}; +sparql.classList = {}; + +import("http://dbpedia.openlinksw.com","SPARQL"); + +/** examples **/ ++"http://dbpedia.org/resource/Pythagoras" ++"http://dbpedia.org/resource/Philolaus" ++"http://dbpedia.org/resource/Archytas" +-"http://dbpedia.org/resource/Socrates" +-"http://dbpedia.org/resource/Plato" +-"http://dbpedia.org/resource/Zeno_of_Elea" +-"http://dbpedia.org/resource/Democritus" \ No newline at end of file Deleted: trunk/examples/dbpedia/AristotleWorking1.conf =================================================================== --- trunk/examples/dbpedia/AristotleWorking1.conf 2007-10-08 15:04:12 UTC (rev 192) +++ trunk/examples/dbpedia/AristotleWorking1.conf 2007-10-08 15:11:34 UTC (rev 193) @@ -1,74 +0,0 @@ -runPreprocessingModule("org.dllearner.modules.sparql.SparqlModule"); - -// reasoner settings -reasoner = dig; -digReasonerURL = "http://localhost:8081"; -useRetrievalForClassification = false; -refinement.useDIGMultiInstanceChecks = twoChecks; - -// algorithm settings -algorithm = refinement; -refinement.horizontalExpansionFactor = 0.6; -refinement.quiet = false; -refinement.useTooWeakList = true; - -// search tree protocol -refinement.writeSearchTree = false; -refinement.searchTreeFile = "Aristotle_searchTree.txt"; - -// control output -showIndividuals = true; -showConcepts = true; -showRoles = true; -showInternalKB = true; -showSubsumptionHierarchy = true; - -hidePrefix="http://dbpedia.org/resource/"; - -refinement.useAllConstructor = false; -refinement.useExistsConstructor = true; -refinement.useNegation = false; - -sparqlModule.numberOfRecursion = 2; -sparqlModule.filterMode = 0; - - -/*sparqlModule.sparqlPredicateFilterList={"http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference"}; -sparqlModule.sparqlObjectFilterList={"http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/resource/Category", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"};*/ -//sparqlModule.classList={}; -//sparqlModule.useLiterals = false; - - - - -//mathematiker -+test("http://dbpedia.org/resource/Pythagoras"). -//well you know -+test("http://dbpedia.org/resource/Philolaus"). -//was a Greek Pythagorean and Presocratic. -+test("http://dbpedia.org/resource/Archytas"). -//was an Ancient Greek philosopher, mathematician, astronomer, statesman, and strategist. - - -//Philosophen --test("http://dbpedia.org/resource/Socrates"). --test("http://dbpedia.org/resource/Plato"). - --test("http://dbpedia.org/resource/Zeno_of_Elea"). -//was a pre-Socratic Greek philosopher --test("http://dbpedia.org/resource/Democritus"). -//was a pre-Socratic Greek philosopher - - - - - Modified: trunk/examples/dbpedia/SilentBobWorking1.conf =================================================================== --- trunk/examples/dbpedia/SilentBobWorking1.conf 2007-10-08 15:04:12 UTC (rev 192) +++ trunk/examples/dbpedia/SilentBobWorking1.conf 2007-10-08 15:11:34 UTC (rev 193) @@ -1,50 +1,43 @@ -runPreprocessingModule("org.dllearner.modules.sparql.SparqlModule"); - +/** settings **/ // reasoner settings reasoner = dig; -digReasonerURL = "http://localhost:8081"; -useRetrievalForClassification = false; -refinement.useDIGMultiInstanceChecks = twoChecks; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; // algorithm settings algorithm = refinement; -refinement.horizontalExpansionFactor = 0.6; -refinement.quiet = false; -refinement.useTooWeakList = true; +horizontalExpansionFactor = 0.5; +//refinement.quiet = false; // search tree protocol -refinement.writeSearchTree = false; -refinement.searchTreeFile = "Aristotle_searchTree.txt"; +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; // control output -showIndividuals = true; -showConcepts = true; -showRoles = true; -showInternalKB = true; -showSubsumptionHierarchy = true; +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; -hidePrefix="http://dbpedia.org/resource/"; +// SPARQL options +sparql.numberOfRecursions = 2; +sparql.instances = {"http://dbpedia.org/resource/Matt_Stone","http://dbpedia.org/resource/Sarah_Silverman","http://dbpedia.org/resource/Jim_Carrey","http://dbpedia.org/resource/Jason_Mewes","http://dbpedia.org/resource/Kevin_Smith","http://dbpedia.org/resource/Trey_Parker","http://dbpedia.org/resource/Adam_Sandler"}; +sparql.filterMode = 2; +sparql.predList = {}; +sparql.objList = {}; +sparql.classList = {}; +import("http://dbpedia.openlinksw.com","SPARQL"); -refinement.useAllConstructor = false; -refinement.useExistsConstructor = true; -refinement.useNegation = false; - -sparqlModule.numberOfRecursion = 3; -sparqlModule.filterMode = 0; - // http://dbpedia.org/class/yago/agnostic OR http://dbpedia.org/class/yago/artist // http://dbpedia.org/class/yago/agnostic OR http://dbpedia.org/class/yago/teetotaler -+test("http://dbpedia.org/resource/Matt_Stone"). -+test("http://dbpedia.org/resource/Sarah_Silverman"). --test("http://dbpedia.org/resource/Jim_Carrey"). --test("http://dbpedia.org/resource/Jason_Mewes"). --test("http://dbpedia.org/resource/Kevin_Smith"). --test("http://dbpedia.org/resource/Trey_Parker"). --test("http://dbpedia.org/resource/Adam_Sandler"). - - - - - ++"http://dbpedia.org/resource/Matt_Stone" ++"http://dbpedia.org/resource/Sarah_Silverman" +-"http://dbpedia.org/resource/Jim_Carrey" +-"http://dbpedia.org/resource/Jason_Mewes" +-"http://dbpedia.org/resource/Kevin_Smith" +-"http://dbpedia.org/resource/Trey_Parker" +-"http://dbpedia.org/resource/Adam_Sandler" \ No newline at end of file Copied: trunk/examples/dbpedia/sparql.conf (from rev 190, trunk/examples/sparql.conf) =================================================================== --- trunk/examples/dbpedia/sparql.conf (rev 0) +++ trunk/examples/dbpedia/sparql.conf 2007-10-08 15:11:34 UTC (rev 193) @@ -0,0 +1,45 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +sparql.numberOfRecursions = 2; +sparql.instances = {"http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; +sparql.filterMode = 0; +sparql.predList = {}; +sparql.objList = {}; +sparql.classList = {}; + +import("http://dbpedia.openlinksw.com","SPARQL"); + +/** examples **/ ++"http://dbpedia.org/resource/Pythagoras" +-"http://dbpedia.org/resource/Socrates" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 15:04:17
|
Revision: 192 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=192&view=rev Author: jenslehmann Date: 2007-10-08 08:04:12 -0700 (Mon, 08 Oct 2007) Log Message: ----------- integrated accuracy and error penalty in strict definition learning problem Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 15:04:12 UTC (rev 192) @@ -19,15 +19,15 @@ // standardmäßig wird bis Tiefe 7 gesucht // public static int maxLength = 7; - public static int maxDepth; + // public static int maxDepth; // Punktabzug für "ungenaue" Klassifizierungen, also positiv als neutral, // neutral als negativ und negativ als neutral - public static double accuracyPenalty = 1; + // public static double accuracyPenalty = 1; // Punktabzug für fehlerhafte Klassifizierungen, also positiv als negativ // und negativ als positiv - public static double errorPenalty = 3; + // public static double errorPenalty = 3; public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 15:04:12 UTC (rev 192) @@ -403,9 +403,9 @@ private void applyDoubleOptions(String option, double value) { // System.out.println(option + " " + value); if (option.equals("accuracyPenalty")) - Config.accuracyPenalty = value; + ; //Config.accuracyPenalty = value; else if (option.equals("errorPenalty")) - Config.errorPenalty = value; + ; //Config.errorPenalty = value; else if (option.equals("gp.crossoverPercent")) Config.GP.crossoverProbability = value / (double) 100; else if (option.equals("gp.mutationPercent")) Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 15:04:12 UTC (rev 192) @@ -334,7 +334,10 @@ // damit stellen wir sicher, dass nur Konzepte in die Auswahl // genommen werden, die besser klassifizieren als das �bergebene // Konzept (falls das nicht existiert, dann hill climbing = reproduction) - double bestScore = score.getScore()+Config.accuracyPenalty/2; + System.err.println("Next line needs fixing to work."); + System.exit(0); + // double bestScore = score.getScore()+Config.accuracyPenalty/2; + double bestScore = 0; Map<Integer,List<String>> bestNeighbours = new TreeMap<Integer,List<String>>(); Score tmpScore; SortedSetTuple<String> tmp, tmp2; @@ -456,7 +459,7 @@ // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); PosNegDefinitionLPStrict lp = (PosNegDefinitionLPStrict)learningProblem; - return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); + return new ScoreThreeValued(conceptLength, lp.getAccuracyPenalty(), lp.getErrorPenalty(), posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); } // aktualisiert die besten Knoten Modified: trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java 2007-10-08 15:04:12 UTC (rev 192) @@ -35,6 +35,10 @@ super(name, description); } + public DoubleConfigOption(String name, String description, double defaultValue) { + super(name, description, defaultValue); + } + /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-08 15:04:12 UTC (rev 192) @@ -35,6 +35,10 @@ super(name, description); } + public IntegerConfigOption(String name, String description, int defaultValue) { + super(name, description, defaultValue); + } + /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-08 15:04:12 UTC (rev 192) @@ -26,6 +26,7 @@ import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; +import org.dllearner.core.DoubleConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -45,6 +46,11 @@ private SortedSet<Individual> neutralExamples; private boolean penaliseNeutralExamples = false; + private static final double defaultAccuracyPenalty = 1; + private double accuracyPenalty = defaultAccuracyPenalty; + private static final double defaultErrorPenalty = 3; + private double errorPenalty = defaultErrorPenalty; + public PosNegDefinitionLPStrict(ReasoningService reasoningService) { super(reasoningService); } @@ -59,6 +65,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = PosNegLP.createConfigOptions(); options.add(new BooleanConfigOption("penaliseNeutralExamples", "if set to true neutral examples are penalised")); + options.add(new DoubleConfigOption("accuracyPenalty", "penalty for pos/neg examples which are classified as neutral", defaultAccuracyPenalty)); + options.add(new DoubleConfigOption("errorPenalty", "penalty for pos. examples classified as negative or vice versa", defaultErrorPenalty)); return options; } @@ -74,6 +82,7 @@ String name = entry.getOptionName(); if(name.equals("penaliseNeutralExamples")) penaliseNeutralExamples = (Boolean) entry.getValue(); + // else if } /* (non-Javadoc) @@ -100,13 +109,13 @@ // this.defPosSet = tuple.getPosSet(); // this.defNegSet = tuple.getNegSet(); SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); } else if(reasoningService.getReasonerType() == ReasonerType.KAON2) { SortedSet<Individual> posClassified = reasoningService.retrieval(concept); SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } else { @@ -146,7 +155,7 @@ SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } @@ -163,4 +172,18 @@ public SortedSet<Individual> getNeutralExamples() { return neutralExamples; } + + /** + * @return the accuracyPenalty + */ + public double getAccuracyPenalty() { + return accuracyPenalty; + } + + /** + * @return the errorPenalty + */ + public double getErrorPenalty() { + return errorPenalty; + } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 14:39:16 UTC (rev 191) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-08 15:04:12 UTC (rev 192) @@ -25,6 +25,9 @@ public enum ScoreMethod {POSITIVE, FULL}; + private double accuracyPenalty; + private double errorPenalty; + private SortedSet<Individual> posClassified; private SortedSet<Individual> neutClassified; private SortedSet<Individual> negClassified; @@ -52,6 +55,8 @@ private int conceptLength; public ScoreThreeValued(int conceptLength, + double accuracyPenalty, + double errorPenalty, SortedSet<Individual> posClassified, SortedSet<Individual> neutClassified, SortedSet<Individual> negClassified, @@ -59,6 +64,8 @@ SortedSet<Individual> neutExamples, SortedSet<Individual> negExamples) { this.conceptLength = conceptLength; + this.accuracyPenalty = accuracyPenalty; + this.errorPenalty = errorPenalty; this.posClassified = posClassified; this.neutClassified = neutClassified; this.negClassified = negClassified; @@ -85,20 +92,20 @@ } private void computeStatistics() { - score = - posAsNeg.size()*Config.errorPenalty - - negAsPos.size()*Config.errorPenalty - - posAsNeut.size()*Config.accuracyPenalty; + score = - posAsNeg.size()*errorPenalty + - negAsPos.size()*errorPenalty + - posAsNeut.size()*accuracyPenalty; if(Config.scoreMethod==ScoreMethod.FULL) - score -= negAsNeut.size()*Config.accuracyPenalty; + score -= negAsNeut.size()*accuracyPenalty; if(Config.penalizeNeutralExamples) - score -= (neutAsPos.size()*Config.accuracyPenalty - + neutAsNeg.size()*Config.accuracyPenalty); + score -= (neutAsPos.size()*accuracyPenalty + + neutAsNeg.size()*accuracyPenalty); // TODO: man könnte hier statt error penality auch accuracy penalty // nehmen - double worstValue = nrOfExamples * Config.errorPenalty; + double worstValue = nrOfExamples * errorPenalty; // ergibt Zahl zwischen -1 und 0 score = score / worstValue; score -= Config.percentPerLengthUnit * conceptLength; @@ -149,7 +156,7 @@ str += " neutral --> neutral: " + neutAsNeut + "\n"; str += " negative --> negative: " + negAsNeg + "\n"; } - str += "Inaccurately classified (penalty of " + df.format(Config.accuracyPenalty) + " per instance):\n"; + str += "Inaccurately classified (penalty of " + df.format(accuracyPenalty) + " per instance):\n"; str += " positive --> neutral: " + posAsNeut + "\n"; if(Config.penalizeNeutralExamples) { str += " neutral --> positive: " + neutAsPos + "\n"; @@ -157,7 +164,7 @@ } if(Config.scoreMethod == ScoreMethod.FULL) str += " negative --> neutral: " + negAsNeut + "\n"; - str += "Classification errors (penalty of " + df.format(Config.errorPenalty) + " per instance):\n"; + str += "Classification errors (penalty of " + df.format(errorPenalty) + " per instance):\n"; str += " positive --> negative: " + posAsNeg + "\n"; str += " negative --> positive: " + negAsPos + "\n"; str += "Statistics:\n"; @@ -194,7 +201,7 @@ @Override public Score getModifiedLengthScore(int newLength) { - return new ScoreThreeValued(newLength, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); + return new ScoreThreeValued(newLength, accuracyPenalty, errorPenalty, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 14:39:20
|
Revision: 191 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=191&view=rev Author: sknappe Date: 2007-10-08 07:39:16 -0700 (Mon, 08 Oct 2007) Log Message: ----------- added author Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 14:38:06 UTC (rev 190) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 14:39:16 UTC (rev 191) @@ -55,7 +55,7 @@ * TODO: Is it necessary to create a class DBpediaSparqlEndpoint? * * @author Jens Lehmann - * + * @author Sebastian Knappe */ public class SparqlEndpoint extends KnowledgeSource { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 14:38:12
|
Revision: 190 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=190&view=rev Author: sknappe Date: 2007-10-08 07:38:06 -0700 (Mon, 08 Oct 2007) Log Message: ----------- added options Modified Paths: -------------- trunk/examples/sparql.conf Modified: trunk/examples/sparql.conf =================================================================== --- trunk/examples/sparql.conf 2007-10-08 14:37:26 UTC (rev 189) +++ trunk/examples/sparql.conf 2007-10-08 14:38:06 UTC (rev 190) @@ -31,10 +31,14 @@ cli.showSubsumptionHierarchy = false; // SPARQL options -numberOfRecursions = 1; -url = "dbpedia.openlinksw.com"; +sparql.numberOfRecursions = 2; +sparql.instances = {"http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; +sparql.filterMode = 0; +sparql.predList = {}; +sparql.objList = {}; +sparql.classList = {}; -import("father.kb","SPARQL"); +import("http://dbpedia.openlinksw.com","SPARQL"); /** examples **/ +"http://dbpedia.org/resource/Pythagoras" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 14:37:27
|
Revision: 189 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=189&view=rev Author: sknappe Date: 2007-10-08 07:37:26 -0700 (Mon, 08 Oct 2007) Log Message: ----------- options added path changed Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 14:33:11 UTC (rev 188) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 14:37:26 UTC (rev 189) @@ -63,7 +63,11 @@ private Set<String> instances; private URL ntFile; private int numberOfRecursions; - + private int filterMode; + private Set<String> predList; + private Set<String> objList; + private Set<String> classList; + public static String getName() { return "SPARQL Endpoint"; } @@ -73,6 +77,10 @@ options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); options.add(new IntegerConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); + options.add(new IntegerConfigOption("filterMode","the mode of the SPARQL Filter")); + options.add(new StringSetConfigOption("predList","a predicate list")); + options.add(new StringSetConfigOption("objList","an object list")); + options.add(new StringSetConfigOption("classList","a class list")); return options; } @@ -89,15 +97,19 @@ url = new URL(s); } catch (MalformedURLException e) { throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); - } //catch (URISyntaxException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - //} + } } else if(option.equals("instances")) { instances = (Set<String>) entry.getValue(); } else if(option.equals("numberOfRecursions")){ - this.numberOfRecursions=(Integer)entry.getValue(); - System.out.println("test "+numberOfRecursions); + numberOfRecursions=(Integer)entry.getValue(); + } else if(option.equals("predList")) { + predList = (Set<String>) entry.getValue(); + } else if(option.equals("objList")) { + objList = (Set<String>) entry.getValue(); + } else if(option.equals("classList")) { + classList = (Set<String>) entry.getValue(); + } else if(option.equals("filterMode")){ + filterMode=(Integer)entry.getValue(); } } @@ -109,14 +121,11 @@ // TODO add code for downloading data from SPARQL endpoint String filename=System.currentTimeMillis()+".nt"; - Set<String> predList=new HashSet<String>(); - Set<String> objList=new HashSet<String>(); - Set<String> classList=new HashSet<String>(); - String prefix=""; - int filterMode=0; - try{ - FileWriter fw=new FileWriter(new File("examples/"+filename),true); + String basedir="cache"+File.separator; + if(!new File(basedir).exists()) + new File(basedir).mkdir(); + FileWriter fw=new FileWriter(new File(basedir+filename),true); System.out.println("SparqlModul: Collecting Ontology"); String[] a=new String[0]; OntologyCollector oc=new OntologyCollector(instances.toArray(a), numberOfRecursions, @@ -129,7 +138,7 @@ System.out.println("SparqlModul: ****Finished"); fw.close(); - this.ntFile=(new File("examples/"+filename)).toURI().toURL(); + this.ntFile=(new File(basedir+filename)).toURI().toURL(); //System.exit(0); }catch (Exception e) {e.printStackTrace();} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 14:33:13
|
Revision: 188 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=188&view=rev Author: jenslehmann Date: 2007-10-08 07:33:11 -0700 (Mon, 08 Oct 2007) Log Message: ----------- cleaned up brute force learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 14:33:11 UTC (rev 188) @@ -17,7 +17,7 @@ public class Config { // standardmäßig wird bis Tiefe 7 gesucht - public static int maxLength = 7; + // public static int maxLength = 7; public static int maxDepth; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 14:33:11 UTC (rev 188) @@ -383,7 +383,7 @@ private void applyIntOptions(String option, int value) { if (option.equals("maxLength")) - Config.maxLength = value; + ;//Config.maxLength = value; else if (option.equals("gp.numberOfIndividuals")) Config.GP.numberOfIndividuals = value; else if (option.equals("gp.numberOfSelectedIndividuals")) Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 14:33:11 UTC (rev 188) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, 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.Collection; @@ -27,30 +47,24 @@ import org.dllearner.core.dl.Top; /** - * TODO: Man könnte den Speicherbedarf gegen Null gehen lassen, wenn man gar keine Programme - * generiert, also in einer Menge speichert, sondern sofort testet. Allerdings ist das - * schwierig, da Programme kleinerer Länge immer weiterverwendet werden. + * A brute force learning algorithm. * + * The algorithm works by generating all concepts starting with the shortest + * ones. + * * @author Jens Lehmann * */ public class BruteForceLearner extends LearningAlgorithm { - LearningProblem learningProblem; + private LearningProblem learningProblem; - // Set<String> posExamples = null; - // Set<String> negExamples = null; - private Concept bestDefinition; private Score bestScore; - // private Set<String> bestDefPosSet = new TreeSet<String>(); - // private Set<String> bestDefNegSet = new TreeSet<String>(); - // int bestScore; - // int maxScore; - // Liste aller generierten Programme - // private List<Node> generatedPrograms = new LinkedList<Node>(); - // Programme nach Anzahl Knoten sortiert + private int maxLength = 7; + + // list of all generated concepts sorted by length private Map<Integer,List<Concept>> generatedDefinitions = new HashMap<Integer,List<Concept>>(); public BruteForceLearner(LearningProblem learningProblem, ReasoningService rs) { @@ -65,8 +79,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); - options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); + options.add(new IntegerConfigOption("maxLength", "maximum length of generated concepts")); return options; } @@ -75,7 +88,9 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // String name = entry.getOptionName(); + String name = entry.getOptionName(); + if(name.equals("maxLength")) + maxLength = (Integer) entry.getValue(); } /* (non-Javadoc) @@ -89,7 +104,6 @@ @Override public void start() { // FlatABox abox = FlatABox.getInstance(); - int maxLength = Config.maxLength; System.out.print("Generating definitions up to length " + maxLength + " ... "); long generationStartTime = System.currentTimeMillis(); @@ -100,49 +114,12 @@ long generationTime = System.currentTimeMillis() - generationStartTime; System.out.println("OK (" + generationTime + " ms)"); - // es wird angenommen, dass nur ein Konzept gelernt wird - /* - for(String s : abox.exampleConceptsPos.keySet()) { - posExamples = abox.exampleConceptsPos.get(s); - } - for(String s : abox.exampleConceptsNeg.keySet()) { - negExamples = abox.exampleConceptsNeg.get(s); - } - */ - testGeneratedDefinitions(maxLength); // System.out.println("test duration: " + testDuration + " ms"); System.out.println(); System.out.println("Best definition found: \n" + bestDefinition); - // System.out.println("classified positive: " + bestScore.getPosClassified()); - // System.out.println("classified negative: " + bestScore.getNegClassified()); - - /* - // HIER WIRD ANGENOMMEN, DASS NUR EIN KONZEPT GERLERNT WIRD - Set<String> posExamples = null; - Set<String> negExamples = null; - Set<String> neutralExamples; - // es wird angenommen, dass nur ein Konzept gelernt wird - for(String s : abox.exampleConceptsPos.keySet()) { - posExamples = abox.exampleConceptsPos.get(s); - } - for(String s : abox.exampleConceptsNeg.keySet()) { - negExamples = abox.exampleConceptsNeg.get(s); - } - neutralExamples = Helper.intersection(abox.top,posExamples); - neutralExamples = Helper.intersection(neutralExamples,negExamples); - - Set<String> bestDefNeutralSet = Helper.intersection(abox.top,bestDefPosSet); - bestDefNeutralSet = Helper.intersection(bestDefNeutralSet,bestDefNegSet); - - // Fehler berechnen - // int numberOfErrors = Helper.intersection(bestDefPosSet) - - - DecimalFormat df = new DecimalFormat("0.00"); - */ System.out.println(); System.out.println("Classification results:"); System.out.println(bestScore); @@ -168,21 +145,18 @@ System.out.print("Testing definitions of length " + i + " ... "); count = 0; for(Concept program : generatedDefinitions.get(i)) { - // falls return type angegeben ist, dann wird hier ein - // entsprechender Baum konstruiert + // if a return type is already given an appropriate tree is + // generated here Concept newRoot; if(!Config.returnType.equals("")) { newRoot = new Conjunction(new AtomicConcept(Config.returnType),program); } else newRoot = program; - // int score = computeScore(abox,program); - // tmp = new Score(newRoot); // newRoot.computeScore(); tmp = learningProblem.computeScore(newRoot); score = tmp.getScore(); - // später Abbruch bei maximaler Punktzahl einführen - //if(score == maxScore) - // return; + + // TODO: find termination criterion if(score > bestScorePoints) { bestDefinition = newRoot; bestScorePoints = score; @@ -199,8 +173,6 @@ System.out.println("Overall: " + overallCount + " definitions tested (" + testDuration + " ms)"); } - - private void generatePrograms(int length) { generatedDefinitions.put(length,new LinkedList<Concept>()); if(length==1) { @@ -212,26 +184,27 @@ } if(length>1) { - // Negation + // negation for(Concept childNode : generatedDefinitions.get(length-1)) { Concept root = new Negation(childNode); generatedDefinitions.get(length).add(root); } } - // Mindestlänge 3, da man sonst mit Disjunktion und Konjunktion nichts - // konstruieren kann + // minimum length 3, otherwise conjunctions and disjunctions cannot be + // constructed if(length>2) { - // Konjunktion oder Disjunktion auswählen + // choose conjunction or disjunction for(int i=0; i<=1; i++) { - // Variable von 1 bis angerundet (length-1)/2 gehen lassen - // = Länge des linken Teilbaumes + // let variable run from 1 to (length-1)/2 (rounded down) + // = length of left subtree for(int z=1; z<=Math.floor(0.5*(length-1)); z++) { - // alle Programme der Länge z durchgehen (linker Teilbaum) + + // cycle through all concepts of length z (left subtree) for(Concept leftChild : generatedDefinitions.get(z)) { - // alle Programme der Länge length-z-1 durchgehen (rechter Teilbaum) + // cycle thorugh all concept of lengt "length-z-1" (right subtree) for(Concept rightChild : generatedDefinitions.get(length-z-1)) { - // Baum erzeugen + // create concept tree Concept root; if(i==0) { root = new Disjunction(leftChild,rightChild); @@ -239,18 +212,18 @@ root = new Conjunction(leftChild,rightChild); } - // man beachte, dass hier nur Links gesetzt werden, d.h. - // dass: - // 1. jede Modifikation an einem generierten Programm auch - // andere Programme beeinflussen kann - // 2. wohin der parent-Link eines Knotens zeigt ist nicht - // spezifiziert, da ein Knoten Kind mehererer anderer - // Knoten sein kann - // Das wird gemacht, da der Retrieval-Algorithmus den parent- - // Link nicht benötigt und die Bäume nicht modifiziert, abgesehen - // vom posSet und negSet, welches aber für jeden Baum neu - // berechnet wird. Das speichern der Programme ist auf diese - // Weise platzsparend, also 1 Programm = 1 Knoten. + // Please not that we only set links here, i.e.: + // 1. Every modification of a generated concept can influence + // other concepts. + // 2. It is not specified where the parent link of a concept + // points to, because one node can be child of several nodes. + // + // For the currently implemented reasoning algorithms this + // does not matter, because they do not modify concepts and + // do not care about the parent link. + // + // This way we save space (1 new concept in the brute force + // learner consumes space for only one tree node). // root.addChild(leftChild); // root.addChild(rightChild); // System.out.println(root); @@ -261,9 +234,8 @@ } } - // Exists und All (zählen als Länge 2 wegen Quantor und Rollennamen) + // EXISTS and ALL for(Concept childNode : generatedDefinitions.get(length-2)) { - // for(String roleName : abox.roles) { for(AtomicRole atomicRole : learningProblem.getReasoningService().getAtomicRoles()) { Concept root1 = new Exists(atomicRole,childNode); generatedDefinitions.get(length).add(root1); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 14:33:11 UTC (rev 188) @@ -250,6 +250,10 @@ rs.prepareRoleHierarchy(); } + public static String getName() { + return "refinement operator based learning algorithm"; + } + // Kernalgorithmus @Override @SuppressWarnings("unchecked") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 13:54:48
|
Revision: 187 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=187&view=rev Author: sknappe Date: 2007-10-08 06:54:46 -0700 (Mon, 08 Oct 2007) Log Message: ----------- update Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 13:43:15 UTC (rev 186) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 13:54:46 UTC (rev 187) @@ -37,6 +37,7 @@ import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; +import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.StringConfigOption; @@ -71,7 +72,7 @@ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new StringConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); + options.add(new IntegerConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); return options; } @@ -95,7 +96,8 @@ } else if(option.equals("instances")) { instances = (Set<String>) entry.getValue(); } else if(option.equals("numberOfRecursions")){ - this.numberOfRecursions=Integer.parseInt((String)entry.getValue()); + this.numberOfRecursions=(Integer)entry.getValue(); + System.out.println("test "+numberOfRecursions); } } @@ -113,9 +115,6 @@ String prefix=""; int filterMode=0; - Individual ind1=new Individual("http://dbpedia.org/resource/Pythagoras"); - Individual ind2=new Individual("http://dbpedia.org/resource/Socrates"); - try{ FileWriter fw=new FileWriter(new File("examples/"+filename),true); System.out.println("SparqlModul: Collecting Ontology"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 13:43:38
|
Revision: 186 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=186&view=rev Author: sknappe Date: 2007-10-08 06:43:15 -0700 (Mon, 08 Oct 2007) Log Message: ----------- Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 13:39:55 UTC (rev 185) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 13:43:15 UTC (rev 186) @@ -43,6 +43,7 @@ import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; +import org.dllearner.reasoning.JenaOWLDIGConverter; import org.dllearner.reasoning.OWLAPIDIGConverter; import org.dllearner.utilities.Datastructures; @@ -59,6 +60,8 @@ private URL url; private Set<String> instances; + private URL ntFile; + private int numberOfRecursions; public static String getName() { return "SPARQL Endpoint"; @@ -68,6 +71,7 @@ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); + options.add(new StringConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); return options; } @@ -90,6 +94,8 @@ //} } else if(option.equals("instances")) { instances = (Set<String>) entry.getValue(); + } else if(option.equals("numberOfRecursions")){ + this.numberOfRecursions=Integer.parseInt((String)entry.getValue()); } } @@ -101,31 +107,20 @@ // TODO add code for downloading data from SPARQL endpoint String filename=System.currentTimeMillis()+".nt"; - int numberOfRecursions=1; Set<String> predList=new HashSet<String>(); Set<String> objList=new HashSet<String>(); Set<String> classList=new HashSet<String>(); String prefix=""; int filterMode=0; - Map<AtomicConcept, SortedSet<Individual>> positive=new HashMap<AtomicConcept, SortedSet<Individual>>(); - Map<AtomicConcept, SortedSet<Individual>> negative=new HashMap<AtomicConcept, SortedSet<Individual>>(); - AtomicConcept concept=new AtomicConcept("test"); + Individual ind1=new Individual("http://dbpedia.org/resource/Pythagoras"); Individual ind2=new Individual("http://dbpedia.org/resource/Socrates"); - SortedSet<Individual> sort1=new TreeSet<Individual>(); - SortedSet<Individual> sort2=new TreeSet<Individual>(); - sort1.add(ind1); - sort2.add(ind2); - positive.put(concept, sort1 ); - negative.put(concept, sort2 ); - String[] subjectList=makeSubjectList(prefix, positive, negative); - - try{ FileWriter fw=new FileWriter(new File("examples/"+filename),true); System.out.println("SparqlModul: Collecting Ontology"); - OntologyCollector oc=new OntologyCollector(subjectList, numberOfRecursions, + String[] a=new String[0]; + OntologyCollector oc=new OntologyCollector(instances.toArray(a), numberOfRecursions, filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList)); String ont=oc.collectOntology(); @@ -135,44 +130,11 @@ System.out.println("SparqlModul: ****Finished"); fw.close(); - this.url=(new File("examples/"+filename)).toURI().toURL(); + this.ntFile=(new File("examples/"+filename)).toURI().toURL(); //System.exit(0); }catch (Exception e) {e.printStackTrace();} } - private String[] makeSubjectList(String prefix, - Map<AtomicConcept, SortedSet<Individual>> positive, - Map<AtomicConcept, SortedSet<Individual>> negative){ - - //prefix - prefix=""; - - ArrayList<String> al=new ArrayList<String>(); - Iterator<AtomicConcept> it=positive.keySet().iterator(); - while(it.hasNext()){ - SortedSet<Individual> s=positive.get(it.next()); - Iterator<Individual> inner =s.iterator(); - while(inner.hasNext()){ - al.add(inner.next().toString()); - } - } - - it=negative.keySet().iterator(); - while(it.hasNext()){ - SortedSet<Individual> s=negative.get(it.next()); - Iterator<Individual> inner =s.iterator(); - while(inner.hasNext()){ - al.add(inner.next().toString()); - } - } - String[] subjectList=new String[al.size()]; - Object[] o=al.toArray(); - for (int i = 0; i < subjectList.length; i++) { - subjectList[i]=prefix+(String)o[i]; - } - return subjectList; - } - /* * (non-Javadoc) * @@ -180,7 +142,7 @@ */ @Override public String toDIG(URI kbURI) { - return OWLAPIDIGConverter.getTellsString(url, OntologyFileFormat.N_TRIPLES, kbURI); + return JenaOWLDIGConverter.getTellsString(ntFile, OntologyFileFormat.N_TRIPLES, kbURI); } public URL getURL() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 13:40:01
|
Revision: 185 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=185&view=rev Author: sknappe Date: 2007-10-08 06:39:55 -0700 (Mon, 08 Oct 2007) Log Message: ----------- example Added Paths: ----------- trunk/examples/sparql.conf Added: trunk/examples/sparql.conf =================================================================== --- trunk/examples/sparql.conf (rev 0) +++ trunk/examples/sparql.conf 2007-10-08 13:39:55 UTC (rev 185) @@ -0,0 +1,41 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +numberOfRecursions = 1; +url = "dbpedia.openlinksw.com"; + +import("father.kb","SPARQL"); + +/** examples **/ ++"http://dbpedia.org/resource/Pythagoras" +-"http://dbpedia.org/resource/Socrates" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 13:37:17
|
Revision: 184 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=184&view=rev Author: jenslehmann Date: 2007-10-08 06:37:15 -0700 (Mon, 08 Oct 2007) Log Message: ----------- query mode is back Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 12:52:31 UTC (rev 183) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 13:37:15 UTC (rev 184) @@ -81,12 +81,18 @@ public class Start { /** + * Entry point for CLI interface. + * * @param args */ public static void main(String[] args) { File file = new File(args[args.length - 1]); String baseDir = file.getParentFile().getPath(); + boolean inQueryMode = false; + if (args.length > 1 && args[0].equals("-q")) + inQueryMode = true; + // create component manager instance System.out.print("starting component manager ... "); long cmStartTime = System.nanoTime(); @@ -133,13 +139,13 @@ ConfFileOption problemOption = parser.getConfOptionsByName("problem"); Class<? extends LearningProblem> lpClass = null; LearningProblem lp = null; - if(problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) + if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) lpClass = PosNegDefinitionLP.class; - else if(problemOption.getStringValue().equals("posNegInclusion")) + else if (problemOption.getStringValue().equals("posNegInclusion")) lpClass = PosNegInclusionLP.class; else handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); - + lp = cm.learningProblem(lpClass, rs); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); @@ -165,7 +171,7 @@ // perform file exports performExports(parser, baseDir, rs); - + // show examples (display each one if they do not take up much space, // otherwise just show the number of examples) boolean oneLineExampleInfo = true; @@ -188,12 +194,17 @@ // handle any CLI options processCLIOptions(cm, parser, rs); - // start algorithm - long algStartTime = System.nanoTime(); - la.start(); - long algDuration = System.nanoTime() - algStartTime; - - printConclusions(rs, algDuration); + if (inQueryMode) + processQueryMode(lp, rs); + else { + // start algorithm + long algStartTime = System.nanoTime(); + la.start(); + long algDuration = System.nanoTime() - algStartTime; + + printConclusions(rs, algDuration); + } + } // creates a mapping from components to option prefix strings @@ -211,7 +222,8 @@ } // convenience method - // basically every prefix (e.g. "refinement" in "refinement.horizontalExpFactor) + // basically every prefix (e.g. "refinement" in + // "refinement.horizontalExpFactor) // corresponds to a specific component - this way the CLI will automatically // support any configuration options supported by the component private static void configureComponent(ComponentManager cm, Component component, @@ -361,9 +373,9 @@ private static void performExports(ConfParser parser, String baseDir, ReasoningService rs) { List<List<String>> exports = parser.getFunctionCalls().get("export"); - if(exports == null) + if (exports == null) return; - for(List<String> export : exports) { + for (List<String> export : exports) { File file = new File(baseDir, export.get(0)); if (export.size() == 1) // use RDF/XML by default @@ -379,72 +391,72 @@ } } } - + private static void processCLIOptions(ComponentManager cm, ConfParser parser, ReasoningService rs) { // CLI options (i.e. options which are related to the CLI // user interface but not to one of the components) List<ConfFileOption> cliOptions = parser.getConfOptionsByPrefix("cli"); - if(cliOptions != null) { - int maxLineLength = 100; - for (ConfFileOption cliOption : cliOptions) { - String name = cliOption.getSubOption(); - if (name.equals("showIndividuals")) { - if (cliOption.getStringValue().equals("true")) { - int stringLength = rs.getIndividuals().toString().length(); - if (stringLength > maxLineLength) { - System.out.println("individuals[" + rs.getIndividuals().size() + "]: "); - for (Individual ind : rs.getIndividuals()) - System.out.println(" " + ind); - } else - System.out.println("individuals[" + rs.getIndividuals().size() + "]: " - + rs.getIndividuals()); - } - } else if (name.equals("showConcepts")) { - if (cliOption.getStringValue().equals("true")) { - int stringLength = rs.getAtomicConcepts().toString().length(); - if (stringLength > maxLineLength) { - System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: "); - for (AtomicConcept ac : rs.getAtomicConcepts()) - System.out.println(" " + ac); - } else - System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: " - + rs.getAtomicConcepts()); - } - } else if (name.equals("showRoles")) { - if (cliOption.getStringValue().equals("true")) { - int stringLength = rs.getAtomicRoles().toString().length(); - if (stringLength > maxLineLength) { - System.out.println("roles[" + rs.getAtomicRoles().size() + "]: "); - for (AtomicRole r : rs.getAtomicRoles()) - System.out.println(" " + r); - } else - System.out.println("roles[" + rs.getAtomicRoles().size() + "]: " - + rs.getAtomicRoles()); - } - } else if (name.equals("showSubsumptionHierarchy")) { - if (cliOption.getStringValue().equals("true")) { - System.out.println("Subsumption Hierarchy:"); - System.out.println(rs.getSubsumptionHierarchy()); - } - // satisfiability check - } else if (name.equals("checkSatisfiability")) { - if (cliOption.getStringValue().equals("true")) { - System.out.print("Satisfiability Check ... "); - long satStartTime = System.nanoTime(); - boolean satisfiable = rs.isSatisfiable(); - long satDuration = System.nanoTime() - satStartTime; + if (cliOptions != null) { + int maxLineLength = 100; + for (ConfFileOption cliOption : cliOptions) { + String name = cliOption.getSubOption(); + if (name.equals("showIndividuals")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getIndividuals().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("individuals[" + rs.getIndividuals().size() + "]: "); + for (Individual ind : rs.getIndividuals()) + System.out.println(" " + ind); + } else + System.out.println("individuals[" + rs.getIndividuals().size() + "]: " + + rs.getIndividuals()); + } + } else if (name.equals("showConcepts")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getAtomicConcepts().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: "); + for (AtomicConcept ac : rs.getAtomicConcepts()) + System.out.println(" " + ac); + } else + System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: " + + rs.getAtomicConcepts()); + } + } else if (name.equals("showRoles")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getAtomicRoles().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("roles[" + rs.getAtomicRoles().size() + "]: "); + for (AtomicRole r : rs.getAtomicRoles()) + System.out.println(" " + r); + } else + System.out.println("roles[" + rs.getAtomicRoles().size() + "]: " + + rs.getAtomicRoles()); + } + } else if (name.equals("showSubsumptionHierarchy")) { + if (cliOption.getStringValue().equals("true")) { + System.out.println("Subsumption Hierarchy:"); + System.out.println(rs.getSubsumptionHierarchy()); + } + // satisfiability check + } else if (name.equals("checkSatisfiability")) { + if (cliOption.getStringValue().equals("true")) { + System.out.print("Satisfiability Check ... "); + long satStartTime = System.nanoTime(); + boolean satisfiable = rs.isSatisfiable(); + long satDuration = System.nanoTime() - satStartTime; - String result = satisfiable ? "OK" : "not satisfiable!"; - System.out.println(result + " (" - + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); - if (!satisfiable) - System.exit(0); - } - } else - handleError("Unknown CLI option \"" + name + "\"."); + String result = satisfiable ? "OK" : "not satisfiable!"; + System.out.println(result + " (" + + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); + if (!satisfiable) + System.exit(0); + } + } else + handleError("Unknown CLI option \"" + name + "\"."); + } } - } } private static void initComponent(ComponentManager cm, Component component) { @@ -467,26 +479,22 @@ System.out.println(message + " (" + Helper.prettyPrintNanoSeconds(initTime, false, false) + ")"); } - + private static void printConclusions(ReasoningService rs, long algorithmDuration) { if (rs.getNrOfRetrievals() > 0) { System.out.println("number of retrievals: " + rs.getNrOfRetrievals()); - System.out.println("retrieval reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getRetrievalReasoningTimeNs()) + " ( " - + Helper.prettyPrintNanoSeconds(rs.getTimePerRetrievalNs()) - + " per retrieval)"); + System.out + .println("retrieval reasoning time: " + + Helper.prettyPrintNanoSeconds(rs.getRetrievalReasoningTimeNs()) + + " ( " + Helper.prettyPrintNanoSeconds(rs.getTimePerRetrievalNs()) + + " per retrieval)"); } if (rs.getNrOfInstanceChecks() > 0) { - System.out.println("number of instance checks: " - + rs.getNrOfInstanceChecks() + " (" + System.out.println("number of instance checks: " + rs.getNrOfInstanceChecks() + " (" + rs.getNrOfMultiInstanceChecks() + " multiple)"); System.out.println("instance check reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getInstanceCheckReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerInstanceCheckNs()) + + Helper.prettyPrintNanoSeconds(rs.getInstanceCheckReasoningTimeNs()) + " ( " + + Helper.prettyPrintNanoSeconds(rs.getTimePerInstanceCheckNs()) + " per instance check)"); } if (rs.getNrOfSubsumptionHierarchyQueries() > 0) { @@ -497,57 +505,50 @@ * Helper.prettyPrintNanoSeconds(rs * .getSubsumptionHierarchyTimeNs()) + " ( " + * Helper.prettyPrintNanoSeconds(rs - * .getTimePerSubsumptionHierarchyQueryNs()) + " per - * subsumption hierachy query)"); + * .getTimePerSubsumptionHierarchyQueryNs()) + " per subsumption + * hierachy query)"); */ } if (rs.getNrOfSubsumptionChecks() > 0) { - System.out.println("(complex) subsumption checks: " - + rs.getNrOfSubsumptionChecks() + " (" - + rs.getNrOfMultiSubsumptionChecks() + " multiple)"); + System.out.println("(complex) subsumption checks: " + rs.getNrOfSubsumptionChecks() + + " (" + rs.getNrOfMultiSubsumptionChecks() + " multiple)"); System.out.println("subsumption reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getSubsumptionReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerSubsumptionCheckNs()) + + Helper.prettyPrintNanoSeconds(rs.getSubsumptionReasoningTimeNs()) + " ( " + + Helper.prettyPrintNanoSeconds(rs.getTimePerSubsumptionCheckNs()) + " per subsumption check)"); } DecimalFormat df = new DecimalFormat(); double reasoningPercentage = 100 * rs.getOverallReasoningTimeNs() / (double) algorithmDuration; - System.out - .println("overall reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getOverallReasoningTimeNs()) + " (" - + df.format(reasoningPercentage) - + "% of overall runtime)"); + System.out.println("overall reasoning time: " + + Helper.prettyPrintNanoSeconds(rs.getOverallReasoningTimeNs()) + " (" + + df.format(reasoningPercentage) + "% of overall runtime)"); System.out.println("overall algorithm runtime: " + Helper.prettyPrintNanoSeconds(algorithmDuration)); } - - // TODO: query mode umschreiben + + // performs a query - used for debugging learning examples private static void processQueryMode(LearningProblem lp, ReasoningService rs) { - System.out - .println("Entering query mode. Enter a concept for performing retrieval or q to quit."); + System.out.println("Entering query mode. Enter a concept for performing " + + "retrieval or q to quit. Use brackets for complex expresssions," + + "e.g. (a AND b)."); String queryStr = ""; do { - System.out.print("enter query: "); // String einlesen + System.out.print("enter query: "); + // read input string BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); - // Eingabestring einlesen try { queryStr = input.readLine(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); } - + if (!queryStr.equals("q")) { - // Konzept parsen + // parse concept Concept concept = null; boolean parsedCorrectly = true; @@ -566,8 +567,7 @@ } if (parsedCorrectly) { - // berechne im Konzept vorkommende atomare Rollen und - // Konzepte + // compute atomic roles and concepts used in concept SortedSet<AtomicConcept> occurringConcepts = new TreeSet<AtomicConcept>( new ConceptComparator()); occurringConcepts.addAll(Helper.getAtomicConcepts(concept)); @@ -575,16 +575,15 @@ new RoleComparator()); occurringRoles.addAll(Helper.getAtomicRoles(concept)); - // ziehe davon die existierenden ab => die resultierenden - // Mengen - // sollten leer sein, ansonsten Fehler (der DIG-Reasoner - // fängt das - // leider nicht selbst ab) - // => momentan etwas umständlich gelöst, da es in Java bei - // removeAll darauf - // ankommt, dass die Argumentmenge den Comparator - // implementiert hat, was hier - // (noch) nicht der Fall ist + // substract existing roles/concepts from detected + // roles/concepts -> the resulting sets should be + // empty, otherwise print a warning (the DIG reasoner + // will just treat them as concepts about which it + // has no knowledge - this makes it hard to + // detect typos + // (note that removeAll currently gives a different + // result here, because the comparator of the argument + // is used) for (AtomicConcept ac : rs.getAtomicConcepts()) occurringConcepts.remove(ac); for (AtomicRole ar : rs.getAtomicRoles()) @@ -595,25 +594,29 @@ System.out .println("You used non-existing atomic concepts or roles. Please correct your query."); if (occurringConcepts.size() > 0) - System.out.println("non-existing concepts: " - + occurringConcepts); + System.out.println("non-existing concepts: " + occurringConcepts); if (occurringRoles.size() > 0) System.out.println("non-existing roles: " + occurringRoles); nonExistingConstructs = true; } if (!nonExistingConstructs) { - // Retrieval stellen + + if(!queryStr.startsWith("(") && (queryStr.contains("AND") || queryStr.contains("OR"))) { + System.out.println("Make sure you did not forget to use outer brackets."); + } + + System.out.println("The query is: " + concept + "."); + + // pose retrieval query Set<Individual> result = null; result = rs.retrieval(concept); - System.out.println(result); + System.out.println("retrieval result: " + result); Score score = lp.computeScore(concept); System.out.println(score); - // feststellen, was zur Lösung noch fehlt - // Set<String> notCoveredPositives } } } @@ -621,7 +624,7 @@ } while (!queryStr.equals("q")); } - + private static void handleError(String message) { System.err.println(message); System.exit(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 12:52:33
|
Revision: 183 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=183&view=rev Author: jenslehmann Date: 2007-10-08 05:52:31 -0700 (Mon, 08 Oct 2007) Log Message: ----------- cleanup (reduced number of warnings) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 12:52:31 UTC (rev 183) @@ -75,7 +75,7 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); + // String name = entry.getOptionName(); } /* (non-Javadoc) @@ -86,6 +86,7 @@ } + @Override public void start() { // FlatABox abox = FlatABox.getInstance(); int maxLength = Config.maxLength; @@ -274,16 +275,17 @@ } } + @Override public Score getSolutionScore() { return bestScore; } + @Override public Concept getBestSolution() { return bestDefinition; } + @Override public void stop() { - // TODO Auto-generated method stub - } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -146,7 +146,7 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); + // String name = entry.getOptionName(); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 12:52:31 UTC (rev 183) @@ -26,7 +26,6 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.PosNegDefinitionLPStrict; -import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 12:52:31 UTC (rev 183) @@ -251,6 +251,7 @@ } // Kernalgorithmus + @Override @SuppressWarnings("unchecked") public void start() { Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 12:52:31 UTC (rev 183) @@ -47,9 +47,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.StringConfigOption; Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 12:52:31 UTC (rev 183) @@ -21,7 +21,6 @@ package org.dllearner.core; import java.io.File; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -19,20 +19,12 @@ */ package org.dllearner.learningproblems; -import java.util.Collection; -import java.util.LinkedList; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.BooleanConfigOption; -import org.dllearner.core.CommonConfigMappings; -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.ConfigOption; -import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; -import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -19,14 +19,11 @@ */ package org.dllearner.learningproblems; -import java.util.SortedSet; - import org.dllearner.core.ConfigEntry; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; /** * @author Jens Lehmann Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-08 12:52:31 UTC (rev 183) @@ -23,7 +23,6 @@ import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-08 12:52:31 UTC (rev 183) @@ -13,12 +13,10 @@ import org.dllearner.Config; import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.core.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java 2007-10-08 12:52:31 UTC (rev 183) @@ -1,7 +1,6 @@ package org.dllearner.server; import org.dllearner.Config; -import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2007-10-08 12:52:31 UTC (rev 183) @@ -11,8 +11,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.Config.Refinement; -import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.AssertionalAxiom; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 12:26:36
|
Revision: 182 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=182&view=rev Author: jenslehmann Date: 2007-10-08 05:26:35 -0700 (Mon, 08 Oct 2007) Log Message: ----------- removed modules package (became obsolete due to new component structure) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/modules/ Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:07:11 UTC (rev 181) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:26:35 UTC (rev 182) @@ -43,7 +43,6 @@ import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; -import org.dllearner.modules.sparql.OntologyCollector; import org.dllearner.reasoning.OWLAPIDIGConverter; import org.dllearner.utilities.Datastructures; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 12:07:12
|
Revision: 181 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=181&view=rev Author: sknappe Date: 2007-10-08 05:07:11 -0700 (Mon, 08 Oct 2007) Log Message: ----------- Sparql Modul in org.dllearner.kb ?\195?\188bertragen Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:05:59 UTC (rev 180) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:07:11 UTC (rev 181) @@ -19,12 +19,21 @@ */ package org.dllearner.kb; +import java.io.File; +import java.io.FileWriter; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; +import java.util.Map; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; @@ -32,6 +41,11 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.Individual; +import org.dllearner.modules.sparql.OntologyCollector; +import org.dllearner.reasoning.OWLAPIDIGConverter; +import org.dllearner.utilities.Datastructures; /** * Represents a SPARQL Endpoint. @@ -85,9 +99,81 @@ */ @Override public void init() { - // TODO add code for downloading data from SPARQL endpoint + // TODO add code for downloading data from SPARQL endpoint + String filename=System.currentTimeMillis()+".nt"; + + int numberOfRecursions=1; + Set<String> predList=new HashSet<String>(); + Set<String> objList=new HashSet<String>(); + Set<String> classList=new HashSet<String>(); + String prefix=""; + int filterMode=0; + Map<AtomicConcept, SortedSet<Individual>> positive=new HashMap<AtomicConcept, SortedSet<Individual>>(); + Map<AtomicConcept, SortedSet<Individual>> negative=new HashMap<AtomicConcept, SortedSet<Individual>>(); + AtomicConcept concept=new AtomicConcept("test"); + Individual ind1=new Individual("http://dbpedia.org/resource/Pythagoras"); + Individual ind2=new Individual("http://dbpedia.org/resource/Socrates"); + SortedSet<Individual> sort1=new TreeSet<Individual>(); + SortedSet<Individual> sort2=new TreeSet<Individual>(); + sort1.add(ind1); + sort2.add(ind2); + positive.put(concept, sort1 ); + negative.put(concept, sort2 ); + + String[] subjectList=makeSubjectList(prefix, positive, negative); + + + try{ + FileWriter fw=new FileWriter(new File("examples/"+filename),true); + System.out.println("SparqlModul: Collecting Ontology"); + OntologyCollector oc=new OntologyCollector(subjectList, numberOfRecursions, + filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList)); + + String ont=oc.collectOntology(); + fw.write(ont); + fw.flush(); + + System.out.println("SparqlModul: ****Finished"); + + fw.close(); + this.url=(new File("examples/"+filename)).toURI().toURL(); + //System.exit(0); + }catch (Exception e) {e.printStackTrace();} } + private String[] makeSubjectList(String prefix, + Map<AtomicConcept, SortedSet<Individual>> positive, + Map<AtomicConcept, SortedSet<Individual>> negative){ + + //prefix + prefix=""; + + ArrayList<String> al=new ArrayList<String>(); + Iterator<AtomicConcept> it=positive.keySet().iterator(); + while(it.hasNext()){ + SortedSet<Individual> s=positive.get(it.next()); + Iterator<Individual> inner =s.iterator(); + while(inner.hasNext()){ + al.add(inner.next().toString()); + } + } + + it=negative.keySet().iterator(); + while(it.hasNext()){ + SortedSet<Individual> s=negative.get(it.next()); + Iterator<Individual> inner =s.iterator(); + while(inner.hasNext()){ + al.add(inner.next().toString()); + } + } + String[] subjectList=new String[al.size()]; + Object[] o=al.toArray(); + for (int i = 0; i < subjectList.length; i++) { + subjectList[i]=prefix+(String)o[i]; + } + return subjectList; + } + /* * (non-Javadoc) * @@ -95,7 +181,7 @@ */ @Override public String toDIG(URI kbURI) { - return null; + return OWLAPIDIGConverter.getTellsString(url, OntologyFileFormat.N_TRIPLES, kbURI); } public URL getURL() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-10-08 12:06:02
|
Revision: 180 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=180&view=rev Author: sknappe Date: 2007-10-08 05:05:59 -0700 (Mon, 08 Oct 2007) Log Message: ----------- Sparql Modul in org.dllearner.kb ?\195?\188bertragen Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/Cache.java trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/QueryMaker.java trunk/src/dl-learner/org/dllearner/kb/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java Added: trunk/src/dl-learner/org/dllearner/kb/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/Cache.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/Cache.java 2007-10-08 12:05:59 UTC (rev 180) @@ -0,0 +1,210 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.net.URLEncoder; +/** + * + * This is a primitive cache. + * The objects of this class can be either the cache itself or just on entry in the cache + * + * the cache remembers: a timestamp, the original sparql-query, the result + * key is the subject http://dbpedia.org/resource/Angela_Merkel which is first urlencoded + * and so serves as the hash for the filename. + * Cache validates if timestamp too old and Sparql-Query the same + * before returning the SPARQL xml-result + * + * @author Sebastian Hellmann + * + */ +public class Cache implements Serializable{ + + + final static long serialVersionUID=104; + transient String basedir=""; + transient String fileending=".cache"; + long timestamp; + String content=""; + long daysoffreshness=15; + long multiplier=24*60*60*1000;//h m s ms + String sparqlquery=""; + + + /** + * Constructor for the cache itself. + * Called once at the beginning + * + * @param path Where the base path to the cache is + */ + public Cache(String path){ + this.basedir=path+File.separator; + if(!new File(path).exists()) + {System.out.println(new File(path).mkdir());;} + + } + +// + /** + * Constructor for single cache object(one entry) + * + * @param content the sparql xml result + * @param sparql the sparql query + */ + public Cache(String content, String sparql){ + this.content=content; + this.sparqlquery=sparql; + this.timestamp=System.currentTimeMillis(); + } + + + + /** + * use only on the cache object describing the cache itself + * + * @param key the individual + * @param sparql the sparql query + * @return the cached sparql result or null + */ + public String get(String key, String sparql){ + //System.out.println("get From "+key); + String ret=null; + try{ + Cache c =readFromFile(makeFilename(key)) ; + if(c==null)return null; + //System.out.println(" file found"); + if(!c.checkFreshness())return null; + //System.out.println("fresh"); + if(!c.validate(sparql))return null; + //System.out.println("valid"); + ret=c.content; + }catch (Exception e) {e.printStackTrace();} + return ret; + } + + /** + * + * constructor for single cache object(one entry) + * + * @param key the individual + * @param content the sparql result + * @param sparql the sparql query + */ + public void put(String key, String content, String sparql){ + //System.out.println("put into "+key); + Cache c=new Cache(content,sparql); + putIntoFile(makeFilename(key), c); + } + + + /** + * to normalize the filenames + * + * @param key + * @return + */ + String makeFilename(String key){ + String ret=""; + try{ + ret=basedir+URLEncoder.encode(key, "UTF-8")+fileending; + }catch (Exception e) {e.printStackTrace();} + return ret; + } + + /** + * how old is the result + * @return + */ + boolean checkFreshness(){ + if((System.currentTimeMillis()-this.timestamp)<=(daysoffreshness*multiplier)) + //fresh + return true; + else return false; + } + + + /** + * some sparql query + * @param sparql + * @return + */ + boolean validate(String sparql){ + if(this.sparqlquery.equals(sparql)) + //valid + return true; + else return false; + } + + /** + * makes a new file if none exists + * @param Filename + */ + public void checkFile(String Filename){ + if(!new File(Filename).exists()){ + try{ + new File(Filename).createNewFile(); + }catch (Exception e) {e.printStackTrace();} + + } + + } + + /** + * internal saving function + * puts a cache object into a file + * + * @param Filename + * @param content + */ + public void putIntoFile(String Filename,Cache content){ + try{ + //FileWriter fw=new FileWriter(new File(Filename),true); + FileOutputStream fos = new FileOutputStream( Filename , false ); + ObjectOutputStream o = new ObjectOutputStream( fos ); + o.writeObject( content ); + fos.flush(); + fos.close(); + }catch (Exception e) {System.out.println("Not in cache creating: "+Filename);} + } + + /** + * internal retrieval function + * + * @param Filename + * @return one entry object + */ + public Cache readFromFile(String Filename){ + Cache content=null; + try{ + FileInputStream fos = new FileInputStream( Filename ); + ObjectInputStream o = new ObjectInputStream( fos ); + content=(Cache)o.readObject(); + //FileReader fr=new FileReader(new File(Filename,"r")); + //BufferedReader br=new BufferedReader(fr); + }catch (Exception e) {} + return content; + + } +} Added: trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyCollector.java 2007-10-08 12:05:59 UTC (rev 180) @@ -0,0 +1,365 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; + +/** + * This class collects the ontology from dbpedia, + * everything is saved in hashsets, so the doublettes are taken care of + * + * + * @author Sebastian Hellmann + * + */ +public class OntologyCollector { + + boolean print_flag=false; + SimpleHTTPRequest s; + QueryMaker q; + Cache c; + InetAddress ia; + SparqlFilter sf; + String[] subjectList; + int numberOfRecursions; + HashSet<String> properties; + HashSet<String> classes; + HashSet<String> instances; + HashSet<String> triples; + + // some namespaces + String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; + String type="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + String objectProperty="http://www.w3.org/2002/07/owl#ObjectProperty"; + String classns="http://www.w3.org/2002/07/owl#Class"; + String thing="http://www.w3.org/2002/07/owl#Thing"; + + + String[] defaultClasses={ + "http://dbpedia.org/class/yago", + "http://dbpedia.org/resource/Category:", + "http://dbpedia.org/resource/Template:", + "http://www.w3.org/2004/02/skos/core", + "http://dbpedia.org/class/"}; //TODO FEHLER hier fehlt yago + + + /** + * + * + * @param subjectList + * @param numberOfRecursions + * @param filterMode + * @param FilterPredList + * @param FilterObjList + * @param defClasses + */ + public OntologyCollector(String[] subjectList,int numberOfRecursions, + int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses){ + this.subjectList=subjectList; + this.numberOfRecursions=numberOfRecursions; + + this.s=new SimpleHTTPRequest(); + this.q=new QueryMaker(); + this.c=new Cache("cache"); + if(defClasses!=null && defClasses.length>0 ){ + this.defaultClasses=defClasses; + } + + try{ + this.sf=new SparqlFilter(filterMode,FilterPredList,FilterObjList); + this.ia=InetAddress.getByName("dbpedia.openlinksw.com"); + //this.fw=new FileWriter(new File(System.currentTimeMillis()+".nt"),true); + this.properties=new HashSet<String>(); + this.classes=new HashSet<String>(); + this.instances=new HashSet<String>(); + this.triples=new HashSet<String>(); + //this.all=new HashSet<String>(); + }catch (Exception e) {e.printStackTrace();} + + } + /** + * first collects the ontology + * then types everything so it becomes owl-dl + * + * @return all triples in n-triple format + */ + public String collectOntology(){ + getRecursiveList(subjectList, numberOfRecursions); + finalize(); + String ret=""; + for (Iterator<String> iter = triples.iterator(); iter.hasNext();) { + ret += iter.next(); + + } + return ret; + } + + /** + * calls getRecursive for each subject in list + * @param subjects + * @param NumberofRecursions + */ + public void getRecursiveList(String[] subjects,int NumberofRecursions){ + for (int i = 0; i < subjects.length; i++) { + getRecursive(subjects[i], NumberofRecursions); + + } + + } + + /** + * gets all triples until numberofrecursion-- gets 0 + * + * @param StartingSubject + * @param NumberofRecursions + */ + public void getRecursive(String StartingSubject,int NumberofRecursions){ + System.out.print("SparqlModul: Depth: "+NumberofRecursions+" @ "+StartingSubject+" "); + if(NumberofRecursions<=0) + { return; + } + else {NumberofRecursions--;} + //System.out.println(NumberofRecursions); + try{ + + String sparql=q.makeQueryFilter(StartingSubject,this.sf); + p(sparql); + p("*******************"); + // checks cache + String FromCache=c.get(StartingSubject, sparql); + String xml; + // if not in cache get it from dbpedia + if(FromCache==null){ + xml=s.sendAndReceive(ia, 8890, sparql); + c.put(StartingSubject, xml, sparql); + System.out.print("\n"); + } + else{ + xml=FromCache; + System.out.println("FROM CACHE"); + } + p(xml); + p("***********************"); + // get new Subjects + String[] newSubjects=processResult(StartingSubject,xml); + + for (int i = 0; (i < newSubjects.length)&& NumberofRecursions!=0; i++) { + getRecursive(newSubjects[i], NumberofRecursions); + } + + //System.out.println(xml); + }catch (Exception e) {e.printStackTrace();} + + } + + /** + * process the sparql result xml in a simple manner + * + * + * @param subject + * @param xml + * @return list of new individuals + */ + public String[] processResult(String subject,String xml){ + //TODO if result is empty, catch exceptions + String one="<binding name=\"predicate\"><uri>"; + String two="<binding name=\"object\"><uri>"; + String end="</uri></binding>"; + String predtmp=""; + String objtmp=""; + ArrayList<String> al=new ArrayList<String>(); + + while(xml.indexOf(one)!=-1){ + //get pred + xml=xml.substring(xml.indexOf(one)+one.length()); + predtmp=xml.substring(0,xml.indexOf(end)); + //getobj + xml=xml.substring(xml.indexOf(two)+two.length()); + objtmp=xml.substring(0,xml.indexOf(end)); + + // writes the triples and resources in the hashsets + // also fills the arraylist al + processTriples(subject, predtmp, objtmp,al); + //System.out.println(al.size()); + + } + + // convert al to list + Object[] o=al.toArray(); + String[] ret=new String[o.length]; + for (int i = 0; i < o.length; i++) { + ret[i]=(String)o[i]; + } + return ret; + //return (String[])al.toArray(); + //System.out.println(xml); + } + + + + /** + * + * writes the triples and resources in the hashsets + * also fills the arraylist al with new individals for further processing + * @param s + * @param p + * @param o + * @param al + */ + public void processTriples(String s,String p, String o,ArrayList<String> al){ + // the next two lines bump out some inconsistencies within dbpedia + String t="/Category"; + if(s.equals(t) || o.equals(t))return ; + + if(sf.mode==2) + { + if( o.startsWith("http://dbpedia.org/resource/Category:") + && + !p.startsWith("http://www.w3.org/2004/02/skos/core") + ) + {return;} + if(p.equals("http://www.w3.org/2004/02/skos/core#broader")){ + p=subclass; + } + else if(p.equals("http://www.w3.org/2004/02/skos/core#subject")){ + p=type; + } + else {} + } + + //save for further processing + al.add(o); + + // type classes + if(isClass(o)){ + classes.add(o); + if(isClass(s))p=subclass; + else p=type; + } + else { + instances.add(o); + this.properties.add(p); + } + + + + //maketriples + try{ + this.triples.add(makeTriples(s, p, o)); + //fw.write(makeTriples(subject, predtmp, objtmp)); + }catch (Exception e) {e.printStackTrace();} + + + return; + } +// + /** + * also makes subclass property between classes + * + * @param s + * @param p + * @param o + * @return triple in the n triple notation + */ + public String makeTriples(String s,String p, String o){ + //s=replaceNamespace(s); + //p=replaceNamespace(p); + //o=replaceNamespace(o); + String ret=""; + ret="<"+s+"> <"+p+"> <"+o+">.\n"; + return ret; + } + + /** + * decides if an object is treated as a class + * + * @param obj + * @return true if obj is in the defaultClassesList + */ + public boolean isClass(String obj){ + + boolean retval=false; + for (String defclass : defaultClasses) { + if(obj.contains(defclass))retval=true; + } + return retval; + } + + + /** + * @see java.lang.Object#finalize() + */ + @Override + public void finalize(){ + typeProperties(); + typeClasses(); + typeInstances(); + } + + public void typeProperties(){ + String rdfns="http://www.w3.org/1999/02/22-rdf-syntax-ns"; + String owlns="http://www.w3.org/2002/07/owl"; + Iterator<String> it=properties.iterator(); + String current=""; + while (it.hasNext()){ + try{ + current=it.next(); + if(current.equals(subclass))continue; + if(current.contains(rdfns)||current.contains(owlns)){/*DO NOTHING*/} + else {this.triples.add(makeTriples(current,type,objectProperty));} + }catch (Exception e) {} + + } + } + public void typeClasses(){ + Iterator<String> it=classes.iterator(); + String current=""; + while (it.hasNext()){ + try{ + current=it.next(); + this.triples.add(makeTriples(current,type,classns)); + }catch (Exception e) {} + } + } + public void typeInstances(){ + Iterator<String> it=instances.iterator(); + String current=""; + while (it.hasNext()){ + try{ + current=it.next(); + this.triples.add(makeTriples(current,type,thing)); + }catch (Exception e) {} + } + } + + /** + * debug print turn on print_flag + * @param s + */ + public void p(String s){ + if(print_flag) + System.out.println(s); + } + + +} Added: trunk/src/dl-learner/org/dllearner/kb/QueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/QueryMaker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/QueryMaker.java 2007-10-08 12:05:59 UTC (rev 180) @@ -0,0 +1,123 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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; + +/** + * + * This class produces sparql queries + * + * @author Sebastian Hellmann + * + */ +public class QueryMaker { + //Good + /*public static String owl ="http://www.w3.org/2002/07/owl#"; + public static String xsd="http://www.w3.org/2001/XMLSchema#"; + public static String rdfs="http://www.w3.org/2000/01/rdf-schema#"; + public static String rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + public static String base="http://dbpedia.org/resource/"; + public static String dbpedia2="http://dbpedia.org/property/"; + public static String dbpedia="http://dbpedia.org/"; + + + //BAD + public static String skos="http://www.w3.org/2004/02/skos/core#"; + public static String foaf="http://xmlns.com/foaf/0.1/"; + public static String dc="http://purl.org/dc/elements/1.1/"; + public static String foreign="http://dbpedia.org/property/wikipage-"; + public static String sameAs="http://www.w3.org/2002/07/owl#sameAs"; + public static String reference="http://dbpedia.org/property/reference";*/ + + int tempyago=0; + + /** + * reads all the options and makes the sparql query accordingly + * @param subject + * @param sf special object encapsulating all options + * @return sparql query + */ + public String makeQueryFilter(String subject, SparqlFilter sf){ + + + String Filter=""; + if(!sf.useLiterals)Filter+="!isLiteral(?object))"; + for (String p : sf.getPredFilter()) { + Filter+="\n" + filterPredicate(p); + } + for (String o : sf.getObjFilter()) { + Filter+="\n" + filterObject(o); + } + + + String ret= + "SELECT * WHERE { \n" + + "<"+ + subject+ + + "> ?predicate ?object.\n" + + "FILTER( \n" + + "(" +Filter+").}"; + //System.out.println(ret); + return ret; + } + + + /*public String makeQueryDefault(String subject){ + String ret= + "SELECT * WHERE { \n" + + "<"+ + subject+ + + "> ?predicate ?object.\n" + + "FILTER( \n" + + "(!isLiteral(?object))" + + "\n" + filterPredicate(skos)+ + //"\n" + filterObject(skos)+ + "\n" + filterPredicate(foaf)+ + "\n" + filterObject(foaf)+ + "\n" + filterPredicate(foreign)+ + "\n" + filterPredicate(sameAs)+ + "\n" + filterPredicate(reference)+ + ")." + + " }"; + + //System.out.println(ret); + return ret; +}*/ + + /** + * add a new object filter + * (objects are filtered out of sparql result) + * @param ns namespace + * @return + */ + public String filterObject(String ns){ + return "&&( !regex((?object), '"+ns+"') )"; + } + /** + * add a new object filter + * (objects are filtered out of sparql result) + * @param ns namespace + * * @return + */ + public String filterPredicate(String ns){ + return "&&( !regex(str(?predicate), '"+ns+"') )"; + } +} Added: trunk/src/dl-learner/org/dllearner/kb/SimpleHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SimpleHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SimpleHTTPRequest.java 2007-10-08 12:05:59 UTC (rev 180) @@ -0,0 +1,126 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URLEncoder; + + + +/** + * + * This class makes a simple http request + * the dbpedia url is hardcoded + * + * @author Sebastian Hellmann + * + * + */ +public class SimpleHTTPRequest { + static final char value[]={13,10}; + static final String cut=new String(value); + + + + + public String sendAndReceive(InetAddress ia, int port, String sparql){ + String retval=""; + // + + byte resp[]=null; + + try{ + Socket SparqlServer=new Socket(ia,port); + String request=makeHeader(sparql); + // send request + (SparqlServer.getOutputStream()).write(request.getBytes()); + + //get Response + resp=readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval=new String(resp); + retval=subtractResponseHeader(retval); + //retval="||"+retval; + + SparqlServer.close(); + + + + } + catch(Exception e){e.printStackTrace();} + //System.out.println("got it"); + return retval; + + }//down + + public static byte[] readBuffer(InputStream IS) + throws IOException{ + byte buffer[] = new byte[0xffff]; + int nbytes=0; + byte resp[]=new byte[0]; + while ((nbytes=IS.read(buffer))!=-1) { + byte tmp[]=new byte[resp.length+nbytes]; + int i=0; + for (;i<resp.length;i++){ + tmp[i]=resp[i]; + } + for(int a=0;a<nbytes;a++,i++){ + tmp[i]=buffer[a]; + } + resp=tmp; + } + return resp; + } + + public String subtractResponseHeader(String in){ + //System.out.println(in.indexOf(cut+""+cut)); + return in.substring(in.indexOf(cut+""+cut)+4); + + + } + + public String makeHeader(String query){ + + + String RequestHeader=""; + try{ + + RequestHeader="GET /sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + + URLEncoder.encode(query, "UTF-8")+ + //query+// URLencode + "&format=application%2Fsparql-results%2Bxml HTTP/1.1"+cut+ + "Host: dbpedia.openlinksw.com"+cut+ + "Connection: close"+cut+ + //"Accept-Encoding: gzip"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"+cut+ + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"+cut+ + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"+cut+ + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"+cut+ + cut; + }catch (Exception e) {e.printStackTrace();} + return RequestHeader; + + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java 2007-10-08 12:05:59 UTC (rev 180) @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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; + +/** + * + * + * encapsulates all the options + * see the documentation for more help + * + * @author Sebastian Hellmann + * + */ +public class SparqlFilter { + public int mode=0; + // 0 yago, 1 only cat, 2 skos+cat + String[] PredFilter=null; + String[] ObjFilter=null; + boolean useLiterals=false; + + + String[] yagoPredFilterDefault={ + "http://www.w3.org/2004/02/skos/core", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/wikipage-", + "http://www.w3.org/2002/07/owl#sameAs", + "http://dbpedia.org/property/reference" }; + String[] yagoObjFilterDefault={ + "http://dbpedia.org/resource/Category:Articles_", + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/resource/Category", + "http://dbpedia.org/resource/Template", + "http://upload.wikimedia.org/wikipedia/commons"}; + + String[] onlyCatPredFilterDefault={ + "http://www.w3.org/2004/02/skos/core", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/wikipage-", + "http://www.w3.org/2002/07/owl#sameAs", + "http://dbpedia.org/property/reference" }; + String[] onlyCatObjFilterDefault={ + "http://dbpedia.org/resource/Category:Articles_", + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/class/yago", + "http://dbpedia.org/resource/Template", + "http://upload.wikimedia.org/wikipedia/commons"}; + + String[] skosPredFilterDefault={ + "http://www.w3.org/2004/02/skos/core#narrower", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/wikipage-", + "http://www.w3.org/2002/07/owl#sameAs", + "http://dbpedia.org/property/reference" }; + String[] skosObjFilterDefault={ + "http://dbpedia.org/resource/Category:Articles_", + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/class/yago", + "http://dbpedia.org/resource/Template", + "http://upload.wikimedia.org/wikipedia/commons"}; + + public SparqlFilter(int mode, String[] pred, String[] obj) { + if (mode==-1 && (pred==null || pred.length==0 || obj==null||obj.length==0)) + {mode=0;} + + switch (mode){ + case 0: //yago + ObjFilter=yagoObjFilterDefault; + PredFilter=yagoPredFilterDefault; + break; + case 1: // only Categories + ObjFilter=onlyCatObjFilterDefault; + PredFilter=onlyCatPredFilterDefault; + break; + case 2: // there are some other changes to, which are made directly in other functions + ObjFilter=skosObjFilterDefault; + PredFilter=skosPredFilterDefault; + break; + default: + ObjFilter=obj; + PredFilter=pred; + break; + + }} + public SparqlFilter(int mode, String[] pred, String[] obj,boolean uselits) throws Exception{ + this(mode, pred,obj); + this.useLiterals=uselits; + } + + public String[] getObjFilter(){ + return this.ObjFilter; + } + public String[] getPredFilter(){ + return this.PredFilter; + } + + + + } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 11:09:39
|
Revision: 179 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=179&view=rev Author: jenslehmann Date: 2007-10-08 04:09:33 -0700 (Mon, 08 Oct 2007) Log Message: ----------- added Config independant protocol support to DIG reasoner Modified Paths: -------------- trunk/examples/uncle.conf trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/utilities/Files.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/examples/uncle.conf =================================================================== --- trunk/examples/uncle.conf 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/examples/uncle.conf 2007-10-08 11:09:33 UTC (rev 179) @@ -16,8 +16,8 @@ problem = posNegDefinition; -//writeDIGProtocol = false; -//digProtocolFile = "log/dig_uncle_fact.txt"; +digReasoner.writeDIGProtocol = true; +digReasoner.digProtocolFile = "log/dig_uncle.txt"; import("uncle.kb"); Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 11:09:33 UTC (rev 179) @@ -112,8 +112,8 @@ public static boolean showInternalKB = false; public static int maxLineLength = 100; - public static boolean writeDIGProtocol = false; - public static File digProtocolFile = new File("log/digProtocol.txt"); + // public static boolean writeDIGProtocol = false; + // public static File digProtocolFile = new File("log/digProtocol.txt"); // public static String preprocessingModule = ""; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 11:09:33 UTC (rev 179) @@ -470,9 +470,9 @@ } else if (option.equals("showSubsumptionHierarchy")) { Config.showSubsumptionHierarchy = Datastructures.strToBool(value); } else if (option.equals("writeDIGProtocol")) { - Config.writeDIGProtocol = Datastructures.strToBool(value); + // Config.writeDIGProtocol = Datastructures.strToBool(value); } else if (option.equals("digProtocolFile")) { - Config.digProtocolFile = new File(value); + // Config.digProtocolFile = new File(value); // } else if (option.equals("preprocessingModule")) { // Config.preprocessingModule = value; } else if (option.equals("gp.selectionType")) { Modified: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-10-08 11:09:33 UTC (rev 179) @@ -28,6 +28,10 @@ public BooleanConfigOption(String name, String description) { super(name, description); } + + public BooleanConfigOption(String name, String description, boolean defaultValue) { + super(name, description, defaultValue); + } /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) Modified: trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-10-08 11:09:33 UTC (rev 179) @@ -31,13 +31,16 @@ */ public class StringConfigOption extends ConfigOption<String> { - private Set<String> allowedValues; + private Set<String> allowedValues = new TreeSet<String>();; public StringConfigOption(String name, String description) { super(name, description); - allowedValues = new TreeSet<String>(); } + public StringConfigOption(String name, String description, String defaultValue) { + super(name, description, defaultValue); + } + /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-08 11:09:33 UTC (rev 179) @@ -1,6 +1,27 @@ +/** + * Copyright (C) 2007, 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.reasoning; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -12,7 +33,6 @@ import java.net.URL; import org.apache.xmlbeans.XmlException; -import org.dllearner.Config; import org.dllearner.utilities.Files; import org.kr.dl.dig.v1_1.GetIdentifierDocument; import org.kr.dl.dig.v1_1.IdRespType; @@ -27,17 +47,23 @@ * Methods for sending messages to a DIG-capable reasoner and receiving answers * using Apache XML Beans. * - * @author jl + * @author Jens Lehmann * */ public class DIGHTTPConnector { private URL url; + private File protocolFile; public DIGHTTPConnector(URL url) { this.url = url; } + public DIGHTTPConnector(URL url, File protocolFile) { + this.url = url; + this.protocolFile = protocolFile; + } + public URI newKB() { NewKBDocument newKB = NewKBDocument.Factory.newInstance(); newKB.addNewNewKB(); @@ -131,10 +157,10 @@ osw.write(send); osw.close(); - if(Config.writeDIGProtocol) - Files.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); + if(protocolFile != null) + Files.appendFile(protocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); - // Antwort empfangen + // receive answer InputStream is = connection.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); @@ -153,9 +179,8 @@ System.exit(0); } - // DIG-Kommunikation protokollieren, falls das eingestellt ist - if(Config.writeDIGProtocol) - Files.appendFile(Config.digProtocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); + if(protocolFile != null) + Files.appendFile(protocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); return answer.toString(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 11:09:33 UTC (rev 179) @@ -37,6 +37,7 @@ import org.apache.xmlbeans.XmlCursor; import org.dllearner.Config; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; @@ -53,6 +54,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; import org.kr.dl.dig.v1_1.Concepts; @@ -69,13 +71,13 @@ * DIG 1.1 implementation of the reasoner interface. * * @author Jens Lehmann - * + * */ public class DIGReasoner extends ReasonerComponent { URL reasonerURL; Set<KnowledgeSource> sources; - + // Variablen für Reasoner DIGHTTPConnector connector; String identifier; @@ -85,9 +87,10 @@ Set<AtomicConcept> atomicConcepts; Set<AtomicRole> atomicRoles; SortedSet<Individual> individuals; - + // Cache für Subsumptionhierarchie - // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des atomaren Konzepts male + // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des + // atomaren Konzepts male // unterschiedlich sind; // alternativ wäre auch eine Indizierung über Strings möglich ConceptComparator conceptComparator = new ConceptComparator(); @@ -95,69 +98,92 @@ SubsumptionHierarchy subsumptionHierarchy; RoleHierarchy roleHierarchy; // enthält atomare Konzepte, sowie Top und Bottom - Set<Concept> allowedConceptsInSubsumptionHierarchy; + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + private boolean writeDIGProtocol; + private File digProtocolFile; + private static String defaultDIGProtocolFile = "log/digProtocol"; public DIGReasoner(Set<KnowledgeSource> sources) { this.sources = sources; try { reasonerURL = new URL("http://localhost:8081"); - } catch (MalformedURLException e) { } + } catch (MalformedURLException e) { + } } - + @Override public void init() { - connector = new DIGHTTPConnector(reasonerURL); + // if a DIG protocol is written clear the file first + if(writeDIGProtocol) { + if(digProtocolFile == null) + digProtocolFile = new File(defaultDIGProtocolFile); + Files.clearFile(digProtocolFile); + connector = new DIGHTTPConnector(reasonerURL, digProtocolFile); + } else { + connector = new DIGHTTPConnector(reasonerURL); + } + identifier = connector.getIdentifier(); kbURI = connector.newKB(); - + // asks-Prefix entsprechend der KB-URI initialisieren asksPrefix = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; - asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + - "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"; - + asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\"" + kbURI + "\">"; + // momementan wird davon ausgegangen, dass toDIG(kbURI) den gesamten // tells-Request liefert StringBuilder sb = new StringBuilder(); -// sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); -// sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + -// "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + -// "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + -// "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); - for(KnowledgeSource source : sources) { + // sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + // sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + // "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + // "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + // "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); + for (KnowledgeSource source : sources) { sb.append(source.toDIG(kbURI)); - + ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { + if (!rd.getResponse().isSetOk()) { System.err.println("DIG-Reasoner cannot read knowledgebase."); System.exit(0); - } + } } -// sb.append("</tells>"); - + // sb.append("</tells>"); + // DIG-Abfragen nach Konzepten, Rollen, Individuals atomicConcepts = getAtomicConceptsDIG(); atomicRoles = getAtomicRolesDIG(); - individuals = getIndividualsDIG(); + individuals = getIndividualsDIG(); + } - + public static String getName() { return "DIG reasoner"; } - + public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("reasonerUrl", "URL of the DIG reasoner")); + options.add(new BooleanConfigOption("writeDIGProtocol", + "specifies whether or not to write a protocoll of send and received DIG requests", + false)); + options.add(new StringConfigOption("digProtocolFile", "the file to store the DIG protocol", + defaultDIGProtocolFile)); return options; - } - - /* (non-Javadoc) + } + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - if (entry.getOptionName().equals("reasonerUrl")) { + String name = entry.getOptionName(); + if (name.equals("reasonerUrl")) { String s = (String) entry.getValue(); try { reasonerURL = new URL(s); @@ -165,558 +191,565 @@ // e.printStackTrace(); throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); } + } else if(name.equals("writeDIGProtocol")) { + writeDIGProtocol = (Boolean) entry.getValue(); + } else if(name.equals("digProtocolFile")) { + digProtocolFile = new File((String) entry.getValue()); } } - - + /** - * Construct a subsumption hierarchy using DIG queries. After calling this + * Construct a subsumption hierarchy using DIG queries. After calling this * method one can ask for children or parents in the subsumption hierarchy. */ public void prepareSubsumptionHierarchy() { - allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); allowedConceptsInSubsumptionHierarchy.addAll(Config.Refinement.allowedConcepts); allowedConceptsInSubsumptionHierarchy.add(new Top()); - allowedConceptsInSubsumptionHierarchy.add(new Bottom()); - - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + // Subsumptionhierarchy berechnen // TODO: kann man effizienter auch in einer Abfrage machen - + // Refinements von Top - TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); + TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(new Top(), tmp); - + // Refinements von Bottom tmp = getMoreGeneralConceptsDIG(new Bottom()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyUp.put(new Bottom(), tmp); - + // Refinement atomarer Konzepte - for(AtomicConcept atom : atomicConcepts) { + for (AtomicConcept atom : atomicConcepts) { tmp = getMoreSpecialConceptsDIG(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(atom, tmp); - + tmp = getMoreGeneralConceptsDIG(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); + subsumptionHierarchyUp.put(atom, tmp); } - - subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); + + subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, + subsumptionHierarchyUp, subsumptionHierarchyDown); } - + /** * Constructs a role hierarchy using DIG queries. After calling this method, * one can query parents or children of roles. * - * @todo Does not yet take ignored roles into account. + * @todo Does not yet take ignored roles into account. */ @Override - public void prepareRoleHierarchy() { - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - + public void prepareRoleHierarchy() { + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + // Refinement atomarer Konzepte - for(AtomicRole role : atomicRoles) { + for (AtomicRole role : atomicRoles) { roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); - roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); } - - roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, roleHierarchyDown); - } - + + roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, + roleHierarchyDown); + } + // eigentlich müsste man klonen um sicherzustellen, dass der parent-Link // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link // nicht immer null, was bei GP negative Auswirkungen haben könnte // Update: wird durch klonen innerhalb der GP-Operationen erledigt public Set<AtomicConcept> getAtomicConcepts() { /* - if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == Config.Algorithm.HYBRID_GP) { - Set<AtomicConcept> returnSet = new HashSet<AtomicConcept>(); - for(AtomicConcept ac : atomicConcepts) - returnSet.add((AtomicConcept)ac.clone()); - return returnSet; - } - */ + * if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == + * Config.Algorithm.HYBRID_GP) { Set<AtomicConcept> returnSet = new + * HashSet<AtomicConcept>(); for(AtomicConcept ac : atomicConcepts) + * returnSet.add((AtomicConcept)ac.clone()); return returnSet; } + */ return atomicConcepts; } - + private Set<AtomicConcept> getAtomicConceptsDIG() { String atomicConceptsDIG = asksPrefix; atomicConceptsDIG += "<allConceptNames id=\"ask_names\"/></asks>"; - + ResponsesDocument rd = connector.asks(atomicConceptsDIG); // Struktur: einzelnes conceptSet außen, dann mehrere synonyms, die dann // die Konzept inkl. Top und Bottom enthalten Csynonyms[] synonymsArray = rd.getResponses().getConceptSetArray(); Concepts[] conceptsArray = synonymsArray[0].getSynonymsArray(); - + Set<AtomicConcept> atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); - for(Concepts concepts : conceptsArray) { + for (Concepts concepts : conceptsArray) { boolean topOrBottomFound = false; - if(concepts.getBottomArray().length != 0 || concepts.getTopArray().length!=0) + if (concepts.getBottomArray().length != 0 || concepts.getTopArray().length != 0) topOrBottomFound = true; - + // nur weitersuchen falls das Konzept nicht äquivalent zu Top // oder Bottom ist - if(!topOrBottomFound) { + if (!topOrBottomFound) { boolean nonAnonymousConceptFound = false; AtomicConcept foundConcept = null; Named[] catoms = concepts.getCatomArray(); - for(Named catom : catoms) { + for (Named catom : catoms) { String name = catom.getName(); - if(!name.startsWith("anon")) { - if(!nonAnonymousConceptFound) { + if (!name.startsWith("anon")) { + if (!nonAnonymousConceptFound) { nonAnonymousConceptFound = true; foundConcept = new AtomicConcept(catom.getName()); atomicConcepts.add(foundConcept); } else { - System.out.println("Warning: Background knowledge contains synonym concepts. " + - "We decide to pick " + foundConcept + ". \nDIG-XML:\n"+concepts); + System.out + .println("Warning: Background knowledge contains synonym concepts. " + + "We decide to pick " + + foundConcept + + ". \nDIG-XML:\n" + concepts); } } } } } - + return atomicConcepts; - } - + } + public Set<AtomicRole> getAtomicRoles() { return atomicRoles; } - + private Set<AtomicRole> getAtomicRolesDIG() { String atomicRolesDIG = asksPrefix; atomicRolesDIG += "<allRoleNames id=\"ask_roles\"/></asks>"; - + ResponsesDocument rd = connector.asks(atomicRolesDIG); // Struktur: einzelnes roleSet außen, dann synonyms mit ratoms // innen Rsynonyms[] synonymsArray = rd.getResponses().getRoleSetArray(); Roles[] rolesArray = synonymsArray[0].getSynonymsArray(); - + Set<AtomicRole> digAtomicRoles = new HashSet<AtomicRole>(); - for(Roles roles : rolesArray) { + for (Roles roles : rolesArray) { // hier koennen wiederum mehrere ratoms enthalten sein, // aber wir wollen nur eins auslesen Named[] ratoms = roles.getRatomArray(); Named role = ratoms[0]; - digAtomicRoles.add(new AtomicRole(role.getName())); - - if(ratoms.length>1) - System.out.println("Warning: Background knowledge contains synonym roles. " + - "Will ignore all but the first. \nDIG-XML:\n"+roles); + digAtomicRoles.add(new AtomicRole(role.getName())); + + if (ratoms.length > 1) + System.out.println("Warning: Background knowledge contains synonym roles. " + + "Will ignore all but the first. \nDIG-XML:\n" + roles); } - + return digAtomicRoles; - } - - public SortedSet<Individual> getIndividuals() { + } + + public SortedSet<Individual> getIndividuals() { return individuals; } private SortedSet<Individual> getIndividualsDIG() { String individualsDIG = asksPrefix; individualsDIG += "<allIndividuals id=\"ask_individuals\"/></asks>"; - + ResponsesDocument rd = connector.asks(individualsDIG); // Struktur: einzelnes individualSet außen, dann Liste von // individual-Elementen IndividualSet[] individualsArray = rd.getResponses().getIndividualSetArray(); Named[] namedIndividuals = individualsArray[0].getIndividualArray(); - + SortedSet<Individual> digIndividuals = new TreeSet<Individual>(); - for(Named named : namedIndividuals) - digIndividuals.add(new Individual(named.getName())); - + for (Named named : namedIndividuals) + digIndividuals.add(new Individual(named.getName())); + return digIndividuals; } - + public ReasonerType getReasonerType() { return ReasonerType.DIG; } - + @Override public boolean subsumes(Concept superConcept, Concept subConcept) { - // System.out.println("subsumes(" + superConcept + "," + subConcept + ")"); + // System.out.println("subsumes(" + superConcept + "," + subConcept + + // ")"); String subsumesDIG = asksPrefix; subsumesDIG += "<subsumes id=\"query_subsume\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes></asks>"; - + return parseBooleanAnswer(subsumesDIG); } - + @Override public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) { String subsumesDIG = asksPrefix; int id = 0; // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs // ausgegeben werden - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept subConcept : subConcepts) { - queryMap.put("query"+id, subConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + Map<String, Concept> queryMap = new HashMap<String, Concept>(); + for (Concept subConcept : subConcepts) { + queryMap.put("query" + id, subConcept); + subsumesDIG += "<subsumes id=\"query" + id + "\">"; + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes>"; id++; } subsumesDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(subsumesDIG); IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - + Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { + for (IdType idType : subsumedConceptsIds) { returnSet.add(queryMap.get(idType.getId())); } return returnSet; } - + @Override public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) { String subsumesDIG = asksPrefix; int id = 0; - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept superConcept : superConcepts) { - queryMap.put("query"+id, superConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + Map<String, Concept> queryMap = new HashMap<String, Concept>(); + for (Concept superConcept : superConcepts) { + queryMap.put("query" + id, superConcept); + subsumesDIG += "<subsumes id=\"query" + id + "\">"; + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes>"; id++; } subsumesDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(subsumesDIG); IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - + Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { + for (IdType idType : subsumedConceptsIds) { returnSet.add(queryMap.get(idType.getId())); } return returnSet; } - + /* - // es wird geklont, damit Subsumptionhierarchie nicht von außen verändert werden - // kann - @SuppressWarnings("unchecked") + * // es wird geklont, damit Subsumptionhierarchie nicht von außen verändert + * werden // kann @SuppressWarnings("unchecked") @Override public SortedSet<Concept> + * getMoreGeneralConcepts(Concept concept) { return (TreeSet<Concept>) + * subsumptionHierarchyUp.get(concept).clone(); // return + * subsumptionHierarchyUp.get(concept); // ohne klonen geht es nicht } + * + * @SuppressWarnings("unchecked") @Override public SortedSet<Concept> + * getMoreSpecialConcepts(Concept concept) { return (TreeSet<Concept>) + * subsumptionHierarchyDown.get(concept).clone(); // return + * subsumptionHierarchyDown.get(concept); // ohne klonen geht es nicht } + */ + @Override - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); - // return subsumptionHierarchyUp.get(concept); // ohne klonen geht es nicht - } - - @SuppressWarnings("unchecked") - @Override - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); - // return subsumptionHierarchyDown.get(concept); // ohne klonen geht es nicht - } - */ - - @Override public SubsumptionHierarchy getSubsumptionHierarchy() { return subsumptionHierarchy; } - + @Override public RoleHierarchy getRoleHierarchy() { return roleHierarchy; } - + private TreeSet<Concept> getMoreGeneralConceptsDIG(Concept concept) { String moreGeneralDIG = asksPrefix; moreGeneralDIG += "<parents id=\"query_parents\">"; moreGeneralDIG += DIGConverter.getDIGString(concept); moreGeneralDIG += "</parents></asks>"; - + ResponsesDocument rd = connector.asks(moreGeneralDIG); TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); - // ein Array, der Synomyms-Elemente enthält, die dann Mengen von + // ein Array, der Synomyms-Elemente enthält, die dann Mengen von // äquivalenten Konzepten enthalten; // (es wird hier nur das erste Element des ConceptSetArrays gelesen, // da nur ein solches Element bei dieser Abfrage erwartet wird) Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { // es werden nur atomare Konzepte erwartet Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) resultsSet.add(ac); } - + // hinzufügen von Top, falls notwendig - if(conceptsArray[i].getTopArray().length>0) + if (conceptsArray[i].getTopArray().length > 0) resultsSet.add(new Top()); - + // falls bisher kein erlaubtes Konzept gefunden wurden, dann gibt es - // entweder keine allgemeineren Konzepte oder es handelt sich um + // entweder keine allgemeineren Konzepte oder es handelt sich um // nicht erlaubte (von Jena erzeugte) Konzepte, die nicht äquivalent - // zu einem erlaubten Konzept sind; in dem Fall muss die Methode rekursiv + // zu einem erlaubten Konzept sind; in dem Fall muss die Methode + // rekursiv // noch einmal aufgerufen werden - if(resultsSet.size()==0 && atoms.length>0) { - // wir wählen das erste Konzept aus, welches ein ignoriertes Konzept ist + if (resultsSet.size() == 0 && atoms.length > 0) { + // wir wählen das erste Konzept aus, welches ein ignoriertes + // Konzept ist // (sonst wäre es weiter oben gefunden wurden) AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); resultsSet.addAll(getMoreGeneralConceptsDIG(ignoredAtomicConcept)); } - + } - + return resultsSet; } - + private TreeSet<Concept> getMoreSpecialConceptsDIG(Concept concept) { String moreSpecialDIG = asksPrefix; moreSpecialDIG += "<children id=\"query_children\">"; moreSpecialDIG += DIGConverter.getDIGString(concept); moreSpecialDIG += "</children></asks>"; - + // Kommentare siehe getMoreGeneralConcepts(Concept) ResponsesDocument rd = connector.asks(moreSpecialDIG); TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) resultsSet.add(ac); - } - + } + // hinzufügen von Bottom, falls notwendig - if(conceptsArray[i].getBottomArray().length>0) + if (conceptsArray[i].getBottomArray().length > 0) resultsSet.add(new Bottom()); - - if(resultsSet.size()==0 && atoms.length>0) { + + if (resultsSet.size() == 0 && atoms.length > 0) { AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); resultsSet.addAll(getMoreSpecialConceptsDIG(ignoredAtomicConcept)); } - } - + } + return resultsSet; - } - + } + private TreeSet<AtomicRole> getMoreGeneralRolesDIG(AtomicRole role) { String moreGeneralRolesDIG = asksPrefix; moreGeneralRolesDIG += "<rparents id=\"query_parents\">"; moreGeneralRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; moreGeneralRolesDIG += "</rparents></asks>"; - + ResponsesDocument rd = connector.asks(moreGeneralRolesDIG); TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for (int i = 0; i < rolesArray.length; i++) { Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { + + for (Named atom : atoms) { AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) + // if(Config.Refinement.allowedRoles.contains(ar)) resultsSet.add(ar); - } + } } - + // System.out.println(rd); - + return resultsSet; } - + private TreeSet<AtomicRole> getMoreSpecialRolesDIG(AtomicRole role) { String moreSpecialRolesDIG = asksPrefix; moreSpecialRolesDIG += "<rchildren id=\"query_children\">"; moreSpecialRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; moreSpecialRolesDIG += "</rchildren></asks>"; - + ResponsesDocument rd = connector.asks(moreSpecialRolesDIG); TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for (int i = 0; i < rolesArray.length; i++) { Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { + + for (Named atom : atoms) { AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) + // if(Config.Refinement.allowedRoles.contains(ar)) resultsSet.add(ar); - } + } } - + return resultsSet; } - - @Override + + @Override public boolean instanceCheck(Concept concept, Individual individual) { String instanceCheckDIG = asksPrefix; instanceCheckDIG += "<instance id= \"query_instance\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; + instanceCheckDIG += "<individual name=\"" + individual.getName() + "\"/>"; instanceCheckDIG += DIGConverter.getDIGString(concept); instanceCheckDIG += "</instance></asks>"; - - return parseBooleanAnswer(instanceCheckDIG); + + return parseBooleanAnswer(instanceCheckDIG); } - - @Override + + @Override public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) { String instanceCheckDIG = asksPrefix; int id = 0; // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs // ausgegeben werden - Map<String,String> queryMap = new HashMap<String,String>(); - for(Individual individual : individuals) { - queryMap.put("query"+id, individual.getName()); - instanceCheckDIG += "<instance id= \"query"+id+"\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; + Map<String, String> queryMap = new HashMap<String, String>(); + for (Individual individual : individuals) { + queryMap.put("query" + id, individual.getName()); + instanceCheckDIG += "<instance id= \"query" + id + "\">"; + instanceCheckDIG += "<individual name=\"" + individual.getName() + "\"/>"; instanceCheckDIG += DIGConverter.getDIGString(concept); instanceCheckDIG += "</instance>"; id++; } instanceCheckDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(instanceCheckDIG); IdType[] ids = rd.getResponses().getTrueArray(); - + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for(IdType idType : ids) { + for (IdType idType : ids) { returnSet.add(new Individual(queryMap.get(idType.getId()))); } - return returnSet; + return returnSet; } - - @Override + + @Override public SortedSet<Individual> retrieval(Concept concept) { - + String retrievalDIG = asksPrefix; retrievalDIG += "<instances id= \"query_instance\">"; retrievalDIG += DIGConverter.getDIGString(concept); retrievalDIG += "</instances></asks>"; - + ResponsesDocument rd = connector.asks(retrievalDIG); // System.out.println(rd); Named[] individuals = rd.getResponses().getIndividualSetArray()[0].getIndividualArray(); - + SortedSet<Individual> results = new TreeSet<Individual>(); - for(Named individual : individuals) + for (Named individual : individuals) results.add(new Individual(individual.getName())); return results; } - + // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus - @Override + @Override public Set<AtomicConcept> getConcepts(Individual individual) { String typesDIG = asksPrefix; typesDIG += "<types id=\"query_types\">"; typesDIG += "<individual name=\"" + individual.getName() + "\" />"; - typesDIG += "</types></asks>"; - + typesDIG += "</types></asks>"; + ResponsesDocument rd = connector.asks(typesDIG); TreeSet<AtomicConcept> resultsSet = new TreeSet<AtomicConcept>(conceptComparator); Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - // if(Config.Refinement.allowedConcepts.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) + // if(Config.Refinement.allowedConcepts.contains(ac)) resultsSet.add(ac); } - } - + } + // System.out.println("document:"); // System.out.println(rd); // System.out.println("parsed:"); // System.out.println(resultsSet); - + return resultsSet; } - + // es sieht so aus, als ob die XSD-Datei kaputt ist - es gibt zumindest // keine getter um ein IndividualPairSet zu finden; in der XSD-Datei ist // das in Responsegroup auch nicht definiert // => deswegen wird hier die XML-Cursor-API verwendet - @Override + @Override public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { String relatedIndividualsDIG = asksPrefix; relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; relatedIndividualsDIG += "<ratom name=\"" + atomicRole.getName() + "\" />"; - relatedIndividualsDIG += "</relatedIndividuals></asks>"; - + relatedIndividualsDIG += "</relatedIndividuals></asks>"; + ResponsesDocument rd = connector.asks(relatedIndividualsDIG); Map<Individual, SortedSet<Individual>> resultMap = new TreeMap<Individual, SortedSet<Individual>>(); - + QName name = new QName("name"); XmlCursor cursor = rd.newCursor(); cursor.toFirstChild(); // Responses cursor.toFirstChild(); // IndividualPairSet - + int childNumber = 0; Individual ind1; Individual ind2; - + // so lange noch Kinder existieren - while(cursor.toChild(childNumber)) { + while (cursor.toChild(childNumber)) { // Cursor steht jetzt bei einem IndividualPair cursor.toFirstChild(); - // jetzt steht er bei einem Individual, dessen Namen wir auslesen können + // jetzt steht er bei einem Individual, dessen Namen wir auslesen + // können ind1 = new Individual(cursor.getAttributeText(name).toString()); cursor.toNextSibling(); ind2 = new Individual(cursor.getAttributeText(name).toString()); - + Helper.addMapEntry(resultMap, ind1, ind2); - + // Cursor wieder hoch auf IndividualPairSet bewegen cursor.toParent(); cursor.toParent(); childNumber++; } - + /* - System.out.println("document:"); - System.out.println(rd); - System.out.println("parsed:"); - System.out.println(resultMap); - */ - + * System.out.println("document:"); System.out.println(rd); + * System.out.println("parsed:"); System.out.println(resultMap); + */ + return resultMap; } - - @Override + + @Override public boolean isSatisfiable() { String satisfiableDIG = asksPrefix; // wenn Top erfüllbar ist, dann gibt es auch ein Modell für die KB // (satisfiability für KB ist nicht Teil von DIG 1.1) satisfiableDIG += "<satisfiable id=\"query_satisfiable\"><top/></satisfiable>"; satisfiableDIG += "</asks>"; - + return parseBooleanAnswer(satisfiableDIG); } - + private boolean parseBooleanAnswer(String asks) { ResponsesDocument rd = connector.asks(asks); - if(rd.getResponses().getTrueArray().length == 1) + if (rd.getResponses().getTrueArray().length == 1) return true; else - return false; + return false; } public String getIdentifier() { return identifier; } - + public void releaseKB() { connector.releaseKB(kbURI); } @@ -735,5 +768,5 @@ public URL getReasonerURL() { return reasonerURL; } - + } Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-08 11:09:33 UTC (rev 179) @@ -74,5 +74,9 @@ e.printStackTrace(); } } + + public static void clearFile(File file) { + createFile(file, ""); + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-08 11:09:33 UTC (rev 179) @@ -127,8 +127,8 @@ int startAlgorithmNr = 0; // Config.GP.maxConceptLength = 30; - Config.writeDIGProtocol = true; - Config.digProtocolFile = new File(statBaseDir, "dig.log"); + // Config.writeDIGProtocol = true; + // Config.digProtocolFile = new File(statBaseDir, "dig.log"); // do not plot anything // File[][][] gnuplotFiles = new File[examples.length][algorithms.length][3]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 10:22:36
|
Revision: 178 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=178&view=rev Author: jenslehmann Date: 2007-10-08 03:22:32 -0700 (Mon, 08 Oct 2007) Log Message: ----------- - added CLI support for inclusion learning - changed uncle example Modified Paths: -------------- trunk/examples/uncle.conf trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java Added Paths: ----------- trunk/examples/uncle.kb Modified: trunk/examples/uncle.conf =================================================================== --- trunk/examples/uncle.conf 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/examples/uncle.conf 2007-10-08 10:22:32 UTC (rev 178) @@ -14,68 +14,26 @@ * Copyright (C) 2007, Jens Lehmann */ -writeDIGProtocol = false; -digProtocolFile = "log/dig_uncle_fact.txt"; +problem = posNegDefinition; -/** background knowledge **/ -BOTTOM = (male AND female). -Functional(married). -Symmetric(married). -Symmetric(hasSibling). +//writeDIGProtocol = false; +//digProtocolFile = "log/dig_uncle_fact.txt"; -male(heinrich). -male(jan). -male(markus). -male(alfred). -male(hans). -male(heinz). -male(alex). -female(susi). -female(anna). -female(maria). -female(katrin). -female(johanna). -female(mandy). -female(miriam). -female(hanna). +import("uncle.kb"); -married(heinrich,susi). -married(anna,jan). -married(alfred,katrin). -married(hans,johanna). - -hasSibling(susi,anna). -hasSibling(alfred,maria). -hasSibling(alfred,heinz). -hasSibling(heinz,maria). -hasSibling(johanna,mandy). -hasSibling(hanna,alex). - -hasChild(anna,alfred). -hasChild(anna,maria). -hasChild(anna,heinz). -hasChild(jan,alfred). -hasChild(jan,maria). -hasChild(jan,heinz). -hasChild(maria,markus). -hasChild(alfred,hans). -hasChild(katrin,hans). -hasChild(mandy,miriam). -hasChild(hanna,jan). - /** examples **/ -+uncle(heinrich). -+uncle(alfred). -+uncle(heinz). -+uncle(hans). -+uncle(alex). --uncle(jan). --uncle(markus). --uncle(susi). --uncle(anna). --uncle(maria). --uncle(katrin). --uncle(johanna). --uncle(mandy). --uncle(miriam). --uncle(hanna). ++heinrich ++alfred ++heinz ++hans ++alex +-jan +-markus +-susi +-anna +-maria +-katrin +-johanna +-mandy +-miriam +-hanna Added: trunk/examples/uncle.kb =================================================================== --- trunk/examples/uncle.kb (rev 0) +++ trunk/examples/uncle.kb 2007-10-08 10:22:32 UTC (rev 178) @@ -0,0 +1,44 @@ +BOTTOM = (male AND female). +Functional(married). +Symmetric(married). +Symmetric(hasSibling). + +male(heinrich). +male(jan). +male(markus). +male(alfred). +male(hans). +male(heinz). +male(alex). +female(susi). +female(anna). +female(maria). +female(katrin). +female(johanna). +female(mandy). +female(miriam). +female(hanna). + +married(heinrich,susi). +married(anna,jan). +married(alfred,katrin). +married(hans,johanna). + +hasSibling(susi,anna). +hasSibling(alfred,maria). +hasSibling(alfred,heinz). +hasSibling(heinz,maria). +hasSibling(johanna,mandy). +hasSibling(hanna,alex). + +hasChild(anna,alfred). +hasChild(anna,maria). +hasChild(anna,heinz). +hasChild(jan,alfred). +hasChild(jan,maria). +hasChild(jan,heinz). +hasChild(maria,markus). +hasChild(alfred,hans). +hasChild(katrin,hans). +hasChild(mandy,miriam). +hasChild(hanna,jan). Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 10:22:32 UTC (rev 178) @@ -63,6 +63,7 @@ import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.parser.ConfParser; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -130,8 +131,18 @@ configureComponent(cm, reasoner, componentPrefixMapping, parser); ReasoningService rs = cm.reasoningService(reasoner); - // step 3: detect learning problem (no options for choosing it yet) - LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + // step 3: detect learning problem + ConfFileOption problemOption = parser.getConfOptionsByName("problem"); + Class<? extends LearningProblem> lpClass = null; + LearningProblem lp = null; + if(problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) + lpClass = PosNegDefinitionLP.class; + else if(problemOption.getStringValue().equals("posNegInclusion")) + lpClass = PosNegInclusionLP.class; + else + handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); + + lp = cm.learningProblem(lpClass, rs); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "positiveExamples", posExamples); @@ -376,6 +387,7 @@ // CLI options (i.e. options which are related to the CLI // user interface but not to one of the components) List<ConfFileOption> cliOptions = parser.getConfOptionsByPrefix("cli"); + if(cliOptions != null) { int maxLineLength = 100; for (ConfFileOption cliOption : cliOptions) { String name = cliOption.getSubOption(); @@ -434,6 +446,7 @@ } else handleError("Unknown CLI option \"" + name + "\"."); } + } } private static void initComponent(ComponentManager cm, Component component) { Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 10:22:32 UTC (rev 178) @@ -142,6 +142,7 @@ } // System.out.println(components); + // System.out.println(learningProblems); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |