From: <ku...@us...> - 2008-04-22 13:07:12
|
Revision: 806 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=806&view=rev Author: kurzum Date: 2008-04-22 06:07:07 -0700 (Tue, 22 Apr 2008) Log Message: ----------- loads of little changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/ConfWriter.java trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java trunk/src/dl-learner/org/dllearner/utilities/NT2RDF.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-04-22 13:07:07 UTC (rev 806) @@ -38,8 +38,8 @@ import org.dllearner.core.config.DoubleConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.config.StringConfigOption; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Description; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -99,13 +99,18 @@ private boolean useOverlyGeneralList = true; private boolean useShortConceptConstruction = true; private boolean improveSubsumptionHierarchy = true; - private boolean useAllConstructor = true; - private boolean useExistsConstructor = true; - private boolean useCardinalityRestrictions = true; - private boolean useNegation = true; - private boolean useBooleanDatatypes = true; + private boolean useAllConstructor = CommonConfigOptions.useAllConstructorDefault; + private boolean useExistsConstructor = CommonConfigOptions.useExistsConstructorDefault; + private boolean useCardinalityRestrictions = CommonConfigOptions.useCardinalityRestrictionsDefault; + private boolean useNegation = CommonConfigOptions.useNegationDefault; + private boolean useBooleanDatatypes = CommonConfigOptions.useBooleanDatatypesDefault; private double noisePercentage = 0.0; private NamedClass startClass = null; + //extended Options + //in seconds + private int maxExecutionTimeInSeconds = CommonConfigOptions.maxExecutionTimeInSecondsDefault; + private int minExecutionTimeInSeconds = CommonConfigOptions.minExecutionTimeInSecondsDefault; + private int guaranteeXgoodDescriptions = CommonConfigOptions.guaranteeXgoodDescriptionsDefault; // Variablen zur Einstellung der Protokollierung // boolean quiet = false; @@ -164,7 +169,9 @@ options.add(CommonConfigOptions.useCardinalityRestrictions()); options.add(CommonConfigOptions.useNegation()); options.add(CommonConfigOptions.useBooleanDatatypes()); - + options.add(CommonConfigOptions.maxExecutionTimeInSeconds()); + options.add(CommonConfigOptions.minExecutionTimeInSeconds()); + options.add(CommonConfigOptions.guaranteeXgoodDescriptions()); DoubleConfigOption noisePercentage = new DoubleConfigOption("noisePercentage", "the (approximated) percentage of noise within the examples"); noisePercentage.setLowerLimit(0); noisePercentage.setUpperLimit(100); @@ -226,6 +233,12 @@ useBooleanDatatypes = (Boolean) entry.getValue(); } else if(name.equals("startClass")) { startClass = new NamedClass((String)entry.getValue()); + }else if(name.equals("maxExecutionTimeInSeconds")) { + maxExecutionTimeInSeconds = (Integer) entry.getValue(); + }else if(name.equals("minExecutionTimeInSeconds")) { + minExecutionTimeInSeconds = (Integer) entry.getValue(); + }else if(name.equals("guaranteeXgoodDescriptions")) { + guaranteeXgoodDescriptions = (Integer) entry.getValue(); } } @@ -319,7 +332,10 @@ searchTreeFile, useTooWeakList, useOverlyGeneralList, - useShortConceptConstruction + useShortConceptConstruction, + maxExecutionTimeInSeconds, + minExecutionTimeInSeconds, + guaranteeXgoodDescriptions ); // note: used concepts and roles do not need to be passed // as argument, because it is sufficient to prepare the @@ -363,4 +379,13 @@ return algorithm.getStartNode(); } + + public void printBestSolutions(int nrOfSolutions){ + + algorithm.printBestSolutions(nrOfSolutions); + } + + + + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-22 13:07:07 UTC (rev 806) @@ -101,6 +101,11 @@ private boolean useOverlyGeneralList = true; private boolean useShortConceptConstruction = true; + //extended Options + private long maxExecutionTimeInSeconds; + private long minExecutionTimeInSeconds; + private int guaranteeXgoodDescriptions; + // if set to false we do not test properness; this may seem wrong // but the disadvantage of properness testing are additional reasoner // queries and a search bias towards ALL r.something because @@ -188,6 +193,7 @@ private long redundancyCheckTimeNs = 0; private long evaluateSetCreationTimeNs = 0; private long improperConceptsRemovalTimeNs = 0; + // prefixes private String baseURI; @@ -206,7 +212,10 @@ File searchTreeFile, boolean useTooWeakList, boolean useOverlyGeneralList, - boolean useShortConceptConstruction + boolean useShortConceptConstruction, + int maxExecutionTimeInSeconds, + int minExecutionTimeInSeconds, + int guaranteeXgoodDescriptions ) { if(learningProblem instanceof PosNegLP) { PosNegLP lp = (PosNegLP) learningProblem; @@ -239,7 +248,10 @@ this.useTooWeakList = useTooWeakList; this.useOverlyGeneralList = useOverlyGeneralList; this.useShortConceptConstruction = useShortConceptConstruction; - baseURI = rs.getBaseURI(); + this.baseURI = rs.getBaseURI(); + this.maxExecutionTimeInSeconds=maxExecutionTimeInSeconds; + this.minExecutionTimeInSeconds=minExecutionTimeInSeconds; + this.guaranteeXgoodDescriptions = guaranteeXgoodDescriptions; // logger.setLevel(Level.DEBUG); } @@ -317,7 +329,7 @@ long reductionInterval = 500l * 1000000000l; long currentTime; - while(!solutionFound && !stop) { + while(!solutionFound && !stop ) { // print statistics at most once a second currentTime = System.nanoTime(); @@ -352,7 +364,8 @@ candidates.add(bestNode); // newCandidates has been filled during node expansion candidates.addAll(newCandidates); - candidatesStable.addAll(newCandidates); + candidatesStable.addAll(newCandidates); + // System.out.println("done"); if(writeSearchTree) { @@ -380,8 +393,10 @@ } - - if(solutionFound) { + if(maxExecutionTimeReached()) { stop=true;} + boolean minSolutionrequirement = (solutions.size()>guaranteeXgoodDescriptions); + + if(solutionFound && minExecutionTimeReached() && minSolutionrequirement) { logger.info("best node " + candidatesStable.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); logger.info("\nsolutions:"); for(Description c : solutions) { @@ -732,6 +747,7 @@ long algorithmRuntime = System.nanoTime() - algorithmStartTime; if(!finalStats) { + ExampleBasedNode bestNode = candidatesStable.last(); // double accuracy = 100 * ((bestNode.getCoveredPositives().size() // + nrOfNegativeExamples - bestNode.getCoveredNegatives().size())/(double)nrOfExamples); @@ -989,6 +1005,19 @@ return best; } + + public void printBestSolutions(int nrOfSolutions){ + + int i=0; + for(ExampleBasedNode n : candidatesStable.descendingSet()) { + System.out.println(n.getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); + if(i==nrOfSolutions) + return ; + i++; + } + + } + public Score getSolutionScore() { if(posOnly) return posOnlyLearningProblem.computeScore(getBestSolution()); @@ -1000,4 +1029,30 @@ return startNode; } + private boolean maxExecutionTimeReached(){ + if(maxExecutionTimeInSeconds==0)return false; + long needed = System.nanoTime()- this.algorithmStartTime; + //millisec /100 + //seconds /1000 + long maxNanoSeconds = maxExecutionTimeInSeconds *100*1000 ; + if(maxNanoSeconds<needed)return true; + else return false; + + } + + /** + * true if minExecutionTime reached + * @return true + */ + private boolean minExecutionTimeReached(){ + //if(minExecutionTimeInSeconds==0)return true; + long needed = System.nanoTime()- this.algorithmStartTime; + //millisec /100 + //seconds /1000 + long minNanoSeconds = minExecutionTimeInSeconds *100*1000 ; + if(minNanoSeconds<needed)return true; + else return false; + + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-04-22 13:07:07 UTC (rev 806) @@ -213,6 +213,10 @@ */ @SuppressWarnings( { "unchecked" }) public <T> void applyConfigEntry(Component component, String optionName, T value) { + System.out.println(component); + System.out.println(optionName); + System.out.println(value); + System.out.println(value.getClass()); // first we look whether the component is registered if (components.contains(component.getClass())) { Modified: trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-04-22 13:07:07 UTC (rev 806) @@ -40,6 +40,9 @@ public static boolean useCardinalityRestrictionsDefault = true; public static boolean useNegationDefault = true; public static boolean useBooleanDatatypesDefault = true; + public static int maxExecutionTimeInSecondsDefault = 0; + public static int minExecutionTimeInSecondsDefault = 0; + public static int guaranteeXgoodDescriptionsDefault = 1; //public static double noisePercentageDefault = 0.0; @@ -105,4 +108,16 @@ public static BooleanConfigOption useBooleanDatatypes() { return new BooleanConfigOption("useBooleanDatatypes", "specifies whether boolean datatypes are used in the learning algorothm",useBooleanDatatypesDefault); } + + public static IntegerConfigOption maxExecutionTimeInSeconds() { + return new IntegerConfigOption("maxExecutionTimeInSeconds", "algorithm will stop after specified seconds",maxExecutionTimeInSecondsDefault); + } + + public static IntegerConfigOption minExecutionTimeInSeconds() { + return new IntegerConfigOption("minExecutionTimeInSeconds", "algorithm will run at least specified seconds",minExecutionTimeInSecondsDefault); + } + + public static IntegerConfigOption guaranteeXgoodDescriptions() { + return new IntegerConfigOption("guaranteeXgoodDescriptions", "algorithm will run until X good (100%) concept descritpions are found",guaranteeXgoodDescriptionsDefault); + } } Modified: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-04-22 13:07:07 UTC (rev 806) @@ -32,7 +32,6 @@ import org.dllearner.core.owl.ObjectPropertyAssertion; import org.dllearner.kb.KBFile; import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegLP; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.OWLAPIReasoner; @@ -258,9 +257,12 @@ r.init(); ReasoningService rs = new ReasoningService(r); + //cm.learningProblem(lpClass, reasoner) LearningProblem lp = new PosNegDefinitionLP(rs); - ((PosNegLP)lp).setPositiveExamples(pos); - ((PosNegLP)lp).setNegativeExamples(neg); + //cm.getConfigOptionValue(lp, ""); + cm.applyConfigEntry(lp, "positiveExamples",pos); + cm.applyConfigEntry(lp, "negativeExamples",neg); + lp.init(); la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-04-22 13:07:07 UTC (rev 806) @@ -405,6 +405,10 @@ // TODO Does this work? return kb; } + + public URL getNTripleURL(){ + return dumpFile; + } /*public static void main(String[] args) throws MalformedURLException { String query = "SELECT ?pred ?obj\n" Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-04-22 13:07:07 UTC (rev 806) @@ -95,6 +95,8 @@ pred.add("http://dbpedia.org/property/wikipage"); pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); pred.add("http://dbpedia.org/property/relatedInstance"); + pred.add("http://dbpedia.org/property/owner"); + pred.add("http://dbpedia.org/property/standard"); Set<String> obj = new HashSet<String>(); //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); @@ -108,7 +110,7 @@ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); obj.add("http://www.w3.org/2004/02/skos/core"); - + return new SparqlQueryType("forbid", obj, pred, false); } public static SparqlQueryType YagoSpecialHierarchy(){ Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-04-22 13:07:07 UTC (rev 806) @@ -162,8 +162,11 @@ public void init() throws ComponentInitException { rc = new OWLAPIReasoner(sources); //TODO make it nice + + rc.setReasonerType(reasonerType); rc.init(); + try { atomicConcepts = rc.getAtomicConcepts(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-04-22 13:07:07 UTC (rev 806) @@ -58,6 +58,7 @@ import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.UntypedConstant; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.RoleComparator; import org.semanticweb.owl.apibinding.OWLManager; @@ -180,9 +181,15 @@ Set<OWLOntology> allImports = new HashSet<OWLOntology>(); for(KnowledgeSource source : sources) { - // OWL files are read directly - if(source instanceof OWLFile) { - URL url = ((OWLFile)source).getURL(); + + if(source instanceof OWLFile || source instanceof SparqlKnowledgeSource ) { + URL url=null; + if(source instanceof OWLFile){ + url = ((OWLFile)source).getURL(); + } + else if(source instanceof SparqlKnowledgeSource) { + url=((SparqlKnowledgeSource)source).getNTripleURL(); + } try { OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); Modified: trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java 2008-04-21 20:21:36 UTC (rev 805) +++ trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java 2008-04-22 13:07:07 UTC (rev 806) @@ -8,7 +8,9 @@ import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.utilities.ConfWriter; import org.dllearner.utilities.JenaResultSetConvenience; +import org.dllearner.utilities.LearnSparql; import org.dllearner.utilities.SimpleClock; import com.hp.hpl.jena.query.ResultSet; @@ -24,12 +26,14 @@ public static void main(String[] args) { init(); try { + SimpleClock sc=new SimpleClock(); SortedSet<String> concepts = new TreeSet<String>(); //concepts.add("\"http://dbpedia.org/class/yago/Person100007846\""); concepts.add("\"http://dbpedia.org/class/yago/FieldMarshal110086821\""); SortedSet<String> posExamples = new TreeSet<String>(); SortedSet<String> negExamples = new TreeSet<String>(); + String url = "http://dbpedia.openlinksw.com:8890/sparql"; //HashMap<String, ResultSet> result = new HashMap<String, ResultSet>(); //HashMap<String, String> result2 = new HashMap<String, String>(); @@ -50,11 +54,16 @@ }*/ System.out.println(negExamples.size()); negExamples.removeAll(posExamples); - - negExamples=shrink(negExamples,posExamples.size()*2); + posExamples=shrink(posExamples,5); + negExamples=shrink(negExamples,posExamples.size()); //System.out.println(posExamples.first())); System.out.println(posExamples.size()); System.out.println(negExamples.size()); + + // + new ConfWriter().writeSPARQL("aaa.conf", posExamples, negExamples, url, new TreeSet<String>()); + new LearnSparql().learn(posExamples, negExamples, "http://dbpedia.openlinksw.com:8890/sparql", new TreeSet<String>()); + sc.printAndSet("Finished"); } catch (Exception e) { e.printStackTrace(); Added: trunk/src/dl-learner/org/dllearner/utilities/ConfWriter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConfWriter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/ConfWriter.java 2008-04-22 13:07:07 UTC (rev 806) @@ -0,0 +1,155 @@ +package org.dllearner.utilities; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.owl.Individual; + +public class ConfWriter { + + + public String workingDir="examples/stest/"; + + + public void writeROLLearnerOWLFileInd(String filename,SortedSet<Individual> pos,SortedSet<Individual> neg, + String owlFile, SortedSet<String> ignoredConcepts){ + + writeROLLearnerOWLFile( filename,toString( pos),toString( neg), + owlFile, ignoredConcepts); + } + + public void writeROLLearnerOWLFile(String filename,SortedSet<String> pos,SortedSet<String> neg, + String owlFile, SortedSet<String> ignoredConcepts){ + + String prefix = "refexamples"; + StringBuffer buf = new StringBuffer(); + buf.append("import(\"" + owlFile + "\");\n\n"); + + buf.append(getIgnoredConcepts(ignoredConcepts,prefix)); + + buf.append(getStandard(prefix)); + + buf.append( getPosAndNeg( pos, neg)); + + + writeToFile(filename, buf.toString()); + + } + + public void writeSPARQL(String filename,SortedSet<String> pos,SortedSet<String> neg, + String uri, SortedSet<String> ignoredConcepts){ + + String prefixAlgortihm = "refexamples"; + String prefixSparql = "sparql"; + + String standardSettings="sparql.recursionDepth = 1;\n" + + "sparql.predefinedFilter = 1;\n" + + "sparql.predefinedEndpoint = 1;\n"; + //"sparql.format = \"KB\";\n\n"; + + StringBuffer buf = new StringBuffer(); + buf.append("import(\"" + uri + "\",\"SPARQL\");\n\n"); + + buf.append(standardSettings); + + buf.append(getIgnoredConcepts(ignoredConcepts,prefixAlgortihm)); + + buf.append(getStandard(prefixAlgortihm)); + + buf.append(sparqlInstances(pos, neg, prefixSparql)); + + buf.append( getPosAndNeg( pos, neg)); + + + writeToFile(filename, buf.toString()); + +} + + public String sparqlInstances(SortedSet<String> pos,SortedSet<String> neg,String prefix){ + SortedSet<String> ret = new TreeSet<String>(); + ret.addAll(pos); + ret.addAll(neg); + + return getStringSet(ret, prefix, "instances"); + + } + + + public String getPosAndNeg(SortedSet<String> pos,SortedSet<String> neg){ + StringBuffer buf = new StringBuffer(); + buf.append("\n\n"); + for (String individuals : pos) { + buf.append("+\"" + individuals + "\"\n"); + + } + buf.append("\n\n"); + for (String individuals : neg) { + + buf.append("-\"" + individuals + "\"\n"); + } + + return buf.toString(); + } + + public String getIgnoredConcepts(SortedSet<String> ignoredConcepts,String prefix){ + + return getStringSet(ignoredConcepts,prefix, "ignoredConcepts"); + } + + public String getStringSet(SortedSet<String> set,String prefix, String type){ + if(set.size()==0)return "\n"; + String ret = prefix+"."+type+"={\n"; + int x=0; + for (String string : set) { + if(x>0)ret+=","; + ret+="\""+string+"\"\n"; + x++; + } + ret+="};\n"; + return ret; + } + + public String getStandard(String prefix){ + String ret = + "algorithm = "+prefix+";\n"+ + "reasoner=fastInstanceChecker;\n\n"+ + + prefix+".useAllConstructor = false;\n"+ + prefix+".useExistsConstructor = true;\n"+ + prefix+".useCardinalityRestrictions = false;\n"+ + prefix+".useNegation = false;\n"; + + return ret; + + } + + + protected void writeToFile(String filename, String content) { + // create the file we want to use + File file = new File(workingDir+filename); + + try { + file.createNewFile(); + FileOutputStream fos = new FileOutputStream(workingDir+filename, false); + // ObjectOutputStream o = new ObjectOutputStream(fos); + fos.write(content.getBytes()); + fos.flush(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + protected SortedSet<String> toString(SortedSet<Individual> set ){ + SortedSet<String> ret = new TreeSet<String>(); + for (Individual ind : set) { + ret.add(ind.toString()); + } + return ret; + } + + +} Added: trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java 2008-04-22 13:07:07 UTC (rev 806) @@ -0,0 +1,97 @@ +package org.dllearner.utilities; + +import java.util.HashSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +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.owl.Individual; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.reasoning.FastInstanceChecker; + +public class LearnSparql { + + + public void learn(SortedSet<String> posExamples,SortedSet<String> negExamples, + String uri, SortedSet<String> ignoredConcepts){ + + ComponentManager cm = ComponentManager.getInstance(); + LearningAlgorithm la = null; + ReasoningService rs = null; + LearningProblem lp = null; + SparqlKnowledgeSource ks =null; + try { + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); + + ks = cm.knowledgeSource(SparqlKnowledgeSource.class); + + SortedSet<String> instances = new TreeSet<String>(); + instances.addAll(posExamples); + instances.addAll(negExamples); + cm.applyConfigEntry(ks, "instances",instances); + cm.applyConfigEntry(ks, "url",uri); + cm.applyConfigEntry(ks, "recursionDepth",1); + cm.applyConfigEntry(ks, "predefinedFilter",1); + cm.applyConfigEntry(ks, "predefinedEndpoint",1); + //cm.applyConfigEntry(ks, "format","KB"); + + ks.init(); + sources.add(ks); + //System.out.println(ks.getNTripleURL()); + // + + ReasonerComponent r = new FastInstanceChecker(sources); + //cm.applyConfigEntry(r,"useAllConstructor",false); + //cm.applyConfigEntry(r,"useExistsConstructor",true); + r.init(); + rs = new ReasoningService(r); + + lp = new PosNegDefinitionLP(rs); + //cm.applyConfigEntry(lp, "positiveExamples",toInd(posExamples)); + ((PosNegLP) lp).setPositiveExamples(toInd(posExamples)); + ((PosNegLP) lp).setNegativeExamples(toInd(negExamples)); + //cm.applyConfigEntry(lp, "negativeExamples",toInd(negExamples)); + lp.init(); + + 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,"minExecutionTimeInSeconds",10); + cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",10); + + //cm.applyConfigEntry(la,"quiet",false); + if(ignoredConcepts.size()>0) + cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts); + la.init(); + + System.out.println("start learning"); + la.start(); + + //System.out.println("best"+la(20)); + ((ExampleBasedROLComponent)la).printBestSolutions(20); + + }catch (Exception e) {e.printStackTrace();} + //System.out.println( la.getBestSolution());; + } + + protected SortedSet<Individual> toInd(SortedSet<String> set ){ + SortedSet<Individual> ret = new TreeSet<Individual>(); + for (String ind : set) { + ret.add(new Individual(ind)); + } + return ret; + } + +} Added: trunk/src/dl-learner/org/dllearner/utilities/NT2RDF.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/NT2RDF.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/NT2RDF.java 2008-04-22 13:07:07 UTC (rev 806) @@ -0,0 +1,35 @@ +package org.dllearner.utilities; +import java.io.File; +import java.net.URI; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.io.RDFXMLOntologyFormat; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyManager; +public class NT2RDF { + + + public static void main(String[] args) { + try { + String ontopath=args[0]; + URI inputURI = new File(ontopath).toURI(); + + // outputURI + String ending = ontopath.substring(ontopath.lastIndexOf(".") + 1); + ontopath = ontopath.replace("." + ending, ".rdf" ); + URI outputURI = new File(ontopath).toURI(); + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(inputURI); + manager.saveOntology(ontology, new RDFXMLOntologyFormat(), outputURI); + // Remove the ontology from the manager + manager.removeOntology(ontology.getURI()); + } + catch (Exception e) { + System.out.println("The ontology could not be created: " + e.getMessage()); + } + + } + } + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |