From: <ku...@us...> - 2008-09-05 12:24:08
|
Revision: 1170 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1170&view=rev Author: kurzum Date: 2008-09-05 12:24:05 +0000 (Fri, 05 Sep 2008) Log Message: ----------- java interface Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/configuration/Configurator.java trunk/src/dl-learner/org/dllearner/core/configuration/OWLFileConfigurator.java trunk/src/dl-learner/org/dllearner/core/configuration/SparqlKnowledgeSourceConfigurator.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/utilities/Files.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/configuration/FastInstanceCheckerConfigurator.java trunk/src/dl-learner/org/dllearner/scripts/NewSample.java Modified: trunk/src/dl-learner/org/dllearner/core/configuration/Configurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configuration/Configurator.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/core/configuration/Configurator.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -18,31 +18,44 @@ **/ package org.dllearner.core.configuration; - import java.util.Set; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.configuration.FastInstanceCheckerConfigurator; import org.dllearner.core.configuration.OWLFileConfigurator; import org.dllearner.core.configuration.SparqlKnowledgeSourceConfigurator; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.reasoning.FastInstanceChecker; /** * automatically generated, do not edit manually **/ -public class Configurator { +public class Configurator { /** -URL pointing to the OWL file +* url: URL pointing to the OWL file **/ public static OWLFile getOWLFile (ComponentManager cm, String url ) { -return OWLFileConfigurator.getOWLFile(cm, url); +return OWLFileConfigurator.getOWLFile(cm, url); } /** -relevant instances e.g. positive and negative examples in a learning problem +* instances: relevant instances e.g. positive and negative examples in a learning problem **/ public static SparqlKnowledgeSource getSparqlKnowledgeSource (ComponentManager cm, Set<String> instances ) { -return SparqlKnowledgeSourceConfigurator.getSparqlKnowledgeSource(cm, instances); +return SparqlKnowledgeSourceConfigurator.getSparqlKnowledgeSource(cm, instances); } +/** +**/ +public static FastInstanceChecker getFastInstanceChecker (ComponentManager cm, KnowledgeSource knowledgeSource ) { +return FastInstanceCheckerConfigurator.getFastInstanceChecker(cm, knowledgeSource); } + + +} Added: trunk/src/dl-learner/org/dllearner/core/configuration/FastInstanceCheckerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configuration/FastInstanceCheckerConfigurator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/configuration/FastInstanceCheckerConfigurator.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + +package org.dllearner.core.configuration; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.configuration.Configurator; +import org.dllearner.reasoning.FastInstanceChecker; + +/** +* automatically generated, do not edit manually +**/ +public class FastInstanceCheckerConfigurator extends Configurator { + +FastInstanceChecker FastInstanceChecker; +private String reasonerType = "pellet"; + +public FastInstanceCheckerConfigurator (FastInstanceChecker FastInstanceChecker){ +this.FastInstanceChecker = FastInstanceChecker; +} + +/** +**/ +public static FastInstanceChecker getFastInstanceChecker (ComponentManager cm, KnowledgeSource knowledgeSource ) { +FastInstanceChecker component = cm.reasoner(FastInstanceChecker.class, knowledgeSource ); +return component; +} + +@SuppressWarnings({ "unchecked" }) +public <T> void applyConfigEntry(ConfigEntry<T> entry){ +String optionName = entry.getOptionName(); +if(false){//empty block +}else if (optionName.equals("reasonerType")){ +reasonerType = (String) entry.getValue(); +} +} + +/** +reasonerType : FaCT++ or Pellet to dematerialize**/ +public String getReasonerType ( ) { +return this.reasonerType; +} + +/** +reasonerType : FaCT++ or Pellet to dematerialize**/ +public void setReasonerType ( ComponentManager cm, String reasonerType) { +cm.applyConfigEntry(FastInstanceChecker, "reasonerType", reasonerType); +} + + +} Modified: trunk/src/dl-learner/org/dllearner/core/configuration/OWLFileConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configuration/OWLFileConfigurator.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/core/configuration/OWLFileConfigurator.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -18,13 +18,11 @@ **/ package org.dllearner.core.configuration; - import org.dllearner.core.ComponentManager; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.configuration.Configurator; import org.dllearner.kb.OWLFile; - /** * automatically generated, do not edit manually **/ @@ -33,49 +31,39 @@ OWLFile OWLFile; private String url = null; +public OWLFileConfigurator (OWLFile OWLFile){ +this.OWLFile = OWLFile; +} /** -URL pointing to the OWL file +* url: URL pointing to the OWL file **/ -public void setMandatoryOptions (String url ) { -this.url = url; -} -/** -URL pointing to the OWL file -**/ public static OWLFile getOWLFile (ComponentManager cm, String url ) { -OWLFile component = cm.knowledgeSource(OWLFile.class); +OWLFile component = cm.knowledgeSource(OWLFile.class ); cm.applyConfigEntry(component, "url", url); return component; } - @SuppressWarnings({ "unchecked" }) public <T> void applyConfigEntry(ConfigEntry<T> entry){ String optionName = entry.getOptionName(); -if (optionName.equals(url)){ +if(false){//empty block +}else if (optionName.equals("url")){ url = (String) entry.getValue(); } } - /** -* URL pointing to the OWL file -**/ -public void setUrl (String url) { -this.url = url; +url : URL pointing to the OWL file**/ +public String getUrl ( ) { +return this.url; } - - /** -* URL pointing to the OWL file -* -**/ -public String getUrl ( ) { -return this.url; +url : URL pointing to the OWL file**/ +public void setUrl ( ComponentManager cm, String url) { +cm.applyConfigEntry(OWLFile, "url", url); } - } Modified: trunk/src/dl-learner/org/dllearner/core/configuration/SparqlKnowledgeSourceConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configuration/SparqlKnowledgeSourceConfigurator.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/core/configuration/SparqlKnowledgeSourceConfigurator.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -18,7 +18,6 @@ **/ package org.dllearner.core.configuration; - import java.util.List; import java.util.Set; import org.dllearner.core.ComponentManager; @@ -27,7 +26,6 @@ import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.datastructures.StringTuple; - /** * automatically generated, do not edit manually **/ @@ -59,440 +57,315 @@ private Set<String> defaultGraphURIs = null; private Set<String> namedGraphURIs = null; +public SparqlKnowledgeSourceConfigurator (SparqlKnowledgeSource SparqlKnowledgeSource){ +this.SparqlKnowledgeSource = SparqlKnowledgeSource; +} /** -relevant instances e.g. positive and negative examples in a learning problem +* instances: relevant instances e.g. positive and negative examples in a learning problem **/ -public void setMandatoryOptions (Set<String> instances ) { -this.instances = instances; -} -/** -relevant instances e.g. positive and negative examples in a learning problem -**/ public static SparqlKnowledgeSource getSparqlKnowledgeSource (ComponentManager cm, Set<String> instances ) { -SparqlKnowledgeSource component = cm.knowledgeSource(SparqlKnowledgeSource.class); +SparqlKnowledgeSource component = cm.knowledgeSource(SparqlKnowledgeSource.class ); cm.applyConfigEntry(component, "instances", instances); return component; } - @SuppressWarnings({ "unchecked" }) public <T> void applyConfigEntry(ConfigEntry<T> entry){ String optionName = entry.getOptionName(); -if (optionName.equals(url)){ +if(false){//empty block +}else if (optionName.equals("url")){ url = (String) entry.getValue(); -}else if (optionName.equals(cacheDir)){ +}else if (optionName.equals("cacheDir")){ cacheDir = (String) entry.getValue(); -}else if (optionName.equals(instances)){ +}else if (optionName.equals("instances")){ instances = (Set<String>) entry.getValue(); -}else if (optionName.equals(recursionDepth)){ +}else if (optionName.equals("recursionDepth")){ recursionDepth = (Integer) entry.getValue(); -}else if (optionName.equals(predefinedFilter)){ +}else if (optionName.equals("predefinedFilter")){ predefinedFilter = (String) entry.getValue(); -}else if (optionName.equals(predefinedEndpoint)){ +}else if (optionName.equals("predefinedEndpoint")){ predefinedEndpoint = (String) entry.getValue(); -}else if (optionName.equals(predefinedManipulator)){ +}else if (optionName.equals("predefinedManipulator")){ predefinedManipulator = (String) entry.getValue(); -}else if (optionName.equals(predList)){ +}else if (optionName.equals("predList")){ predList = (Set<String>) entry.getValue(); -}else if (optionName.equals(objList)){ +}else if (optionName.equals("objList")){ objList = (Set<String>) entry.getValue(); -}else if (optionName.equals(classList)){ +}else if (optionName.equals("classList")){ classList = (Set<String>) entry.getValue(); -}else if (optionName.equals(format)){ +}else if (optionName.equals("format")){ format = (String) entry.getValue(); -}else if (optionName.equals(dumpToFile)){ +}else if (optionName.equals("dumpToFile")){ dumpToFile = (Boolean) entry.getValue(); -}else if (optionName.equals(convertNT2RDF)){ +}else if (optionName.equals("convertNT2RDF")){ convertNT2RDF = (Boolean) entry.getValue(); -}else if (optionName.equals(useLits)){ +}else if (optionName.equals("useLits")){ useLits = (Boolean) entry.getValue(); -}else if (optionName.equals(getAllSuperClasses)){ +}else if (optionName.equals("getAllSuperClasses")){ getAllSuperClasses = (Boolean) entry.getValue(); -}else if (optionName.equals(useCache)){ +}else if (optionName.equals("useCache")){ useCache = (Boolean) entry.getValue(); -}else if (optionName.equals(replacePredicate)){ +}else if (optionName.equals("replacePredicate")){ replacePredicate = (List<StringTuple>) entry.getValue(); -}else if (optionName.equals(replaceObject)){ +}else if (optionName.equals("replaceObject")){ replaceObject = (List<StringTuple>) entry.getValue(); -}else if (optionName.equals(breakSuperClassRetrievalAfter)){ +}else if (optionName.equals("breakSuperClassRetrievalAfter")){ breakSuperClassRetrievalAfter = (Integer) entry.getValue(); -}else if (optionName.equals(closeAfterRecursion)){ +}else if (optionName.equals("closeAfterRecursion")){ closeAfterRecursion = (Boolean) entry.getValue(); -}else if (optionName.equals(getPropertyInformation)){ +}else if (optionName.equals("getPropertyInformation")){ getPropertyInformation = (Boolean) entry.getValue(); -}else if (optionName.equals(verbosity)){ +}else if (optionName.equals("verbosity")){ verbosity = (String) entry.getValue(); -}else if (optionName.equals(defaultGraphURIs)){ +}else if (optionName.equals("defaultGraphURIs")){ defaultGraphURIs = (Set<String>) entry.getValue(); -}else if (optionName.equals(namedGraphURIs)){ +}else if (optionName.equals("namedGraphURIs")){ namedGraphURIs = (Set<String>) entry.getValue(); } } - /** -* URL of SPARQL Endpoint -**/ -public void setUrl (String url) { -this.url = url; +url : URL of SPARQL Endpoint**/ +public String getUrl ( ) { +return this.url; } - /** -* dir of cache -**/ -public void setCacheDir (String cacheDir) { -this.cacheDir = cacheDir; +cacheDir : dir of cache**/ +public String getCacheDir ( ) { +return this.cacheDir; } - /** -* relevant instances e.g. positive and negative examples in a learning problem -**/ -public void setInstances (Set<String> instances) { -this.instances = instances; +instances : relevant instances e.g. positive and negative examples in a learning problem**/ +public Set<String> getInstances ( ) { +return this.instances; } - /** -* recursion depth of KB fragment selection -**/ -public void setRecursionDepth (int recursionDepth) { -this.recursionDepth = recursionDepth; +recursionDepth : recursion depth of KB fragment selection**/ +public int getRecursionDepth ( ) { +return this.recursionDepth; } - /** -* the mode of the SPARQL Filter, use one of YAGO,SKOS,YAGOSKOS , YAGOSPECIALHIERARCHY, TEST -**/ -public void setPredefinedFilter (String predefinedFilter) { -this.predefinedFilter = predefinedFilter; +predefinedFilter : the mode of the SPARQL Filter, use one of YAGO,SKOS,YAGOSKOS , YAGOSPECIALHIERARCHY, TEST**/ +public String getPredefinedFilter ( ) { +return this.predefinedFilter; } - /** -* the mode of the SPARQL Filter, use one of DBPEDIA, LOCAL, GOVTRACK, REVYU, MYOPENLINK, FACTBOOK -**/ -public void setPredefinedEndpoint (String predefinedEndpoint) { -this.predefinedEndpoint = predefinedEndpoint; +predefinedEndpoint : the mode of the SPARQL Filter, use one of DBPEDIA, LOCAL, GOVTRACK, REVYU, MYOPENLINK, FACTBOOK**/ +public String getPredefinedEndpoint ( ) { +return this.predefinedEndpoint; } - /** -* the mode of the Manipulator, use one of STANDARD, DBPEDIA-NAVIGATOR -**/ -public void setPredefinedManipulator (String predefinedManipulator) { -this.predefinedManipulator = predefinedManipulator; +predefinedManipulator : the mode of the Manipulator, use one of STANDARD, DBPEDIA-NAVIGATOR**/ +public String getPredefinedManipulator ( ) { +return this.predefinedManipulator; } - /** -* list of all ignored roles -**/ -public void setPredList (Set<String> predList) { -this.predList = predList; +predList : list of all ignored roles**/ +public Set<String> getPredList ( ) { +return this.predList; } - /** -* list of all ignored objects -**/ -public void setObjList (Set<String> objList) { -this.objList = objList; +objList : list of all ignored objects**/ +public Set<String> getObjList ( ) { +return this.objList; } - /** -* list of all ignored classes -**/ -public void setClassList (Set<String> classList) { -this.classList = classList; +classList : list of all ignored classes**/ +public Set<String> getClassList ( ) { +return this.classList; } - /** -* N-TRIPLES or KB format -**/ -public void setFormat (String format) { -this.format = format; +format : N-TRIPLES or KB format**/ +public String getFormat ( ) { +return this.format; } - /** -* Specifies whether the extracted ontology is written to a file or not. -**/ -public void setDumpToFile (boolean dumpToFile) { -this.dumpToFile = dumpToFile; +dumpToFile : Specifies whether the extracted ontology is written to a file or not.**/ +public boolean getDumpToFile ( ) { +return this.dumpToFile; } - /** -* Specifies whether the extracted NTriples are converted to RDF and deleted. -**/ -public void setConvertNT2RDF (boolean convertNT2RDF) { -this.convertNT2RDF = convertNT2RDF; +convertNT2RDF : Specifies whether the extracted NTriples are converted to RDF and deleted.**/ +public boolean getConvertNT2RDF ( ) { +return this.convertNT2RDF; } - /** -* use Literals in SPARQL query -**/ -public void setUseLits (boolean useLits) { -this.useLits = useLits; +useLits : use Literals in SPARQL query**/ +public boolean getUseLits ( ) { +return this.useLits; } - /** -* If true then all superclasses are retrieved until the most general class (owl:Thing) is reached. -**/ -public void setGetAllSuperClasses (boolean getAllSuperClasses) { -this.getAllSuperClasses = getAllSuperClasses; +getAllSuperClasses : If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.**/ +public boolean getGetAllSuperClasses ( ) { +return this.getAllSuperClasses; } - /** -* If true a Cache is used -**/ -public void setUseCache (boolean useCache) { -this.useCache = useCache; +useCache : If true a Cache is used**/ +public boolean getUseCache ( ) { +return this.useCache; } - /** -* rule for replacing predicates -**/ -public void setReplacePredicate (List<StringTuple> replacePredicate) { -this.replacePredicate = replacePredicate; +replacePredicate : rule for replacing predicates**/ +public List<StringTuple> getReplacePredicate ( ) { +return this.replacePredicate; } - /** -* rule for replacing predicates -**/ -public void setReplaceObject (List<StringTuple> replaceObject) { -this.replaceObject = replaceObject; +replaceObject : rule for replacing predicates**/ +public List<StringTuple> getReplaceObject ( ) { +return this.replaceObject; } - /** -* stops a cyclic hierarchy after specified number of classes -**/ -public void setBreakSuperClassRetrievalAfter (int breakSuperClassRetrievalAfter) { -this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; +breakSuperClassRetrievalAfter : stops a cyclic hierarchy after specified number of classes**/ +public int getBreakSuperClassRetrievalAfter ( ) { +return this.breakSuperClassRetrievalAfter; } - /** -* gets all classes for all instances -**/ -public void setCloseAfterRecursion (boolean closeAfterRecursion) { -this.closeAfterRecursion = closeAfterRecursion; +closeAfterRecursion : gets all classes for all instances**/ +public boolean getCloseAfterRecursion ( ) { +return this.closeAfterRecursion; } - /** -* gets all types for extracted ObjectProperties -**/ -public void setGetPropertyInformation (boolean getPropertyInformation) { -this.getPropertyInformation = getPropertyInformation; +getPropertyInformation : gets all types for extracted ObjectProperties**/ +public boolean getGetPropertyInformation ( ) { +return this.getPropertyInformation; } - /** -* control verbosity of output for this component -**/ -public void setVerbosity (String verbosity) { -this.verbosity = verbosity; +verbosity : control verbosity of output for this component**/ +public String getVerbosity ( ) { +return this.verbosity; } - /** -* a list of all default Graph URIs -**/ -public void setDefaultGraphURIs (Set<String> defaultGraphURIs) { -this.defaultGraphURIs = defaultGraphURIs; +defaultGraphURIs : a list of all default Graph URIs**/ +public Set<String> getDefaultGraphURIs ( ) { +return this.defaultGraphURIs; } - /** -* a list of all named Graph URIs -**/ -public void setNamedGraphURIs (Set<String> namedGraphURIs) { -this.namedGraphURIs = namedGraphURIs; +namedGraphURIs : a list of all named Graph URIs**/ +public Set<String> getNamedGraphURIs ( ) { +return this.namedGraphURIs; } - - /** -* URL of SPARQL Endpoint -* -**/ -public String getUrl ( ) { -return this.url; +url : URL of SPARQL Endpoint**/ +public void setUrl ( ComponentManager cm, String url) { +cm.applyConfigEntry(SparqlKnowledgeSource, "url", url); } - /** -* dir of cache -* -**/ -public String getCacheDir ( ) { -return this.cacheDir; +cacheDir : dir of cache**/ +public void setCacheDir ( ComponentManager cm, String cacheDir) { +cm.applyConfigEntry(SparqlKnowledgeSource, "cacheDir", cacheDir); } - /** -* relevant instances e.g. positive and negative examples in a learning problem -* -**/ -public Set<String> getInstances ( ) { -return this.instances; +instances : relevant instances e.g. positive and negative examples in a learning problem**/ +public void setInstances ( ComponentManager cm, Set<String> instances) { +cm.applyConfigEntry(SparqlKnowledgeSource, "instances", instances); } - /** -* recursion depth of KB fragment selection -* -**/ -public int getRecursionDepth ( ) { -return this.recursionDepth; +recursionDepth : recursion depth of KB fragment selection**/ +public void setRecursionDepth ( ComponentManager cm, int recursionDepth) { +cm.applyConfigEntry(SparqlKnowledgeSource, "recursionDepth", recursionDepth); } - /** -* the mode of the SPARQL Filter, use one of YAGO,SKOS,YAGOSKOS , YAGOSPECIALHIERARCHY, TEST -* -**/ -public String getPredefinedFilter ( ) { -return this.predefinedFilter; +predefinedFilter : the mode of the SPARQL Filter, use one of YAGO,SKOS,YAGOSKOS , YAGOSPECIALHIERARCHY, TEST**/ +public void setPredefinedFilter ( ComponentManager cm, String predefinedFilter) { +cm.applyConfigEntry(SparqlKnowledgeSource, "predefinedFilter", predefinedFilter); } - /** -* the mode of the SPARQL Filter, use one of DBPEDIA, LOCAL, GOVTRACK, REVYU, MYOPENLINK, FACTBOOK -* -**/ -public String getPredefinedEndpoint ( ) { -return this.predefinedEndpoint; +predefinedEndpoint : the mode of the SPARQL Filter, use one of DBPEDIA, LOCAL, GOVTRACK, REVYU, MYOPENLINK, FACTBOOK**/ +public void setPredefinedEndpoint ( ComponentManager cm, String predefinedEndpoint) { +cm.applyConfigEntry(SparqlKnowledgeSource, "predefinedEndpoint", predefinedEndpoint); } - /** -* the mode of the Manipulator, use one of STANDARD, DBPEDIA-NAVIGATOR -* -**/ -public String getPredefinedManipulator ( ) { -return this.predefinedManipulator; +predefinedManipulator : the mode of the Manipulator, use one of STANDARD, DBPEDIA-NAVIGATOR**/ +public void setPredefinedManipulator ( ComponentManager cm, String predefinedManipulator) { +cm.applyConfigEntry(SparqlKnowledgeSource, "predefinedManipulator", predefinedManipulator); } - /** -* list of all ignored roles -* -**/ -public Set<String> getPredList ( ) { -return this.predList; +predList : list of all ignored roles**/ +public void setPredList ( ComponentManager cm, Set<String> predList) { +cm.applyConfigEntry(SparqlKnowledgeSource, "predList", predList); } - /** -* list of all ignored objects -* -**/ -public Set<String> getObjList ( ) { -return this.objList; +objList : list of all ignored objects**/ +public void setObjList ( ComponentManager cm, Set<String> objList) { +cm.applyConfigEntry(SparqlKnowledgeSource, "objList", objList); } - /** -* list of all ignored classes -* -**/ -public Set<String> getClassList ( ) { -return this.classList; +classList : list of all ignored classes**/ +public void setClassList ( ComponentManager cm, Set<String> classList) { +cm.applyConfigEntry(SparqlKnowledgeSource, "classList", classList); } - /** -* N-TRIPLES or KB format -* -**/ -public String getFormat ( ) { -return this.format; +format : N-TRIPLES or KB format**/ +public void setFormat ( ComponentManager cm, String format) { +cm.applyConfigEntry(SparqlKnowledgeSource, "format", format); } - /** -* Specifies whether the extracted ontology is written to a file or not. -* -**/ -public boolean getDumpToFile ( ) { -return this.dumpToFile; +dumpToFile : Specifies whether the extracted ontology is written to a file or not.**/ +public void setDumpToFile ( ComponentManager cm, boolean dumpToFile) { +cm.applyConfigEntry(SparqlKnowledgeSource, "dumpToFile", dumpToFile); } - /** -* Specifies whether the extracted NTriples are converted to RDF and deleted. -* -**/ -public boolean getConvertNT2RDF ( ) { -return this.convertNT2RDF; +convertNT2RDF : Specifies whether the extracted NTriples are converted to RDF and deleted.**/ +public void setConvertNT2RDF ( ComponentManager cm, boolean convertNT2RDF) { +cm.applyConfigEntry(SparqlKnowledgeSource, "convertNT2RDF", convertNT2RDF); } - /** -* use Literals in SPARQL query -* -**/ -public boolean getUseLits ( ) { -return this.useLits; +useLits : use Literals in SPARQL query**/ +public void setUseLits ( ComponentManager cm, boolean useLits) { +cm.applyConfigEntry(SparqlKnowledgeSource, "useLits", useLits); } - /** -* If true then all superclasses are retrieved until the most general class (owl:Thing) is reached. -* -**/ -public boolean getGetAllSuperClasses ( ) { -return this.getAllSuperClasses; +getAllSuperClasses : If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.**/ +public void setGetAllSuperClasses ( ComponentManager cm, boolean getAllSuperClasses) { +cm.applyConfigEntry(SparqlKnowledgeSource, "getAllSuperClasses", getAllSuperClasses); } - /** -* If true a Cache is used -* -**/ -public boolean getUseCache ( ) { -return this.useCache; +useCache : If true a Cache is used**/ +public void setUseCache ( ComponentManager cm, boolean useCache) { +cm.applyConfigEntry(SparqlKnowledgeSource, "useCache", useCache); } - /** -* rule for replacing predicates -* -**/ -public List<StringTuple> getReplacePredicate ( ) { -return this.replacePredicate; +replacePredicate : rule for replacing predicates**/ +public void setReplacePredicate ( ComponentManager cm, List<StringTuple> replacePredicate) { +cm.applyConfigEntry(SparqlKnowledgeSource, "replacePredicate", replacePredicate); } - /** -* rule for replacing predicates -* -**/ -public List<StringTuple> getReplaceObject ( ) { -return this.replaceObject; +replaceObject : rule for replacing predicates**/ +public void setReplaceObject ( ComponentManager cm, List<StringTuple> replaceObject) { +cm.applyConfigEntry(SparqlKnowledgeSource, "replaceObject", replaceObject); } - /** -* stops a cyclic hierarchy after specified number of classes -* -**/ -public int getBreakSuperClassRetrievalAfter ( ) { -return this.breakSuperClassRetrievalAfter; +breakSuperClassRetrievalAfter : stops a cyclic hierarchy after specified number of classes**/ +public void setBreakSuperClassRetrievalAfter ( ComponentManager cm, int breakSuperClassRetrievalAfter) { +cm.applyConfigEntry(SparqlKnowledgeSource, "breakSuperClassRetrievalAfter", breakSuperClassRetrievalAfter); } - /** -* gets all classes for all instances -* -**/ -public boolean getCloseAfterRecursion ( ) { -return this.closeAfterRecursion; +closeAfterRecursion : gets all classes for all instances**/ +public void setCloseAfterRecursion ( ComponentManager cm, boolean closeAfterRecursion) { +cm.applyConfigEntry(SparqlKnowledgeSource, "closeAfterRecursion", closeAfterRecursion); } - /** -* gets all types for extracted ObjectProperties -* -**/ -public boolean getGetPropertyInformation ( ) { -return this.getPropertyInformation; +getPropertyInformation : gets all types for extracted ObjectProperties**/ +public void setGetPropertyInformation ( ComponentManager cm, boolean getPropertyInformation) { +cm.applyConfigEntry(SparqlKnowledgeSource, "getPropertyInformation", getPropertyInformation); } - /** -* control verbosity of output for this component -* -**/ -public String getVerbosity ( ) { -return this.verbosity; +verbosity : control verbosity of output for this component**/ +public void setVerbosity ( ComponentManager cm, String verbosity) { +cm.applyConfigEntry(SparqlKnowledgeSource, "verbosity", verbosity); } - /** -* a list of all default Graph URIs -* -**/ -public Set<String> getDefaultGraphURIs ( ) { -return this.defaultGraphURIs; +defaultGraphURIs : a list of all default Graph URIs**/ +public void setDefaultGraphURIs ( ComponentManager cm, Set<String> defaultGraphURIs) { +cm.applyConfigEntry(SparqlKnowledgeSource, "defaultGraphURIs", defaultGraphURIs); } - /** -* a list of all named Graph URIs -* -**/ -public Set<String> getNamedGraphURIs ( ) { -return this.namedGraphURIs; +namedGraphURIs : a list of all named Graph URIs**/ +public void setNamedGraphURIs ( ComponentManager cm, Set<String> namedGraphURIs) { +cm.applyConfigEntry(SparqlKnowledgeSource, "namedGraphURIs", namedGraphURIs); } - } Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -45,7 +45,7 @@ public class OWLFile extends KnowledgeSource { private URL url; - private OWLFileConfigurator configurator = new OWLFileConfigurator(); + private OWLFileConfigurator configurator ; public OWLFileConfigurator getOWLFileConfigurator(){ return configurator; } @@ -54,6 +54,9 @@ return "OWL file"; } + public OWLFile(){ + configurator = new OWLFileConfigurator(this); + } public static Collection<ConfigOption<?>> createConfigOptions() { @@ -67,19 +70,24 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + configurator.applyConfigEntry(entry); + + //postprocessing if (entry.getOptionName().equals("url")) { - String s = (String) entry.getValue(); try { - url = new URL(s); - // File f = new File(url.toURI()); - //if(!f.canRead()) - // throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); + url = new URL(configurator.getUrl()); } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); - } //catch (URISyntaxException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - //} + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + configurator.getUrl()); + } + +// File f = new File(url.toURI()); +//if(!f.canRead()) +// throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); +// String s = (String) entry.getValue(); +//catch (URISyntaxException e) { +//e.printStackTrace(); +//} + } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -46,7 +46,6 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.config.ConfigOption.Tags; -import org.dllearner.core.configuration.OWLFileConfigurator; import org.dllearner.core.configuration.SparqlKnowledgeSourceConfigurator; import org.dllearner.core.owl.KB; import org.dllearner.kb.aquisitors.SparqlTupleAquisitor; @@ -85,11 +84,16 @@ static final boolean debugUseImprovedTupleAquisitor = debug && false; //switches tupleaquisitor static final boolean debugExitAfterExtraction = debug && false; //switches sysex und rdf generation - private SparqlKnowledgeSourceConfigurator configurator = new SparqlKnowledgeSourceConfigurator(); + private SparqlKnowledgeSourceConfigurator configurator; + public SparqlKnowledgeSourceConfigurator getSparqlKnowledgeSourceConfigurator(){ return configurator; } +/*public SparqlKnowledgeSource (){ + this.configurator = new SparqlKnowledgeSourceConfigurator(this); + } +*/ private boolean useCache=true; // ConfigOptions public URL url; Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -20,13 +20,23 @@ package org.dllearner.scripts; import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.collections.map.LinkedMap; +import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.configuration.Configurator; @@ -51,256 +61,361 @@ private static final String TEMPLATE_DIR = "doc/template/"; - private static final String CLASSADDITION = "Configurator"; + private static final String CONFIGURATOR = "Configurator"; private static final SortedSet<String> configuratorImports = new TreeSet<String>(); - private static final SortedSet<String> configuratorMethods = new TreeSet<String>(); + private static final List<String> configuratorMethods = new ArrayList<String>(); + + Class<? extends Component> component; + String className; + String componentType; + List<String> body = new ArrayList<String>(); + List<String> vars = new ArrayList<String>(); + List<String> setters = new ArrayList<String>(); + List<String> getters = new ArrayList<String>(); + SortedSet<String> imports = new TreeSet<String>(); + Map<String,String> additionalMandatoryVars = new LinkedHashMap<String, String>(); + Map<String,String> mandatoryVars = new LinkedHashMap<String, String>(); + Map<String,String> varMap = new LinkedHashMap<String, String>(); + + List<ConfigOption<?>> mandatoryOptions = new LinkedList<ConfigOption<?>>(); + /** * @param args */ public static void main(String[] args) { + Files.backupDirectory(TARGET_DIR); + //System.exit(0); Files.deleteDir(TARGET_DIR); - + ComponentManager cm = ComponentManager.getInstance(); configuratorImports.add(ComponentManager.class.getCanonicalName()); - + configuratorImports.add(KnowledgeSource.class.getCanonicalName()); + configuratorImports.add(ReasonerComponent.class.getCanonicalName()); + configuratorImports.add(ReasoningService.class.getCanonicalName()); + configuratorImports.add(LearningProblem.class.getCanonicalName()); + configuratorImports.add(LearningAlgorithm.class.getCanonicalName()); for (Class<? extends KnowledgeSource> component : cm .getKnowledgeSources()) { String componentType = "knowledgeSource"; + + if (component.getSimpleName().equalsIgnoreCase( "OWLFile")) { configuratorImports.add(component.getCanonicalName()); - configuratorImports.add("org.dllearner.core.configuration."+component.getSimpleName()+CLASSADDITION); - make (component, componentType); + configuratorImports.add("org.dllearner.core.configuration."+component.getSimpleName()+CONFIGURATOR); + ConfigJavaGenerator c = new ConfigJavaGenerator(component, componentType); + + c.makeSubclasses(); + }if (component.getSimpleName().equalsIgnoreCase( "SparqlKnowledgeSource")) { configuratorImports.add(component.getCanonicalName()); - configuratorImports.add("org.dllearner.core.configuration."+component.getSimpleName()+CLASSADDITION); - make (component, componentType); + configuratorImports.add("org.dllearner.core.configuration."+component.getSimpleName()+CONFIGURATOR); + ConfigJavaGenerator c = new ConfigJavaGenerator(component, componentType); + c.makeSubclasses(); } } + for (Class<? extends ReasonerComponent> component : cm.getReasonerComponents()) { + + + if (component.getSimpleName().equalsIgnoreCase( + "FastInstanceChecker")) { + configuratorImports.add(component.getCanonicalName()); + configuratorImports.add("org.dllearner.core.configuration."+component.getSimpleName()+CONFIGURATOR); + + ConfigJavaGenerator c = new ConfigJavaGenerator(component, "reasoner"); + c.imports.add("org.dllearner.core.KnowledgeSource"); + c.additionalMandatoryVars.put("KnowledgeSource knowledgeSource","knowledgeSource"); + c.makeSubclasses(); + + } + + + } + + makeConfiguratorSuperClass(); System.out.println("Done"); } - public static void makeConfiguratorSuperClass(){ - StringBuffer current = new StringBuffer(); - current.append(HEADER+"\n"); - current.append("package org.dllearner.core.configuration;\n\n"); - for (String string : configuratorImports) { - current.append("import "+string+";\n"); - } - current.append("\n"+getClassComment()); - current.append("public class "+CLASSADDITION+" {\n\n"); - for (String string : configuratorMethods) { - current.append(string+"\n"); - } - current.append("}\n"); - Files.createFile(new File(TARGET_DIR + "/" + CLASSADDITION + ".java"), current.toString()); - } - - public static void make(Class<? extends KnowledgeSource> component, String componentType){ - StringBuffer current = new StringBuffer(); - StringBuffer vars = new StringBuffer(); - StringBuffer setters = new StringBuffer(); - StringBuffer getters = new StringBuffer(); - SortedSet<String> imports = new TreeSet<String>(); - String className = component.getSimpleName(); - List<ConfigOption<?>> mandatoryOptions = new LinkedList<ConfigOption<?>>(); - + public ConfigJavaGenerator (Class<? extends Component> component, String componentType){ + className = component.getSimpleName(); + this.component = component; + this.componentType = componentType; imports.add(component.getCanonicalName()); imports.add(ComponentManager.class.getCanonicalName()); imports.add(Configurator.class.getCanonicalName()); imports.add(ConfigEntry.class.getCanonicalName()); + + vars.add(className+" "+className+";\n"); + + } + + public void makeSubclasses(){ + + + //imports.add("import "+ConfigOption.class.getCanonicalName()+";"); + //vars.put(key, value) + //vars.add(className+" "+ className+";\n"); - vars.append(className+" "+ className+";\n"); - current.append(HEADER + "\n"); - current.append("package org.dllearner.core.configuration;\n\n"); for (ConfigOption<?> option : ComponentManager .getConfigOptions(component)) { + + String type = option.getValueTypeAsJavaString(); + String optionName = option.getName(); + String defaultValue = option.getDefaultValueInJava(); + String comment = option.getDescription(); + if(option.isMandatory()){ + mandatoryVars.put(type + " " + optionName , optionName); mandatoryOptions.add(option); configuratorImports.addAll(option.getJavaImports()); - } + } imports.addAll(option.getJavaImports()); - vars.append(getVarDef(option)); - setters.append(getSetter(option)); - getters.append(getGetter(option)); + vars.add(fillVariableDefTemplate(optionName, type, defaultValue)); + setters.add(fillSetterTemplate(className, comment, optionName, type)); + getters.add(fillGetterTemplate(comment, optionName, type)); // System.out.println(option); // componentOptions.get(component)) { } - for (String string : imports) { - current.append("import "+string+";\n"); - } - current.append("\n\n"); - current.append(getClassDefinition(className)); - current.append(vars); - current.append("\n\n"); - current.append(getMandatoryFunctions(className, componentType, mandatoryOptions)); - current.append("\n\n"); - current.append(makeApplyConfigEntry(ComponentManager.getConfigOptions(component))); - current.append("\n\n"); - current.append(setters+"\n\n"+getters+"\n\n"); - current.append("}\n"); - configuratorMethods.add(getSuperClassFunction(className, componentType, mandatoryOptions)); + + + body.add(expandCollection(vars, "", "", 0)); + body.add(fillConstructorTemplate(className)); + + body.add(makeGetInstanceForSubclass(className, componentType, + getAllCommentsForOptionList(mandatoryOptions))); + + body.add(makeApplyConfigEntryForOptionList(ComponentManager.getConfigOptions(component))); + + body.add(expandCollection(getters, "", "", 0)); + body.add(expandCollection(setters, "", "", 0)); + String ret = fillClassTemplate( + "org.dllearner.core.configuration", + expandCollection(imports, "import ", ";\n", 0), + className+CONFIGURATOR, + CONFIGURATOR, + expandCollection(body, "", "\n", 0) ); + + + + + + //configuratorMethods.add((className, componentType, mandatoryOptions)); + Files.createFile(new File(TARGET_DIR + "/" + className - + CLASSADDITION + ".java"), current.toString()); + + CONFIGURATOR + ".java"), ret); + + configuratorMethods.add( + makeSuperConfiguratorMethods( + className, + componentType, + getAllCommentsForOptionList(mandatoryOptions))); } - private static String getConstructor(String className){ - return ""; - } - public static String makeApplyConfigEntry(List<ConfigOption<?>> options){ + + public static String makeApplyConfigEntryForOptionList(List<ConfigOption<?>> options){ String ret ="@SuppressWarnings({ \"unchecked\" })\n" + "public <T> void applyConfigEntry(ConfigEntry<T> entry){\n"; ret+="String optionName = entry.getOptionName();\n"; //ret+="ConfigOption<T> option = entry.getOption();\n"; - if(!options.isEmpty()){ - ConfigOption<?> first = options.remove(0); - ret+="if (optionName.equals("+first.getName()+")){\n" + - ""+first.getName()+" = ("+rightType(first.getValueTypeAsJavaString())+") " + - " entry.getValue();\n"; - } + ret+="if(false){//empty block \n}"; + for (ConfigOption<?> option : options) { - ret+="}else if (optionName.equals("+option.getName()+")){\n"; + ret+="else if (optionName.equals(\""+option.getName()+"\")){\n"; ret+=""+option.getName()+" = ("+rightType(option.getValueTypeAsJavaString())+") " + - " entry.getValue();\n"; + " entry.getValue();\n}"; } - ret+="}\n}\n"; + ret+="\n}\n"; return ret; } - public static String rightType(String type){ - if(type.equals("int"))return "Integer"; - else if(type.equals("boolean"))return "Boolean"; - else return type; + + private static String getAllCommentsForOptionList(List<ConfigOption<?>> options){ + String ret = ""; + for (ConfigOption<?> option : options) { + ret+="* "+option.getName()+": "+option.getDescription()+"\n"; + } + return fillJavaDocComment(ret); } - private static String getMandatoryFunctionComment(List<ConfigOption<?>> options){ - String ret = "/**\n"; - for (ConfigOption<?> option : options) { - ret+=option.getDescription()+"\n"; + private String makeGetInstanceForSubclass(String className, String componentType, + String comments){ + Map<String, String> parametersWithType = new LinkedHashMap<String,String>(); + Map<String, String> parametersNoType = new LinkedHashMap<String,String>(); + String applyConf = ""; + parametersWithType.put("ComponentManager cm", "cm"); + parametersNoType.put(className+".class", className+".class"); + for (String s : additionalMandatoryVars.keySet()) { + parametersWithType.put(s, additionalMandatoryVars.get(s)); + parametersNoType.put(s, additionalMandatoryVars.get(s)); } - ret+="**/\n"; + for (String s : mandatoryVars.keySet()) { + parametersWithType.put(s, mandatoryVars.get(s)); + applyConf += fillApplyConfigEntry("component", mandatoryVars.get(s))+""; + } + + String parWithType = expandCollection(parametersWithType.keySet(), "", ", ", 2); + + String par = expandCollection(parametersNoType.values(), "", ", ", 2); + + //TODO + String ret = comments; + ret += "public static "+className+" get"+className+" ("+parWithType+" ) {\n"; + ret += className+" component = cm."+componentType+"(" +par+" );\n"; + ret += applyConf; + + ret+="return component;\n}\n"; return ret; } - private static String getMandatoryFunctions(String className, String componentType, List<ConfigOption<?>> options){ - String mandParametersWithType = getMandatoryParameters(options, true); - //String mandParametersNoType = getMandatoryParameters(options, false); - String mandFunctionBody = mandatoryFunctionBody(options); - String ret= getMandatoryFunctionComment(options); - ret += "public void setMandatoryOptions ("+mandParametersWithType+" ) {\n" + - ""+mandFunctionBody+"}\n"; + private String makeSuperConfiguratorMethods( + String className, String componentType, String comments){ - ret+= getMandatoryFunctionComment(options); - ret+= "public static "+className+" get"+className+" (ComponentManager cm, "+mandParametersWithType+" ) {\n" + - className+" component = cm."+componentType+"("+className+".class);\n"; - for (ConfigOption<?> option : options) { - ret+="cm.applyConfigEntry(component, \""+option.getName()+"\", "+option.getName()+");\n"; + Map<String, String> parametersWithType = new LinkedHashMap<String,String>(); + Map<String, String> parametersNoType = new LinkedHashMap<String,String>(); + String applyConf = ""; + parametersWithType.put("ComponentManager cm", "cm"); + parametersNoType.put(className+".class", className+".class"); + for (String s : additionalMandatoryVars.keySet()) { + parametersWithType.put(s, additionalMandatoryVars.get(s)); + parametersNoType.put(s, additionalMandatoryVars.get(s)); } + for (String s : mandatoryVars.keySet()) { + parametersWithType.put(s, mandatoryVars.get(s)); + applyConf += fillApplyConfigEntry("component", mandatoryVars.get(s))+""; + } - ret+="return component;\n}\n"; + String parWithType = expandCollection(parametersWithType.keySet(), "", ", ", 2); + + String par = expandCollection(parametersWithType.values(), "", ", ", 2); + + String ret = comments; + ret += "public static "+className+" get"+className+" ("+parWithType+" ) {\n" + + "return "+ className+CONFIGURATOR+".get"+className+"("+par+");\n}\n"; return ret; } - private static String getSuperClassFunction(String className, String componentType, List<ConfigOption<?>> options){ - String mandParametersWithType = getMandatoryParameters(options, true); - String mandParametersNoType = getMandatoryParameters(options, false); - //String mandFunctionBody = mandatoryFunctionBody(options); - String ret = getMandatoryFunctionComment(options); - ret += "public static "+className+" get"+className+" (ComponentManager cm, "+mandParametersWithType+" ) {\n" + - "return "+ className+CLASSADDITION+".get"+className+"(cm, "+mandParametersNoType+");\n}\n"; - return ret; + public static void makeConfiguratorSuperClass(){ + String ret= + fillClassTemplate( + "org.dllearner.core.configuration", + expandCollection(configuratorImports, "import ", ";\n",0), + CONFIGURATOR, + "", + expandCollection(configuratorMethods, "", "\n", 0) + ); + + + Files.createFile(new File(TARGET_DIR + "/" + CONFIGURATOR + ".java"), ret); } - public static String getMandatoryParameters (List<ConfigOption<?>> options, boolean includeType){ - if(options.isEmpty())return ""; - String ret = ""; - String type = ""; - for (ConfigOption<?> option : options) { - type = (includeType)?option.getValueTypeAsJavaString():""; - ret += type + " " + option.getName()+", "; - } - ret = ret.substring(0,ret.length()-2); - return ret; + + + private static String fillApplyConfigEntry(String className, String optionName){ + return "cm.applyConfigEntry("+className+", \""+optionName+"\", "+optionName+");\n"; } - private static String mandatoryFunctionBody(List<ConfigOption<?>> options){ - String ret = ""; - for (ConfigOption<?> option : options) { - ret += "this."+option.getName()+" = "+option.getName()+";\n"; - } - return ret; + private static String fillConstructorTemplate(String className){ + return "public "+className+CONFIGURATOR+" ("+className+" "+className+"){\n" + + "this."+className+" = "+className+";\n" + + "}\n"; } - private static String getVarDef(ConfigOption<?> option) { - return "private " + option.getValueTypeAsJavaString() + " " - + option.getName() + " = " + option.getDefaultValueInJava() + private static String fillVariableDefTemplate(String optionName, String type, String defaultValue) { + return "private " + type + " " + + optionName + " = " + defaultValue + ";\n"; } + + private static String fillJavaDocComment(String lines){ + return "/**\n"+lines+"**/\n"; + } - private static String getSetter(ConfigOption<?> option) { - String s = option.getName().substring(0, 1); - s = s.toUpperCase() + option.getName().substring(1); - String comment = "/**\n" + - "* "+option.getDescription()+"\n" + - "**/\n"; + + + private static String fillGetterTemplate( String comment, String optionName, String type) { + String ret = fillJavaDocComment (optionName+" : "+comment); + ret+= "public "+type+" get" + capitalize(optionName) + " ( ) {\n"; + ret+= "return this." + optionName+";\n"; + ret+= "}\n"; + return ret; + } + private static String fillSetterTemplate(String className, String comment, String optionName, String type ){ + String ret = fillJavaDocComment (optionName+" : "+comment); + ret += "public void set" + capitalize(optionName); + ret += " ( ComponentManager cm, " + type +" "+ optionName+") {\n"; + ret += fillApplyConfigEntry(className, optionName); + ret += "}\n" ; + return ret; + } + + + + private static String fillClassTemplate(String Package, String imports, String className, String Extends, String body){ + String ret = HEADER +"\n"; + ret += "package "+Package+";\n"; + ret += imports+"\n"; + ret += fillJavaDocComment("* automatically generated, do not edit manually\n"); + ret += "public class "+className+" "+((Extends.length()>0)?"extends "+Extends:"")+" {\n\n"; + ret += body+"\n"; + ret +="}\n"; + return ret; - return comment + "public void set" + s + " (" + option.getValueTypeAsJavaString() - + " "+option.getName()+") {\n" + - "this." + option.getName()+" = "+ option.getName()+ - ";\n" + - "}\n\n"; - } - private static String getGetter(ConfigOption<?> option) { - String s = option.getName().substring(0, 1); - s = s.toUpperCase() + option.getName().substring(1); - String comment = "/**\n" + - "* "+option.getDescription()+"\n" + - "* \n" + - "**/\n"; + + + private static String expandCollection (Collection<String> col, String before, String after, int removeChars){ + if(col.isEmpty())return ""; + String ret =""; + for (String string : col) { + ret+= before+string+after; + } + + if(removeChars==0){ + return ret; + }else { + return ret.substring(0, ret.length()-removeChars); + } + } - return comment + "public "+option.getValueTypeAsJavaString()+" get" + s + " ( ) {\n" + - "return this." + option.getName()+";\n" + - "}\n\n"; - + + + private static String capitalize(String s){ + String tmp = s.substring(0, 1); + return tmp.toUpperCase() + s.substring(1); } - - private static String getClassDefinition(String className) { - String ret = getClassComment() - + "public class " + className + CLASSADDITION + " extends Configurator {\n" + "\n"; - return ret; + + public static String rightType(String type){ + if(type.equals("int"))return "Integer"; + else if(type.equals("boolean"))return "Boolean"; + else return type; + } - private static String getClassComment(){ - return "" + "/**\n" - + "* automatically generated, do not edit manually\n" + "**/\n"; - } - private static String getHeader() { try { return Files.readFile(new File(HEADER_FILE)); Added: trunk/src/dl-learner/org/dllearner/scripts/NewSample.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/NewSample.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/NewSample.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -0,0 +1,160 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>.**/ +package org.dllearner.scripts; + +import java.io.File; +import java.io.IOException; +import java.text.DecimalFormat; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.configuration.Configurator; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.utilities.Files; + +import com.jamonapi.MonitorFactory; + +/** + * Sample script showing how to use DL-Learner. Provides an entry point for tool + * developers. + * + * @author Sebastian Hellmann + * @author Jens Lehmann + * + */ +public class NewSample { + + private static Logger logger = Logger.getRootLogger(); + private static DecimalFormat df = new DecimalFormat(); + + public static void main(String[] args) throws IOException, ComponentInitException, + LearningProblemUnsupportedException { + + // create logger (configure this to your needs) + SimpleLayout layout = new SimpleLayout(); + FileAppender fileAppender = new FileAppender(layout, "log/sample_log.txt", false); + + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.addAppender(fileAppender); + logger.setLevel(Level.DEBUG); + + // OWL file containing background knowledge + String owlFile = "examples/trains/trains.owl"; + + // examples + SortedSet<String> posExamples = new TreeSet<String>(); + posExamples.add("http://example.com/foo#east1"); + posExamples.add("http://example.com/foo#east2"); + posExamples.add("http://example.com/foo#east3"); + posExamples.add("http://example.com/foo#east4"); + posExamples.add("http://example.com/foo#east5"); + + SortedSet<String> negExamples = new TreeSet<String>(); + negExamples.add("http://example.com/foo#west6"); + negExamples.add("http://example.com/foo#west7"); + negExamples.add("http://example.com/foo#west8"); + negExamples.add("http://example.com/foo#west9"); + negExamples.add("http://example.com/foo#west10"); + + List<EvaluatedDescription> results = learn(owlFile, posExamples, negExamples, 5); + int x = 0; + for (EvaluatedDescription ed : results) { + System.out.println("solution: " + x); + System.out.println(" description: \t" + + ed.getDescription().toManchesterSyntaxString(null, null)); + System.out.println(" accuracy: \t" + df.format(ed.getAccuracy() * 100) + "%"); + System.out.println(); + x++; + } + + Files.createFile(new File("log/jamon_sample.html"), MonitorFactory.getReport()); + } + + public static List<EvaluatedDescription> learn(String owlFile, SortedSet<String> posExamples, + SortedSet<String> negExamples, int maxNrOfResults) throws ComponentInitException, + LearningProblemUnsupportedException { + + logger.info("Start Learning with"); + logger.info("positive examples: \t" + posExamples.size()); + logger.info("negative examples: \t" + negExamples.size()); + + // the component manager is the central object to create + // and configure components + ComponentManager cm = ComponentManager.getInstance(); + + // knowledge source + //KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); + + String fileURL = new File(owlFile).toURI().toString(); + OWLFile ks = Configurator.getOWLFile(cm, fileURL); + + + // reasoner + ReasonerComponent r = cm.reasoner(FastInstanceChecker.class, ks); + ReasoningService rs = cm.reasoningService(r); + + + // learning problem + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + cm.applyConfigEntry(lp, "positiveExamples", posExamples); + cm.applyConfigEntry(lp, "negativeExamples", negExamples); + + // learning algorithm + LearningAlgorithm la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs); + cm.applyConfigEntry(la, "useAllConstructor", false); + cm.applyConfigEntry(la, "useExistsConstructor", true); + cm.applyConfigEntry(la, "useCardinalityRestrictions", false); + cm.applyConfigEntry(la, "useNegation", false); + cm.applyConfigEntry(la, "writeSearchTree", false); + cm.applyConfigEntry(la, "searchTreeFile", "log/searchTree.txt"); + cm.applyConfigEntry(la, "replaceSearchTree", true); + cm.applyConfigEntry(la, "noisePercentage", 0.0); + + // all components need to be initialised before they can be used + ks.init(); + r.init(); + lp.init(); + la.init(); + + // start learning algorithm + logger.debug("start learning"); + la.start(); + + return la.getCurrentlyBestEvaluatedDescriptions(maxNrOfResults); + } + +} Modified: trunk/src/dl-learner/org/dllearner/scripts/Sample.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -33,13 +33,11 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; -import org.dllearner.core.configuration.Configurator; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.reasoning.FastInstanceChecker; @@ -121,9 +119,10 @@ //KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); String fileURL = new File(owlFile).toURI().toString(); - OWLFile ks = Configurator.getOWLFile(cm, fileURL); - //cm.applyConfigEntry(ks, "url", fileURL); - + OWLFile ks = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(ks, "url", fileURL); + + // reasoner ReasonerComponent r = cm.reasoner(FastInstanceChecker.class, ks); ReasoningService rs = cm.reasoningService(r); Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2008-09-03 19:29:41 UTC (rev 1169) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2008-09-05 12:24:05 UTC (rev 1170) @@ -156,5 +156,30 @@ Files.deleteFile(new File(dir+File.separator+files[i])); } } + + public static void backupDirect... [truncated message content] |