From: <ku...@us...> - 2008-08-29 18:29:15
|
Revision: 1136 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1136&view=rev Author: kurzum Date: 2008-08-29 18:29:12 +0000 (Fri, 29 Aug 2008) Log Message: ----------- AutomaticExampleFinder + java interface for learning Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/utilities/JamonMonitorLogger.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/learn/ConfWriter.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFileConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -27,17 +27,19 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Logger; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; -import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.SubsumptionHierarchy; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.owl.OWLVocabulary; /** * The reasoning service is the interface to the used reasoner. Basically, @@ -50,6 +52,8 @@ * */ public class ReasoningService { + + public static Logger logger = Logger.getLogger(ReasoningService.class); // statistische Daten private long instanceCheckReasoningTimeNs = 0; @@ -150,7 +154,7 @@ public SortedSet<Individual> retrieval(Description concept) { // Test, ob tatsächlich keine doppelten Retrievals ausgeführt werden // retrievals.add(concept); - + reasoningStartTimeTmp = System.nanoTime(); SortedSet<Individual> result; try { @@ -377,6 +381,10 @@ public SubsumptionHierarchy getSubsumptionHierarchy() { try { + if(reasoner.getSubsumptionHierarchy() == null){ + this.prepareSubsumptionHierarchy(); + } + nrOfSubsumptionHierarchyQueries++; return reasoner.getSubsumptionHierarchy(); } catch (ReasoningMethodUnsupportedException e) { @@ -592,6 +600,24 @@ atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); return atomicConceptsList; } + + public List<NamedClass> getAtomicConceptsList(boolean removeOWLThing) { + if(!removeOWLThing) { + return getAtomicConceptsList(); + }else { + List<NamedClass> l = new LinkedList<NamedClass>(); + for (NamedClass class1 : getAtomicConceptsList()) { + if(class1.compareTo(new NamedClass(OWLVocabulary.OWL_NOTHING)) == 0 || + class1.compareTo(new NamedClass(OWLVocabulary.OWL_THING)) == 0 ){ + ;//do nothing + }else{ + l.add(class1); + } + } + return l; + } + + } public List<ObjectProperty> getAtomicRolesList() { if(atomicRolesList == null) Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -80,7 +80,7 @@ static int recursionDepthDefault = 1; //RBC - static final boolean debug = false; + static final boolean debug = true; static final boolean debugUseImprovedTupleAquisitor = debug && false; //switches tupleaquisitor static final boolean debugExitAfterExtraction = debug && false; //switches sysex und rdf generation static final boolean debugAdditionallyGenerateRDF = debug && true; Modified: trunk/src/dl-learner/org/dllearner/scripts/Sample.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -124,6 +124,7 @@ // reasoner ReasonerComponent r = cm.reasoner(FastInstanceChecker.class, ks); ReasoningService rs = cm.reasoningService(r); + // learning problem LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Added: trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,351 @@ +/** + * 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.util.ArrayList; +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.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.extraction.ExtractionAlgorithm; +import org.dllearner.kb.extraction.Manager; +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.utilities.datastructures.SetManipulation; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderOWL; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; +import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderOWL; +import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; +import org.dllearner.utilities.learn.ConfWriter; +import org.dllearner.utilities.learn.LearnOWLFile; +import org.dllearner.utilities.learn.LearnOWLFileConfiguration; +import org.dllearner.utilities.learn.LearnSPARQLConfiguration; +import org.dllearner.utilities.owl.ReasoningServiceFactory; +import org.dllearner.utilities.owl.ReasoningServiceFactory.AvailableReasoners; +import org.dllearner.utilities.statistics.SimpleClock; + +public class SemanticBible { + + private static ReasoningService reasoningService; + + private static Logger logger = Logger.getRootLogger(); + + // size of randomly choosen negative examples compared to positives + public static double NEGFACTOR = 3.0; + + // different negative Ex (randomizes) each run, if set to false + private static final boolean DEVELOP = true; + + public static String ontologyPath = "examples/semantic_bible/NTNcombined.owl"; + + /** + * @param args + */ + public static void main(String[] args) { + SimpleClock sc = new SimpleClock(); + initLogger(); + logger.info("Start"); + + //String fileURL = new File(ontologyFile).toURI().toString(); + + reasoningService = ReasoningServiceFactory.getReasoningService( + ontologyPath, AvailableReasoners.OWLAPIREASONERPELLET); + // SortedSet<NamedClass> classesToRelearn = new + // TreeSet<NamedClass>(rs.getAtomicConceptsList(true)); + // for (NamedClass target : classesToRelearn) { + // System.out.println("classesToRelearn.add(new + // NamedClass(\""+target.toString()+"\"));"); + + // } + + SortedSet<NamedClass> classesToRelearn = getClassesToRelearn(true); + SortedSet<Individual> positiveEx = new TreeSet<Individual>(); + SortedSet<Individual> negativeEx = new TreeSet<Individual>(); + + for (NamedClass target : classesToRelearn) { + positiveEx.clear(); + negativeEx.clear(); + + AutomaticPositiveExampleFinderOWL ape = new AutomaticPositiveExampleFinderOWL( + reasoningService); + ape.makePositiveExamplesFromConcept(target); + positiveEx = ape.getPosExamples(); + + AutomaticNegativeExampleFinderOWL ane = new AutomaticNegativeExampleFinderOWL( + positiveEx, reasoningService); + ane.makeNegativeExamplesFromSuperClasses(target); + ane.makeNegativeExamplesFromAllOtherInstances(); + //double correct = () + // System.out.println((positiveEx.size()*NEGFACTOR)); + negativeEx = ane.getNegativeExamples( + (int) (positiveEx.size() * NEGFACTOR), DEVELOP); + + // reasoningService.prepareSubsumptionHierarchy(); + // System.out.println(reasoningService.getMoreGeneralConcepts(target)); + + // for every class execute the learning algorithm + learnOriginal(target, positiveEx, negativeEx); + + } + + sc.printAndSet("Finished"); + // JamonMonitorLogger.printAllSortedByLabel(); + + } + + private static void learnOriginal(NamedClass target, SortedSet<Individual> posExamples, SortedSet<Individual> negExamples) { + List<EvaluatedDescription> conceptresults = new ArrayList<EvaluatedDescription>(); + System.out.println("Starting to learn original"); + //System.out.println(ConfWriter.listExamples(true, posExamples)); + //System.out.println(ConfWriter.listExamples(false, negExamples)); + //System.exit(0); + LearnOWLFile learner = new LearnOWLFile(getConfForOriginal(target)); + LearningAlgorithm la = null; + try{ + la = learner.learn( + SetManipulation.indToString(posExamples), + SetManipulation.indToString(negExamples), + FastInstanceChecker.class); + }catch (Exception e) { + // TODO: handle exception + } + la.start(); + System.out.println(la.getCurrentlyBestDescription()); + } + + private static LearnSPARQLConfiguration getConfForSparql(NamedClass c) { + LearnSPARQLConfiguration lsc = new LearnSPARQLConfiguration(); + // lsc.sparqlEndpoint = sparqlTasks.getSparqlEndpoint(); + + + lsc.recursiondepth = 2; + lsc.closeAfterRecursion = true; + lsc.ignoredConcepts.add(c.toString()); + + lsc.noisePercentage = 20; + lsc.guaranteeXgoodDescriptions = 100; + lsc.maxExecutionTimeInSeconds = 50; + + // lsc.searchTreeFile = "log/WikipediaCleaner.txt"; + + return lsc; + + } + + private static LearnOWLFileConfiguration getConfForOriginal(NamedClass c) { + LearnOWLFileConfiguration loc = new LearnOWLFileConfiguration(); + + + loc.setOWLFileURL(ontologyPath); + + + //loc.ignoredConcepts.add(c.toString()); + + + loc.noisePercentage = 0; + // loc.guaranteeXgoodDescriptions = 100; + loc.maxExecutionTimeInSeconds = 20; + loc.writeSearchTree = true; + loc.replaceSearchTree = true; + loc.searchTreeFile = "log/treeSemanticBible.txt"; + + return loc; + + } + + private static void initLogger() { + + SimpleLayout layout = new SimpleLayout(); + // create logger (a simple logger which outputs + // its messages to the console) + FileAppender fileAppender = null; + try { + fileAppender = new FileAppender(layout, "log/semBibleLog.txt", + false); + } catch (Exception e) { + e.printStackTrace(); + } + + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.addAppender(fileAppender); + logger.setLevel(Level.DEBUG); + Logger.getLogger(Manager.class).setLevel(Level.INFO); + Level lwarn = Level.DEBUG; + Logger.getLogger(KnowledgeSource.class).setLevel(lwarn); + Logger.getLogger(SparqlKnowledgeSource.class).setLevel(lwarn); + + Logger.getLogger(ExtractionAlgorithm.class).setLevel(lwarn); + Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel( + lwarn); + Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel( + lwarn); + Logger.getLogger(ExampleBasedROLComponent.class).setLevel(lwarn); + Logger.getLogger(SparqlQuery.class).setLevel(lwarn); + Logger.getLogger(Cache.class).setLevel(lwarn); + Logger.getLogger(AutomaticPositiveExampleFinderOWL.class).setLevel( + lwarn); + + } + + public static SortedSet<NamedClass> getClassesToRelearn(boolean firstOnly) { + + SortedSet<NamedClass> classesToRelearn = new TreeSet<NamedClass>(); + if (firstOnly) { + //classesToRelearn.add(new NamedClass( + // "http://semanticbible.org/ns/2006/NTNames#Angel")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Woman")); + + } else { + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Agent")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Angel")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#BeliefGroup")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#BeliefSystem")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Character")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#CitizenshipAttribute")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#City")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#CognitiveAgent")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ContentBearingObject")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#EthnicGroup")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#EthnicityAttribute")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#EvilSupernaturalBeing")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#FixedHoliday")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#FreshWaterArea")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#GeographicArea")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#GeographicLocation")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#GeopoliticalArea")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#God")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Group")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#GroupOfPeople")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Human")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#HumanAttribute")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Island")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#LandArea")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Man")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Mountain")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Nation")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#NaturalLanguage")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Object")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Organization")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#PoliticalAttribute")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#PoliticalBeliefSystem")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#PoliticalOrganization")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Region")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ReligiousBelief")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ReligiousBeliefSystem")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ReligiousOrganization")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ResidenceGroup")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#ResidencyAttribute")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#SaltWaterArea")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Series")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#SonOfGod")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#StateOrProvince")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#SupernaturalBeing")); + classesToRelearn + .add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#SupernaturalRegion")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Tribe")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#WaterArea")); + classesToRelearn.add(new NamedClass( + "http://semanticbible.org/ns/2006/NTNames#Woman")); + } + return classesToRelearn; + } + +} Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -226,7 +226,7 @@ lsc.noisePercentage = 20; lsc.guaranteeXgoodDescriptions = 100; lsc.maxExecutionTimeInSeconds = 50; - lsc.logLevel = "TRACE"; + // lsc.searchTreeFile = "log/WikipediaCleaner.txt"; return lsc; Modified: trunk/src/dl-learner/org/dllearner/utilities/JamonMonitorLogger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/JamonMonitorLogger.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/JamonMonitorLogger.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -26,8 +26,10 @@ import java.util.TreeSet; import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.cli.Start; import org.dllearner.kb.extraction.ExtractionAlgorithm; import org.dllearner.kb.manipulator.Manipulator; +import org.dllearner.kb.manipulator.TypeFilterRule; import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SparqlQuery; @@ -116,14 +118,14 @@ retval= "Extraction:"; } else if (clazz == Manipulator.class) { retval= "Extraction:"; + } else if (clazz == Start.class) { + retval= "Init:"; + } else if (clazz == TypeFilterRule.class) { + retval= "Extraction:"; } else if (clazz == SparqlQuery.class) { retval= "sparql:"; } else if (clazz == SparqlQuery.class) { retval= "sparql:"; - } else if (clazz == SparqlQuery.class) { - retval= "sparql:"; - } else if (clazz == SparqlQuery.class) { - retval= "sparql:"; } else if (clazz == ExampleBasedROLComponent.class) { retval= "Learning:"; } else if (clazz == SparqlQuery.class) { Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -41,7 +41,38 @@ } return ret; } + + /** + * shrinks a set to the limit fuzzy here means the elements will be randomly + * picked + * + * @param set + * @param limit + * @return + */ + public static SortedSet<Individual> fuzzyShrinkInd(SortedSet<Individual> set, int limit) { + if (set.size() <= limit) { + return set; + } + SortedSet<Individual> ret = new TreeSet<Individual>(); + Random r = new Random(); + double treshold = ((double) limit) / set.size(); + // System.out.println("treshold"+howmany); + // System.out.println("treshold"+allRetrieved.size()); + // System.out.println("treshold"+treshold); + while (ret.size() < limit) { + for (Individual oneInd : set) { + if (r.nextDouble() < treshold) { + ret.add(oneInd); + if (ret.size() >= limit) + break; + } + } + } + return ret; + } + /** * shrinks a set to the limit takes the first elements up to limit * @@ -65,7 +96,31 @@ return ret; } + + /** + * shrinks a set to the limit takes the first elements up to limit + * + * @param set + * @param limit + * @return + */ + public static SortedSet<Individual> stableShrinkInd(SortedSet<Individual> set, + int limit) { + if (set.size() <= limit) { + return set; + } + SortedSet<Individual> ret = new TreeSet<Individual>(); + for (Individual oneInd : set) { + ret.add(oneInd); + if (ret.size() >= limit) + break; + + } + + return ret; + } + /** * XXX * getFirst n Elements from list. @@ -90,6 +145,14 @@ return ret; } + public static SortedSet<String>indToString(SortedSet<Individual> set) { + SortedSet<String> ret = new TreeSet<String>(); + for (Individual ind : set) { + ret.add(ind.toString()); + } + return ret; + } + public static void printSet(String s, SortedSet set, Logger logger) { if(logger.getLevel().equals(Level.DEBUG)){ logger.info(s +" ["+ set.size()+"]: "+set); Added: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,268 @@ +/** + * 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.utilities.examples; + +import java.util.Collection; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.utilities.datastructures.SetManipulation; + +public class AutomaticNegativeExampleFinderOWL { + + // LOGGER: ComponentManager + private static Logger logger = Logger.getLogger(ComponentManager.class); + + private ReasoningService reasoningService; + + private SortedSet<Individual> fullPositiveSet; + + private SortedSet<Individual> fromRelated = new TreeSet<Individual>(); + private SortedSet<Individual> fromSuperclasses = new TreeSet<Individual>(); + private SortedSet<Individual> fromParallelClasses = new TreeSet<Individual>(); + private SortedSet<Individual> fromAllOther = new TreeSet<Individual>(); + private SortedSet<Individual> fromDomain = new TreeSet<Individual>(); + private SortedSet<Individual> fromRange = new TreeSet<Individual>(); + + static int poslimit = 10; + static int neglimit = 20; + + + /** + * + * takes as input a full positive set to make sure no negatives are added as positives + * + * @param fullPositiveSet + * @param reasoningService + */ + public AutomaticNegativeExampleFinderOWL( + SortedSet<Individual> fullPositiveSet, + ReasoningService reasoningService) { + super(); + this.fullPositiveSet = new TreeSet<Individual>(); + this.fullPositiveSet.addAll(fullPositiveSet); + this.reasoningService = reasoningService; + + } + + /** + * see <code> getNegativeExamples(int neglimit, boolean stable )</code> + * @param neglimit + * @return + */ + public SortedSet<Individual> getNegativeExamples(int neglimit ) { + return getNegativeExamples(neglimit, false); + } + + /** + * aggregates all collected neg examples + * CAVE: it is necessary to call one of the make functions before calling this + * OTHERWISE it will choose random examples + * + * @param neglimit size of negative Example set, 0 means all, which can be quite large + * @param stable decides whether neg Examples are randomly picked, default false, faster for developing, since the cache can be used + * @return + */ + public SortedSet<Individual> getNegativeExamples(int neglimit, boolean stable ) { + SortedSet<Individual> negatives = new TreeSet<Individual>(); + negatives.addAll(fromParallelClasses); + negatives.addAll(fromRelated); + negatives.addAll(fromSuperclasses); + if(negatives.isEmpty()) { + negatives.addAll(fromAllOther); + } + if(neglimit<=0){ + logger.debug("neg Example size NO shrinking: " + negatives.size()); + return negatives; + } + + + logger.debug("neg Example size before shrinking: " + negatives.size()); + if (stable ) { + negatives = SetManipulation.stableShrinkInd(negatives,neglimit); + } + else { + negatives = SetManipulation.fuzzyShrinkInd(negatives,neglimit); + } + logger.debug("neg Example size after shrinking: " + negatives.size()); + return negatives; + } + + + /** + * just takes all other instances from the ontology, except the ones + * in the fullPositiveSet (see Constructor) + */ + public void makeNegativeExamplesFromAllOtherInstances() { + logger.debug("making random examples "); + fromAllOther = reasoningService.getIndividuals(); + fromAllOther.removeAll(fullPositiveSet); + logger.debug("|-negExample size from random: " + fromAllOther.size()); + } + + /** + * NOT IMPLEMENTED YET, DO NOT USE + * makes neg ex from related instances, that take part in a role R(pos,neg) + * filters all objects, that don't use the given namespace + * @param instances + * @param objectNamespace + */ + public void makeNegativeExamplesFromRelatedInstances(SortedSet<Individual> instances, + String objectNamespace) { + logger.debug("making examples from related instances"); + for (Individual oneInstance : instances) { + makeNegativeExamplesFromRelatedInstances(oneInstance, objectNamespace); + } + logger.debug("|-negExample size from related: " + fromRelated.size()); + } + + /** + * NOT IMPLEMENTED YET, DO NOT USE + * @param oneInstance + * @param objectnamespace + */ + private void makeNegativeExamplesFromRelatedInstances(Individual oneInstance, String objectnamespace) { + // SortedSet<String> result = new TreeSet<String>(); + + //reasoningService.getRoleMembers(atomicRole) + + //fromRelated.removeAll(fullPositiveSet); + throw new RuntimeException("method makeNegativeExamplesFromRelatedInstances not implemented yet"); + } + + + + /** + * NOT IMPLEMENTED YET, DO NOT USE + * makes negEx from classes, the posEx belong to. + * Gets all Classes from PosEx, gets Instances from these Classes, returns all + * @param positiveSet + */ + public void makeNegativeExamplesFromParallelClasses(SortedSet<Individual> positiveSet){ + makeNegativeExamplesFromClassesOfInstances(positiveSet); + } + + /** + * NOT IMPLEMENTED YET, DO NOT USE + * see <code> makeNegativeExamplesFromParallelClasses</code> + * @param positiveSet + */ + @SuppressWarnings("unused") + private void makeNegativeExamplesFromClassesOfInstances(SortedSet<Individual> positiveSet) { + logger.debug("making neg Examples from parallel classes"); + SortedSet<Description> classes = new TreeSet<Description>(); + + + for (Individual instance : positiveSet) { + try{ + // realization is not implemented in reasoningservice + //classes.addAll(reasoningService.realize() + }catch (Exception e) { + logger.warn("not implemented in "+this.getClass()); + } + } + logger.debug("getting negExamples from " + classes.size() + " parallel classes"); + for (Description oneClass : classes) { + logger.debug(oneClass); + // rsc = new + // JenaResultSetConvenience(queryConcept("\""+oneClass+"\"",limit)); + try{ + this.fromParallelClasses.addAll(reasoningService.retrieval(oneClass)); + }catch (Exception e) { + logger.warn("not implemented in "+this.getClass()); + } + } + + fromParallelClasses.removeAll(fullPositiveSet); + logger.debug("|-neg Example size from parallelclass: " + fromParallelClasses.size()); + throw new RuntimeException("not implemented in "+ this.getClass()+"method makeNegativeExamplesFromParallelClasses"); + } + + + + + + /** + * if pos ex derive from one class, then neg ex are taken from a superclass + * @param concept + */ + public void makeNegativeExamplesFromSuperClasses(NamedClass concept) { + makeNegativeExamplesFromSuperClasses( concept, 0); + } + + /** + * if pos ex derive from one class, then neg ex are taken from a superclass + * CURRENTLY SAME METHOD AS makeNegativeExamplesFromSuperClasses(NamedClass concept) + * but works quite often + * @param concept + * @param depth PARAMETER CURRENTLY NOT USED, ONLY DIRECT SUPERCLASSES + */ + public void makeNegativeExamplesFromSuperClasses(NamedClass concept, int depth) { + + + SortedSet<Description> superClasses = reasoningService.getMoreGeneralConcepts(concept); + logger.debug("making neg Examples from " + superClasses.size() + " superclasses"); + + for (Description oneSuperClass : superClasses) { + logger.debug(oneSuperClass); + fromSuperclasses.addAll(reasoningService.retrieval(oneSuperClass)); + } + this.fromSuperclasses.removeAll(fullPositiveSet); + logger.debug("|-neg Example from superclass: " + fromSuperclasses.size()); + } + + /** + * misleading method name, + * examples are all instances from the a-Part of the atomicRole(a,b) + * it has nothing to do with the actual Domain class + * @param atomicRole + */ + + public void makeNegativeExamplesFromDomain(ObjectProperty atomicRole){ + logger.debug("making Negative Examples from Domain of : "+atomicRole); + fromDomain.addAll(reasoningService.getRoleMembers(atomicRole).keySet()); + fromDomain.removeAll(fullPositiveSet); + logger.debug("|-neg Example size from Domain: "+this.fromDomain.size()); + } + + /** + * misleading method name, + * examples are all instances from the b-Part of the atomicRole(a,b) + * it has nothing to do with the actual Range class + * @param atomicRole + */ + + public void makeNegativeExamplesFromRange(ObjectProperty atomicRole){ + logger.debug("making Negative Examples from Range of : "+atomicRole); + Collection<SortedSet<Individual>> tmp = reasoningService.getRoleMembers(atomicRole).values(); + for (SortedSet<Individual> set : tmp) { + fromRange.addAll(set); + } + fromRange.removeAll(fullPositiveSet); + logger.debug("|-neg Example size from Range: "+fromRange.size()); + } +} Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -60,11 +60,19 @@ SortedSet<String> fullPositiveSet, SPARQLTasks st) { super(); - this.fullPositiveSet = fullPositiveSet; + this.fullPositiveSet = new TreeSet<String>(); + this.fullPositiveSet.addAll(fullPositiveSet); this.sparqltasks = st; } + + + /** + * see <code> getNegativeExamples(int neglimit, boolean stable )</code> + * @param neglimit + * @return + */ public SortedSet<String> getNegativeExamples(int neglimit ) { return getNegativeExamples(neglimit, false); } @@ -72,8 +80,9 @@ /** * aggregates all collected neg examples * CAVE: it is necessary to call one of the make functions before calling this + * OTHERWISE it will choose random examples * - * @param neglimit size of negative Example set + * @param neglimit size of negative Example set, 0 means all, which can be quite large several thousands * @param stable decides whether neg Examples are randomly picked, default false, faster for developing, since the cache can be used * @return */ @@ -85,6 +94,11 @@ if(negatives.isEmpty()) { negatives.addAll(fromRandom); } + if(neglimit<=0){ + logger.debug("neg Example size NO shrinking: " + negatives.size()); + return negatives; + } + logger.debug("neg Example size before shrinking: " + negatives.size()); if (stable) { negatives = SetManipulation.stableShrink(negatives,neglimit); @@ -106,7 +120,7 @@ fromRandom = sparqltasks.queryAsSet(sparqlQueryString, variable); fromRandom.removeAll(fullPositiveSet); - logger.debug("|-negExample size from related: " + fromRelated.size()); + logger.debug("|-negExample size from random: " + fromRandom.size()); } /** Added: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,45 @@ +package org.dllearner.utilities.examples; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; + +public class AutomaticPositiveExampleFinderOWL { + + // LOGGER: ComponentManager + private static Logger logger = Logger + .getLogger(AutomaticPositiveExampleFinderOWL.class); + + + private ReasoningService reasoningService; + + private SortedSet<Individual> posExamples; + + public AutomaticPositiveExampleFinderOWL(ReasoningService reasoningService) { + + this.posExamples = new TreeSet<Individual>(); + this.reasoningService = reasoningService; + } + + //QUALITY resultsize is not accounted for + public void makePositiveExamplesFromConcept(Description concept){ + logger.debug("making Positive Examples from Concept: "+concept); + this.posExamples = reasoningService.retrieval(concept); + //this.posExamples = sparqltasks.retrieveInstancesForClassDescription(conceptKBSyntax, 0); + logger.debug("pos Example size: "+posExamples.size()); + } + + + public SortedSet<Individual> getPosExamples() { + return posExamples; + } + + + + + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/learn/ConfWriter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/ConfWriter.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/ConfWriter.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -150,6 +150,18 @@ } return ret; } + + + public static String listExamples (boolean posOrNeg, SortedSet<Individual> s ){ + StringBuffer sbuf = new StringBuffer(); + String sign = (posOrNeg)?"+":"-"; + for (Individual individual : s) { + sbuf.append(sign+"\""+individual+"\"\n"); + } + + return sbuf.toString(); + } + public void addToStats(String add) { stats.append(add); Added: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnConfiguration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnConfiguration.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnConfiguration.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,63 @@ +package org.dllearner.utilities.learn; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; + +public class LearnConfiguration { + + public double noisePercentage = 0; + public int maxExecutionTimeInSeconds = 0; + public int minExecutionTimeInSeconds = 0; + public int guaranteeXgoodDescriptions = 1; + + public SortedSet<String> ignoredConcepts = new TreeSet<String>(); + + public boolean useAllConstructor = false; + public boolean useExistsConstructor = true; + public boolean useCardinalityRestrictions = false; + public boolean useNegation = false; + + public boolean writeSearchTree = false; + public String searchTreeFile = "log/searchTree.txt"; + public boolean replaceSearchTree = true; + + + public void applyConfigEntries(ComponentManager cm, KnowledgeSource ks, LearningProblem lp, ReasoningService rs, LearningAlgorithm la) { + try { + + // LEARNINGALGORITHM + cm.applyConfigEntry(la, "useAllConstructor", useAllConstructor); + cm.applyConfigEntry(la, "useExistsConstructor", useExistsConstructor); + cm.applyConfigEntry(la, "useCardinalityRestrictions", useCardinalityRestrictions); + cm.applyConfigEntry(la, "useNegation", useNegation); + + cm.applyConfigEntry(la, "minExecutionTimeInSeconds", minExecutionTimeInSeconds); + cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + cm.applyConfigEntry(la, "guaranteeXgoodDescriptions", + guaranteeXgoodDescriptions); + + cm.applyConfigEntry(la, "writeSearchTree", writeSearchTree); + cm.applyConfigEntry(la, "searchTreeFile", searchTreeFile); + cm.applyConfigEntry(la, "replaceSearchTree", replaceSearchTree); + + cm.applyConfigEntry(la, "noisePercentage", noisePercentage); + + if(ignoredConcepts.size()>0) { + cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts); + } + + + } catch (Exception e) { + e.printStackTrace(); + } + // return null; + + } +} Added: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,95 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>.**/ +package org.dllearner.utilities.learn; + +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +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.kb.OWLFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; + +/** + * + * + * @author Sebastian Hellmann + * + * + */ +public class LearnOWLFile { + + private static Logger logger = Logger.getLogger(LearnOWLFile.class); + + public LearnOWLFileConfiguration configuration; + + public LearnOWLFile (LearnOWLFileConfiguration configuration){ + this.configuration = configuration; + } + + //return will be replaced by List Description + public LearningAlgorithm learn( SortedSet<String> posExamples, + SortedSet<String> negExamples, Class<? extends ReasonerComponent> Reasoner) 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); + + // reasoner + ReasonerComponent r = cm.reasoner(Reasoner, 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); + + + configuration.applyConfigEntries(cm, ks, lp, rs, la); + + + // all components need to be initialised before they can be used + ks.init(); + r.init(); + lp.init(); + la.init(); + + return la; + + } + +} Added: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFileConfiguration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFileConfiguration.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFileConfiguration.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,38 @@ +package org.dllearner.utilities.learn; + +import java.io.File; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; + +public class LearnOWLFileConfiguration extends LearnConfiguration { + + + + // SparqlKnowledgeSource + public String OWLFileURL = ""; + + + public void setOWLFileURL(String ontologyPath){ + OWLFileURL = new File(ontologyPath).toURI().toString(); + + } + + @Override + public void applyConfigEntries(ComponentManager cm, KnowledgeSource ks, LearningProblem lp, ReasoningService rs, LearningAlgorithm la) { + try { + super.applyConfigEntries(cm, ks, lp, rs, la); + // KNOWLEDGESOURCE + cm.applyConfigEntry(ks, "url", OWLFileURL); + + + } catch (Exception e) { + e.printStackTrace(); + } + // return null; + + } +} Modified: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -8,7 +8,7 @@ import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SparqlEndpoint; -public class LearnSPARQLConfiguration { +public class LearnSPARQLConfiguration extends LearnConfiguration { @@ -19,27 +19,11 @@ public boolean randomizeCache = false; public String predefinedFilter = "YAGO"; - - public double noisePercentage = 15; - public int maxExecutionTimeInSeconds = 30; - public int minExecutionTimeInSeconds = 0; - public int guaranteeXgoodDescriptions = 40; - - public boolean useAllConstructor = false; - public boolean useExistsConstructor = true; - public boolean useCardinalityRestrictions = false; - public boolean useNegation = false; - - public boolean writeSearchTree = false; - public String searchTreeFile = "log/searchTree.txt"; - public boolean replaceSearchTree = true; - public String logLevel = "TRACE"; - - - + + @Override public void applyConfigEntries(ComponentManager cm, KnowledgeSource ks, LearningProblem lp, ReasoningService rs, LearningAlgorithm la) { try { - + super.applyConfigEntries(cm, ks, lp, rs, la); // KNOWLEDGESOURCE cm.applyConfigEntry(ks, "url", sparqlEndpoint.getURL().toString()); cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA"); @@ -52,32 +36,8 @@ else { cm.applyConfigEntry(ks, "cacheDir", Cache.getDefaultCacheDir()); } - - - // LEARNINGALGORITHM - cm.applyConfigEntry(la, "useAllConstructor", useAllConstructor); - cm.applyConfigEntry(la, "useExistsConstructor", useExistsConstructor); - cm.applyConfigEntry(la, "useCardinalityRestrictions", useCardinalityRestrictions); - cm.applyConfigEntry(la, "useNegation", useNegation); - - cm.applyConfigEntry(la, "minExecutionTimeInSeconds", minExecutionTimeInSeconds); - cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - cm.applyConfigEntry(la, "guaranteeXgoodDescriptions", - guaranteeXgoodDescriptions); - - cm.applyConfigEntry(la, "writeSearchTree", writeSearchTree); - cm.applyConfigEntry(la, "searchTreeFile", searchTreeFile); - cm.applyConfigEntry(la, "replaceSearchTree", replaceSearchTree); - - cm.applyConfigEntry(la, "noisePercentage", noisePercentage); - cm.applyConfigEntry(la, "logLevel", logLevel); - /* - * if(ignoredConcepts.size()>0) - * cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts); - */ - - + + } catch (Exception e) { e.printStackTrace(); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-29 18:26:42 UTC (rev 1135) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -34,6 +34,8 @@ public static final String OWL_SUBCLASS_OF = "http://www.w3.org/2002/07/owl#subClassOf"; public static final String OWL_THING = "http://www.w3.org/2002/07/owl#Thing"; + public static final String OWL_NOTHING = "http://www.w3.org/2002/07/owl#Nothing"; + //OWL2 Namespace: http://www.w3.org/2006/12/owl2# public static boolean isStringClassVocab (String possClass){ Added: trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java 2008-08-29 18:29:12 UTC (rev 1136) @@ -0,0 +1,107 @@ +/** + * Copyright (C) 2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package org.dllearner.utilities.owl; + +import java.io.File; +import java.util.List; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.OWLFile; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.OWLAPIReasoner; + +/** + * This class should maybe be included in ReasoningService + * + * @author Sebastian Hellmann + * + */ +public class ReasoningServiceFactory { + + public enum AvailableReasoners {FASTINSTANCECHECKER, OWLAPIREASONERPELLET, OWLAPIREASONERFACT}; + + public static void main(String[] args) { + String ontologyURL = "examples/arch/arch.owl"; + System.out.println(ontologyURL); + + ReasoningService rs; + for (AvailableReasoners r : AvailableReasoners.values()) { + System.out.println(r); + rs = getReasoningService(ontologyURL, r); + List<NamedClass> l = rs.getAtomicConceptsList(); + System.out.println(l); + l = rs.getAtomicConceptsList(true); + + System.out.println(l); + } + + + } + + public static ReasoningService getReasoningService (String ontologyFile, AvailableReasoners r ){ + ReasoningService rs = null; + try{ + // 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(ontologyFile).toURI().toString(); + cm.applyConfigEntry(ks, "url", fileURL); + ks.init(); + + // reasoner + ReasonerComponent rc; + switch (r) { + case FASTINSTANCECHECKER: + rc = cm.reasoner(FastInstanceChecker.class, ks); + break; + case OWLAPIREASONERFACT: + rc = cm.reasoner(OWLAPIReasoner.class, ks); + ((OWLAPIReasoner)rc).setReasonerType("fact"); + break; + case OWLAPIREASONERPELLET: + rc = cm.reasoner(OWLAPIReasoner.class, ks); + ((OWLAPIReasoner)rc).setReasonerType("pellet"); + break; + default: + rc = cm.reasoner(FastInstanceChecker.class, ks); + break; + } + + + rs = cm.reasoningService(rc); + rc.init(); + }catch (Exception e) { + e.printStackTrace(); + } + return rs; + } + + + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |