From: <jen...@us...> - 2007-09-26 16:57:56
|
Revision: 156 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=156&view=rev Author: jenslehmann Date: 2007-09-26 09:57:52 -0700 (Wed, 26 Sep 2007) Log Message: ----------- - proper component detection in the core package - constructor detection for learning algorithms - learning problem adapted to new configuration and improved - GP algorithm adapted to new structure - first successful simple test using random guesser => warning: parts of DL-Learner will not work as expected anymore Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/lib/components.ini 2007-09-26 16:57:52 UTC (rev 156) @@ -3,6 +3,7 @@ # knowledge sources org.dllearner.kb.OWLFile # reasoners +org.dllearner.reasoning.DIGReasonerNew # learning problems org.dllearner.learningproblems.DefinitionLPTwoValued # learning algorithms Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-09-26 16:57:52 UTC (rev 156) @@ -13,6 +13,7 @@ import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; +import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; public class Config { @@ -149,17 +150,13 @@ public static Heuristic heuristic = Heuristic.LEXICOGRAPHIC; - public enum UseDIGMultiInstanceChecks { - NEVER, TWOCHECKS, ONECHECK - }; - // multi instance check => es wird versucht mehrere instance checks pro // Anfrage auf einmal an den Reasoner zu schicken; Vorteil bei DIG: // weniger Kommunikation; Nachteil: es müssen alle instanceChecks // ausgeführt // werden, bevor too weak festgestellt werden kann // TODO: not implemented - public static UseDIGMultiInstanceChecks useDIGMultiInstanceChecks = UseDIGMultiInstanceChecks.TWOCHECKS; + public static UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; // geplante Optionen um den Suchraum einzuschränken Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-09-26 16:57:52 UTC (rev 156) @@ -531,14 +531,14 @@ } } else if (option.equals("useRetrievalForClassification")) Config.useRetrievalForClassification = strToBool(value); - else if (option.equals("refinement.useDIGMultiInstanceChecks")) { - if(value.equals("never")) - Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.NEVER; - else if(value.equals("twoChecks")) - Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.TWOCHECKS; - else if(value.equals("oneCheck")) - Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.ONECHECK; - } +// else if (option.equals("refinement.useDIGMultiInstanceChecks")) { +// if(value.equals("never")) +// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.NEVER; +// else if(value.equals("twoChecks")) +// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.TWOCHECKS; +// else if(value.equals("oneCheck")) +// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.ONECHECK; +// } } private void applySetOptions(String optionString, Set<String> setValues) { Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-09-26 16:57:52 UTC (rev 156) @@ -9,6 +9,7 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.Negation; +import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; import org.dllearner.utilities.SortedSetTuple; @@ -79,11 +80,11 @@ //} else // throw new Error("LP not completely implemented"); } else { - if(Refinement.useDIGMultiInstanceChecks != Config.Refinement.UseDIGMultiInstanceChecks.NEVER) { + if(Refinement.useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { // Option wird nur bei DIG-Reasoner genutzt, ansonsten einfach ignoriert if(Config.reasonerType == ReasonerType.DIG) { // two checks - if(Config.Refinement.useDIGMultiInstanceChecks == Config.Refinement.UseDIGMultiInstanceChecks.TWOCHECKS) { + if(Config.Refinement.useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); // if the concept is too weak, then do not query negative examples if(s.size()!=positiveExamples.size()) Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-09-26 16:57:52 UTC (rev 156) @@ -45,6 +45,8 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningProblemNew; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; @@ -58,6 +60,8 @@ import org.dllearner.core.dl.KB; import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.RoleAssertion; +import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.DefinitionLPTwoValued; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.DLLearner; import org.dllearner.parser.ParseException; @@ -401,7 +405,7 @@ processQueryMode(reasoner); } else { if (Config.statisticMode) - createStatistics(learningProblem, baseDir); + ; // createStatistics(learningProblem, baseDir); else { rs.resetStatistics(); @@ -411,11 +415,11 @@ LearningAlgorithm la = new BruteForceLearner(learningProblem); la.start(); } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { - new RandomGuesser(learningProblem, 10000, 10); + // new RandomGuesser(learningProblem, 10000, 10); } else if (Config.algorithm == Algorithm.GP || Config.algorithm == Algorithm.HYBRID_GP) { - LearningAlgorithm la = new GP(learningProblem); - la.start(); + //LearningAlgorithm la = new GP(learningProblem); + //la.start(); } else { if (Config.Refinement.improveSubsumptionHierarchy) { // if(Config.reasonerType == ReasonerType.DIG) { @@ -741,83 +745,83 @@ // Statistikerzeugung wird ausgelagert, damit im "normalen" Programm // nichts ge�ndert werden muss - private void createStatistics(LearningProblem learningProblem, String baseDir) { +// private void createStatistics(LearningProblemNew learningProblem, String baseDir) { +// +// int runs = 20; +// LearningAlgorithm alg; +// +// Stat stat1 = new Stat(); +// Stat stat2 = new Stat(); +// Stat stat3 = new Stat(); +// // Stat stat4 = new Stat(); +// File exportFile1 = new File(baseDir, "../../stats/guesser.data"); +// File exportFile2 = new File(baseDir, "../../stats/gp1.data"); +// File exportFile3 = new File(baseDir, "../../stats/gp2.data"); +// // File exportFile4 = new File(baseDir, "../../stats/gp3.data"); +// StringBuilder exportString1 = new StringBuilder(); +// StringBuilder exportString2 = new StringBuilder(); +// StringBuilder exportString3 = new StringBuilder(); +// // StringBuilder exportString4 = new StringBuilder(); +// +// for (int i = 1000; i <= 30000; i += 2000) { +// stat1 = new Stat(); +// stat2 = new Stat(); +// stat3 = new Stat(); +// // stat4 = new Stat(); +// for (int run = 0; run < runs; run++) { +// System.out.println("============="); +// System.out.println("i " + i + " run " + run); +// System.out.println("============="); +// alg = new RandomGuesser(learningProblem, i, 6); +// stat1.addNumber(alg.getSolutionScore().getScore() - 0.1 +// * alg.getBestSolution().getLength()); +// +// Config.GP.numberOfIndividuals = i / 10; +// Config.GP.mutationProbability = 0.03f; +// Config.GP.crossoverProbability = 0.9f; +// Config.GP.hillClimbingProbability = 0.0f; +// alg = new GP(learningProblem); +// stat2.addNumber(alg.getSolutionScore().getScore() - 0.1 +// * alg.getBestSolution().getLength()); +// +// // wie GP 1, aber mit Hill Climbing +// Config.GP.crossoverProbability = 0.8f; +// Config.GP.hillClimbingProbability = 0.15f; +// alg = new GP(learningProblem); +// stat3.addNumber(alg.getSolutionScore().getScore() - 0.1 +// * alg.getBestSolution().getLength()); +// // stat.addNumber(((GP)alg).fittestIndividualGeneration); +// +// // wie GP 1, aber mit festem return type +// /* +// * Config.GP.crossoverProbability = 0.85f; +// * Config.GP.hillClimbingProbability = 0.0f; Config.returnType = +// * "male"; alg = new GP(); +// * stat4.addNumber(alg.getSolutionScore().getScore()-0.1*alg.getBestSolution().getConceptLength()); +// * Config.returnType = ""; +// */ +// +// } +// exportString1.append(i + " " + stat1.getMean() + " " +// + stat1.getStandardDeviation() + "\n"); +// exportString2.append(i + " " + stat2.getMean() + " " +// + stat2.getStandardDeviation() + "\n"); +// exportString3.append(i + " " + stat3.getMean() + " " +// + stat3.getStandardDeviation() + "\n"); +// // exportString4.append(i + " " + stat4.getMean() + " " + +// // stat4.getStandardDeviation() + "\n"); +// } +// +// createFile(exportFile1, exportString1.toString()); +// createFile(exportFile2, exportString2.toString()); +// createFile(exportFile3, exportString3.toString()); +// // createFile(exportFile4, exportString4.toString()); +// } - int runs = 20; - LearningAlgorithm alg; - - Stat stat1 = new Stat(); - Stat stat2 = new Stat(); - Stat stat3 = new Stat(); - // Stat stat4 = new Stat(); - File exportFile1 = new File(baseDir, "../../stats/guesser.data"); - File exportFile2 = new File(baseDir, "../../stats/gp1.data"); - File exportFile3 = new File(baseDir, "../../stats/gp2.data"); - // File exportFile4 = new File(baseDir, "../../stats/gp3.data"); - StringBuilder exportString1 = new StringBuilder(); - StringBuilder exportString2 = new StringBuilder(); - StringBuilder exportString3 = new StringBuilder(); - // StringBuilder exportString4 = new StringBuilder(); - - for (int i = 1000; i <= 30000; i += 2000) { - stat1 = new Stat(); - stat2 = new Stat(); - stat3 = new Stat(); - // stat4 = new Stat(); - for (int run = 0; run < runs; run++) { - System.out.println("============="); - System.out.println("i " + i + " run " + run); - System.out.println("============="); - alg = new RandomGuesser(learningProblem, i, 6); - stat1.addNumber(alg.getSolutionScore().getScore() - 0.1 - * alg.getBestSolution().getLength()); - - Config.GP.numberOfIndividuals = i / 10; - Config.GP.mutationProbability = 0.03f; - Config.GP.crossoverProbability = 0.9f; - Config.GP.hillClimbingProbability = 0.0f; - alg = new GP(learningProblem); - stat2.addNumber(alg.getSolutionScore().getScore() - 0.1 - * alg.getBestSolution().getLength()); - - // wie GP 1, aber mit Hill Climbing - Config.GP.crossoverProbability = 0.8f; - Config.GP.hillClimbingProbability = 0.15f; - alg = new GP(learningProblem); - stat3.addNumber(alg.getSolutionScore().getScore() - 0.1 - * alg.getBestSolution().getLength()); - // stat.addNumber(((GP)alg).fittestIndividualGeneration); - - // wie GP 1, aber mit festem return type - /* - * Config.GP.crossoverProbability = 0.85f; - * Config.GP.hillClimbingProbability = 0.0f; Config.returnType = - * "male"; alg = new GP(); - * stat4.addNumber(alg.getSolutionScore().getScore()-0.1*alg.getBestSolution().getConceptLength()); - * Config.returnType = ""; - */ - - } - exportString1.append(i + " " + stat1.getMean() + " " - + stat1.getStandardDeviation() + "\n"); - exportString2.append(i + " " + stat2.getMean() + " " - + stat2.getStandardDeviation() + "\n"); - exportString3.append(i + " " + stat3.getMean() + " " - + stat3.getStandardDeviation() + "\n"); - // exportString4.append(i + " " + stat4.getMean() + " " + - // stat4.getStandardDeviation() + "\n"); - } - - createFile(exportFile1, exportString1.toString()); - createFile(exportFile2, exportString2.toString()); - createFile(exportFile3, exportString3.toString()); - // createFile(exportFile4, exportString4.toString()); - } - // erzeugt Statistiken für MLDM-Paper zur Verarbeitung mit GnuPlot // Vorsicht: Laufzeit von mehreren Stunden @SuppressWarnings("unused") - private void createStatisticsMLDMPaper(LearningProblem learningProblem, String baseDir) { + private void createStatisticsMLDMPaper(DefinitionLP learningProblem, String baseDir) { // Algorithmus 1: hybrid GP (100% refinement) // Algorithmus 2: 50% refinement, 40% crossover, 1% mutation // Algorithmus 3: 80% crossover, 2% mutation @@ -856,6 +860,8 @@ fileAr[3][1] = new File(baseDir, "gnuplot/extralength.data"); fileAr[3][2] = new File(baseDir, "gnuplot/extraruntime.data"); + ComponentManager cm = ComponentManager.getInstance(); + long overallTimeStart = System.nanoTime(); // allgemeine Einstellungen @@ -881,7 +887,10 @@ reasoner = new DIGReasoner(kb, Config.digReasonerURL, importedFiles); reasoner.prepareSubsumptionHierarchy(); rs = new ReasoningService(reasoner); - learningProblem = new LearningProblem(rs, posExamples, negExamples); + // learningProblem = new LearningProblem(rs, posExamples, negExamples); + learningProblem = cm.learningProblem(DefinitionLPTwoValued.class, rs); + cm.applyConfigEntry(learningProblem, "positiveExamples", posExamples); + cm.applyConfigEntry(learningProblem, "negativeExamples", negExamples); if (j == 0) { Config.algorithm = Algorithm.HYBRID_GP; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-26 16:57:52 UTC (rev 156) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.algorithms; import java.util.Collection; @@ -14,20 +33,29 @@ import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; import org.dllearner.core.dl.Concept; +import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.DefinitionLPThreeValued; +import org.dllearner.learningproblems.DefinitionLPTwoValued; public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private LearningProblem learningProblem; + private DefinitionLP learningProblem; private int numberOfTrees; private int maxDepth; - public RandomGuesser(LearningProblemNew lp) { - + public RandomGuesser(DefinitionLP learningProblem) { + this.learningProblem = learningProblem; } + public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { + Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); + problems.add(DefinitionLP.class); + return problems; + } + public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new IntegerConfigOption("numberOfTrees")); @@ -55,17 +83,7 @@ // TODO Auto-generated method stub } - - /** - * Generiert zufaellig Loesungen. - * @param numberOfTrees Anzahl zu generierender Loesungen. - */ - public RandomGuesser(LearningProblem learningProblem, int numberOfTrees, int maxDepth) { - this.learningProblem = learningProblem; - this.numberOfTrees = numberOfTrees; - this.maxDepth = maxDepth; - } - + @Override public void start() { // this.learningProblem = learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-26 16:57:52 UTC (rev 156) @@ -38,7 +38,9 @@ import java.text.DecimalFormat; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; +import java.util.LinkedList; import java.util.Random; import java.util.Set; import java.util.Map.Entry; @@ -48,8 +50,14 @@ import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblemNew; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.Helper; /** @@ -59,7 +67,7 @@ * @author Jens Lehmann * */ -public class GP implements LearningAlgorithm { +public class GP extends LearningAlgorithmNew implements LearningAlgorithm { // NumberFormat f; DecimalFormat df = new DecimalFormat("0.00"); @@ -108,7 +116,7 @@ private Score bestScore; private Concept bestConcept; - private LearningProblem learningProblem; + private DefinitionLP learningProblem; // private GeneticRefinementOperator psi; private Psi psi; @@ -120,10 +128,36 @@ * 1.0 and a probability of mutation of 0.01. * */ - public GP(LearningProblem learningProblem) { + public GP(DefinitionLP learningProblem) { this.learningProblem = learningProblem; } + public static Collection<Class<? extends LearningProblemNew>> supportedLearningAlgorithms() { + Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); + problems.add(DefinitionLP.class); + return problems; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + return options; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + } + public void start() { // falls refinement-Wahrscheinlichkeit größer 0, dann erzeuge psi psi = new Psi(learningProblem); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-26 16:57:52 UTC (rev 156) @@ -1,7 +1,5 @@ package org.dllearner.algorithms.gp; - - import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -10,10 +8,10 @@ import java.util.TreeMap; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.Main; import org.dllearner.Score; import org.dllearner.ScoreThreeValued; +import org.dllearner.core.LearningProblemNew; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -28,6 +26,8 @@ import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.DefinitionLPThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; @@ -57,7 +57,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(LearningProblem learningProblem, Concept hypothesis) { + private static Score calculateFitness(DefinitionLP learningProblem, Concept hypothesis) { return calculateFitness(learningProblem, hypothesis, null); } @@ -66,7 +66,7 @@ // (macht aber nicht so viel Sinn, da man das bei richtigen Reasoning-Algorithmen // ohnehin mit einer Erweiterung der Wissensbasis um die Inklusion Target SUBSETOF ReturnType // erschlagen kann) - private static Score calculateFitness(LearningProblem learningProblem, Concept hypothesis, Concept adc) { + private static Score calculateFitness(DefinitionLP learningProblem, Concept hypothesis, Concept adc) { Concept extendedHypothesis; if (!Config.returnType.equals("")) { @@ -121,11 +121,11 @@ return score; } - public static Program createProgram(LearningProblem learningProblem, Concept mainTree) { + public static Program createProgram(DefinitionLP learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); } - private static Program createProgram(LearningProblem learningProblem, Concept mainTree, Concept adc) { + private static Program createProgram(DefinitionLP learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); } @@ -133,7 +133,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(LearningProblem learningProblem, Program p) { + public static Program mutation(DefinitionLP learningProblem, Program p) { mutation++; if(Config.GP.adc) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -157,7 +157,7 @@ } } - private static Concept mutation(LearningProblem learningProblem, Concept tree, boolean useADC) { + private static Concept mutation(DefinitionLP learningProblem, Concept tree, boolean useADC) { // auch bei Mutation muss darauf geachtet werden, dass // Baum nicht modifiziert wird (sonst w�rde man automatisch auch // andere "selected individuals" modifizieren) @@ -226,7 +226,7 @@ * @param p2 Second parent. * @return A two-element array containing the offpsring. */ - public static Program[] crossover(LearningProblem learningProblem, Program p1, Program p2) { + public static Program[] crossover(DefinitionLP learningProblem, Program p1, Program p2) { crossover++; if(Config.GP.adc) { Concept[] pt; @@ -302,7 +302,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(LearningProblem learningProblem, Program p) { + public static Program hillClimbing(DefinitionLP learningProblem, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -325,7 +325,7 @@ // Alternativen zu speichern und dann ein Element zuf�llig auszuw�hlen, // aber w�rde man das nicht machen, dann w�re das ein starker Bias // zu z.B. Disjunktion (weil die als erstes getestet wird) - private static Concept hillClimbing(LearningProblem learningProblem, Concept node, ScoreThreeValued score) { + private static Concept hillClimbing(DefinitionLP learningProblem, Concept node, ScoreThreeValued score) { SortedSetTuple<Individual> tuple = new SortedSetTuple<Individual>(score.getPosClassified(),score.getNegClassified()); SortedSetTuple<String> stringTuple = Helper.getStringTuple(tuple); // FlatABox abox = FlatABox.getInstance(); @@ -440,7 +440,7 @@ } } - private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, DefinitionLP learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! SortedSet<Individual> neutClassified = Helper.intersection(learningProblem.getReasoningService().getIndividuals(),posClassified); @@ -448,7 +448,7 @@ // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, learningProblem.getPositiveExamples(),learningProblem.getNeutralExamples(),learningProblem.getNegativeExamples()); + return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, learningProblem.getPositiveExamples(),((DefinitionLPThreeValued)learningProblem).getNeutralExamples(),learningProblem.getNegativeExamples()); } // aktualisiert die besten Knoten @@ -477,7 +477,7 @@ return returnMap; } - private static Concept pickTerminalSymbol(LearningProblem learningProblem, boolean useADC) { + private static Concept pickTerminalSymbol(DefinitionLP learningProblem, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size(); @@ -607,7 +607,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(LearningProblem learningProblem, int depth) { + public static Program createFullRandomProgram(DefinitionLP learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), @@ -617,7 +617,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false)); } - private static Concept createFullRandomTree(LearningProblem learningProblem, int depth, boolean useADC) { + private static Concept createFullRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size(); @@ -668,7 +668,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth) { + public static Program createGrowRandomProgram(DefinitionLP learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), @@ -678,7 +678,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false)); } - private static Concept createGrowRandomTree(LearningProblem learningProblem, int depth, boolean useADC) { + private static Concept createGrowRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { /* private static Concept pickAlphabetSymbol(boolean useADC) { FlatABox abox = FlatABox.getInstance(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-09-26 16:57:52 UTC (rev 156) @@ -8,7 +8,9 @@ import org.dllearner.LearningProblem; import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; +import org.dllearner.core.LearningProblemNew; import org.dllearner.core.dl.Concept; +import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -16,7 +18,7 @@ PsiUp pu; PsiDown pd; - LearningProblem learningProblem; + DefinitionLP learningProblem; int nrOfPositiveExamples; int nrOfNegativeExamples; Random random; @@ -46,7 +48,7 @@ private long someTimeStart = 0; public long someTime = 0; - public Psi(LearningProblem learningProblem) { //, PsiUp pu, PsiDown pd) { + public Psi(DefinitionLP learningProblem) { //, PsiUp pu, PsiDown pd) { // this.pu = pu; // this.pd = pd; this.learningProblem = learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-09-26 16:57:52 UTC (rev 156) @@ -21,6 +21,7 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.ConceptComparator; /** @@ -39,12 +40,12 @@ ConceptComparator conceptComparator = new ConceptComparator(); - LearningProblem learningProblem; + DefinitionLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> topSet; - public PsiDown(LearningProblem learningProblem) { + public PsiDown(DefinitionLP learningProblem) { this.learningProblem = learningProblem; reasoningService = learningProblem.getReasoningService(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-09-26 16:57:52 UTC (rev 156) @@ -21,18 +21,19 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.ConceptComparator; public class PsiUp implements RefinementOperator { ConceptComparator conceptComparator = new ConceptComparator(); - LearningProblem learningProblem; + DefinitionLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> bottomSet; - public PsiUp(LearningProblem learningProblem) { + public PsiUp(DefinitionLP learningProblem) { this.learningProblem = learningProblem; reasoningService = learningProblem.getReasoningService(); Added: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) @@ -0,0 +1,50 @@ +/** + * 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.core; + +import java.util.TreeSet; + +/** + * @author Jens Lehmann + * + */ +public class BooleanConfigOption extends ConfigOption<Boolean> { + + public BooleanConfigOption(String name) { + super(name); + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) + */ + @Override + public boolean checkType(Object object) { + return (object instanceof Boolean); + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(Boolean value) { + return true; + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-26 16:57:52 UTC (rev 156) @@ -27,6 +27,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -34,9 +35,12 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.TreeSet; +import org.dllearner.kb.OWLFile; + /** * Central manager class for DL-Learner. * @@ -49,10 +53,15 @@ private static String componentsFile = "lib/components.ini"; private static ComponentManager cm = new ComponentManager(); private static Set<Class<? extends Component>> components; + private static Set<Class<? extends KnowledgeSource>> knowledgeSources; + private static Set<Class<? extends ReasonerComponent>> reasonerComponents; + private static Set<Class<? extends LearningProblemNew>> learningProblems; + private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; // list of all configuration options of all components - private Map<Class<? extends Component>,List<ConfigOption<?>>> componentOptions; - private Map<Class<? extends Component>,Map<String,ConfigOption<?>>> componentOptionsByName; + private static Map<Class<? extends Component>,List<ConfigOption<?>>> componentOptions; + private static Map<Class<? extends Component>,Map<String,ConfigOption<?>>> componentOptionsByName; + private static Map<Class<? extends LearningAlgorithmNew>,Collection<Class<? extends LearningProblemNew>>> algorithmProblemsMapping; private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { @@ -69,12 +78,51 @@ // component list components = new TreeSet<Class<? extends Component>>(classComparator); + knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); + reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); + learningProblems = new TreeSet<Class<? extends LearningProblemNew>>(classComparator); + learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>,Collection<Class<? extends LearningProblemNew>>>(classComparator); // create classes from strings for(String componentString : componentsString) { try { Class<? extends Component> component = Class.forName(componentString).asSubclass(Component.class); components.add(component); + + if(KnowledgeSource.class.isAssignableFrom(component)) + knowledgeSources.add((Class<? extends KnowledgeSource>)component); + else if(ReasonerComponent.class.isAssignableFrom(component)) + reasonerComponents.add((Class<? extends ReasonerComponent>)component); + else if(LearningProblemNew.class.isAssignableFrom(component)) + learningProblems.add((Class<? extends LearningProblemNew>)component); + else if(LearningAlgorithmNew.class.isAssignableFrom(component)) { + Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>)component; + learningAlgorithms.add(learningAlgorithmClass); + + try { + Method method = learningAlgorithmClass.getMethod("supportedLearningProblems"); + Collection<Class<? extends LearningProblemNew>> problems = (Collection<Class<? extends LearningProblemNew>>) method.invoke(null); + algorithmProblemsMapping.put(learningAlgorithmClass, problems); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -120,6 +168,7 @@ } + // System.out.println(components); } public static ComponentManager getInstance() { @@ -186,6 +235,9 @@ } public KnowledgeSource knowledgeSource(Class<? extends KnowledgeSource> source) { + if(!knowledgeSources.contains(source)) + System.err.println("Warning: knowledge source " + source + " is not a registered knowledge source component."); + try { Constructor<? extends KnowledgeSource> constructor = source.getConstructor(); return constructor.newInstance(); @@ -219,6 +271,9 @@ } public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, Set<KnowledgeSource> sources) { + if(!reasonerComponents.contains(reasoner)) + System.err.println("Warning: reasoner component " + reasoner + " is not a registered reasoner component."); + try { Constructor<T> constructor = reasoner.getConstructor(Set.class); T reasonerInstance = constructor.newInstance(sources); @@ -247,6 +302,9 @@ } public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasoningService reasoner) { + if(!learningProblems.contains(lp)) + System.err.println("Warning: learning problem " + lp + " is not a registered learning problem component."); + try { Constructor<T> constructor = lp.getConstructor(ReasoningService.class); return constructor.newInstance(reasoner); @@ -273,9 +331,26 @@ return null; } + // automagically calls the right constructor for the given learning problem public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblemNew lp) { + if(!learningAlgorithms.contains(la)) + System.err.println("Warning: learning algorithm " + la + " is not a registered learning algorithm component."); + + // find the right constructor: use the one that is registered and + // has the class of the learning problem as a subclass + Class<? extends LearningProblemNew> constructorArgument = null; + for(Class<? extends LearningProblemNew> problemClass : algorithmProblemsMapping.get(la)) { + if(problemClass.isAssignableFrom(lp.getClass())) + constructorArgument = problemClass; + } + + if(constructorArgument == null) { + System.err.println("Warning: No suitable constructor registered for algorithm " + la.getName() + " and problem " + lp.getClass().getName() + ". Registered constructors for " + la.getName() + ": " + algorithmProblemsMapping.get(la) + "."); + return null; + } + try { - Constructor<T> constructor = la.getConstructor(LearningProblemNew.class); + Constructor<T> constructor = la.getConstructor(constructorArgument); return constructor.newInstance(lp); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-26 16:57:52 UTC (rev 156) @@ -20,7 +20,6 @@ package org.dllearner.core; import java.io.File; -import java.net.MalformedURLException; import java.util.Set; import java.util.TreeSet; @@ -41,26 +40,22 @@ * @param args */ public static void main(String[] args) { - - String example = null; - try { - example = new File("examples/father.owl").toURI().toURL().toString(); - } catch (MalformedURLException e) { - e.printStackTrace(); - System.exit(0); - } // get singleton instance of component manager ComponentManager cm = ComponentManager.getInstance(); // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(source, "url", example); + String example = "examples/father.owl"; + cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); source.init(); + // create DIG reasoning service with standard settings ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); rs.init(); + // create a learning problem and set positive and negative examples + LearningProblemNew lp = cm.learningProblem(DefinitionLPTwoValued.class, rs); Set<String> positiveExamples = new TreeSet<String>(); positiveExamples.add("http://example.com/father#stefan"); positiveExamples.add("http://example.com/father#markus"); @@ -69,19 +64,18 @@ negativeExamples.add("http://example.com/father#heinz"); negativeExamples.add("http://example.com/father#anna"); negativeExamples.add("http://example.com/father#michelle"); - - LearningProblemNew lp = cm.learningProblem(DefinitionLPTwoValued.class, rs); cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); lp.init(); + // create the learning algorithm LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp); cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); la.init(); + // start the algorithm and print the best concept found la.start(); - System.out.println(la.getBestSolution()); } Modified: trunk/src/dl-learner/org/dllearner/core/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) @@ -23,6 +23,11 @@ * This class represents a configuration option (without a value for the * option). * + * Note: Currently, handling the type of a configuration option is not + * straightforward to implement, because Java Generics information is + * erased at runtime. This will be fixed in Java 7, in particular JSR 308, + * which is due at approx. the end of 2008. + * * @author Jens Lehmann * */ Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-09-26 16:57:52 UTC (rev 156) @@ -19,6 +19,9 @@ */ package org.dllearner.core; +import java.util.Collection; +import java.util.LinkedList; + import org.dllearner.Score; import org.dllearner.core.dl.Concept; @@ -52,6 +55,13 @@ * Returns the best solutions obtained so far. * @return Best solution. */ - public abstract Concept getBestSolution(); + public abstract Concept getBestSolution(); + /** + * Returns all learning problems supported by this component. + */ + public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { + return new LinkedList<Class<? extends LearningProblemNew>>(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-09-26 16:57:52 UTC (rev 156) @@ -28,4 +28,10 @@ */ public abstract class LearningProblemNew extends Component { + protected ReasoningService reasoningService; + + public LearningProblemNew(ReasoningService reasoningService) { + this.reasoningService = reasoningService; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-09-26 16:57:52 UTC (rev 156) @@ -73,7 +73,7 @@ public boolean instanceCheck(Concept concept, Individual individual) throws ReasoningMethodUnsupportedException; // mehrere instance checks für ein Konzept - spart bei DIG Anfragen - public Set<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException; public SortedSetTuple<Individual> doubleRetrieval(Concept concept) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-26 16:57:52 UTC (rev 156) @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -78,9 +79,9 @@ throw new ReasoningMethodUnsupportedException(); } - public Set<Individual> instanceCheck(Concept concept, Set<Individual> individuals) + public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException { - Set<Individual> returnSet = new HashSet<Individual>(); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); for (Individual individual : individuals) { if (instanceCheck(concept, individual)) returnSet.add(individual); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-26 16:57:52 UTC (rev 156) @@ -193,9 +193,9 @@ return result; } - public Set<Individual> instanceCheck(Concept concept, Set<Individual> s) { + public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> s) { reasoningStartTimeTmp = System.nanoTime(); - Set<Individual> result = null; + SortedSet<Individual> result = null; try { result = reasoner.instanceCheck(concept, s); } catch (ReasoningMethodUnsupportedException e) { Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-26 16:57:52 UTC (rev 156) @@ -19,13 +19,75 @@ */ package org.dllearner.learningproblems; -import org.dllearner.core.ConfigEntry; +import java.util.SortedSet; + +import org.dllearner.Score; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; /** + * The definition learning problem. + * * @author Jens Lehmann * */ public abstract class DefinitionLP extends LearningProblemNew { + + protected boolean useRetrievalForClassification = false; + protected UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + + /** + * If instance checks are used for testing concepts (e.g. no retrieval), then + * there are several options to do this. The enumeration lists the supported + * options. These options are only important if the reasoning mechanism + * supports sending several reasoning requests at once as it is the case for + * DIG reasoners. + * + * @author Jens Lehmann + * + */ + public enum UseMultiInstanceChecks { + /** + * Perform a separate instance check for each example. + */ + NEVER, + /** + * Perform one instance check for all positive and one instance check + * for all negative examples. + */ + TWOCHECKS, + /** + * Perform all instance checks at once. + */ + ONECHECK + }; + public DefinitionLP(ReasoningService reasoningService) { + super(reasoningService); + } + + public abstract int coveredNegativeExamplesOrTooWeak(Concept concept); + + public abstract Score computeScore(Concept concept); + + /** + * @todo Method not implemented yet. + * @param concept + * @param adc + * @return + */ + public Score computeScore(Concept concept, Concept adc) { + throw new UnsupportedOperationException(); + } + + public abstract SortedSet<Individual> getNegativeExamples(); + + public abstract SortedSet<Individual> getPositiveExamples(); + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public abstract ReasoningService getReasoningService(); + } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-26 16:57:52 UTC (rev 156) @@ -19,8 +19,14 @@ */ package org.dllearner.learningproblems; +import java.util.SortedSet; + +import org.dllearner.Score; import org.dllearner.core.ConfigEntry; import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; /** * @author Jens Lehmann @@ -28,6 +34,10 @@ */ public class DefinitionLPThreeValued extends DefinitionLP { + public DefinitionLPThreeValued(ReasoningService reasoningService) { + super(reasoningService); + } + /* (non-Javadoc) * @see org.dllearner.core.Component#getName() */ @@ -53,4 +63,52 @@ } + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#computeScore(org.dllearner.core.dl.Concept) + */ + @Override + public Score computeScore(Concept concept) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getNegativeExamples() + */ + @Override + public SortedSet<Individual> getNegativeExamples() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getPositiveExamples() + */ + @Override + public SortedSet<Individual> getPositiveExamples() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getReasoningService() + */ + @Override + public ReasoningService getReasoningService() { + // TODO Auto-generated method stub + return null; + } + + public SortedSet<Individual> getNeutralExamples() { + throw new UnsupportedOperationException(); + } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-26 12:44:02 UTC (rev 155) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-26 16:57:52 UTC (rev 156) @@ -23,67 +23,235 @@ import java.util.LinkedList; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.Score; +import org.dllearner.ScoreTwoValued; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.CommonConfigMappings; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; -import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; /** + * The aim of this learning problem is to learn a concept definition such that + * the positive examples and the negative examples do not follow. It is + * 2-valued, because we only distinguish between covered and non-covered + * examples. (A 3-valued problem distinguishes between covered examples, + * examples covered by the negation of the concept, and all other examples.) The + * 2-valued learning problem is often more useful for Description Logics due to + * (the Open World Assumption and) the fact that negative knowledge, e.g. that a + * person does not have a child, is or cannot be expressed. + * * @author Jens Lehmann - * + * */ public class DefinitionLPTwoValued extends DefinitionLP { - private ReasoningService rs; - private SortedSet<Individual> positiveExamples; private SortedSet<Individual> negativeExamples; - - public DefinitionLPTwoValued(ReasoningService rs) { - this.rs = rs; + private SortedSet<Individual> posNegExamples; + + public DefinitionLPTwoValued(ReasoningService reasoningService) { + super(reasoningService); } - + public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringSetConfigOption("positiveExamples")); options.add(new StringSetConfigOption("negativeExamples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation")); return options; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override - @SuppressWarnings({"unchecked"}) + @SuppressWarnings( { "unchecked" }) public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { String name = entry.getOptionName(); - if(name.equals("positiveExamples")) - positiveExamples = CommonConfigMappings.getIndividualSet((Set<String>) entry.getValue()); - else if(name.equals("negativeExamples")) - negativeExamples = CommonConfigMappings.getIndividualSet((Set<String>) entry.getValue()); + if (name.equals("positiveExamples")) + positiveExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); + else if (name.equals("negativeExamples")) + negativeExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); + else if (name.equals("useRetrievalForClassification")) + useRetrievalForClassification = (Boolean) entry.getValue(); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#getName() */ public static String getName() { return "two valued definition learning problem"; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#init() */ @Override public void init() { - // TODO Auto-generated method stub - + posNegExamples = Helper.union(positiveExamples, negativeExamples); } - + + /** + * This method computes (using the reasoner) whether a concept is too weak. + * If it is not weak, it returns the number of covered negative example. It + * can use retrieval or instance checks for classification. + * + * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks + * @todo Performance could be slightly improved by counting the number of + * covers instead of using sets and counting their size. + * @param concept + * The concept to test. + * @return -1 if concept is too weak and the number of covered negative + * e... [truncated message content] |
From: <jen...@us...> - 2007-09-30 13:11:06
|
Revision: 158 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=158&view=rev Author: jenslehmann Date: 2007-09-30 06:11:00 -0700 (Sun, 30 Sep 2007) Log Message: ----------- - improved reflection code in component manager - several smaller changes Modified Paths: -------------- trunk/build.xml trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/build.xml 2007-09-30 13:11:00 UTC (rev 158) @@ -207,7 +207,6 @@ nonavbar="false" notree="false" overview="src/dl-learner/overview.html" - packagenames="org.dllearner.reasoning,org.dllearner.dl,org.dllearner.server,org.dllearner,org.dllearner.server.exceptions,org.dllearner.server.jaxws,org.dllearner.algorithms.gp,org.dllearner.parser,org.dllearner.modules,org.dllearner.modules.sparql,org.dllearner.algorithms,org.dllearner.examples,org.dllearner.utilities,org.dllearner.algorithms.hybridgp,org.dllearner.algorithms.refinement" source="1.6" sourcepath="src/dl-learner" splitindex="true" Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-09-30 13:11:00 UTC (rev 158) @@ -42,11 +42,9 @@ import org.dllearner.Config.Algorithm; import org.dllearner.algorithms.BruteForceLearner; import org.dllearner.algorithms.LearningAlgorithm; -import org.dllearner.algorithms.RandomGuesser; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.ComponentManager; -import org.dllearner.core.LearningProblemNew; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-30 13:11:00 UTC (rev 158) @@ -158,6 +158,7 @@ public void init() { } + @Override public void start() { // falls refinement-Wahrscheinlichkeit größer 0, dann erzeuge psi psi = new Psi(learningProblem); @@ -828,15 +829,18 @@ System.exit(0); } + @Override public Score getSolutionScore() { return bestScore; } + @Override public Concept getBestSolution() { // return fittestIndividual.getTree(); return bestConcept; } + @Override public void stop() { // TODO Auto-generated method stub Modified: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-30 13:11:00 UTC (rev 158) @@ -19,8 +19,6 @@ */ package org.dllearner.core; -import java.util.TreeSet; - /** * @author Jens Lehmann * Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-30 13:11:00 UTC (rev 158) @@ -38,21 +38,18 @@ import java.util.TreeMap; import java.util.TreeSet; -import org.dllearner.kb.OWLFile; - - /** - * Central manager class for DL-Learner. There are currently four types of components - * in DL-Learner: knowledge sources, reasoners, learning problems, and learning - * algorithms. For accessing these components you should create instances and - * configure them using this class. The component manager is implemented as a - * Singleton and will read the components file (containing a list of all components) - * at startup. This allows interfaces (command line, graphical, web service) to - * easily query the available components, set and get their configuration options, - * and run the algorithm. + * Central manager class for DL-Learner. There are currently four types of + * components in DL-Learner: knowledge sources, reasoners, learning problems, + * and learning algorithms. For accessing these components you should create + * instances and configure them using this class. The component manager is + * implemented as a Singleton and will read the components file (containing a + * list of all components) at startup. This allows interfaces (command line, + * graphical, web service) to easily query the available components, set and get + * their configuration options, and run the algorithm. * * @author Jens Lehmann - * + * */ public class ComponentManager { @@ -64,127 +61,93 @@ private static Set<Class<? extends ReasonerComponent>> reasonerComponents; private static Set<Class<? extends LearningProblemNew>> learningProblems; private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; - + // list of all configuration options of all components - private static Map<Class<? extends Component>,List<ConfigOption<?>>> componentOptions; - private static Map<Class<? extends Component>,Map<String,ConfigOption<?>>> componentOptionsByName; - private static Map<Class<? extends LearningAlgorithmNew>,Collection<Class<? extends LearningProblemNew>>> algorithmProblemsMapping; - + private static Map<Class<? extends Component>, List<ConfigOption<?>>> componentOptions; + private static Map<Class<? extends Component>, Map<String, ConfigOption<?>>> componentOptionsByName; + private static Map<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblemNew>>> algorithmProblemsMapping; + private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { public int compare(Class<?> c1, Class<?> c2) { return c1.getName().compareTo(c2.getName()); } - + }; - - @SuppressWarnings({"unchecked"}) + + @SuppressWarnings( { "unchecked" }) private ComponentManager() { // read in components file List<String> componentsString = readComponentsFile(); - + // component list components = new TreeSet<Class<? extends Component>>(classComparator); knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); learningProblems = new TreeSet<Class<? extends LearningProblemNew>>(classComparator); learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); - algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>,Collection<Class<? extends LearningProblemNew>>>(classComparator); - + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblemNew>>>( + classComparator); + // create classes from strings - for(String componentString : componentsString) { + for (String componentString : componentsString) { try { - Class<? extends Component> component = Class.forName(componentString).asSubclass(Component.class); + Class<? extends Component> component = Class.forName(componentString).asSubclass( + Component.class); components.add(component); - - if(KnowledgeSource.class.isAssignableFrom(component)) - knowledgeSources.add((Class<? extends KnowledgeSource>)component); - else if(ReasonerComponent.class.isAssignableFrom(component)) - reasonerComponents.add((Class<? extends ReasonerComponent>)component); - else if(LearningProblemNew.class.isAssignableFrom(component)) - learningProblems.add((Class<? extends LearningProblemNew>)component); - else if(LearningAlgorithmNew.class.isAssignableFrom(component)) { - Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>)component; + + if (KnowledgeSource.class.isAssignableFrom(component)) + knowledgeSources.add((Class<? extends KnowledgeSource>) component); + else if (ReasonerComponent.class.isAssignableFrom(component)) + reasonerComponents.add((Class<? extends ReasonerComponent>) component); + else if (LearningProblemNew.class.isAssignableFrom(component)) + learningProblems.add((Class<? extends LearningProblemNew>) component); + else if (LearningAlgorithmNew.class.isAssignableFrom(component)) { + Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>) component; learningAlgorithms.add(learningAlgorithmClass); - - try { - Method method = learningAlgorithmClass.getMethod("supportedLearningProblems"); - Collection<Class<? extends LearningProblemNew>> problems = (Collection<Class<? extends LearningProblemNew>>) method.invoke(null); - algorithmProblemsMapping.put(learningAlgorithmClass, problems); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + Collection<Class<? extends LearningProblemNew>> problems = (Collection<Class<? extends LearningProblemNew>>) invokeStaticMethod( + learningAlgorithmClass, "supportedLearningProblems"); + algorithmProblemsMapping.put(learningAlgorithmClass, problems); } - + } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } - + // read in all configuration options - componentOptions = new HashMap<Class<? extends Component>,List<ConfigOption<?>>>(); - componentOptionsByName = new HashMap<Class<? extends Component>,Map<String,ConfigOption<?>>>(); - - for(Class<? extends Component> component : components) { - // unfortunately Java does not seem to offer a way to call - // a static method given a class object directly, so we have - // to use reflection - try { - Method createConfig = component.getMethod("createConfigOptions"); - List<ConfigOption<?>> options = (List<ConfigOption<?>>) createConfig.invoke(null); - - componentOptions.put(component, options); - - Map<String,ConfigOption<?>> byName = new HashMap<String,ConfigOption<?>>(); - for(ConfigOption<?> option : options) - byName.put(option.getName(), option); - componentOptionsByName.put(component, byName); - - // componentOptionsByName.put(key, value) - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + componentOptions = new HashMap<Class<? extends Component>, List<ConfigOption<?>>>(); + componentOptionsByName = new HashMap<Class<? extends Component>, Map<String, ConfigOption<?>>>(); + + for (Class<? extends Component> component : components) { + + List<ConfigOption<?>> options = (List<ConfigOption<?>>) invokeStaticMethod(component, + "createConfigOptions"); + + componentOptions.put(component, options); + + Map<String, ConfigOption<?>> byName = new HashMap<String, ConfigOption<?>>(); + for (ConfigOption<?> option : options) + byName.put(option.getName(), option); + componentOptionsByName.put(component, byName); + } - + // System.out.println(components); } - + + /** + * + * @return The singleton <code>ComponentManager</code> instance. + */ public static ComponentManager getInstance() { return cm; } - + private static List<String> readComponentsFile() { List<String> componentStrings = new LinkedList<String>(); - + try { FileInputStream fstream = new FileInputStream(componentsFile); @@ -193,199 +156,178 @@ String line; while ((line = br.readLine()) != null) { - if(!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%") || line.length()<=1)) + if (!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%") || line + .length() <= 1)) componentStrings.add(line); } - - in.close(); + + in.close(); } catch (IOException e) { e.printStackTrace(); } - + return componentStrings; } - + /** * Convenience method for testing purposes. If you know that the type of the - * value is correct, it is preferable to create a ConfigEntry object and apply - * it to the component (no type checking necessary). + * value is correct, it is preferable to create a ConfigEntry object and + * apply it to the component (no type checking necessary). + * * @param component * @param optionName * @param value */ public <T> void applyConfigEntry(Component component, String optionName, T value) { // first we look whether the component is registered - if(components.contains(component.getClass())) { + if (components.contains(component.getClass())) { // look for a config option with the specified name - ConfigOption<?> option = (ConfigOption<?>) componentOptionsByName.get(component.getClass()).get(optionName); - if(option!=null) { + ConfigOption<?> option = (ConfigOption<?>) componentOptionsByName.get( + component.getClass()).get(optionName); + if (option != null) { // check whether the given object has the correct type - if(!option.checkType(value)) { - System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component + ". It does not have the correct type."); + if (!option.checkType(value)) { + System.out.println("Warning: value " + value + " is not valid for option " + + optionName + " in component " + component + + ". It does not have the correct type."); return; } - - // we have checked the type, hence it should now be safe to typecast and + + // we have checked the type, hence it should now be safe to + // typecast and // create a ConfigEntry object try { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings( { "unchecked" }) ConfigEntry<T> entry = new ConfigEntry<T>((ConfigOption<T>) option, value); component.applyConfigEntry(entry); } catch (InvalidConfigOptionValueException e) { - System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component); + System.out.println("Warning: value " + value + " is not valid for option " + + optionName + " in component " + component); } } else - System.out.println("Warning: undefined option " + optionName + " in component " + component); + System.out.println("Warning: undefined option " + optionName + " in component " + + component); } else - System.out.println("Warning: unregistered component " + component); + System.out.println("Warning: unregistered component " + component); } - - public KnowledgeSource knowledgeSource(Class<? extends KnowledgeSource> source) { - if(!knowledgeSources.contains(source)) - System.err.println("Warning: knowledge source " + source + " is not a registered knowledge source component."); - + + /** + * Applies a config entry to a component. If the entry is not valid, the method + * prints an exception and returns false. + * @param <T> Type of the config option. + * @param component A component object. + * @param entry The configuration entry to set. + * @return True of the config entry could be applied succesfully, otherwise false. + */ + public <T> boolean applyConfigEntry(Component component, ConfigEntry<T> entry) { try { - Constructor<? extends KnowledgeSource> constructor = source.getConstructor(); - return constructor.newInstance(); - } catch (InstantiationException e) { + component.applyConfigEntry(entry); + return true; + } catch (InvalidConfigOptionValueException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return false; } - - return null; } - public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, KnowledgeSource source) { + /** + * Factory method for creating a knowledge source. + * @param source A registered knowledge source component. + * @return An instance of the given knowledge source class. + */ + public KnowledgeSource knowledgeSource(Class<? extends KnowledgeSource> source) { + if (!knowledgeSources.contains(source)) + System.err.println("Warning: knowledge source " + source + + " is not a registered knowledge source component."); + + return invokeConstructor(source, new Class[] {}, new Object[] {}); + } + + public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, + KnowledgeSource source) { Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(source); return reasoningService(reasoner, sources); } - - public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, Set<KnowledgeSource> sources) { - if(!reasonerComponents.contains(reasoner)) - System.err.println("Warning: reasoner component " + reasoner + " is not a registered reasoner component."); - - try { - Constructor<T> constructor = reasoner.getConstructor(Set.class); - T reasonerInstance = constructor.newInstance(sources); - return new ReasoningService(reasonerInstance); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return null; + + public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, + Set<KnowledgeSource> sources) { + if (!reasonerComponents.contains(reasoner)) + System.err.println("Warning: reasoner component " + reasoner + + " is not a registered reasoner component."); + + T reasonerInstance = invokeConstructor(reasoner, new Class[] { Set.class }, + new Object[] { sources }); + return new ReasoningService(reasonerInstance); } - + public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasoningService reasoner) { - if(!learningProblems.contains(lp)) - System.err.println("Warning: learning problem " + lp + " is not a registered learning problem component."); - - try { - Constructor<T> constructor = lp.getConstructor(ReasoningService.class); - return constructor.newInstance(reasoner); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return null; + if (!learningProblems.contains(lp)) + System.err.println("Warning: learning problem " + lp + + " is not a registered learning problem component."); + + return invokeConstructor(lp, new Class[] { ReasoningService.class }, + new Object[] { reasoner }); } - + // automagically calls the right constructor for the given learning problem public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblemNew lp) { - if(!learningAlgorithms.contains(la)) - System.err.println("Warning: learning algorithm " + la + " is not a registered learning algorithm component."); - + if (!learningAlgorithms.contains(la)) + System.err.println("Warning: learning algorithm " + la + + " is not a registered learning algorithm component."); + // find the right constructor: use the one that is registered and // has the class of the learning problem as a subclass Class<? extends LearningProblemNew> constructorArgument = null; - for(Class<? extends LearningProblemNew> problemClass : algorithmProblemsMapping.get(la)) { - if(problemClass.isAssignableFrom(lp.getClass())) + for (Class<? extends LearningProblemNew> problemClass : algorithmProblemsMapping.get(la)) { + if (problemClass.isAssignableFrom(lp.getClass())) constructorArgument = problemClass; } - - if(constructorArgument == null) { - System.err.println("Warning: No suitable constructor registered for algorithm " + la.getName() + " and problem " + lp.getClass().getName() + ". Registered constructors for " + la.getName() + ": " + algorithmProblemsMapping.get(la) + "."); + + if (constructorArgument == null) { + System.err.println("Warning: No suitable constructor registered for algorithm " + + la.getName() + " and problem " + lp.getClass().getName() + + ". Registered constructors for " + la.getName() + ": " + + algorithmProblemsMapping.get(la) + "."); return null; } - + + return invokeConstructor(la, new Class[] { constructorArgument }, new Object[] { lp }); + } + + private Object invokeStaticMethod(Class<?> clazz, String methodName, Object... args) { + // unfortunately Java does not seem to offer a way to call + // a static method given a class object directly, so we have + // to use reflection try { - Constructor<T> constructor = la.getConstructor(constructorArgument); - return constructor.newInstance(lp); - } catch (IllegalArgumentException e) { + Method method = clazz.getMethod(methodName); + return method.invoke(null, args); + } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (InstantiationException e) { + } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } - + return null; } - - private <T,U> T invokeConstructor(Class<T> clazz, Class<U> argumentClass, U argumentObject) { + + private <T> T invokeConstructor(Class<T> clazz, Class<?>[] argumentClasses, + Object[] argumentObjects) { try { - Constructor<T> constructor = clazz.getConstructor(argumentClass); - return constructor.newInstance(argumentObject); + Constructor<T> constructor = clazz.getConstructor(argumentClasses); + return constructor.newInstance(argumentObjects); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -405,8 +347,8 @@ // TODO Auto-generated catch block e.printStackTrace(); } - + return null; } - + } Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-30 13:11:00 UTC (rev 158) @@ -19,10 +19,8 @@ */ package org.dllearner.kb; -import java.io.File; import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.util.Collection; import java.util.LinkedList; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-30 13:11:00 UTC (rev 158) @@ -199,6 +199,7 @@ * The concept to test. * @return Corresponding Score object. */ + @Override public Score computeScore(Concept concept) { if (useRetrievalForClassification) { SortedSet<Individual> posClassified = reasoningService.retrieval(concept); @@ -255,16 +256,19 @@ } } + @Override public SortedSet<Individual> getNegativeExamples() { return negativeExamples; } + @Override public SortedSet<Individual> getPositiveExamples() { return positiveExamples; } // TODO: remove? reasoning service should probably not be accessed via // learning problem + @Override public ReasoningService getReasoningService() { return reasoningService; } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-09-29 18:30:29 UTC (rev 157) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-09-30 13:11:00 UTC (rev 158) @@ -26,16 +26,14 @@ import java.util.List; import java.util.Map; import java.util.SortedSet; + import org.dllearner.Config; import org.dllearner.ConfigurationManager; -import org.dllearner.LearningProblem; import org.dllearner.Main; import org.dllearner.OntologyFileFormat; import org.dllearner.Score; import org.dllearner.Config.Algorithm; -import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-05 14:17:58
|
Revision: 170 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=170&view=rev Author: jenslehmann Date: 2007-10-05 07:17:55 -0700 (Fri, 05 Oct 2007) Log Message: ----------- - adaption of command line interface to new structure continued - first successful test on father.conf and father.kb Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/reasoning/DIGConverter.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/doc/configOptions.txt trunk/doc/configOptionsOld.txt trunk/examples/father.conf trunk/examples/father.kb trunk/examples/fatherOld.conf Removed Paths: ------------- trunk/doc/configOptions.txt trunk/examples/father.conf Deleted: trunk/doc/configOptions.txt =================================================================== --- trunk/doc/configOptions.txt 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/doc/configOptions.txt 2007-10-05 14:17:55 UTC (rev 170) @@ -1,294 +0,0 @@ -Configuration Files -=================== - -This file gives an overview for running DL-Learner using configuration files -as provided in the examples directory. - -The background knowledge can either be given as OWL DL file (using the import -function in the configuration files) or by specifying it directly in the -configuration file (which we refer to as the internal knowledge base). - -Some examples of the syntax of the background knowledge in the internal -knowledge base: - -person = (male OR female). -mother = (female AND EXISTS hasChild.TOP). -motherManyDaughters = (female AND >= 4 hasChild.female). -(mother AND father) SUBCLASSOF person. - -Also see the example files. - -This is the EBNF description of the input language [slightly outdated]: - -Number = ["1"-"9"] (["0"-"9"])* -Id = ["a"-"z"] (["_","a"-"z","A"-"Z","0"-"9"])* -String: "\"" (~["\"","\\","\n","\r"])* "\"" -Instruction = ConfOption - | FunctionCall - | PosExample - | NegExample - | ABoxConcept - | ABoxRole - | Transitive - | Functional - | Symmetric - | Inverse - | Subrole - | TBoxEquiv - | TBoxSub -ConfOption = Id [ "." Id ] "=" ( Id | Number ) ";" -FunctionCall = Id "(" String ")" ";" -PosExample = "+" Id "(" Id ")" "." -NegExample = "-" Id "(" Id ")" "." -ABoxConcept = Concept "(" Id ")" "." -ABoxRole = Id "(" Id "," Id ")" "." -Transitive = "Transitive" "(" Id ")" "." -Functional = "Functional" "(" Id ")" "." -Symmetric = "Symmetric" "(" Id ")" "." -Inverse = "Inverse" "(" Id "," Id ")" "." -Subrole = "Subrole" "(" Id "," Id ")" "." -TBoxEquiv = Concept "=" Concept "." -TBoxSub = Concept ("SUBCLASSOF" | "SUB" ) Concept "." -Concept = "TOP" - | "BOTTOM" - | Id - | "(" Concept "AND" Concept ")" - | "(" Concept "OR" Concept ")" - | "EXISTS" Id "." Concept - | "ALL" Id "." Concept - | "NOT" Concept - | ">=" Number Id "." Concept - | "<=" Number Id "." Concept - -Configuration Options -===================== - -General -------- - -Option: algorithm -Possible Values: bruteForce, gp, random, refinement, hybridGP -Default: refinement -Effect: Specifies the algorithm to use for solving the learning problem. Note, - that hybridGP is not an algorithm itself, but starts the GP algorithm - with a sensible set of default values for the hybrid algorithm combining - GP with refinement operators. In particular the probability of all - operators except refinement is set to 0. - -Option: reasoner -Possible Values: dig, kaon2, fastRetrieval -Default: dig -Effect: Specifies the reasoner to be used. DIG communicates with a reasoner - using the DIG Interface. KAON2 means to use the KAON2 Java API directly. - FastRetrieval is an internal algorithm, which can only be used for - retrieval (not for subsumption). Currently the DIG reasoner cannot read - OWL files. - -Option: digReasonerURL -Possible Values: a valid URL -Default: http://localhost:8081 -Effect: Specifies the URL to be used to look for a DIG capable reasoner. - -Option: writeDIGProtocol -Possible Values: true, false -Default: false -Effect: Specifies whether to store all DIG communication. - -Option: digProtocolFile -Possible Values: strings -Default: digProtocol.txt -Effect: The file to store all DIG communication if writeDIGProtocol is true. - -Option: useRetrievalForClassification -Possible Values: true, false -Default: false -Effect: To measure which concepts are covered, one can either use one retrieval - or several instance checks (at most one for each example). This option - controls which of both options should be used. - -Option: percentPerLengthUnit -Possible Values: 0-1 -Default: 0.05 -Effect: How much percent (wrt classification accuracy) can a concept be worse to - justify an increase in length of 1. This variable is used for GP and in - refinement when the flexible heuristic is used. For GP, you should use a - value smaller than the default. - -> general options below are ignored < -> by the refinement operator algorithm < - -Option: accuracyPenalty -Possible Values: 1-1000 -Default: 1 -Effect: Sets the penalty for "small misclassifications". - -Option: errorPenalty -Possible Values: 1-1000 -Default: 3 -Effect: Sets the penalty for classification errors. - -Option: maxLength -Possible Values: 1-20 -Default: 7 -Effect: For the brute force learner this specifies the depth limit for the - search. The GP learner currently ignores it. - -Option: scoreMethod -Possible Values: full, positive -Default: positive -Effect: The positive score method ignores if a negative examples cannot be - classified. This is often usefull, because of the limited expressiveness - of SHIQ wrt. negated role assertions. The full method penalizes this. - -Option: showCorrectClassifications -Possible Values: true, false -Default: false -Effect: Controls if correct classifications are printed (does not effect the - algorithm). - -Option: penalizeNeutralExamples -Possible Values: true, false -Default: false -Effect: If true there is a penalty if a neutral (neither positive nor negative) - individual is classified as either positive or negative. This should - usually be set to false. - -Refinement Operator Algorithm Specific --------------------------------------- - -Option: refinement.horizontalExpansionFactor -Possible Values: 0-1 -Default: 0.6 -Effect: Specifies horizontal expansion factor. - -Option: refinement.writeSearchTree -Possible Values: true, false -Default: false -Effect: Specifies whether to write the search tree to a file. - -Option: refinement.searchTreeFile -Possible Values: strings -Default: "searchTree.txt" -Effect: Specifies a file to save the current search tree after each loop of - the refinement algorithm. - -Option: refinement.heuristic -Possible Values: flexible, lexicographic -Default: lexicographic -Effect: The refinement operator together with a heuristic yields a learning - algorithm. The lexicographic heuristic uses a lexicographic order of - covered negative examples and horizontal expansion of a node (i.e. - the covered examples are the first criterion, the horizontal expansion - the second criterion). The flexible heuristic computes a combined node - score of both criteria. Note, that the lexicographic needs a horizontal - expansion factor greater than 0 to ensure correctness of the learning - algorithm. - -Option: refinement.quiet -Possible Values: true, false -Default: false -Effect: If set to true, no messages will be shown during the run of the - algorithm (but there will still be startup and summary messages). - -Option: refinement.applyAllFilter -Possible Values: true, false -Default: true -Effect: Specifies wether all equivalences should be used. - -Option: refinement.applyExistsFilter -Possible Values: true, false -Default: true -Effect: Specifies wether exists equivalences should be used. - -Option: refinement.useTooWeakList -Possible Values: true, false -Default: true -Effect: Specifies wether a too weak list should be used to reduce reasoner - requests. - -Option: refinement.useOverlyGeneralList -Possible Values: true, false -Default: true -Effect: Specifies wether an overly general list should be used to reduce - reasoner requests. - -Option: refinement.useShortConceptConstruction -Possible Values: true, false -Default: true -Effect: Specifies wether the algorithm should try to reduce a concept to a - known more general concept to reduce the number of necessary - subsumption checks for the reasoner. - -Option: refinement.useDIGMultiInstanceChecks -Possible Values: never, twoChecks, oneCheck -Default: twoChecks -Effect: The DIG protocol allows to send several queries to a DIG reasoner at - once. [This is automatically done for subsumption tests.] However, - for instance checks this has the disadvantage that it may not be - necessary to send all instance to the DIG reasoner if one of the - positive examples is not covered (meaning that the concept is - classified as too weak). - If the option is set to never, then each instance check is send - separately. - If the option is set to twoChecks, then first all positive examples will - be send in one query. If all of them are covered, i.e. the concept is - not classified as too weak, then all the negative examples are send in - one query. - If the option is set to oneCheck, then all examples will be send in one - query. - -Genetic Programming Specific ----------------------------- - -Option: gp.algorithmType -Possible Values: steadyState, generational -Default: steadyState -Effect: Uses either a steady state (population partly replaced) or generational - (population completely replaced) algorithm. - -Option: gp.elitism -Possible Values: true, false -Default: true -Effect: If true an the GP algorithm uses elitism, i.e. the best individual is - guarenteed to survive. - -Option: gp.numberOfIndividuals -Possible Values: 1-1000000 -Default: 1000 -Effect: Sets the number of individuals in the population. A higher value - improves classification, but is computationally more expensive. - -Option: gp.numberOfSelectedIndividuals -Possible Values: 1-1000000 -Default: 960 -Effect: Sets the number of individuals, which are selected for replacement in a - steady state GP algorithm. - -Option: gp.crossoverPercent -Possible Values: 0-100 -Default: 95 -Effect: The probability that offspring is produced using crossover (in contrast - to simply being copied over to the next generation). - -Option: gp.mutationPercent -Possible Values: 0-100 -Default: 3 -Effect: The probability that offspring is mutated after reproduction. - -Option: gp.hillClimbingPercent -Possible Values: 0-100 -Default: 0 -Effect: The probability that offspring is produced using the hill climbing - operator. - -Option: gp.refinementPercent -Possible Values: 0-100 -Default: 0 -Effect: The probability that offspring is produced using the genetic refinement - operator. - -Option: gp.postConvergenceGenerations -Possible Values: 10-1000 -Default: 50 -Effect: If the algorithm does not find a better solution for this number of - generations it stops. Added: trunk/doc/configOptions.txt =================================================================== --- trunk/doc/configOptions.txt (rev 0) +++ trunk/doc/configOptions.txt 2007-10-05 14:17:55 UTC (rev 170) @@ -0,0 +1,65 @@ +This file contains an automatically generated files of all components and their config options. + +********************* +* Knowledge Sources * +********************* + +component: OWL file (org.dllearner.kb.OWLFile) +============================================== + +option name: url +description: URL pointing to the OWL file +values: none +default value: null + +************* +* Reasoners * +************* + +component: DIG reasoner (org.dllearner.reasoning.DIGReasonerNew) +================================================================ + +option name: reasonerUrl +description: URL of the DIG reasoner +values: none +default value: null + +********************* +* Learning Problems * +********************* + +component: two valued definition learning problem (org.dllearner.learningproblems.DefinitionLPTwoValued) +======================================================================================================== + +option name: positiveExamples +description: positive examples +values: none +default value: null + +option name: negativeExamples +description: negative examples +values: none +default value: null + +option name: useRetrievalForClassficiation +description: Specifies whether to use retrieval or instance checks for testing a concept. +values: none +default value: null + +*********************** +* Learning Algorithms * +*********************** + +component: unnamed component (org.dllearner.algorithms.RandomGuesser) +===================================================================== + +option name: numberOfTrees +description: number of randomly generated concepts/trees +values: none +default value: null + +option name: maxDepth +description: maximum depth of generated concepts/trees +values: none +default value: null + Copied: trunk/doc/configOptionsOld.txt (from rev 162, trunk/doc/configOptions.txt) =================================================================== --- trunk/doc/configOptionsOld.txt (rev 0) +++ trunk/doc/configOptionsOld.txt 2007-10-05 14:17:55 UTC (rev 170) @@ -0,0 +1,294 @@ +Configuration Files +=================== + +This file gives an overview for running DL-Learner using configuration files +as provided in the examples directory. + +The background knowledge can either be given as OWL DL file (using the import +function in the configuration files) or by specifying it directly in the +configuration file (which we refer to as the internal knowledge base). + +Some examples of the syntax of the background knowledge in the internal +knowledge base: + +person = (male OR female). +mother = (female AND EXISTS hasChild.TOP). +motherManyDaughters = (female AND >= 4 hasChild.female). +(mother AND father) SUBCLASSOF person. + +Also see the example files. + +This is the EBNF description of the input language [slightly outdated]: + +Number = ["1"-"9"] (["0"-"9"])* +Id = ["a"-"z"] (["_","a"-"z","A"-"Z","0"-"9"])* +String: "\"" (~["\"","\\","\n","\r"])* "\"" +Instruction = ConfOption + | FunctionCall + | PosExample + | NegExample + | ABoxConcept + | ABoxRole + | Transitive + | Functional + | Symmetric + | Inverse + | Subrole + | TBoxEquiv + | TBoxSub +ConfOption = Id [ "." Id ] "=" ( Id | Number ) ";" +FunctionCall = Id "(" String ")" ";" +PosExample = "+" Id "(" Id ")" "." +NegExample = "-" Id "(" Id ")" "." +ABoxConcept = Concept "(" Id ")" "." +ABoxRole = Id "(" Id "," Id ")" "." +Transitive = "Transitive" "(" Id ")" "." +Functional = "Functional" "(" Id ")" "." +Symmetric = "Symmetric" "(" Id ")" "." +Inverse = "Inverse" "(" Id "," Id ")" "." +Subrole = "Subrole" "(" Id "," Id ")" "." +TBoxEquiv = Concept "=" Concept "." +TBoxSub = Concept ("SUBCLASSOF" | "SUB" ) Concept "." +Concept = "TOP" + | "BOTTOM" + | Id + | "(" Concept "AND" Concept ")" + | "(" Concept "OR" Concept ")" + | "EXISTS" Id "." Concept + | "ALL" Id "." Concept + | "NOT" Concept + | ">=" Number Id "." Concept + | "<=" Number Id "." Concept + +Configuration Options +===================== + +General +------- + +Option: algorithm +Possible Values: bruteForce, gp, random, refinement, hybridGP +Default: refinement +Effect: Specifies the algorithm to use for solving the learning problem. Note, + that hybridGP is not an algorithm itself, but starts the GP algorithm + with a sensible set of default values for the hybrid algorithm combining + GP with refinement operators. In particular the probability of all + operators except refinement is set to 0. + +Option: reasoner +Possible Values: dig, kaon2, fastRetrieval +Default: dig +Effect: Specifies the reasoner to be used. DIG communicates with a reasoner + using the DIG Interface. KAON2 means to use the KAON2 Java API directly. + FastRetrieval is an internal algorithm, which can only be used for + retrieval (not for subsumption). Currently the DIG reasoner cannot read + OWL files. + +Option: digReasonerURL +Possible Values: a valid URL +Default: http://localhost:8081 +Effect: Specifies the URL to be used to look for a DIG capable reasoner. + +Option: writeDIGProtocol +Possible Values: true, false +Default: false +Effect: Specifies whether to store all DIG communication. + +Option: digProtocolFile +Possible Values: strings +Default: digProtocol.txt +Effect: The file to store all DIG communication if writeDIGProtocol is true. + +Option: useRetrievalForClassification +Possible Values: true, false +Default: false +Effect: To measure which concepts are covered, one can either use one retrieval + or several instance checks (at most one for each example). This option + controls which of both options should be used. + +Option: percentPerLengthUnit +Possible Values: 0-1 +Default: 0.05 +Effect: How much percent (wrt classification accuracy) can a concept be worse to + justify an increase in length of 1. This variable is used for GP and in + refinement when the flexible heuristic is used. For GP, you should use a + value smaller than the default. + +> general options below are ignored < +> by the refinement operator algorithm < + +Option: accuracyPenalty +Possible Values: 1-1000 +Default: 1 +Effect: Sets the penalty for "small misclassifications". + +Option: errorPenalty +Possible Values: 1-1000 +Default: 3 +Effect: Sets the penalty for classification errors. + +Option: maxLength +Possible Values: 1-20 +Default: 7 +Effect: For the brute force learner this specifies the depth limit for the + search. The GP learner currently ignores it. + +Option: scoreMethod +Possible Values: full, positive +Default: positive +Effect: The positive score method ignores if a negative examples cannot be + classified. This is often usefull, because of the limited expressiveness + of SHIQ wrt. negated role assertions. The full method penalizes this. + +Option: showCorrectClassifications +Possible Values: true, false +Default: false +Effect: Controls if correct classifications are printed (does not effect the + algorithm). + +Option: penalizeNeutralExamples +Possible Values: true, false +Default: false +Effect: If true there is a penalty if a neutral (neither positive nor negative) + individual is classified as either positive or negative. This should + usually be set to false. + +Refinement Operator Algorithm Specific +-------------------------------------- + +Option: refinement.horizontalExpansionFactor +Possible Values: 0-1 +Default: 0.6 +Effect: Specifies horizontal expansion factor. + +Option: refinement.writeSearchTree +Possible Values: true, false +Default: false +Effect: Specifies whether to write the search tree to a file. + +Option: refinement.searchTreeFile +Possible Values: strings +Default: "searchTree.txt" +Effect: Specifies a file to save the current search tree after each loop of + the refinement algorithm. + +Option: refinement.heuristic +Possible Values: flexible, lexicographic +Default: lexicographic +Effect: The refinement operator together with a heuristic yields a learning + algorithm. The lexicographic heuristic uses a lexicographic order of + covered negative examples and horizontal expansion of a node (i.e. + the covered examples are the first criterion, the horizontal expansion + the second criterion). The flexible heuristic computes a combined node + score of both criteria. Note, that the lexicographic needs a horizontal + expansion factor greater than 0 to ensure correctness of the learning + algorithm. + +Option: refinement.quiet +Possible Values: true, false +Default: false +Effect: If set to true, no messages will be shown during the run of the + algorithm (but there will still be startup and summary messages). + +Option: refinement.applyAllFilter +Possible Values: true, false +Default: true +Effect: Specifies wether all equivalences should be used. + +Option: refinement.applyExistsFilter +Possible Values: true, false +Default: true +Effect: Specifies wether exists equivalences should be used. + +Option: refinement.useTooWeakList +Possible Values: true, false +Default: true +Effect: Specifies wether a too weak list should be used to reduce reasoner + requests. + +Option: refinement.useOverlyGeneralList +Possible Values: true, false +Default: true +Effect: Specifies wether an overly general list should be used to reduce + reasoner requests. + +Option: refinement.useShortConceptConstruction +Possible Values: true, false +Default: true +Effect: Specifies wether the algorithm should try to reduce a concept to a + known more general concept to reduce the number of necessary + subsumption checks for the reasoner. + +Option: refinement.useDIGMultiInstanceChecks +Possible Values: never, twoChecks, oneCheck +Default: twoChecks +Effect: The DIG protocol allows to send several queries to a DIG reasoner at + once. [This is automatically done for subsumption tests.] However, + for instance checks this has the disadvantage that it may not be + necessary to send all instance to the DIG reasoner if one of the + positive examples is not covered (meaning that the concept is + classified as too weak). + If the option is set to never, then each instance check is send + separately. + If the option is set to twoChecks, then first all positive examples will + be send in one query. If all of them are covered, i.e. the concept is + not classified as too weak, then all the negative examples are send in + one query. + If the option is set to oneCheck, then all examples will be send in one + query. + +Genetic Programming Specific +---------------------------- + +Option: gp.algorithmType +Possible Values: steadyState, generational +Default: steadyState +Effect: Uses either a steady state (population partly replaced) or generational + (population completely replaced) algorithm. + +Option: gp.elitism +Possible Values: true, false +Default: true +Effect: If true an the GP algorithm uses elitism, i.e. the best individual is + guarenteed to survive. + +Option: gp.numberOfIndividuals +Possible Values: 1-1000000 +Default: 1000 +Effect: Sets the number of individuals in the population. A higher value + improves classification, but is computationally more expensive. + +Option: gp.numberOfSelectedIndividuals +Possible Values: 1-1000000 +Default: 960 +Effect: Sets the number of individuals, which are selected for replacement in a + steady state GP algorithm. + +Option: gp.crossoverPercent +Possible Values: 0-100 +Default: 95 +Effect: The probability that offspring is produced using crossover (in contrast + to simply being copied over to the next generation). + +Option: gp.mutationPercent +Possible Values: 0-100 +Default: 3 +Effect: The probability that offspring is mutated after reproduction. + +Option: gp.hillClimbingPercent +Possible Values: 0-100 +Default: 0 +Effect: The probability that offspring is produced using the hill climbing + operator. + +Option: gp.refinementPercent +Possible Values: 0-100 +Default: 0 +Effect: The probability that offspring is produced using the genetic refinement + operator. + +Option: gp.postConvergenceGenerations +Possible Values: 10-1000 +Default: 50 +Effect: If the algorithm does not find a better solution for this number of + generations it stops. Deleted: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/examples/father.conf 2007-10-05 14:17:55 UTC (rev 170) @@ -1,58 +0,0 @@ -/** - * Father Example - * - * possible solution: - * male AND EXISTS hasChild.TOP - * - * Copyright (C) 2007, Jens Lehmann - */ - -/** settings **/ -// reasoner settings -reasoner = dig; -digReasonerURL = "http://localhost:8081"; -useRetrievalForClassification = true; -refinement.useDIGMultiInstanceChecks = twoChecks; - -// algorithm settings -algorithm = refinement; -refinement.horizontalExpansionFactor = 0.5; -refinement.quiet = false; - -// search tree protocol -refinement.writeSearchTree = false; -refinement.searchTreeFile = "log/searchTree.txt"; - -// control output -showIndividuals = true; -showConcepts = true; -showRoles = true; -showInternalKB = true; -showSubsumptionHierarchy = true; - -/** background knowledge ***/ -BOTTOM = (male AND female). - -// persons -male(markus). -male(stefan). -male(heinz). -male(bernd). -female(anna). -female(gabi). -female(michelle). - -// children -hasChild(stefan,markus). -hasChild(markus,anna). -hasChild(bernd,gabi). -hasChild(anna,heinz). - -/** examples **/ -+father(stefan). -+father(markus). -+father(bernd). --father(heinz). --father(anna). --father(gabi). --father(michelle). Added: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf (rev 0) +++ trunk/examples/father.conf 2007-10-05 14:17:55 UTC (rev 170) @@ -0,0 +1,42 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +showIndividuals = true; +showConcepts = true; +showRoles = true; +showInternalKB = true; +showSubsumptionHierarchy = true; + +import("father.kb"); + +/** examples **/ ++stefan ++markus ++bernd +-heinz +-anna +-gabi +-michelle Added: trunk/examples/father.kb =================================================================== --- trunk/examples/father.kb (rev 0) +++ trunk/examples/father.kb 2007-10-05 14:17:55 UTC (rev 170) @@ -0,0 +1,16 @@ +BOTTOM = (male AND female). + +// persons +male(markus). +male(stefan). +male(heinz). +male(bernd). +female(anna). +female(gabi). +female(michelle). + +// children +hasChild(stefan,markus). +hasChild(markus,anna). +hasChild(bernd,gabi). +hasChild(anna,heinz). Property changes on: trunk/examples/father.kb ___________________________________________________________________ Name: svn:executable + * Copied: trunk/examples/fatherOld.conf (from rev 162, trunk/examples/father.conf) =================================================================== --- trunk/examples/fatherOld.conf (rev 0) +++ trunk/examples/fatherOld.conf 2007-10-05 14:17:55 UTC (rev 170) @@ -0,0 +1,58 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +digReasonerURL = "http://localhost:8081"; +useRetrievalForClassification = true; +refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +refinement.horizontalExpansionFactor = 0.5; +refinement.quiet = false; + +// search tree protocol +refinement.writeSearchTree = false; +refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +showIndividuals = true; +showConcepts = true; +showRoles = true; +showInternalKB = true; +showSubsumptionHierarchy = true; + +/** background knowledge ***/ +BOTTOM = (male AND female). + +// persons +male(markus). +male(stefan). +male(heinz). +male(bernd). +female(anna). +female(gabi). +female(michelle). + +// children +hasChild(stefan,markus). +hasChild(markus,anna). +hasChild(bernd,gabi). +hasChild(anna,heinz). + +/** examples **/ ++father(stefan). ++father(markus). ++father(bernd). +-father(heinz). +-father(anna). +-father(gabi). +-father(michelle). Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/lib/components.ini 2007-10-05 14:17:55 UTC (rev 170) @@ -2,9 +2,13 @@ // (if you implement your own components add them here) # knowledge sources org.dllearner.kb.OWLFile +org.dllearner.kb.KBFile +org.dllearner.kb.SparqlEndpoint # reasoners org.dllearner.reasoning.DIGReasonerNew # learning problems -org.dllearner.learningproblems.DefinitionLPTwoValued +org.dllearner.learningproblems.PosNegDefinitionLP # learning algorithms org.dllearner.algorithms.RandomGuesser +org.dllearner.algorithms.refinement.ROLearner +org.dllearner.algorithms.gp.GP Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-05 14:17:55 UTC (rev 170) @@ -112,7 +112,7 @@ public static boolean showInternalKB = false; public static int maxLineLength = 100; - public static boolean writeDIGProtocol = false; + public static boolean writeDIGProtocol = true; public static File digProtocolFile = new File("log/digProtocol.txt"); // public static String preprocessingModule = ""; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-05 14:17:55 UTC (rev 170) @@ -417,7 +417,7 @@ algorithmStartTime = System.nanoTime(); if (Config.algorithm == Algorithm.BRUTE_FORCE) { - LearningAlgorithmNew la = new BruteForceLearner(learningProblem); + LearningAlgorithmNew la = new BruteForceLearner(learningProblem, null); la.start(); } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { // new RandomGuesser(learningProblem, 10000, 10); @@ -449,7 +449,7 @@ // implemented)"); // } } - LearningAlgorithmNew la = new ROLearner(learningProblem); + LearningAlgorithmNew la = new ROLearner(learningProblem, null); la.start(); // new ROLearner(learningProblem, learningProblem2); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-05 14:17:55 UTC (rev 170) @@ -13,6 +13,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -52,7 +53,7 @@ // Programme nach Anzahl Knoten sortiert private Map<Integer,List<Concept>> generatedDefinitions = new HashMap<Integer,List<Concept>>(); - public BruteForceLearner(LearningProblem learningProblem) { + public BruteForceLearner(LearningProblem learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-05 14:17:55 UTC (rev 170) @@ -30,6 +30,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; @@ -42,7 +43,7 @@ private int numberOfTrees; private int maxDepth; - public RandomGuesser(LearningProblem learningProblem) { + public RandomGuesser(LearningProblem learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-05 14:17:55 UTC (rev 170) @@ -11,19 +11,18 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.algorithms.LearningAlgorithm; +import org.dllearner.Main; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; -import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -34,6 +33,8 @@ private boolean stop = false; + private ReasoningService rs; + private Comparator<Node> nodeComparator; private NodeComparatorStable nodeComparatorStable = new NodeComparatorStable(); private ConceptComparator conceptComparator = new ConceptComparator(); @@ -111,8 +112,12 @@ // soll später einen Operator und eine Heuristik entgegennehmen // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { - public ROLearner(PosNegLP learningProblem) { + public ROLearner(PosNegLP learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; + this.rs = rs; + + // rs.getR + // this.learningProblem2 = learningProblem2; operator = new RhoDown(learningProblem); @@ -214,7 +219,7 @@ public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); - problems.add(PosNegDefinitionLP.class); + problems.add(PosNegLP.class); return problems; } @@ -237,8 +242,13 @@ */ @Override public void init() { - // TODO Auto-generated method stub - + // TODO: this needs to be changed + Main.autoDetectConceptsAndRoles(rs); + // prepare subsumption and role hierarchies, because they are needed + // during the run of the algorithm + rs.prepareSubsumptionHierarchy(); + rs.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + rs.prepareRoleHierarchy(); } // Kernalgorithmus @@ -851,14 +861,17 @@ return false; } + @Override public Concept getBestSolution() { return candidatesStable.last().getConcept(); } + @Override public Score getSolutionScore() { return learningProblem.computeScore(getBestSolution()); } + @Override public void stop() { stop = true; } Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-05 14:17:55 UTC (rev 170) @@ -92,7 +92,7 @@ // TODO: SPARQL-specific settings // ks.applyConfigEntry(new ConfigEntry) - + sources.add(ks); } // step 2: detect used reasoner @@ -106,8 +106,10 @@ + "for option \"reasoner\"."); } - // step 3: detect learning problem (no options yet) + // step 3: detect learning problem (no options for choosing it yet) LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + cm.applyConfigEntry(lp, "positiveExamples", parser.getPositiveExamples()); + cm.applyConfigEntry(lp, "negativeExamples", parser.getNegativeExamples()); // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); @@ -116,16 +118,21 @@ if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; - la = cm.learningAlgorithm(ROLearner.class, lp); + la = cm.learningAlgorithm(ROLearner.class, lp, rs); - configureComponent(cm, la, parser.getConfOptionsByPrefix(componentPrefixMapping - .get(la))); + String algPrefix = componentPrefixMapping.get(la.getClass()); + configureComponent(cm, la, parser.getConfOptionsByPrefix(algPrefix)); + // initialise all structures + for(KnowledgeSource source : sources) + source.init(); + rs.init(); + lp.init(); + la.init(); + // start algorithm la.start(); - // use parsed values to configure components - // several classes of options: function calls, conf options for a // component, // CLI specific options, general conf options for all components @@ -139,17 +146,22 @@ // creates a mapping from components to option prefix strings private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); + // knowledge sources + componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); + // reasoners + componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); + // learning problems - configured via + and - flags for examples + // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); componentPrefixMapping.put(GP.class, "gp"); - componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); - componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); return componentPrefixMapping; } private static void configureComponent(ComponentManager cm, Component component, List<ConfFileOption> options) { - for (ConfFileOption option : options) - applyConfFileOption(cm, component, option); + if(options != null) + for (ConfFileOption option : options) + applyConfFileOption(cm, component, option); } private static void applyConfFileOption(ComponentManager cm, @@ -240,8 +252,8 @@ Class<? extends KnowledgeSource> ksClass; if (arguments.size() == 1) { String filename = url.getPath(); - String ending = filename.substring(filename.lastIndexOf(".")); - + String ending = filename.substring(filename.lastIndexOf(".")+1); + if (ending.equals("rdf") || ending.equals("owl")) ksClass = OWLFile.class; else if (ending.equals("nt")) @@ -249,7 +261,7 @@ else if (ending.equals("kb")) ksClass = KBFile.class; else { - System.err.println("Warning: no format fiven for " + arguments.get(0) + System.err.println("Warning: no format given for " + arguments.get(0) + " and could not detect it. Chosing RDF/XML."); ksClass = OWLFile.class; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-05 14:17:55 UTC (rev 170) @@ -275,7 +275,7 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem lp) { + public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem lp, ReasoningService rs) { if (!learningAlgorithms.contains(la)) System.err.println("Warning: learning algorithm " + la + " is not a registered learning algorithm component."); @@ -296,7 +296,7 @@ return null; } - return invokeConstructor(la, new Class[] { constructorArgument }, new Object[] { lp }); + return invokeConstructor(la, new Class[] { constructorArgument, ReasoningService.class }, new Object[] { lp, rs }); } public void writeConfigDocumentation(File file) { Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-05 14:17:55 UTC (rev 170) @@ -71,7 +71,7 @@ lp.init(); // create the learning algorithm - LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp); + LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); la.init(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-05 14:17:55 UTC (rev 170) @@ -341,6 +341,10 @@ return getRoleHierarchy().getMostSpecialRoles(); } + public void prepareSubsumptionHierarchy() { + reasoner.prepareSubsumptionHierarchy(); + } + public SubsumptionHierarchy getSubsumptionHierarchy() { try { nrOfSubsumptionHierarchyQueries++; @@ -351,6 +355,14 @@ } } + public void prepareRoleHierarchy() { + try { + reasoner.prepareRoleHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + public RoleHierarchy getRoleHierarchy() { try { return reasoner.getRoleHierarchy(); Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-05 14:17:55 UTC (rev 170) @@ -21,7 +21,10 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; +import java.net.URL; import java.util.Collection; import java.util.LinkedList; @@ -41,7 +44,8 @@ */ public class KBFile extends KnowledgeSource { - private File file; + // private File file; + private URL url; private KB kb; public static String getName() { @@ -50,7 +54,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("filename", "pointer to the KB file")); + options.add(new StringConfigOption("filename", "pointer to the KB file on local file system")); + options.add(new StringConfigOption("url", "URL pointer to the KB file")); return options; } @@ -61,7 +66,18 @@ public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { String option = entry.getOptionName(); if (option.equals("filename")) { - file = new File((String)entry.getValue()); + // file = new File((String)entry.getValue()); + try { + url = new File((String)entry.getValue()).toURI().toURL(); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(),entry.getValue()); + } + } else if(option.equals("url")) { + try { + url = new URL((String)entry.getValue()); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(),entry.getValue()); + } } } @@ -71,12 +87,10 @@ @Override public void init() { try { - kb = KBParser.parseKBFile(file); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block + kb = KBParser.parseKBFile(url); + } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -88,7 +102,15 @@ */ @Override public String toDIG(URI kbURI) { - return DIGConverter.getDIGString(kb).toString(); + return DIGConverter.getDIGString(kb, kbURI).toString(); } + @Override + public String toString() { + if(kb==null) + return "KB file (not initialised)"; + else + return kb.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-05 14:17:55 UTC (rev 170) @@ -27,8 +27,8 @@ public @SuppressWarnings("all") class ConfParser implements ConfParserConstants { // examples - private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); - private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + private SortedSet<String> positiveExamples = new TreeSet<String>(); + private SortedSet<String> negativeExamples = new TreeSet<String>(); // conf file options private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); @@ -70,11 +70,11 @@ } } - public SortedSet<Individual> getPositiveExamples() { + public SortedSet<String> getPositiveExamples() { return positiveExamples; } - public SortedSet<Individual> getNegativeExamples() { + public SortedSet<String> getNegativeExamples() { return negativeExamples; } @@ -385,20 +385,20 @@ } final public void PosExample() throws ParseException { - Individual i; + String i; jj_consume_token(POS_EX); i = Individual(); positiveExamples.add(i); } final public void NegExample() throws ParseException { - Individual i; + String i; jj_consume_token(NEG_EX); i = Individual(); negativeExamples.add(i); } - final public Individual Individual() throws ParseException { + final public String Individual() throws ParseException { String name; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ID: @@ -412,7 +412,7 @@ jj_consume_token(-1); throw new ParseException(); } - {if (true) return new Individual(KBParser.getInternalURI(name));} + {if (true) return KBParser.getInternalURI(name);} throw new Error("Missing return statement in function"); } Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-05 14:17:55 UTC (rev 170) @@ -2,10 +2,8 @@ package org.dllearner.parser; import org.dllearner.core.dl.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.StringReader; +import java.io.*; +import java.net.URL; public @SuppressWarnings("all") class KBParser implements KBParserConstants { @@ -25,6 +23,11 @@ return parser.Concept(); } + public static KB parseKBFile(URL url) throws IOException, ParseException { + KBParser parser = new KBParser(url.openStream()); + return parser.KB(); + } + public static KB parseKBFile(File file) throws FileNotFoundException, ParseException { KBParser parser = new KBParser(new FileInputStream(file)); return parser.KB(); @@ -491,35 +494,6 @@ finally { jj_save(5, xla); } } - final private boolean jj_3R_18() { - if (jj_3R_22()) return true; - return false; - } - - final private boolean jj_3R_14() { - if (jj_scan_token(20)) return true; - if (jj_3R_20()) return true; - if (jj_3R_4()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_2()) return true; - return false; - } - - final private boolean jj_3R_15() { - if (jj_3R_21()) return true; - return false; - } - - final private boolean jj_3R_3() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_15()) { - jj_scanpos = xsp; - if (jj_3R_16()) return true; - } - return false; - } - final private boolean jj_3R_13() { if (jj_scan_token(19)) return true; if (jj_3R_20()) return true; @@ -724,6 +698,35 @@ return false; } + final private boolean jj_3R_18() { + if (jj_3R_22()) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_scan_token(20)) return true; + if (jj_3R_20()) return true; + if (jj_3R_4()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_2()) return true; + return false; + } + + final private boolean jj_3R_15() { + if (jj_3R_21()) return true; + return false; + } + + final private boolean jj_3R_3() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_15()) { + jj_scanpos = xsp; + if (jj_3R_16()) return true; + } + return false; + } + public KBParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; Modified: trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java 2007-10-05 14:17:55 UTC (rev 170) @@ -1,10 +1,8 @@ /* Generated By:JavaCC: Do not edit this line. KBParserTokenManager.java */ package org.dllearner.parser; import org.dllearner.core.dl.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.StringReader; +import java.io.*; +import java.net.URL; public @SuppressWarnings("all") class KBParserTokenManager implements KBParserConstants { Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-05 14:17:55 UTC (rev 170) @@ -56,8 +56,8 @@ public class ConfParser { // examples - private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); - private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + private SortedSet<String> positiveExamples = new TreeSet<String>(); + private SortedSet<String> negativeExamples = new TreeSet<String>(); // conf file options private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); @@ -99,11 +99,11 @@ } } - public SortedSet<Individual> getPositiveExamples() { + public SortedSet<String> getPositiveExamples() { return positiveExamples; } - public SortedSet<Individual> getNegativeExamples() { + public SortedSet<String> getNegativeExamples() { return negativeExamples; } @@ -349,26 +349,26 @@ { addFunctionCall(s1,list); } } -void PosExample() : { Individual i; } +void PosExample() : { String i; } { <POS_EX> i=Individual() { positiveExamples.add(i); } } -void NegExample() : { Individual i; } +void NegExample() : { String i; } { <NEG_EX> i=Individual() { negativeExamples.add(i); } } -Individual Individual() : +String Individual() : { String name; } { (name=Id() | name=String()) { - return new Individual(KBParser.getInternalURI(name)); + return KBParser.getInternalURI(name); } } Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2007-10-05 14:17:55 UTC (rev 170) @@ -31,10 +31,8 @@ package org.dllearner.parser; import org.dllearner.core.dl.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.StringReader; +import java.io.*; +import java.net.URL; public class KBParser { @@ -54,6 +52,11 @@ return parser.Concept(); } + public static KB parseKBFile(URL url) throws IOException, ParseException { + KBParser parser = new KBParser(url.openStream()); + return parser.KB(); + } + public static KB parseKBFile(File file) throws FileNotFoundException, ParseException { KBParser parser = new KBParser(new FileInputStream(file)); return parser.KB(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGConverter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGConverter.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGConverter.java 2007-10-05 14:17:55 UTC (rev 170) @@ -1,5 +1,6 @@ package org.dllearner.reasoning; +import java.net.URI; import java.util.Set; import org.dllearner.core.dl.All; @@ -38,6 +39,18 @@ */ public class DIGConverter { + public static StringBuilder getDIGString(KB kb, URI kbURI) { + StringBuilder sb = new StringBuilder(); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); + sb.append(getDIGString(kb)); + sb.append("</tells>"); + return sb; + } + public static StringBuilder getDIGString(KB kb) { StringBuilder sb = new StringBuilder(); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-05 14:17:55 UTC (rev 170) @@ -155,7 +155,7 @@ // LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); PosNegLP learningProblem = null; // erstmal wird nur der Refinement-Learner als Web-Service angeboten - ROLearner learner = new ROLearner(learningProblem); + ROLearner learner = new ROLearner(learningProblem, null); return learner.getBestSolution().toString(); } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-04 15:08:33 UTC (rev 169) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-05 14:17:55 UTC (rev 170) @@ -162,8 +162,8 @@ Map<URL, OntologyFileFormat> imports = getImports(learner.getFunctionCalls(), confFiles[exampleNr]); // detect specified positive and negative examples - SortedSet<Individual> positiveExamples = learner.getPositiveExamples(); - SortedSet<Individual> negativeExamples = learner.getNegativeExamples(); + SortedSet<String> positiveExamples = learner.getPositiveExamples(); + SortedSet<String> negativeExamples = learner.getNegativeExamples(); int nrOfExamples = positiveExamples.size() + negativeExamples.size(); statString += "example: " + examples[exampleNr] + "\n\n"; @@ -237,7 +237,7 @@ if(exampleNr==3 || exampleNr==5 || exampleNr == 6) Config.percentPerLengthUnit = 0.002; // learningAlgorithm = new GP(learningProblem); - learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem); + learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); } else if(algorithmNr==2) { Config.algorithm = Algorithm.HYBRID_GP; Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; @@ -255,7 +255,7 @@ if(exampleNr == 3 || exampleNr==5 || exampleNr==6) Config.percentPerLengthUnit = 0.002; // learningAlgorithm = new GP(learningProblem); - learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem); + learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); } // rs.resetStatistics(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-05 16:29:59
|
Revision: 171 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=171&view=rev Author: jenslehmann Date: 2007-10-05 09:29:52 -0700 (Fri, 05 Oct 2007) Log Message: ----------- further improvements of command line interface Modified Paths: -------------- trunk/examples/father.conf trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2007-10-05 14:17:55 UTC (rev 170) +++ trunk/examples/father.conf 2007-10-05 16:29:52 UTC (rev 171) @@ -24,11 +24,12 @@ // refinement.searchTreeFile = "log/searchTree.txt"; // control output -showIndividuals = true; -showConcepts = true; -showRoles = true; -showInternalKB = true; -showSubsumptionHierarchy = true; +cli.checkSatisfiability = true; +cli.showIndividuals = true; +cli.showConcepts = true; +cli.showRoles = true; +cli.showInternalKB = true; +cli.showSubsumptionHierarchy = true; import("father.kb"); Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-05 14:17:55 UTC (rev 170) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-05 16:29:52 UTC (rev 171) @@ -112,7 +112,7 @@ public static boolean showInternalKB = false; public static int maxLineLength = 100; - public static boolean writeDIGProtocol = true; + public static boolean writeDIGProtocol = false; public static File digProtocolFile = new File("log/digProtocol.txt"); // public static String preprocessingModule = ""; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-05 14:17:55 UTC (rev 170) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-05 16:29:52 UTC (rev 171) @@ -41,6 +41,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; @@ -51,6 +52,7 @@ import org.dllearner.parser.ConfParser; import org.dllearner.reasoning.DIGReasonerNew; import org.dllearner.utilities.Datastructures; +import org.dllearner.utilities.Helper; /** * Startup file for Command Line Interface. @@ -76,35 +78,33 @@ // parse conf file ConfParser parser = ConfParser.parseFile(file); - // try { - // step 1: detect knowledge sources Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); Map<URL, Class<? extends KnowledgeSource>> importedFiles = getImportedFiles(parser, baseDir); for (Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles.entrySet()) { KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); - // ConfigOption<?> urlOption = cm.getConfigOption(entry.getValue(), - // "url"); - // cm.applyConfigEntry(ks, new ConfigEntry<String>(urlOption, - // entry.getValue())); + // apply URL entry (this assumes that every knowledge source has a + // configuration option "url"), so this may need to be changed in the + // future cm.applyConfigEntry(ks, "url", entry.getKey().toString()); - // TODO: SPARQL-specific settings - - // ks.applyConfigEntry(new ConfigEntry) sources.add(ks); + configureComponent(cm, ks, componentPrefixMapping, parser); } // step 2: detect used reasoner ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); - ReasoningService rs = null; + Class<? extends ReasonerComponent> reasonerClass = null; // default value if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) - rs = cm.reasoningService(DIGReasonerNew.class, sources); + reasonerClass = DIGReasonerNew.class; else { handleError("Unknown value " + reasonerOption.getStringValue() + "for option \"reasoner\"."); } + ReasonerComponent reasoner = cm.reasoner(reasonerClass, sources); + configureComponent(cm, reasoner, componentPrefixMapping, parser); + ReasoningService rs = cm.reasoningService(reasoner); // step 3: detect learning problem (no options for choosing it yet) LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); @@ -118,11 +118,9 @@ if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; - la = cm.learningAlgorithm(ROLearner.class, lp, rs); + la = cm.learningAlgorithm(laClass, lp, rs); + configureComponent(cm, la, componentPrefixMapping, parser); - String algPrefix = componentPrefixMapping.get(la.getClass()); - configureComponent(cm, la, parser.getConfOptionsByPrefix(algPrefix)); - // initialise all structures for(KnowledgeSource source : sources) source.init(); @@ -130,17 +128,22 @@ lp.init(); la.init(); + // Satisfiability Check + if (parser.getConfOptionsByName("cli.checkSatisfiability").getStringValue().equals("true")) { + System.out.print("Satisfiability Check ... "); + long satStartTime = System.nanoTime(); + boolean satisfiable = rs.isSatisfiable(); + long satDuration = System.nanoTime() - satStartTime; + + String result = satisfiable ? "OK" : "not satisfiable!"; + System.out.println(result + " (" + + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); + if (!satisfiable) + System.exit(0); + } + // start algorithm la.start(); - - // several classes of options: function calls, conf options for a - // component, - // CLI specific options, general conf options for all components - - // } catch (InvalidConfigOptionValueException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } } // creates a mapping from components to option prefix strings @@ -157,6 +160,13 @@ return componentPrefixMapping; } + private static void configureComponent(ComponentManager cm, Component component, + Map<Class<? extends Component>,String> componentPrefixMapping, ConfParser parser) { + String prefix = componentPrefixMapping.get(component.getClass()); + if(prefix != null) + configureComponent(cm, component, parser.getConfOptionsByPrefix(prefix)); + } + private static void configureComponent(ComponentManager cm, Component component, List<ConfFileOption> options) { if(options != null) Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-05 14:17:55 UTC (rev 170) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-05 16:29:52 UTC (rev 171) @@ -247,24 +247,42 @@ return invokeConstructor(source, new Class[] {}, new Object[] {}); } - public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, + public <T extends ReasonerComponent> T reasoner(Class<T> reasoner, KnowledgeSource source) { Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(source); - return reasoningService(reasoner, sources); + return reasoner(reasoner, sources); } - public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, + public <T extends ReasonerComponent> T reasoner(Class<T> reasoner, Set<KnowledgeSource> sources) { if (!reasonerComponents.contains(reasoner)) System.err.println("Warning: reasoner component " + reasoner + " is not a registered reasoner component."); - T reasonerInstance = invokeConstructor(reasoner, new Class[] { Set.class }, + return invokeConstructor(reasoner, new Class[] { Set.class }, new Object[] { sources }); - return new ReasoningService(reasonerInstance); +// T reasonerInstance = invokeConstructor(reasoner, new Class[] { Set.class }, +// new Object[] { sources }); +// return new ReasoningService(reasonerInstance); } + /** + * This method returns an instance of <code>ReasoningService</code>. The + * difference between <code>ReasoningService</code> and <code>ReasonerComponent</code> + * is that the former delegates all calls to the latter and collects statistics + * while doing this. This means that the reasoning service enables the + * collection of query information, while the <code>ReasonerComponent</code> + * implements the actual reasoning methods defined by the <code>Reasoner</code> + * interface. + * + * @param reasoner A reasoner component. + * @return The reasoning service encapsulating the reasoner. + */ + public ReasoningService reasoningService(ReasonerComponent reasoner) { + return new ReasoningService(reasoner); + } + public <T extends LearningProblem> T learningProblem(Class<T> lp, ReasoningService reasoner) { if (!learningProblems.contains(lp)) System.err.println("Warning: learning problem " + lp Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-05 14:17:55 UTC (rev 170) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-05 16:29:52 UTC (rev 171) @@ -53,7 +53,9 @@ source.init(); // create DIG reasoning service with standard settings - ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + ReasonerComponent reasoner = cm.reasoner(DIGReasonerNew.class, source); + // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + ReasoningService rs = cm.reasoningService(reasoner); rs.init(); // create a learning problem and set positive and negative examples This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-07 16:32:15
|
Revision: 172 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=172&view=rev Author: jenslehmann Date: 2007-10-07 09:32:12 -0700 (Sun, 07 Oct 2007) Log Message: ----------- extended CLI to accept some output controlling conf options (same as in old interface) Modified Paths: -------------- trunk/examples/father.conf trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/examples/father.conf 2007-10-07 16:32:12 UTC (rev 172) @@ -25,11 +25,10 @@ // control output cli.checkSatisfiability = true; -cli.showIndividuals = true; -cli.showConcepts = true; +cli.showIndividuals = false; +cli.showConcepts = false; cli.showRoles = true; -cli.showInternalKB = true; -cli.showSubsumptionHierarchy = true; +cli.showSubsumptionHierarchy = false; import("father.kb"); Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-07 16:32:12 UTC (rev 172) @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; @@ -42,9 +43,13 @@ import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Individual; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpoint; @@ -70,7 +75,11 @@ String baseDir = file.getParentFile().getPath(); // create component manager instance + System.out.print("starting component manager ... "); + long cmStartTime = System.nanoTime(); ComponentManager cm = ComponentManager.getInstance(); + long cmTime = System.nanoTime() - cmStartTime; + System.out.println("OK (" + Helper.prettyPrintNanoSeconds(cmTime) + ")"); // create a mapping between components and prefixes in the conf file Map<Class<? extends Component>, String> componentPrefixMapping = createComponentPrefixMapping(); @@ -84,7 +93,8 @@ for (Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles.entrySet()) { KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); // apply URL entry (this assumes that every knowledge source has a - // configuration option "url"), so this may need to be changed in the + // configuration option "url"), so this may need to be changed in + // the // future cm.applyConfigEntry(ks, "url", entry.getKey().toString()); @@ -108,8 +118,10 @@ // step 3: detect learning problem (no options for choosing it yet) LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); - cm.applyConfigEntry(lp, "positiveExamples", parser.getPositiveExamples()); - cm.applyConfigEntry(lp, "negativeExamples", parser.getNegativeExamples()); + SortedSet<String> posExamples = parser.getPositiveExamples(); + SortedSet<String> negExamples = parser.getNegativeExamples(); + cm.applyConfigEntry(lp, "positiveExamples", posExamples); + cm.applyConfigEntry(lp, "negativeExamples", negExamples); // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); @@ -122,26 +134,34 @@ configureComponent(cm, la, componentPrefixMapping, parser); // initialise all structures - for(KnowledgeSource source : sources) - source.init(); - rs.init(); - lp.init(); - la.init(); - - // Satisfiability Check - if (parser.getConfOptionsByName("cli.checkSatisfiability").getStringValue().equals("true")) { - System.out.print("Satisfiability Check ... "); - long satStartTime = System.nanoTime(); - boolean satisfiable = rs.isSatisfiable(); - long satDuration = System.nanoTime() - satStartTime; + for (KnowledgeSource source : sources) + initComponent(cm, source); + initComponent(cm, reasoner); + initComponent(cm, lp); + initComponent(cm, la); - String result = satisfiable ? "OK" : "not satisfiable!"; - System.out.println(result + " (" - + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); - if (!satisfiable) - System.exit(0); + // show examples (display each one if they do not take up much space, + // otherwise just show the number of examples) + boolean oneLineExampleInfo = true; + int maxExampleStringLength = Math.max(posExamples.toString().length(), negExamples + .toString().length()); + if (maxExampleStringLength > 100) + oneLineExampleInfo = false; + if (oneLineExampleInfo) { + System.out.println("positive examples[" + posExamples.size() + "]: " + posExamples); + System.out.println("negative examples[" + negExamples.size() + "]: " + negExamples); + } else { + System.out.println("positive examples[" + posExamples.size() + "]: "); + for (String ex : posExamples) + System.out.println(" " + ex); + System.out.println("negative examples[" + negExamples.size() + "]: "); + for (String ex : negExamples) + System.out.println(" " + ex); } - + + // handle any CLI options + processCLIOptions(cm, parser, rs); + // start algorithm la.start(); } @@ -150,9 +170,9 @@ private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); // knowledge sources - componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); + componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); // reasoners - componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); + componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); // learning problems - configured via + and - flags for examples // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); @@ -161,21 +181,21 @@ } private static void configureComponent(ComponentManager cm, Component component, - Map<Class<? extends Component>,String> componentPrefixMapping, ConfParser parser) { + Map<Class<? extends Component>, String> componentPrefixMapping, ConfParser parser) { String prefix = componentPrefixMapping.get(component.getClass()); - if(prefix != null) + if (prefix != null) configureComponent(cm, component, parser.getConfOptionsByPrefix(prefix)); } - - private static void configureComponent(ComponentManager cm, - Component component, List<ConfFileOption> options) { - if(options != null) + + private static void configureComponent(ComponentManager cm, Component component, + List<ConfFileOption> options) { + if (options != null) for (ConfFileOption option : options) applyConfFileOption(cm, component, option); } - private static void applyConfFileOption(ComponentManager cm, - Component component, ConfFileOption option) { + private static void applyConfFileOption(ComponentManager cm, Component component, + ConfFileOption option) { // the name of the option is suboption-part (the first part refers // to its component) String optionName = option.getSubOption(); @@ -186,44 +206,46 @@ // catch all invalid config options try { - + // perform compatibility checks if (configOption instanceof StringConfigOption && option.isStringOption()) { ConfigEntry<String> entry = new ConfigEntry<String>( (StringConfigOption) configOption, option.getStringValue()); cm.applyConfigEntry(component, entry); - - } else if(configOption instanceof IntegerConfigOption && option.isIntegerOption()) { - + + } else if (configOption instanceof IntegerConfigOption && option.isIntegerOption()) { + ConfigEntry<Integer> entry = new ConfigEntry<Integer>( (IntegerConfigOption) configOption, option.getIntValue()); - cm.applyConfigEntry(component, entry); - - } else if(configOption instanceof DoubleConfigOption && (option.isIntegerOption() || option.isDoubleOption())) { - + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof DoubleConfigOption + && (option.isIntegerOption() || option.isDoubleOption())) { + double value; - if(option.isIntegerOption()) + if (option.isIntegerOption()) value = option.getIntValue(); else value = option.getDoubleValue(); - + ConfigEntry<Double> entry = new ConfigEntry<Double>( (DoubleConfigOption) configOption, value); - cm.applyConfigEntry(component, entry); - - } else if(configOption instanceof BooleanConfigOption && option.isStringOption()) { - + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof BooleanConfigOption && option.isStringOption()) { + ConfigEntry<Boolean> entry = new ConfigEntry<Boolean>( - (BooleanConfigOption) configOption, Datastructures.strToBool(option.getStringValue())); - cm.applyConfigEntry(component, entry); - - } else if(configOption instanceof StringSetConfigOption && option.isSetOption()) { - + (BooleanConfigOption) configOption, Datastructures.strToBool(option + .getStringValue())); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof StringSetConfigOption && option.isSetOption()) { + ConfigEntry<Set<String>> entry = new ConfigEntry<Set<String>>( (StringSetConfigOption) configOption, option.getSetValues()); - cm.applyConfigEntry(component, entry); - + cm.applyConfigEntry(component, entry); + } else { handleError("The type of conf file entry " + option + " is not correct."); } @@ -262,8 +284,8 @@ Class<? extends KnowledgeSource> ksClass; if (arguments.size() == 1) { String filename = url.getPath(); - String ending = filename.substring(filename.lastIndexOf(".")+1); - + String ending = filename.substring(filename.lastIndexOf(".") + 1); + if (ending.equals("rdf") || ending.equals("owl")) ksClass = OWLFile.class; else if (ending.equals("nt")) @@ -300,6 +322,92 @@ return importedFiles; } + private static void processCLIOptions(ComponentManager cm, ConfParser parser, + ReasoningService rs) { + // CLI options (i.e. options which are related to the CLI + // user interface but not to one of the components) + List<ConfFileOption> cliOptions = parser.getConfOptionsByPrefix("cli"); + int maxLineLength = 100; + for (ConfFileOption cliOption : cliOptions) { + String name = cliOption.getSubOption(); + if (name.equals("showIndividuals")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getIndividuals().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("individuals[" + rs.getIndividuals().size() + "]: "); + for (Individual ind : rs.getIndividuals()) + System.out.println(" " + ind); + } else + System.out.println("individuals[" + rs.getIndividuals().size() + "]: " + + rs.getIndividuals()); + } + } else if (name.equals("showConcepts")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getAtomicConcepts().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: "); + for (AtomicConcept ac : rs.getAtomicConcepts()) + System.out.println(" " + ac); + } else + System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: " + + rs.getAtomicConcepts()); + } + } else if (name.equals("showRoles")) { + if (cliOption.getStringValue().equals("true")) { + int stringLength = rs.getAtomicRoles().toString().length(); + if (stringLength > maxLineLength) { + System.out.println("roles[" + rs.getAtomicRoles().size() + "]: "); + for (AtomicRole r : rs.getAtomicRoles()) + System.out.println(" " + r); + } else + System.out.println("roles[" + rs.getAtomicRoles().size() + "]: " + + rs.getAtomicRoles()); + } + } else if (name.equals("showSubsumptionHierarchy")) { + if (cliOption.getStringValue().equals("true")) { + System.out.println("Subsumption Hierarchy:"); + System.out.println(rs.getSubsumptionHierarchy()); + } + // satisfiability check + } else if (name.equals("checkSatisfiability")) { + if (cliOption.getStringValue().equals("true")) { + System.out.print("Satisfiability Check ... "); + long satStartTime = System.nanoTime(); + boolean satisfiable = rs.isSatisfiable(); + long satDuration = System.nanoTime() - satStartTime; + + String result = satisfiable ? "OK" : "not satisfiable!"; + System.out.println(result + " (" + + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); + if (!satisfiable) + System.exit(0); + } + } else + handleError("Unknown CLI option \"" + name + "\"."); + } + } + + private static void initComponent(ComponentManager cm, Component component) { + System.out.print("initialising component \"" + cm.getComponentName(component.getClass()) + + "\" ... "); + long initStartTime = System.nanoTime(); + component.init(); + // standard messsage is just "OK" but can be more detailed for certain + // components + String message = "OK"; + if (component instanceof KBFile) + message = ((KBFile) component).getURL().toString() + " read"; + else if (component instanceof DIGReasonerNew) { + DIGReasonerNew reasoner = (DIGReasonerNew) component; + message = "using " + reasoner.getIdentifier() + " connected via DIG 1.1 at " + + reasoner.getReasonerURL().toString(); + } + + long initTime = System.nanoTime() - initStartTime; + System.out.println(message + " (" + Helper.prettyPrintNanoSeconds(initTime, false, false) + + ")"); + } + private static void handleError(String message) { System.err.println(message); System.exit(0); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-07 16:32:12 UTC (rev 172) @@ -66,6 +66,7 @@ private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; // list of all configuration options of all components + private static Map<Class<? extends Component>, String> componentNames; private static Map<Class<? extends Component>, List<ConfigOption<?>>> componentOptions; private static Map<Class<? extends Component>, Map<String, ConfigOption<?>>> componentOptionsByName; private static Map<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; @@ -119,15 +120,18 @@ } } + componentNames = new HashMap<Class<? extends Component>, String>(); // read in all configuration options componentOptions = new HashMap<Class<? extends Component>, List<ConfigOption<?>>>(); componentOptionsByName = new HashMap<Class<? extends Component>, Map<String, ConfigOption<?>>>(); for (Class<? extends Component> component : components) { + String name = (String) invokeStaticMethod(component, "getName"); + componentNames.put(component, name); + List<ConfigOption<?>> options = (List<ConfigOption<?>>) invokeStaticMethod(component, "createConfigOptions"); - componentOptions.put(component, options); Map<String, ConfigOption<?>> byName = new HashMap<String, ConfigOption<?>>(); @@ -420,5 +424,9 @@ public ConfigOption<?> getConfigOption(Class<? extends Component> component, String name) { return componentOptionsByName.get(component).get(name); } + + public String getComponentName(Class<? extends Component> component) { + return componentNames.get(component); + } } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-07 16:32:12 UTC (rev 172) @@ -56,7 +56,7 @@ ReasonerComponent reasoner = cm.reasoner(DIGReasonerNew.class, source); // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); ReasoningService rs = cm.reasoningService(reasoner); - rs.init(); + reasoner.init(); // create a learning problem and set positive and negative examples LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-07 16:32:12 UTC (rev 172) @@ -102,6 +102,7 @@ this.reasoner = reasoner; } + /* public void init() { // temporary ugly hack to keep old version working ((ReasonerComponent)reasoner).init(); @@ -110,6 +111,7 @@ atomicConceptsList = new LinkedList<AtomicConcept>(getAtomicConcepts()); atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); } + */ // zurücksetzen aller Statistiken (wenn z.B. vorher ein Satisfiability Check gemacht wird, // der allerdings nicht zum eigentlichen Algorithmus gehört) Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-07 16:32:12 UTC (rev 172) @@ -20,7 +20,6 @@ package org.dllearner.kb; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -113,4 +112,8 @@ return kb.toString(); } + public URL getURL() { + return url; + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-07 16:32:12 UTC (rev 172) @@ -91,6 +91,8 @@ return OWLAPIDIGConverter.getTellsString(url, OntologyFileFormat.RDF_XML, kbURI); } + public URL getURL() { + return url; + } - } Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-07 16:32:12 UTC (rev 172) @@ -98,4 +98,7 @@ return null; } + public URL getURL() { + return url; + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-10-05 16:29:52 UTC (rev 171) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-10-07 16:32:12 UTC (rev 172) @@ -729,6 +729,8 @@ // kaon2Reasoner.saveOntology(file, format); } - + public URL getReasonerURL() { + return reasonerURL; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 09:49:16
|
Revision: 177 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=177&view=rev Author: jenslehmann Date: 2007-10-08 02:49:14 -0700 (Mon, 08 Oct 2007) Log Message: ----------- implemented inclusion learning problem Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-10-08 08:30:59 UTC (rev 176) +++ trunk/lib/components.ini 2007-10-08 09:49:14 UTC (rev 177) @@ -5,9 +5,10 @@ org.dllearner.kb.KBFile org.dllearner.kb.SparqlEndpoint # reasoners -org.dllearner.reasoning.DIGReasonerNew +org.dllearner.reasoning.DIGReasoner # learning problems org.dllearner.learningproblems.PosNegDefinitionLP +org.dllearner.learningproblems.PosNegInclusionLP # learning algorithms org.dllearner.algorithms.RandomGuesser org.dllearner.algorithms.refinement.ROLearner Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 08:30:59 UTC (rev 176) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 09:49:14 UTC (rev 177) @@ -56,6 +56,12 @@ super(reasoningService); } + public PosNegDefinitionLP(ReasoningService reasoningService, SortedSet<Individual> positiveExamples, SortedSet<Individual> negativeExamples) { + super(reasoningService); + this.positiveExamples = positiveExamples; + this.negativeExamples = negativeExamples; + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-08 08:30:59 UTC (rev 176) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-08 09:49:14 UTC (rev 177) @@ -21,31 +21,38 @@ import java.util.Collection; import java.util.LinkedList; -import java.util.Set; -import java.util.SortedSet; import org.dllearner.core.BooleanConfigOption; -import org.dllearner.core.CommonConfigMappings; -import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; -import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.Negation; /** + * The aim of this learning problem is to find an appropriate inclusion axiom + * given positive and negative examples. + * + * This is similar to the definition learning problem, but here the positive + * and negative examples usually do not follow when the inclusion is added to + * the knowledge base. This raises the question how the quality of a concept + * with respect to this learning problem can be measured. Due to the fact that + * the inclusion does not entail examples, we have to look at the negation of + * the concept we are looking at. For a good solution it is the case that + * no positive examples follow from the negated concept, the negative + * examples follow from it. This means that the standard definition learning + * problem and the inclusion learning problem can be seen as two possible + * weakenings of the strict definition learning problem. (Of course, both problems + * can yield the same solution.) + * * @author Jens Lehmann * */ public class PosNegInclusionLP extends PosNegLP implements InclusionLP { - private SortedSet<Individual> positiveExamples; - private SortedSet<Individual> negativeExamples; - private SortedSet<Individual> posNegExamples; - + private PosNegDefinitionLP definitionLP; + public PosNegInclusionLP(ReasoningService reasoningService) { super(reasoningService); } @@ -64,56 +71,43 @@ /* * (non-Javadoc) * - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + * @see org.dllearner.core.Component#getName() */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if (name.equals("positiveExamples")) - positiveExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("negativeExamples")) - negativeExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("useRetrievalForClassification")) - useRetrievalForClassification = (Boolean) entry.getValue(); + public static String getName() { + return "inclusion learning problem"; } /* * (non-Javadoc) * - * @see org.dllearner.core.Component#getName() - */ - public static String getName() { - return "two valued definition learning problem"; - } - - /* (non-Javadoc) * @see org.dllearner.core.Component#init() */ @Override public void init() { - // TODO Auto-generated method stub - + super.init(); + definitionLP = new PosNegDefinitionLP(reasoningService, negativeExamples, positiveExamples); } - - /* (non-Javadoc) + + /** + * Calls the same method on the standard definition learning problem, but + * negates the concept before and permutes positive and negative examples. + * * @see org.dllearner.learningproblems.PosNegLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) */ @Override public int coveredNegativeExamplesOrTooWeak(Concept concept) { - // TODO Auto-generated method stub - return 0; + return definitionLP.coveredNegativeExamplesOrTooWeak(new Negation(concept)); } - /* (non-Javadoc) + /** + * Calls the same method on the standard definition learning problem, but + * negates the concept before and permutes positive and negative examples. + * * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.dl.Concept) */ @Override public Score computeScore(Concept concept) { - // TODO Auto-generated method stub - return null; + return definitionLP.computeScore(new Negation(concept)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 10:22:36
|
Revision: 178 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=178&view=rev Author: jenslehmann Date: 2007-10-08 03:22:32 -0700 (Mon, 08 Oct 2007) Log Message: ----------- - added CLI support for inclusion learning - changed uncle example Modified Paths: -------------- trunk/examples/uncle.conf trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java Added Paths: ----------- trunk/examples/uncle.kb Modified: trunk/examples/uncle.conf =================================================================== --- trunk/examples/uncle.conf 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/examples/uncle.conf 2007-10-08 10:22:32 UTC (rev 178) @@ -14,68 +14,26 @@ * Copyright (C) 2007, Jens Lehmann */ -writeDIGProtocol = false; -digProtocolFile = "log/dig_uncle_fact.txt"; +problem = posNegDefinition; -/** background knowledge **/ -BOTTOM = (male AND female). -Functional(married). -Symmetric(married). -Symmetric(hasSibling). +//writeDIGProtocol = false; +//digProtocolFile = "log/dig_uncle_fact.txt"; -male(heinrich). -male(jan). -male(markus). -male(alfred). -male(hans). -male(heinz). -male(alex). -female(susi). -female(anna). -female(maria). -female(katrin). -female(johanna). -female(mandy). -female(miriam). -female(hanna). +import("uncle.kb"); -married(heinrich,susi). -married(anna,jan). -married(alfred,katrin). -married(hans,johanna). - -hasSibling(susi,anna). -hasSibling(alfred,maria). -hasSibling(alfred,heinz). -hasSibling(heinz,maria). -hasSibling(johanna,mandy). -hasSibling(hanna,alex). - -hasChild(anna,alfred). -hasChild(anna,maria). -hasChild(anna,heinz). -hasChild(jan,alfred). -hasChild(jan,maria). -hasChild(jan,heinz). -hasChild(maria,markus). -hasChild(alfred,hans). -hasChild(katrin,hans). -hasChild(mandy,miriam). -hasChild(hanna,jan). - /** examples **/ -+uncle(heinrich). -+uncle(alfred). -+uncle(heinz). -+uncle(hans). -+uncle(alex). --uncle(jan). --uncle(markus). --uncle(susi). --uncle(anna). --uncle(maria). --uncle(katrin). --uncle(johanna). --uncle(mandy). --uncle(miriam). --uncle(hanna). ++heinrich ++alfred ++heinz ++hans ++alex +-jan +-markus +-susi +-anna +-maria +-katrin +-johanna +-mandy +-miriam +-hanna Added: trunk/examples/uncle.kb =================================================================== --- trunk/examples/uncle.kb (rev 0) +++ trunk/examples/uncle.kb 2007-10-08 10:22:32 UTC (rev 178) @@ -0,0 +1,44 @@ +BOTTOM = (male AND female). +Functional(married). +Symmetric(married). +Symmetric(hasSibling). + +male(heinrich). +male(jan). +male(markus). +male(alfred). +male(hans). +male(heinz). +male(alex). +female(susi). +female(anna). +female(maria). +female(katrin). +female(johanna). +female(mandy). +female(miriam). +female(hanna). + +married(heinrich,susi). +married(anna,jan). +married(alfred,katrin). +married(hans,johanna). + +hasSibling(susi,anna). +hasSibling(alfred,maria). +hasSibling(alfred,heinz). +hasSibling(heinz,maria). +hasSibling(johanna,mandy). +hasSibling(hanna,alex). + +hasChild(anna,alfred). +hasChild(anna,maria). +hasChild(anna,heinz). +hasChild(jan,alfred). +hasChild(jan,maria). +hasChild(jan,heinz). +hasChild(maria,markus). +hasChild(alfred,hans). +hasChild(katrin,hans). +hasChild(mandy,miriam). +hasChild(hanna,jan). Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 10:22:32 UTC (rev 178) @@ -63,6 +63,7 @@ import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.parser.ConfParser; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -130,8 +131,18 @@ configureComponent(cm, reasoner, componentPrefixMapping, parser); ReasoningService rs = cm.reasoningService(reasoner); - // step 3: detect learning problem (no options for choosing it yet) - LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + // step 3: detect learning problem + ConfFileOption problemOption = parser.getConfOptionsByName("problem"); + Class<? extends LearningProblem> lpClass = null; + LearningProblem lp = null; + if(problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) + lpClass = PosNegDefinitionLP.class; + else if(problemOption.getStringValue().equals("posNegInclusion")) + lpClass = PosNegInclusionLP.class; + else + handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); + + lp = cm.learningProblem(lpClass, rs); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "positiveExamples", posExamples); @@ -376,6 +387,7 @@ // CLI options (i.e. options which are related to the CLI // user interface but not to one of the components) List<ConfFileOption> cliOptions = parser.getConfOptionsByPrefix("cli"); + if(cliOptions != null) { int maxLineLength = 100; for (ConfFileOption cliOption : cliOptions) { String name = cliOption.getSubOption(); @@ -434,6 +446,7 @@ } else handleError("Unknown CLI option \"" + name + "\"."); } + } } private static void initComponent(ComponentManager cm, Component component) { Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 09:49:14 UTC (rev 177) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 10:22:32 UTC (rev 178) @@ -142,6 +142,7 @@ } // System.out.println(components); + // System.out.println(learningProblems); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 11:09:39
|
Revision: 179 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=179&view=rev Author: jenslehmann Date: 2007-10-08 04:09:33 -0700 (Mon, 08 Oct 2007) Log Message: ----------- added Config independant protocol support to DIG reasoner Modified Paths: -------------- trunk/examples/uncle.conf trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/utilities/Files.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/examples/uncle.conf =================================================================== --- trunk/examples/uncle.conf 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/examples/uncle.conf 2007-10-08 11:09:33 UTC (rev 179) @@ -16,8 +16,8 @@ problem = posNegDefinition; -//writeDIGProtocol = false; -//digProtocolFile = "log/dig_uncle_fact.txt"; +digReasoner.writeDIGProtocol = true; +digReasoner.digProtocolFile = "log/dig_uncle.txt"; import("uncle.kb"); Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 11:09:33 UTC (rev 179) @@ -112,8 +112,8 @@ public static boolean showInternalKB = false; public static int maxLineLength = 100; - public static boolean writeDIGProtocol = false; - public static File digProtocolFile = new File("log/digProtocol.txt"); + // public static boolean writeDIGProtocol = false; + // public static File digProtocolFile = new File("log/digProtocol.txt"); // public static String preprocessingModule = ""; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 11:09:33 UTC (rev 179) @@ -470,9 +470,9 @@ } else if (option.equals("showSubsumptionHierarchy")) { Config.showSubsumptionHierarchy = Datastructures.strToBool(value); } else if (option.equals("writeDIGProtocol")) { - Config.writeDIGProtocol = Datastructures.strToBool(value); + // Config.writeDIGProtocol = Datastructures.strToBool(value); } else if (option.equals("digProtocolFile")) { - Config.digProtocolFile = new File(value); + // Config.digProtocolFile = new File(value); // } else if (option.equals("preprocessingModule")) { // Config.preprocessingModule = value; } else if (option.equals("gp.selectionType")) { Modified: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-10-08 11:09:33 UTC (rev 179) @@ -28,6 +28,10 @@ public BooleanConfigOption(String name, String description) { super(name, description); } + + public BooleanConfigOption(String name, String description, boolean defaultValue) { + super(name, description, defaultValue); + } /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) Modified: trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-10-08 11:09:33 UTC (rev 179) @@ -31,13 +31,16 @@ */ public class StringConfigOption extends ConfigOption<String> { - private Set<String> allowedValues; + private Set<String> allowedValues = new TreeSet<String>();; public StringConfigOption(String name, String description) { super(name, description); - allowedValues = new TreeSet<String>(); } + public StringConfigOption(String name, String description, String defaultValue) { + super(name, description, defaultValue); + } + /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-08 11:09:33 UTC (rev 179) @@ -1,6 +1,27 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.reasoning; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -12,7 +33,6 @@ import java.net.URL; import org.apache.xmlbeans.XmlException; -import org.dllearner.Config; import org.dllearner.utilities.Files; import org.kr.dl.dig.v1_1.GetIdentifierDocument; import org.kr.dl.dig.v1_1.IdRespType; @@ -27,17 +47,23 @@ * Methods for sending messages to a DIG-capable reasoner and receiving answers * using Apache XML Beans. * - * @author jl + * @author Jens Lehmann * */ public class DIGHTTPConnector { private URL url; + private File protocolFile; public DIGHTTPConnector(URL url) { this.url = url; } + public DIGHTTPConnector(URL url, File protocolFile) { + this.url = url; + this.protocolFile = protocolFile; + } + public URI newKB() { NewKBDocument newKB = NewKBDocument.Factory.newInstance(); newKB.addNewNewKB(); @@ -131,10 +157,10 @@ osw.write(send); osw.close(); - if(Config.writeDIGProtocol) - Files.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); + if(protocolFile != null) + Files.appendFile(protocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); - // Antwort empfangen + // receive answer InputStream is = connection.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); @@ -153,9 +179,8 @@ System.exit(0); } - // DIG-Kommunikation protokollieren, falls das eingestellt ist - if(Config.writeDIGProtocol) - Files.appendFile(Config.digProtocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); + if(protocolFile != null) + Files.appendFile(protocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); return answer.toString(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 11:09:33 UTC (rev 179) @@ -37,6 +37,7 @@ import org.apache.xmlbeans.XmlCursor; import org.dllearner.Config; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; @@ -53,6 +54,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; import org.kr.dl.dig.v1_1.Concepts; @@ -69,13 +71,13 @@ * DIG 1.1 implementation of the reasoner interface. * * @author Jens Lehmann - * + * */ public class DIGReasoner extends ReasonerComponent { URL reasonerURL; Set<KnowledgeSource> sources; - + // Variablen für Reasoner DIGHTTPConnector connector; String identifier; @@ -85,9 +87,10 @@ Set<AtomicConcept> atomicConcepts; Set<AtomicRole> atomicRoles; SortedSet<Individual> individuals; - + // Cache für Subsumptionhierarchie - // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des atomaren Konzepts male + // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des + // atomaren Konzepts male // unterschiedlich sind; // alternativ wäre auch eine Indizierung über Strings möglich ConceptComparator conceptComparator = new ConceptComparator(); @@ -95,69 +98,92 @@ SubsumptionHierarchy subsumptionHierarchy; RoleHierarchy roleHierarchy; // enthält atomare Konzepte, sowie Top und Bottom - Set<Concept> allowedConceptsInSubsumptionHierarchy; + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + private boolean writeDIGProtocol; + private File digProtocolFile; + private static String defaultDIGProtocolFile = "log/digProtocol"; public DIGReasoner(Set<KnowledgeSource> sources) { this.sources = sources; try { reasonerURL = new URL("http://localhost:8081"); - } catch (MalformedURLException e) { } + } catch (MalformedURLException e) { + } } - + @Override public void init() { - connector = new DIGHTTPConnector(reasonerURL); + // if a DIG protocol is written clear the file first + if(writeDIGProtocol) { + if(digProtocolFile == null) + digProtocolFile = new File(defaultDIGProtocolFile); + Files.clearFile(digProtocolFile); + connector = new DIGHTTPConnector(reasonerURL, digProtocolFile); + } else { + connector = new DIGHTTPConnector(reasonerURL); + } + identifier = connector.getIdentifier(); kbURI = connector.newKB(); - + // asks-Prefix entsprechend der KB-URI initialisieren asksPrefix = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; - asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + - "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"; - + asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\"" + kbURI + "\">"; + // momementan wird davon ausgegangen, dass toDIG(kbURI) den gesamten // tells-Request liefert StringBuilder sb = new StringBuilder(); -// sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); -// sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + -// "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + -// "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + -// "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); - for(KnowledgeSource source : sources) { + // sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + // sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + // "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + // "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + // "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); + for (KnowledgeSource source : sources) { sb.append(source.toDIG(kbURI)); - + ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { + if (!rd.getResponse().isSetOk()) { System.err.println("DIG-Reasoner cannot read knowledgebase."); System.exit(0); - } + } } -// sb.append("</tells>"); - + // sb.append("</tells>"); + // DIG-Abfragen nach Konzepten, Rollen, Individuals atomicConcepts = getAtomicConceptsDIG(); atomicRoles = getAtomicRolesDIG(); - individuals = getIndividualsDIG(); + individuals = getIndividualsDIG(); + } - + public static String getName() { return "DIG reasoner"; } - + public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("reasonerUrl", "URL of the DIG reasoner")); + options.add(new BooleanConfigOption("writeDIGProtocol", + "specifies whether or not to write a protocoll of send and received DIG requests", + false)); + options.add(new StringConfigOption("digProtocolFile", "the file to store the DIG protocol", + defaultDIGProtocolFile)); return options; - } - - /* (non-Javadoc) + } + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - if (entry.getOptionName().equals("reasonerUrl")) { + String name = entry.getOptionName(); + if (name.equals("reasonerUrl")) { String s = (String) entry.getValue(); try { reasonerURL = new URL(s); @@ -165,558 +191,565 @@ // e.printStackTrace(); throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); } + } else if(name.equals("writeDIGProtocol")) { + writeDIGProtocol = (Boolean) entry.getValue(); + } else if(name.equals("digProtocolFile")) { + digProtocolFile = new File((String) entry.getValue()); } } - - + /** - * Construct a subsumption hierarchy using DIG queries. After calling this + * Construct a subsumption hierarchy using DIG queries. After calling this * method one can ask for children or parents in the subsumption hierarchy. */ public void prepareSubsumptionHierarchy() { - allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); allowedConceptsInSubsumptionHierarchy.addAll(Config.Refinement.allowedConcepts); allowedConceptsInSubsumptionHierarchy.add(new Top()); - allowedConceptsInSubsumptionHierarchy.add(new Bottom()); - - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + // Subsumptionhierarchy berechnen // TODO: kann man effizienter auch in einer Abfrage machen - + // Refinements von Top - TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); + TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(new Top(), tmp); - + // Refinements von Bottom tmp = getMoreGeneralConceptsDIG(new Bottom()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyUp.put(new Bottom(), tmp); - + // Refinement atomarer Konzepte - for(AtomicConcept atom : atomicConcepts) { + for (AtomicConcept atom : atomicConcepts) { tmp = getMoreSpecialConceptsDIG(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(atom, tmp); - + tmp = getMoreGeneralConceptsDIG(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); + subsumptionHierarchyUp.put(atom, tmp); } - - subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); + + subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, + subsumptionHierarchyUp, subsumptionHierarchyDown); } - + /** * Constructs a role hierarchy using DIG queries. After calling this method, * one can query parents or children of roles. * - * @todo Does not yet take ignored roles into account. + * @todo Does not yet take ignored roles into account. */ @Override - public void prepareRoleHierarchy() { - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - + public void prepareRoleHierarchy() { + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + // Refinement atomarer Konzepte - for(AtomicRole role : atomicRoles) { + for (AtomicRole role : atomicRoles) { roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); - roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); } - - roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, roleHierarchyDown); - } - + + roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, + roleHierarchyDown); + } + // eigentlich müsste man klonen um sicherzustellen, dass der parent-Link // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link // nicht immer null, was bei GP negative Auswirkungen haben könnte // Update: wird durch klonen innerhalb der GP-Operationen erledigt public Set<AtomicConcept> getAtomicConcepts() { /* - if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == Config.Algorithm.HYBRID_GP) { - Set<AtomicConcept> returnSet = new HashSet<AtomicConcept>(); - for(AtomicConcept ac : atomicConcepts) - returnSet.add((AtomicConcept)ac.clone()); - return returnSet; - } - */ + * if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == + * Config.Algorithm.HYBRID_GP) { Set<AtomicConcept> returnSet = new + * HashSet<AtomicConcept>(); for(AtomicConcept ac : atomicConcepts) + * returnSet.add((AtomicConcept)ac.clone()); return returnSet; } + */ return atomicConcepts; } - + private Set<AtomicConcept> getAtomicConceptsDIG() { String atomicConceptsDIG = asksPrefix; atomicConceptsDIG += "<allConceptNames id=\"ask_names\"/></asks>"; - + ResponsesDocument rd = connector.asks(atomicConceptsDIG); // Struktur: einzelnes conceptSet außen, dann mehrere synonyms, die dann // die Konzept inkl. Top und Bottom enthalten Csynonyms[] synonymsArray = rd.getResponses().getConceptSetArray(); Concepts[] conceptsArray = synonymsArray[0].getSynonymsArray(); - + Set<AtomicConcept> atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); - for(Concepts concepts : conceptsArray) { + for (Concepts concepts : conceptsArray) { boolean topOrBottomFound = false; - if(concepts.getBottomArray().length != 0 || concepts.getTopArray().length!=0) + if (concepts.getBottomArray().length != 0 || concepts.getTopArray().length != 0) topOrBottomFound = true; - + // nur weitersuchen falls das Konzept nicht äquivalent zu Top // oder Bottom ist - if(!topOrBottomFound) { + if (!topOrBottomFound) { boolean nonAnonymousConceptFound = false; AtomicConcept foundConcept = null; Named[] catoms = concepts.getCatomArray(); - for(Named catom : catoms) { + for (Named catom : catoms) { String name = catom.getName(); - if(!name.startsWith("anon")) { - if(!nonAnonymousConceptFound) { + if (!name.startsWith("anon")) { + if (!nonAnonymousConceptFound) { nonAnonymousConceptFound = true; foundConcept = new AtomicConcept(catom.getName()); atomicConcepts.add(foundConcept); } else { - System.out.println("Warning: Background knowledge contains synonym concepts. " + - "We decide to pick " + foundConcept + ". \nDIG-XML:\n"+concepts); + System.out + .println("Warning: Background knowledge contains synonym concepts. " + + "We decide to pick " + + foundConcept + + ". \nDIG-XML:\n" + concepts); } } } } } - + return atomicConcepts; - } - + } + public Set<AtomicRole> getAtomicRoles() { return atomicRoles; } - + private Set<AtomicRole> getAtomicRolesDIG() { String atomicRolesDIG = asksPrefix; atomicRolesDIG += "<allRoleNames id=\"ask_roles\"/></asks>"; - + ResponsesDocument rd = connector.asks(atomicRolesDIG); // Struktur: einzelnes roleSet außen, dann synonyms mit ratoms // innen Rsynonyms[] synonymsArray = rd.getResponses().getRoleSetArray(); Roles[] rolesArray = synonymsArray[0].getSynonymsArray(); - + Set<AtomicRole> digAtomicRoles = new HashSet<AtomicRole>(); - for(Roles roles : rolesArray) { + for (Roles roles : rolesArray) { // hier koennen wiederum mehrere ratoms enthalten sein, // aber wir wollen nur eins auslesen Named[] ratoms = roles.getRatomArray(); Named role = ratoms[0]; - digAtomicRoles.add(new AtomicRole(role.getName())); - - if(ratoms.length>1) - System.out.println("Warning: Background knowledge contains synonym roles. " + - "Will ignore all but the first. \nDIG-XML:\n"+roles); + digAtomicRoles.add(new AtomicRole(role.getName())); + + if (ratoms.length > 1) + System.out.println("Warning: Background knowledge contains synonym roles. " + + "Will ignore all but the first. \nDIG-XML:\n" + roles); } - + return digAtomicRoles; - } - - public SortedSet<Individual> getIndividuals() { + } + + public SortedSet<Individual> getIndividuals() { return individuals; } private SortedSet<Individual> getIndividualsDIG() { String individualsDIG = asksPrefix; individualsDIG += "<allIndividuals id=\"ask_individuals\"/></asks>"; - + ResponsesDocument rd = connector.asks(individualsDIG); // Struktur: einzelnes individualSet außen, dann Liste von // individual-Elementen IndividualSet[] individualsArray = rd.getResponses().getIndividualSetArray(); Named[] namedIndividuals = individualsArray[0].getIndividualArray(); - + SortedSet<Individual> digIndividuals = new TreeSet<Individual>(); - for(Named named : namedIndividuals) - digIndividuals.add(new Individual(named.getName())); - + for (Named named : namedIndividuals) + digIndividuals.add(new Individual(named.getName())); + return digIndividuals; } - + public ReasonerType getReasonerType() { return ReasonerType.DIG; } - + @Override public boolean subsumes(Concept superConcept, Concept subConcept) { - // System.out.println("subsumes(" + superConcept + "," + subConcept + ")"); + // System.out.println("subsumes(" + superConcept + "," + subConcept + + // ")"); String subsumesDIG = asksPrefix; subsumesDIG += "<subsumes id=\"query_subsume\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes></asks>"; - + return parseBooleanAnswer(subsumesDIG); } - + @Override public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) { String subsumesDIG = asksPrefix; int id = 0; // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs // ausgegeben werden - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept subConcept : subConcepts) { - queryMap.put("query"+id, subConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + Map<String, Concept> queryMap = new HashMap<String, Concept>(); + for (Concept subConcept : subConcepts) { + queryMap.put("query" + id, subConcept); + subsumesDIG += "<subsumes id=\"query" + id + "\">"; + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes>"; id++; } subsumesDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(subsumesDIG); IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - + Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { + for (IdType idType : subsumedConceptsIds) { returnSet.add(queryMap.get(idType.getId())); } return returnSet; } - + @Override public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) { String subsumesDIG = asksPrefix; int id = 0; - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept superConcept : superConcepts) { - queryMap.put("query"+id, superConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); + Map<String, Concept> queryMap = new HashMap<String, Concept>(); + for (Concept superConcept : superConcepts) { + queryMap.put("query" + id, superConcept); + subsumesDIG += "<subsumes id=\"query" + id + "\">"; + subsumesDIG += DIGConverter.getDIGString(superConcept); subsumesDIG += DIGConverter.getDIGString(subConcept); subsumesDIG += "</subsumes>"; id++; } subsumesDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(subsumesDIG); IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - + Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { + for (IdType idType : subsumedConceptsIds) { returnSet.add(queryMap.get(idType.getId())); } return returnSet; } - + /* - // es wird geklont, damit Subsumptionhierarchie nicht von außen verändert werden - // kann - @SuppressWarnings("unchecked") + * // es wird geklont, damit Subsumptionhierarchie nicht von außen verändert + * werden // kann @SuppressWarnings("unchecked") @Override public SortedSet<Concept> + * getMoreGeneralConcepts(Concept concept) { return (TreeSet<Concept>) + * subsumptionHierarchyUp.get(concept).clone(); // return + * subsumptionHierarchyUp.get(concept); // ohne klonen geht es nicht } + * + * @SuppressWarnings("unchecked") @Override public SortedSet<Concept> + * getMoreSpecialConcepts(Concept concept) { return (TreeSet<Concept>) + * subsumptionHierarchyDown.get(concept).clone(); // return + * subsumptionHierarchyDown.get(concept); // ohne klonen geht es nicht } + */ + @Override - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); - // return subsumptionHierarchyUp.get(concept); // ohne klonen geht es nicht - } - - @SuppressWarnings("unchecked") - @Override - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); - // return subsumptionHierarchyDown.get(concept); // ohne klonen geht es nicht - } - */ - - @Override public SubsumptionHierarchy getSubsumptionHierarchy() { return subsumptionHierarchy; } - + @Override public RoleHierarchy getRoleHierarchy() { return roleHierarchy; } - + private TreeSet<Concept> getMoreGeneralConceptsDIG(Concept concept) { String moreGeneralDIG = asksPrefix; moreGeneralDIG += "<parents id=\"query_parents\">"; moreGeneralDIG += DIGConverter.getDIGString(concept); moreGeneralDIG += "</parents></asks>"; - + ResponsesDocument rd = connector.asks(moreGeneralDIG); TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); - // ein Array, der Synomyms-Elemente enthält, die dann Mengen von + // ein Array, der Synomyms-Elemente enthält, die dann Mengen von // äquivalenten Konzepten enthalten; // (es wird hier nur das erste Element des ConceptSetArrays gelesen, // da nur ein solches Element bei dieser Abfrage erwartet wird) Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { // es werden nur atomare Konzepte erwartet Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) resultsSet.add(ac); } - + // hinzufügen von Top, falls notwendig - if(conceptsArray[i].getTopArray().length>0) + if (conceptsArray[i].getTopArray().length > 0) resultsSet.add(new Top()); - + // falls bisher kein erlaubtes Konzept gefunden wurden, dann gibt es - // entweder keine allgemeineren Konzepte oder es handelt sich um + // entweder keine allgemeineren Konzepte oder es handelt sich um // nicht erlaubte (von Jena erzeugte) Konzepte, die nicht äquivalent - // zu einem erlaubten Konzept sind; in dem Fall muss die Methode rekursiv + // zu einem erlaubten Konzept sind; in dem Fall muss die Methode + // rekursiv // noch einmal aufgerufen werden - if(resultsSet.size()==0 && atoms.length>0) { - // wir wählen das erste Konzept aus, welches ein ignoriertes Konzept ist + if (resultsSet.size() == 0 && atoms.length > 0) { + // wir wählen das erste Konzept aus, welches ein ignoriertes + // Konzept ist // (sonst wäre es weiter oben gefunden wurden) AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); resultsSet.addAll(getMoreGeneralConceptsDIG(ignoredAtomicConcept)); } - + } - + return resultsSet; } - + private TreeSet<Concept> getMoreSpecialConceptsDIG(Concept concept) { String moreSpecialDIG = asksPrefix; moreSpecialDIG += "<children id=\"query_children\">"; moreSpecialDIG += DIGConverter.getDIGString(concept); moreSpecialDIG += "</children></asks>"; - + // Kommentare siehe getMoreGeneralConcepts(Concept) ResponsesDocument rd = connector.asks(moreSpecialDIG); TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) resultsSet.add(ac); - } - + } + // hinzufügen von Bottom, falls notwendig - if(conceptsArray[i].getBottomArray().length>0) + if (conceptsArray[i].getBottomArray().length > 0) resultsSet.add(new Bottom()); - - if(resultsSet.size()==0 && atoms.length>0) { + + if (resultsSet.size() == 0 && atoms.length > 0) { AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); resultsSet.addAll(getMoreSpecialConceptsDIG(ignoredAtomicConcept)); } - } - + } + return resultsSet; - } - + } + private TreeSet<AtomicRole> getMoreGeneralRolesDIG(AtomicRole role) { String moreGeneralRolesDIG = asksPrefix; moreGeneralRolesDIG += "<rparents id=\"query_parents\">"; moreGeneralRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; moreGeneralRolesDIG += "</rparents></asks>"; - + ResponsesDocument rd = connector.asks(moreGeneralRolesDIG); TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for (int i = 0; i < rolesArray.length; i++) { Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { + + for (Named atom : atoms) { AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) + // if(Config.Refinement.allowedRoles.contains(ar)) resultsSet.add(ar); - } + } } - + // System.out.println(rd); - + return resultsSet; } - + private TreeSet<AtomicRole> getMoreSpecialRolesDIG(AtomicRole role) { String moreSpecialRolesDIG = asksPrefix; moreSpecialRolesDIG += "<rchildren id=\"query_children\">"; moreSpecialRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; moreSpecialRolesDIG += "</rchildren></asks>"; - + ResponsesDocument rd = connector.asks(moreSpecialRolesDIG); TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for (int i = 0; i < rolesArray.length; i++) { Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { + + for (Named atom : atoms) { AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) + // if(Config.Refinement.allowedRoles.contains(ar)) resultsSet.add(ar); - } + } } - + return resultsSet; } - - @Override + + @Override public boolean instanceCheck(Concept concept, Individual individual) { String instanceCheckDIG = asksPrefix; instanceCheckDIG += "<instance id= \"query_instance\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; + instanceCheckDIG += "<individual name=\"" + individual.getName() + "\"/>"; instanceCheckDIG += DIGConverter.getDIGString(concept); instanceCheckDIG += "</instance></asks>"; - - return parseBooleanAnswer(instanceCheckDIG); + + return parseBooleanAnswer(instanceCheckDIG); } - - @Override + + @Override public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) { String instanceCheckDIG = asksPrefix; int id = 0; // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs // ausgegeben werden - Map<String,String> queryMap = new HashMap<String,String>(); - for(Individual individual : individuals) { - queryMap.put("query"+id, individual.getName()); - instanceCheckDIG += "<instance id= \"query"+id+"\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; + Map<String, String> queryMap = new HashMap<String, String>(); + for (Individual individual : individuals) { + queryMap.put("query" + id, individual.getName()); + instanceCheckDIG += "<instance id= \"query" + id + "\">"; + instanceCheckDIG += "<individual name=\"" + individual.getName() + "\"/>"; instanceCheckDIG += DIGConverter.getDIGString(concept); instanceCheckDIG += "</instance>"; id++; } instanceCheckDIG += "</asks>"; - + ResponsesDocument rd = connector.asks(instanceCheckDIG); IdType[] ids = rd.getResponses().getTrueArray(); - + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for(IdType idType : ids) { + for (IdType idType : ids) { returnSet.add(new Individual(queryMap.get(idType.getId()))); } - return returnSet; + return returnSet; } - - @Override + + @Override public SortedSet<Individual> retrieval(Concept concept) { - + String retrievalDIG = asksPrefix; retrievalDIG += "<instances id= \"query_instance\">"; retrievalDIG += DIGConverter.getDIGString(concept); retrievalDIG += "</instances></asks>"; - + ResponsesDocument rd = connector.asks(retrievalDIG); // System.out.println(rd); Named[] individuals = rd.getResponses().getIndividualSetArray()[0].getIndividualArray(); - + SortedSet<Individual> results = new TreeSet<Individual>(); - for(Named individual : individuals) + for (Named individual : individuals) results.add(new Individual(individual.getName())); return results; } - + // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus - @Override + @Override public Set<AtomicConcept> getConcepts(Individual individual) { String typesDIG = asksPrefix; typesDIG += "<types id=\"query_types\">"; typesDIG += "<individual name=\"" + individual.getName() + "\" />"; - typesDIG += "</types></asks>"; - + typesDIG += "</types></asks>"; + ResponsesDocument rd = connector.asks(typesDIG); TreeSet<AtomicConcept> resultsSet = new TreeSet<AtomicConcept>(conceptComparator); Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { + + for (int i = 0; i < conceptsArray.length; i++) { Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { + for (Named atom : atoms) { AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - // if(Config.Refinement.allowedConcepts.contains(ac)) + if (allowedConceptsInSubsumptionHierarchy.contains(ac)) + // if(Config.Refinement.allowedConcepts.contains(ac)) resultsSet.add(ac); } - } - + } + // System.out.println("document:"); // System.out.println(rd); // System.out.println("parsed:"); // System.out.println(resultsSet); - + return resultsSet; } - + // es sieht so aus, als ob die XSD-Datei kaputt ist - es gibt zumindest // keine getter um ein IndividualPairSet zu finden; in der XSD-Datei ist // das in Responsegroup auch nicht definiert // => deswegen wird hier die XML-Cursor-API verwendet - @Override + @Override public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { String relatedIndividualsDIG = asksPrefix; relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; relatedIndividualsDIG += "<ratom name=\"" + atomicRole.getName() + "\" />"; - relatedIndividualsDIG += "</relatedIndividuals></asks>"; - + relatedIndividualsDIG += "</relatedIndividuals></asks>"; + ResponsesDocument rd = connector.asks(relatedIndividualsDIG); Map<Individual, SortedSet<Individual>> resultMap = new TreeMap<Individual, SortedSet<Individual>>(); - + QName name = new QName("name"); XmlCursor cursor = rd.newCursor(); cursor.toFirstChild(); // Responses cursor.toFirstChild(); // IndividualPairSet - + int childNumber = 0; Individual ind1; Individual ind2; - + // so lange noch Kinder existieren - while(cursor.toChild(childNumber)) { + while (cursor.toChild(childNumber)) { // Cursor steht jetzt bei einem IndividualPair cursor.toFirstChild(); - // jetzt steht er bei einem Individual, dessen Namen wir auslesen können + // jetzt steht er bei einem Individual, dessen Namen wir auslesen + // können ind1 = new Individual(cursor.getAttributeText(name).toString()); cursor.toNextSibling(); ind2 = new Individual(cursor.getAttributeText(name).toString()); - + Helper.addMapEntry(resultMap, ind1, ind2); - + // Cursor wieder hoch auf IndividualPairSet bewegen cursor.toParent(); cursor.toParent(); childNumber++; } - + /* - System.out.println("document:"); - System.out.println(rd); - System.out.println("parsed:"); - System.out.println(resultMap); - */ - + * System.out.println("document:"); System.out.println(rd); + * System.out.println("parsed:"); System.out.println(resultMap); + */ + return resultMap; } - - @Override + + @Override public boolean isSatisfiable() { String satisfiableDIG = asksPrefix; // wenn Top erfüllbar ist, dann gibt es auch ein Modell für die KB // (satisfiability für KB ist nicht Teil von DIG 1.1) satisfiableDIG += "<satisfiable id=\"query_satisfiable\"><top/></satisfiable>"; satisfiableDIG += "</asks>"; - + return parseBooleanAnswer(satisfiableDIG); } - + private boolean parseBooleanAnswer(String asks) { ResponsesDocument rd = connector.asks(asks); - if(rd.getResponses().getTrueArray().length == 1) + if (rd.getResponses().getTrueArray().length == 1) return true; else - return false; + return false; } public String getIdentifier() { return identifier; } - + public void releaseKB() { connector.releaseKB(kbURI); } @@ -735,5 +768,5 @@ public URL getReasonerURL() { return reasonerURL; } - + } Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-08 11:09:33 UTC (rev 179) @@ -74,5 +74,9 @@ e.printStackTrace(); } } + + public static void clearFile(File file) { + createFile(file, ""); + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-08 10:22:32 UTC (rev 178) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-08 11:09:33 UTC (rev 179) @@ -127,8 +127,8 @@ int startAlgorithmNr = 0; // Config.GP.maxConceptLength = 30; - Config.writeDIGProtocol = true; - Config.digProtocolFile = new File(statBaseDir, "dig.log"); + // Config.writeDIGProtocol = true; + // Config.digProtocolFile = new File(statBaseDir, "dig.log"); // do not plot anything // File[][][] gnuplotFiles = new File[examples.length][algorithms.length][3]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-09 15:52:21
|
Revision: 204 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=204&view=rev Author: jenslehmann Date: 2007-10-09 08:52:15 -0700 (Tue, 09 Oct 2007) Log Message: ----------- - extended new DL-Learner web service - first working PHP example for a basic learning task Modified Paths: -------------- trunk/build.xml trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java trunk/src/dl-learner/org/dllearner/server/State.java trunk/src/dl-learner/org/dllearner/server/jaxws/ClientNotKnownExceptionBean.java trunk/src/php-client/testnew.php Added Paths: ----------- trunk/src/dl-learner/org/dllearner/server/jaxws/UnknownComponentExceptionBean.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-10-09 14:06:57 UTC (rev 203) +++ trunk/build.xml 2007-10-09 15:52:15 UTC (rev 204) @@ -165,7 +165,7 @@ <arg value="-cp"/> <arg value="${wsgenpath}"/> <!--<arg value=".;../../classes;../../library/dig1.1-xmlbeans.jar;../../library/kaon2.jar;../../library/xbean.jar;../../library/owlapi/;../../library/owlapi/antlr-runtime-3.0.jar;../../library/owlapi/commons-lang-2.2.jar;../../library/owlapi/owlapi-api.jar;../../library/owlapi/owlapi-apibinding.jar;../../library/owlapi/owlapi-change.jar;../../library/owlapi/owlapi-debugging.jar;../../library/owlapi/owlapi-dig1_1.jar;../../library/owlapi/owlapi-functionalparser.jar;../../library/owlapi/owlapi-functionalrenderer.jar;../../library/owlapi/owlapi-impl.jar;../../library/owlapi/owlapi-krssparser.jar;../../library/owlapi/owlapi-mansyntaxparser.jar;../../library/owlapi/owlapi-mansyntaxrenderer.jar;../../library/owlapi/owlapi-metrics.jar;../../library/owlapi/owlapi-oboparser.jar;../../library/owlapi/owlapi-owlxmlparser.jar;../../library/owlapi/owlapi-owlxmlrenderer.jar;../../library/owlapi/owlapi-rdfapi.jar;../../library/owlapi/owlapi-rdfxmlparser.jar;../../library/owlapi/owlapi-rdfxmlrenderer.jar;../../library/owlapi/owlapi-util.jar"/>--> - <arg value="org.dllearner.server.DLLearnerWS"/> + <arg value="org.dllearner.server.DLLearnerWSNew"/> </exec> </target> Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java 2007-10-09 14:06:57 UTC (rev 203) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java 2007-10-09 15:52:15 UTC (rev 204) @@ -19,8 +19,12 @@ */ package org.dllearner.server; +import java.util.Arrays; import java.util.HashMap; +import java.util.Map; import java.util.Random; +import java.util.Set; +import java.util.TreeSet; import javax.jws.WebMethod; import javax.jws.WebService; @@ -49,9 +53,9 @@ @SOAPBinding(style = SOAPBinding.Style.RPC) public class DLLearnerWSNew { - private HashMap<Long, State> clients; + private Map<Long, State> clients = new HashMap<Long,State>(); private Random rand=new Random(); - private ComponentManager cm = ComponentManager.getInstance(); + private static ComponentManager cm = ComponentManager.getInstance(); /** * Generates a unique ID for the client and initialises a session. @@ -66,6 +70,7 @@ do { id = rand.nextLong(); } while(clients.containsKey(id)); + clients.put(id, new State()); return id; } @@ -77,14 +82,20 @@ return state; } + /////////////////////////////////////// + // methods for basic component setup // + /////////////////////////////////////// + @WebMethod - public boolean addKnowledgeSource(long id, String component, String url) throws ClientNotKnownException { + public boolean addKnowledgeSource(long id, String component, String url) throws ClientNotKnownException, UnknownComponentException { State state = getState(id); Class<? extends KnowledgeSource> ksClass; if(component.equals("sparql")) ksClass = SparqlEndpoint.class; + else if(component.equals("owlfile")) + ksClass = OWLFile.class; else - ksClass = OWLFile.class; + throw new UnknownComponentException(component); KnowledgeSource ks = cm.knowledgeSource(ksClass); cm.applyConfigEntry(ks, "url", url); return state.addKnowledgeSource(ks); @@ -136,4 +147,47 @@ state.setLearningAlgorithm(la); } + /** + * Initialise all components. + * @param id Session ID. + */ + @WebMethod + public void init(long id) throws ClientNotKnownException { + State state = getState(id); + for(KnowledgeSource ks : state.getKnowledgeSources()) + ks.init(); + state.getReasonerComponent().init(); + state.getLearningProblem().init(); + state.getLearningAlgorithm().init(); + } + + @WebMethod + public String learn(long id) throws ClientNotKnownException { + State state = getState(id); + state.getLearningAlgorithm().start(); + return state.getLearningAlgorithm().getBestSolution().toString(); + } + + ///////////////////////////////////////// + // methods for component configuration // + ///////////////////////////////////////// + + @WebMethod + public void setPositiveExamples(long id, String[] positiveExamples) throws ClientNotKnownException { + State state = getState(id); + Set<String> posExamples = new TreeSet<String>(Arrays.asList(positiveExamples)); + cm.applyConfigEntry(state.getLearningProblem(), "positiveExamples", posExamples); + } + + @WebMethod + public void setNegativeExamples(long id, String[] negativeExamples) throws ClientNotKnownException { + State state = getState(id); + Set<String> negExamples = new TreeSet<String>(Arrays.asList(negativeExamples)); + cm.applyConfigEntry(state.getLearningProblem(), "negativeExamples", negExamples); + } + + //////////////////////////////////// + // reasoning and querying methods // + //////////////////////////////////// + } Modified: trunk/src/dl-learner/org/dllearner/server/State.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/State.java 2007-10-09 14:06:57 UTC (rev 203) +++ trunk/src/dl-learner/org/dllearner/server/State.java 2007-10-09 15:52:15 UTC (rev 204) @@ -19,6 +19,7 @@ */ package org.dllearner.server; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -38,7 +39,7 @@ */ public class State { - private Set<KnowledgeSource> knowledgeSources; + private Set<KnowledgeSource> knowledgeSources = new HashSet<KnowledgeSource>(); private LearningProblem learningProblem; Modified: trunk/src/dl-learner/org/dllearner/server/jaxws/ClientNotKnownExceptionBean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/jaxws/ClientNotKnownExceptionBean.java 2007-10-09 14:06:57 UTC (rev 203) +++ trunk/src/dl-learner/org/dllearner/server/jaxws/ClientNotKnownExceptionBean.java 2007-10-09 15:52:15 UTC (rev 204) @@ -1,63 +1,41 @@ - -package org.dllearner.server.jaxws; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - - -/** - * This class was generated by the JAXWS SI. - * JAX-WS RI 2.0_02-b08-fcs - * Generated source version: 2.0_02 - * - */ -@XmlRootElement(name = "ClientNotKnownException", namespace = "http://server.dllearner.org/") -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "ClientNotKnownException", namespace = "http://server.dllearner.org/", propOrder = { - "detail", - "message" -}) -public class ClientNotKnownExceptionBean { - - private String detail; - private String message; - - /** - * - * @return - * returns String - */ - public String getDetail() { - return this.detail; - } - - /** - * - * @param detail - * the value for the detail property - */ - public void setDetail(String detail) { - this.detail = detail; - } - - /** - * - * @return - * returns String - */ - public String getMessage() { - return this.message; - } - - /** - * - * @param message - * the value for the message property - */ - public void setMessage(String message) { - this.message = message; - } - -} + +package org.dllearner.server.jaxws; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * This class was generated by the JAXWS SI. + * JAX-WS RI 2.0_02-b08-fcs + * Generated source version: 2.0_02 + * + */ +@XmlRootElement(name = "ClientNotKnownException", namespace = "http://server.dllearner.org/") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "ClientNotKnownException", namespace = "http://server.dllearner.org/") +public class ClientNotKnownExceptionBean { + + private String message; + + /** + * + * @return + * returns String + */ + public String getMessage() { + return this.message; + } + + /** + * + * @param message + * the value for the message property + */ + public void setMessage(String message) { + this.message = message; + } + +} Added: trunk/src/dl-learner/org/dllearner/server/jaxws/UnknownComponentExceptionBean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/jaxws/UnknownComponentExceptionBean.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/jaxws/UnknownComponentExceptionBean.java 2007-10-09 15:52:15 UTC (rev 204) @@ -0,0 +1,41 @@ + +package org.dllearner.server.jaxws; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * This class was generated by the JAXWS SI. + * JAX-WS RI 2.0_02-b08-fcs + * Generated source version: 2.0_02 + * + */ +@XmlRootElement(name = "UnknownComponentException", namespace = "http://server.dllearner.org/") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "UnknownComponentException", namespace = "http://server.dllearner.org/") +public class UnknownComponentExceptionBean { + + private String message; + + /** + * + * @return + * returns String + */ + public String getMessage() { + return this.message; + } + + /** + * + * @param message + * the value for the message property + */ + public void setMessage(String message) { + this.message = message; + } + +} Modified: trunk/src/php-client/testnew.php =================================================================== --- trunk/src/php-client/testnew.php 2007-10-09 14:06:57 UTC (rev 203) +++ trunk/src/php-client/testnew.php 2007-10-09 15:52:15 UTC (rev 204) @@ -5,18 +5,43 @@ ini_set("soap.wsdl_cache_enabled","0"); $wsdluri="http://localhost:8181/services?wsdl"; +$ontology="file:/home/jl/promotion/dl-learner-svn/trunk/examples/father.owl"; +$posExamples = array('http://example.com/father#stefan', + 'http://example.com/father#markus', + 'http://example.com/father#martin'); +$negExamples = array('http://example.com/father#heinz', + 'http://example.com/father#anna', + 'http://example.com/father#michelle'); + // always update WSDL LearnerClient::loadWSDLfiles($wsdluri); // test web service $client = new SoapClient("main.wsdl"); -$test = $client->hello(); -echo $test; +$id = $client->generateID(); -$stringar = array('blub','blab'); -$ret = $client->test($stringar); -print_r($ret); +$client->addKnowledgeSource($id, "owlfile", $ontology); +$client->setReasoner($id, "dig"); +$client->setLearningProblem($id, "posNegDefinition"); +$client->setPositiveExamples($id, $posExamples); +$client->setNegativeExamples($id, $negExamples); +$client->setLearningAlgorithm($id, "refinement"); +$start = microtime(true); + +$client->init($id); + +$learn_start = microtime(true); +$init = $learn_start - $start; +echo 'components initialised in '.$init.' seconds<br />'; + +$concept = $client->learn($id); + +$learn = microtime(true) - $learn_start; +echo 'concept learned in '.$learn.' seconds<br />'; + +echo 'result: '.$concept; + ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-12 09:20:41
|
Revision: 219 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=219&view=rev Author: jenslehmann Date: 2007-10-12 02:20:39 -0700 (Fri, 12 Oct 2007) Log Message: ----------- Added ConfigDocumentationGenerator class, which contains a main method. Calling this class will automatically query all the components (specified in components.ini) for the configuration options they support. A documentation file is created and written to doc/configOptions.txt. This way the config option documentation is always in sync with the source code and does not need to be written manually. Modified Paths: -------------- trunk/doc/configOptions.txt trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/core/dl/Role.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/ConfigDocumentationGenerator.java Modified: trunk/doc/configOptions.txt =================================================================== --- trunk/doc/configOptions.txt 2007-10-12 08:44:21 UTC (rev 218) +++ trunk/doc/configOptions.txt 2007-10-12 09:20:39 UTC (rev 219) @@ -4,6 +4,19 @@ * Knowledge Sources * ********************* +component: KB file (org.dllearner.kb.KBFile) +============================================ + +option name: filename +description: pointer to the KB file on local file system +values: none +default value: null + +option name: url +description: URL pointer to the KB file +values: none +default value: null + component: OWL file (org.dllearner.kb.OWLFile) ============================================== @@ -12,24 +25,93 @@ values: none default value: null +component: SPARQL Endpoint (org.dllearner.kb.SparqlEndpoint) +============================================================ + +option name: url +description: URL of SPARQL Endpoint +values: none +default value: null + +option name: instances +description: relevant instances e.g. positive and negative examples in a learning problem +values: none +default value: null + +option name: numberOfRecursions +description: number of Recursions, the Sparql-Endpoint is asked +values: none +default value: null + +option name: filterMode +description: the mode of the SPARQL Filter +values: none +default value: null + +option name: predList +description: a predicate list +values: none +default value: null + +option name: objList +description: an object list +values: none +default value: null + +option name: classList +description: a class list +values: none +default value: null + +option name: format +description: N-TRIPLES or KB format +values: none +default value: null + +option name: dumpToFile +description: wether Ontology from DBPedia is written to a file or not +values: none +default value: null + ************* * Reasoners * ************* -component: DIG reasoner (org.dllearner.reasoning.DIGReasonerNew) -================================================================ +component: DIG reasoner (org.dllearner.reasoning.DIGReasoner) +============================================================= option name: reasonerUrl description: URL of the DIG reasoner values: none default value: null +option name: writeDIGProtocol +description: specifies whether or not to write a protocoll of send and received DIG requests +values: none +default value: false + +option name: digProtocolFile +description: the file to store the DIG protocol +values: none +default value: log/digProtocol.txt + +component: unnamed component (org.dllearner.reasoning.FastRetrievalReasoner) +============================================================================ + +component: unnamed component (org.dllearner.reasoning.KAON2Reasoner) +==================================================================== + +option name: una +description: unique names assumption +values: none +default value: false + ********************* * Learning Problems * ********************* -component: two valued definition learning problem (org.dllearner.learningproblems.DefinitionLPTwoValued) -======================================================================================================== +component: two valued definition learning problem (org.dllearner.learningproblems.PosNegDefinitionLP) +===================================================================================================== option name: positiveExamples description: positive examples @@ -46,10 +128,46 @@ values: none default value: null +option name: percentPerLenghtUnit +description: describes the reduction in classification accuracy in percent one is willing to accept for reducing the length of the concept by one +values: none +default value: 0.05 + +component: inclusion learning problem (org.dllearner.learningproblems.PosNegInclusionLP) +======================================================================================== + +option name: positiveExamples +description: positive examples +values: none +default value: null + +option name: negativeExamples +description: negative examples +values: none +default value: null + +option name: useRetrievalForClassficiation +description: Specifies whether to use retrieval or instance checks for testing a concept. +values: none +default value: null + *********************** * Learning Algorithms * *********************** +component: unnamed component (org.dllearner.algorithms.BruteForceLearner) +========================================================================= + +option name: maxLength +description: maximum length of generated concepts +values: none +default value: null + +option name: returnType +description: Specifies the type which the solution has to belong to (if already) known. This means we inform the learning algorithm that the solution is a subclass of this type. +values: none +default value: null + component: unnamed component (org.dllearner.algorithms.RandomGuesser) ===================================================================== @@ -63,3 +181,24 @@ values: none default value: null +component: unnamed component (org.dllearner.algorithms.gp.GP) +============================================================= + +component: refinement operator based learning algorithm (org.dllearner.algorithms.refinement.ROLearner) +======================================================================================================= + +option name: writeSearchTree +description: specifies whether to write a search tree +values: none +default value: false + +option name: searchTreeFile +description: file to use for the search tree +values: none +default value: log/searchTree.txt + +option name: heuristic +description: specifiy the heuristic to use +values: none +default value: lexicographic + Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-10-12 08:44:21 UTC (rev 218) +++ trunk/lib/components.ini 2007-10-12 09:20:39 UTC (rev 219) @@ -6,10 +6,13 @@ org.dllearner.kb.SparqlEndpoint # reasoners org.dllearner.reasoning.DIGReasoner +org.dllearner.reasoning.FastRetrievalReasoner +org.dllearner.reasoning.KAON2Reasoner # learning problems org.dllearner.learningproblems.PosNegDefinitionLP org.dllearner.learningproblems.PosNegInclusionLP # learning algorithms org.dllearner.algorithms.RandomGuesser +org.dllearner.algorithms.BruteForceLearner org.dllearner.algorithms.refinement.ROLearner org.dllearner.algorithms.gp.GP Added: trunk/src/dl-learner/org/dllearner/core/ConfigDocumentationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigDocumentationGenerator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ConfigDocumentationGenerator.java 2007-10-12 09:20:39 UTC (rev 219) @@ -0,0 +1,43 @@ +/** + * 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.core; + +import java.io.File; + +/** + * Collects information about all used configuration options and + * writes them into a file. This way the documentation is always + * in sync with the source code. + * + * @author Jens Lehmann + * + */ +public class ConfigDocumentationGenerator { + + /** + * @param args + */ + public static void main(String[] args) { + File file = new File("doc/configOptions.txt"); + ComponentManager cm = ComponentManager.getInstance(); + cm.writeConfigDocumentation(file); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/dl/Role.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/dl/Role.java 2007-10-12 08:44:21 UTC (rev 218) +++ trunk/src/dl-learner/org/dllearner/core/dl/Role.java 2007-10-12 09:20:39 UTC (rev 219) @@ -1,7 +1,5 @@ package org.dllearner.core.dl; -import java.util.Map; - public abstract class Role implements KBElement { protected String name; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-14 15:49:39
|
Revision: 222 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=222&view=rev Author: jenslehmann Date: 2007-10-14 08:49:31 -0700 (Sun, 14 Oct 2007) Log Message: ----------- - implemented evaluation for inclusion learning problem => inclusion learning should now work - note that it can happen that no 100% accuracy solution for the inclusion problem exists, although the standard definition problem has a solution (see provided father example) - further note that if a concept is a solution of the standard definition learning problem and the inclusion problem, then it is also a solution of the strict definition learning problem Modified Paths: -------------- trunk/examples/father.conf trunk/examples/uncle.conf trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java Added Paths: ----------- trunk/examples/father_incl.kb Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2007-10-12 13:20:01 UTC (rev 221) +++ trunk/examples/father.conf 2007-10-14 15:49:31 UTC (rev 222) @@ -16,12 +16,12 @@ // algorithm settings algorithm = refinement; -//refinement.horizontalExpansionFactor = 0.5; -//refinement.quiet = false; +// problem = posNegInclusion; + // search tree protocol -// refinement.writeSearchTree = false; -// refinement.searchTreeFile = "log/searchTree.txt"; +refinement.writeSearchTree = false; +refinement.searchTreeFile = "log/searchFather.txt"; // control output cli.checkSatisfiability = true; @@ -31,6 +31,7 @@ cli.showSubsumptionHierarchy = false; import("father.kb"); +// import("father_incl.kb"); /** examples **/ +stefan Added: trunk/examples/father_incl.kb =================================================================== --- trunk/examples/father_incl.kb (rev 0) +++ trunk/examples/father_incl.kb 2007-10-14 15:49:31 UTC (rev 222) @@ -0,0 +1,20 @@ +BOTTOM = (male AND female). + +// persons +male(markus). +male(stefan). +male(heinz). +male(bernd). +female(anna). +female(gabi). +female(michelle). + +// children +hasChild(stefan,markus). +hasChild(markus,anna). +hasChild(bernd,gabi). +hasChild(anna,heinz). + +// to learn the inclusion axiom father SUBCLASS OF male AND EXISTS hasChild.TOP +// properly, we have to specifiy explicity that heinz does not have children +NOT EXISTS hasChild.TOP(heinz). Modified: trunk/examples/uncle.conf =================================================================== --- trunk/examples/uncle.conf 2007-10-12 13:20:01 UTC (rev 221) +++ trunk/examples/uncle.conf 2007-10-14 15:49:31 UTC (rev 222) @@ -14,9 +14,10 @@ * Copyright (C) 2007, Jens Lehmann */ -problem = posNegDefinition; +refinement.writeSearchTree = false; +refinement.searchTreeFile = "log/search_uncle.txt"; -digReasoner.writeDIGProtocol = true; +digReasoner.writeDIGProtocol = false; digReasoner.digProtocolFile = "log/dig_uncle.txt"; import("uncle.kb"); Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-12 13:20:01 UTC (rev 221) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-14 15:49:31 UTC (rev 222) @@ -21,6 +21,9 @@ import java.util.Collection; import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigOption; @@ -28,7 +31,10 @@ import org.dllearner.core.Score; import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.Negation; +import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; +import org.dllearner.utilities.Helper; /** * The aim of this learning problem is to find an appropriate inclusion axiom @@ -56,7 +62,7 @@ public PosNegInclusionLP(ReasoningService reasoningService) { super(reasoningService); } - +/* public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringSetConfigOption("positiveExamples", @@ -67,7 +73,7 @@ "Specifies whether to use retrieval or instance checks for testing a concept.")); return options; } - +*/ /* * (non-Javadoc) * @@ -86,19 +92,89 @@ public void init() { super.init(); definitionLP = new PosNegDefinitionLP(reasoningService, negativeExamples, positiveExamples); + // TODO: we must make sure that the problem also gets the same + // reasoning options (i.e. options are the same up to reversed example sets) + definitionLP.init(); } /** - * Calls the same method on the standard definition learning problem, but - * negates the concept before and permutes positive and negative examples. + * See the documentation of <code>coveredNegativeExamplesOrTooWeak</code> in + * the definition learning problem case. This method works differently: + * First, it tests whether none of the positive examples is covered by the + * negation of the given concept. Should this be the case, it returns + * too weak. If this is not the case, the method returns the number of + * negative examples, which do not follow from the negation of the input + * concept. Thus, this methods uses a different notion of coverage than + * the one for the standard definition learning problem. * - * @see org.dllearner.learningproblems.PosNegLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) + * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks + * @param concept + * The concept to test. + * @return -1 if concept is too weak and the number of covered negative + * examples otherwise. */ @Override public int coveredNegativeExamplesOrTooWeak(Concept concept) { - return definitionLP.coveredNegativeExamplesOrTooWeak(new Negation(concept)); + + if (useRetrievalForClassification) { + SortedSet<Individual> inNegatedConcept = reasoningService.retrieval(new Negation(concept)); + + for (Individual posExample : positiveExamples) { + // if any positive example follows from the negation, then + // the concept is "too weak" + if (inNegatedConcept.contains(posExample)) + return -1; + } + + // number of covered negatives + // cover = neg. example does not belong to the negated concept + SortedSet<Individual> negExInNegatedConcept = Helper.intersection(negativeExamples, inNegatedConcept); + return (negativeExamples.size() - negExInNegatedConcept.size()); + } else { + if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + // two checks + if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + Set<Individual> posExInNegatedConcept = reasoningService.instanceCheck(new Negation(concept), positiveExamples); + + if(posExInNegatedConcept.size()>0) { + return -1; + } else { + Set<Individual> negExInNegatedConcept = reasoningService.instanceCheck(new Negation(concept), negativeExamples); + return (negativeExamples.size() - negExInNegatedConcept.size()); + } + + // one check + } else { + Set<Individual> inNegatedConcept = reasoningService.instanceCheck(new Negation(concept), allExamples); + + for(Individual i : positiveExamples) { + if(inNegatedConcept.contains(i)) + return -1; + } + + // we can now be sure that inNegatedConcept contains only + // negative examples + return (negativeExamples.size() - inNegatedConcept.size()); + + } + // single instance checks + } else { + int coverCount = negativeExamples.size(); + + for (Individual example : positiveExamples) { + if (reasoningService.instanceCheck(new Negation(concept), example)) + return -1; + } + for (Individual example : negativeExamples) { + if (!reasoningService.instanceCheck(new Negation(concept), example)) + coverCount--; + } + + return coverCount; + } + } } - + /** * Calls the same method on the standard definition learning problem, but * negates the concept before and permutes positive and negative examples. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-15 16:37:29
|
Revision: 224 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=224&view=rev Author: jenslehmann Date: 2007-10-15 09:37:22 -0700 (Mon, 15 Oct 2007) Log Message: ----------- - positive only definition learning problem partly implemented - refinement operator based approach adapted for positive only learning - CLI extended to handle positive only problem (use "problem = posOnlyDefinition;" in conf file) Modified Paths: -------------- trunk/examples/father.conf trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/examples/father.conf 2007-10-15 16:37:22 UTC (rev 224) @@ -17,7 +17,7 @@ // algorithm settings algorithm = refinement; -// problem = posNegInclusion; +// problem = posOnlyDefinition; // search tree protocol refinement.writeSearchTree = false; Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/lib/components.ini 2007-10-15 16:37:22 UTC (rev 224) @@ -11,6 +11,7 @@ # learning problems org.dllearner.learningproblems.PosNegDefinitionLP org.dllearner.learningproblems.PosNegInclusionLP +org.dllearner.learningproblems.PosOnlyDefinitionLP # learning algorithms org.dllearner.algorithms.RandomGuesser org.dllearner.algorithms.BruteForceLearner Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-15 16:37:22 UTC (rev 224) @@ -28,6 +28,7 @@ import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; @@ -53,7 +54,8 @@ DecimalFormat df = new DecimalFormat(); private PosNegLP learningProblem; - // private LearningProblem learningProblem2; + private PosOnlyDefinitionLP posOnlyLearningProblem; + private boolean posOnly = false; // Menge von Kandidaten für Refinement // (wird für Direktzugriff auf Baumknoten verwendet) @@ -127,13 +129,19 @@ public ROLearner(PosNegLP learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; this.rs = rs; - - + posOnly=false; } + public ROLearner(PosOnlyDefinitionLP learningProblem, ReasoningService rs) { + this.posOnlyLearningProblem = learningProblem; + this.rs = rs; + posOnly=true; + } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); + problems.add(PosOnlyDefinitionLP.class); return problems; } @@ -196,11 +204,15 @@ // adjust heuristic if(heuristic == Heuristic.LEXICOGRAPHIC) nodeComparator = new NodeComparator(); - else - nodeComparator = new NodeComparator2(learningProblem.getNegativeExamples().size(), learningProblem.getPercentPerLengthUnit()); + else { + if(posOnly) { + throw new RuntimeException("does not work with positive examples only yet"); + } + nodeComparator = new NodeComparator2(learningProblem.getNegativeExamples().size(), learningProblem.getPercentPerLengthUnit()); + } // this.learningProblem2 = learningProblem2; - operator = new RhoDown(learningProblem); + operator = new RhoDown(rs); // candidate sets entsprechend der gewählten Heuristik initialisieren candidates = new TreeSet<Node>(nodeComparator); @@ -219,6 +231,20 @@ return "refinement operator based learning algorithm"; } + private int coveredNegativesOrTooWeak(Concept concept) { + if(posOnly) + return posOnlyLearningProblem.coveredPseudoNegativeExamplesOrTooWeak(concept); + else + return learningProblem.coveredNegativeExamplesOrTooWeak(concept); + } + + private int getNumberOfNegatives() { + if(posOnly) + return posOnlyLearningProblem.getPseudoNegatives().size(); + else + return learningProblem.getNegativeExamples().size(); + } + // Kernalgorithmus @Override @SuppressWarnings("unchecked") @@ -230,7 +256,7 @@ // int coveredNegativeExamples = learningProblem.coveredNegativeExamplesOrTooWeak(top); // aus Top folgen immer alle negativen Beispiele, d.h. es ist nur eine Lösung, wenn // es keine negativen Beispiele gibt - int coveredNegativeExamples = learningProblem.getNegativeExamples().size(); + int coveredNegativeExamples = getNumberOfNegatives(); topNode.setCoveredNegativeExamples(coveredNegativeExamples); // topNode.setHorizontalExpansion(1); // die 0 ist eigentlich richtig, da keine Refinements // der Länge 1 untersucht wurden @@ -553,7 +579,7 @@ if(toEvaluateConcepts.size()>0) { // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) long propCalcReasoningStart = System.nanoTime(); - improperConcepts = learningProblem.getReasoningService().subsumes(toEvaluateConcepts, concept); + improperConcepts = rs.subsumes(toEvaluateConcepts, concept); propernessTestsReasoner+=toEvaluateConcepts.size(); // boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; @@ -622,7 +648,7 @@ if(Config.Refinement.useOverlyGeneralList && refinement instanceof MultiDisjunction) { if(containsOverlyGeneralElement((MultiDisjunction)refinement)) { conceptTestsOverlyGeneralList++; - quality = learningProblem.getNegativeExamples().size(); + quality = getNumberOfNegatives(); qualityKnown = true; newNode.setQualityEvaluationMethod(Node.QualityEvaluationMethod.OVERLY_GENERAL_LIST); } @@ -632,7 +658,7 @@ if(!qualityKnown) { long propCalcReasoningStart2 = System.nanoTime(); conceptTestsReasoner++; - quality = learningProblem.coveredNegativeExamplesOrTooWeak(refinement); + quality = coveredNegativesOrTooWeak(refinement); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart2; newNode.setQualityEvaluationMethod(Node.QualityEvaluationMethod.REASONER); } @@ -654,7 +680,7 @@ // candidatesStable.add(newNode); - if(quality == learningProblem.getNegativeExamples().size()) + if(quality == getNumberOfNegatives()) overlyGeneralList.add(refinement); // System.out.print("."); @@ -773,12 +799,12 @@ if(showBenchmarkInformation) { - long reasoningTime = learningProblem.getReasoningService().getOverallReasoningTimeNs(); + long reasoningTime = rs.getOverallReasoningTimeNs(); double reasoningPercentage = 100 * reasoningTime/(double)algorithmRuntime; long propWithoutReasoning = propernessCalcTimeNs-propernessCalcReasoningTimeNs; double propPercentage = 100 * propWithoutReasoning/(double)algorithmRuntime; double deletionPercentage = 100 * childConceptsDeletionTimeNs/(double)algorithmRuntime; - long subTime = learningProblem.getReasoningService().getSubsumptionReasoningTimeNs(); + long subTime = rs.getSubsumptionReasoningTimeNs(); double subPercentage = 100 * subTime/(double)algorithmRuntime; double refinementPercentage = 100 * refinementCalcTimeNs/(double)algorithmRuntime; double redundancyCheckPercentage = 100 * redundancyCheckTimeNs/(double)algorithmRuntime; @@ -837,7 +863,10 @@ @Override public Score getSolutionScore() { - return learningProblem.computeScore(getBestSolution()); + if(posOnly) + return posOnlyLearningProblem.computeScore(getBestSolution()); + else + return learningProblem.computeScore(getBestSolution()); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-15 16:37:22 UTC (rev 224) @@ -45,7 +45,6 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Role; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -62,7 +61,7 @@ */ public class RhoDown implements RefinementOperator { - private PosNegLP learningProblem; +// private PosNegLP learningProblem; private ReasoningService rs; // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts @@ -91,9 +90,10 @@ // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(PosNegLP learningProblem) { - this.learningProblem = learningProblem; - rs = learningProblem.getReasoningService(); + public RhoDown(ReasoningService reasoningService) { + this.rs = reasoningService; +// this.learningProblem = learningProblem; +// rs = learningProblem.getReasoningService(); } public Set<Concept> refine(Concept concept) { @@ -141,7 +141,7 @@ // beachte: die Funktion gibt bereits nur nicht-äquivalente Konzepte zurück // TODO: der Cast auf SortedSet ist nur ein Hack und muss später geeignet // behandelt werden - refinements = learningProblem.getReasoningService().getMoreSpecialConcepts(concept); + refinements = rs.getMoreSpecialConcepts(concept); // refinements.addAll(learningProblem.getReasoningService().getMoreSpecialConcepts(concept)); // Bottom rausschmeißen (nicht im Operator vorgesehen) @@ -506,14 +506,14 @@ // TODO: Spezialfälle, dass zwischen Top und Bottom nichts liegt behandeln if(topRefinementsLength==0 && maxLength>0) { // Konzepte der Länge 1 = alle Konzepte, die in der Subsumptionhierarchie unter Top liegen - Set<Concept> m1 = learningProblem.getReasoningService().getMoreSpecialConcepts(new Top()); + Set<Concept> m1 = rs.getMoreSpecialConcepts(new Top()); m.put(1,m1); } if(topRefinementsLength<2 && maxLength>1) { // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen if(Config.Refinement.useNegation) { - Set<Concept> m2tmp = learningProblem.getReasoningService().getMoreGeneralConcepts(new Bottom()); + Set<Concept> m2tmp = rs.getMoreGeneralConcepts(new Bottom()); Set<Concept> m2 = new TreeSet<Concept>(conceptComparator); for(Concept c : m2tmp) { m2.add(new Negation(c)); Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-15 16:37:22 UTC (rev 224) @@ -62,6 +62,7 @@ import org.dllearner.kb.SparqlEndpoint; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; +import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.parser.ConfParser; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -143,6 +144,8 @@ lpClass = PosNegDefinitionLP.class; else if (problemOption.getStringValue().equals("posNegInclusion")) lpClass = PosNegInclusionLP.class; + else if (problemOption.getStringValue().equals("posOnlyDefinition")) + lpClass = PosOnlyDefinitionLP.class; else handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); @@ -150,7 +153,8 @@ SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "positiveExamples", posExamples); - cm.applyConfigEntry(lp, "negativeExamples", negExamples); + if(lpClass != PosOnlyDefinitionLP.class) + cm.applyConfigEntry(lp, "negativeExamples", negExamples); // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2007-10-15 15:04:57 UTC (rev 223) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2007-10-15 16:37:22 UTC (rev 224) @@ -19,38 +19,81 @@ */ package org.dllearner.learningproblems; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.CommonConfigMappings; import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; +import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; /** + * Definition learning problem from only positive examples. + * * @author Jens Lehmann * */ public class PosOnlyDefinitionLP extends PosOnlyLP implements DefinitionLP { + protected SortedSet<Individual> positiveExamples; + protected SortedSet<Individual> pseudoNegatives; + + private PosNegDefinitionLP definitionLP; + public PosOnlyDefinitionLP(ReasoningService reasoningService) { super(reasoningService); } - /* (non-Javadoc) - * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.dl.Concept) + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override - public Score computeScore(Concept concept) { - // TODO Auto-generated method stub - return null; + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + if (name.equals("positiveExamples")) + positiveExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "positive only definition learning problem"; + } + + /** + * @return the positiveExamples + */ + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + /** + * @return the pseudoNegatives */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - + public SortedSet<Individual> getPseudoNegatives() { + return pseudoNegatives; } /* (non-Javadoc) @@ -58,8 +101,33 @@ */ @Override public void init() { - // TODO Auto-generated method stub - + // by default we test all other instances of the knowledge base + pseudoNegatives = Helper.difference(reasoningService.getIndividuals(), positiveExamples); + + // create an instance of a standard definition learning problem + // instanciated with pseudo-negatives + definitionLP = new PosNegDefinitionLP(reasoningService, positiveExamples, pseudoNegatives); + // TODO: we must make sure that the problem also gets the same + // reasoning options (i.e. options are the same up to reversed example sets) + definitionLP.init(); } - + + /* (non-Javadoc) + * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.dl.Concept) + */ + @Override + public Score computeScore(Concept concept) { + // TODO need to implement class <code>ScoreOneValued</code> + return null; + } + + /** + * + * @param concept + * @return -1 for too weak, otherwise the number of pseudo-negatives (more is usually worse). + */ + public int coveredPseudoNegativeExamplesOrTooWeak(Concept concept) { + return definitionLP.coveredNegativeExamplesOrTooWeak(concept); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-16 09:32:14
|
Revision: 227 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=227&view=rev Author: jenslehmann Date: 2007-10-16 02:32:08 -0700 (Tue, 16 Oct 2007) Log Message: ----------- refactored web service classes, added some documentation, adjusted build script Modified Paths: -------------- trunk/build.xml trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java trunk/src/dl-learner/org/dllearner/server/package.html Added Paths: ----------- trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/server/jaxws/package.html Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java trunk/src/dl-learner/org/dllearner/server/State.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-10-16 09:27:26 UTC (rev 226) +++ trunk/build.xml 2007-10-16 09:32:08 UTC (rev 227) @@ -164,8 +164,7 @@ <arg value="-verbose"/> <arg value="-cp"/> <arg value="${wsgenpath}"/> - <!--<arg value=".;../../classes;../../library/dig1.1-xmlbeans.jar;../../library/kaon2.jar;../../library/xbean.jar;../../library/owlapi/;../../library/owlapi/antlr-runtime-3.0.jar;../../library/owlapi/commons-lang-2.2.jar;../../library/owlapi/owlapi-api.jar;../../library/owlapi/owlapi-apibinding.jar;../../library/owlapi/owlapi-change.jar;../../library/owlapi/owlapi-debugging.jar;../../library/owlapi/owlapi-dig1_1.jar;../../library/owlapi/owlapi-functionalparser.jar;../../library/owlapi/owlapi-functionalrenderer.jar;../../library/owlapi/owlapi-impl.jar;../../library/owlapi/owlapi-krssparser.jar;../../library/owlapi/owlapi-mansyntaxparser.jar;../../library/owlapi/owlapi-mansyntaxrenderer.jar;../../library/owlapi/owlapi-metrics.jar;../../library/owlapi/owlapi-oboparser.jar;../../library/owlapi/owlapi-owlxmlparser.jar;../../library/owlapi/owlapi-owlxmlrenderer.jar;../../library/owlapi/owlapi-rdfapi.jar;../../library/owlapi/owlapi-rdfxmlparser.jar;../../library/owlapi/owlapi-rdfxmlrenderer.jar;../../library/owlapi/owlapi-util.jar"/>--> - <arg value="org.dllearner.server.DLLearnerWSNew"/> + <arg value="org.dllearner.server.DLLearnerWS"/> </exec> </target> Copied: trunk/src/dl-learner/org/dllearner/server/ClientState.java (from rev 218, trunk/src/dl-learner/org/dllearner/server/State.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-16 09:32:08 UTC (rev 227) @@ -0,0 +1,209 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.server; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import org.dllearner.core.Component; +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.kb.OWLFile; +import org.dllearner.kb.SparqlEndpoint; + +/** + * Stores the state of a DL-Learner client session. + * + * @author Jens Lehmann + * + */ +public class ClientState { + + // stores the mapping between component IDs and component + // (note that this allows us to keep all references to components even + // if they are note used anymore e.g. a deleted knowledge source) + private Map<Integer,Component> componentIDs = new HashMap<Integer,Component>(); + + private Set<KnowledgeSource> knowledgeSources = new HashSet<KnowledgeSource>(); + + private LearningProblem learningProblem; + + private ReasonerComponent reasonerComponent; + private ReasoningService reasoningService; + + private LearningAlgorithm learningAlgorithm; + + private Random rand=new Random(); + + private boolean isAlgorithmRunning = false; + + private int generateComponentID(Component component) { + int id; + do { + id = rand.nextInt(); + } while(componentIDs.keySet().contains(id)); + componentIDs.put(id, component); + return id; + } + + /** + * @return the isAlgorithmRunning + */ + public boolean isAlgorithmRunning() { + return isAlgorithmRunning; + } + + /** + * @param isAlgorithmRunning the isAlgorithmRunning to set + */ + public void setAlgorithmRunning(boolean isAlgorithmRunning) { + this.isAlgorithmRunning = isAlgorithmRunning; + } + +// public Component getComponent(Class<? extends Component> componentClass) throws UnknownComponentException { +// if(learningProblem.getClass().equals(componentClass)) +// return learningProblem; +// else if(learningAlgorithm.getClass().equals(componentClass)) +// return learningAlgorithm; +// else if(reasonerComponent.getClass().equals(componentClass)) +// return reasonerComponent; +// else if(KnowledgeSource.class.isAssignableFrom(componentClass)) { +// +// +// for(KnowledgeSource ks : knowledgeSources) { +// if(ks.getClass().equals(componentClass)) +// return ks; +// } +// throw new UnknownComponentException(componentClass.getName()); +// } else +// throw new UnknownComponentException(componentClass.getName()); +// } + + /** + * Removes a knowledge source with the given URL (independant of its type). + * @param url URL of the OWL file or SPARQL Endpoint. + * @return True if a knowledge source was deleted, false otherwise. + */ + public boolean removeKnowledgeSource(String url) { + Iterator<KnowledgeSource> it = knowledgeSources.iterator(); + while(it.hasNext()) { + KnowledgeSource source = it.next(); + if((source instanceof OWLFile && ((OWLFile)source).getURL().toString().equals(url)) + || (source instanceof SparqlEndpoint && ((SparqlEndpoint)source).getURL().toString().equals(url)) ) { + it.remove(); + return true; + } + } + return false; + } + + /** + * @return the learningProblem + */ + public LearningProblem getLearningProblem() { + return learningProblem; + } + + /** + * @param learningProblem the learningProblem to set + */ + public int setLearningProblem(LearningProblem learningProblem) { + this.learningProblem = learningProblem; + return generateComponentID(learningProblem); + } + + /** + * @return the reasonerComponent + */ + public ReasonerComponent getReasonerComponent() { + return reasonerComponent; + } + + /** + * Sets the reasoner component and creates the corresponding + * <code>ReasoningService</code> instance. + * + * @param reasonerComponent the reasonerComponent to set + */ + public int setReasonerComponent(ReasonerComponent reasonerComponent) { + this.reasonerComponent = reasonerComponent; + reasoningService = new ReasoningService(reasonerComponent); + return generateComponentID(reasonerComponent); + } + + /** + * @return the learningAlgorithm + */ + public LearningAlgorithm getLearningAlgorithm() { + return learningAlgorithm; + } + + /** + * @param learningAlgorithm the learningAlgorithm to set + */ + public int setLearningAlgorithm(LearningAlgorithm learningAlgorithm) { + this.learningAlgorithm = learningAlgorithm; + return generateComponentID(learningAlgorithm); + } + + /** + * @return the reasoningService + */ + public ReasoningService getReasoningService() { + return reasoningService; + } + + /** + * @param key + * @return + * @see java.util.Map#get(java.lang.Object) + */ + public Component getComponent(int id) { + return componentIDs.get(id); + } + + /** + * @param e + * @return + */ + public int addKnowledgeSource(KnowledgeSource ks) { + knowledgeSources.add(ks); + return generateComponentID(ks); + + } + + public boolean removeKnowledgeSource(int componentID) { + return knowledgeSources.remove(componentIDs.get(componentID)); + } + + /** + * @return the knowledgeSources + */ + public Set<KnowledgeSource> getKnowledgeSources() { + return knowledgeSources; + } +} Copied: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java (from rev 225, trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-10-16 09:32:08 UTC (rev 227) @@ -0,0 +1,350 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.server; + +import java.util.Arrays; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import org.dllearner.algorithms.refinement.ROLearner; +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.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegInclusionLP; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.utilities.Datastructures; + +/** + * DL-Learner web service interface. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ +@WebService(name = "DLLearnerWebService") +@SOAPBinding(style = SOAPBinding.Style.RPC) +public class DLLearnerWS { + + private Map<Integer, ClientState> clients = new TreeMap<Integer,ClientState>(); + private Random rand=new Random(); + private static ComponentManager cm = ComponentManager.getInstance(); + + // defines the components, which are accessible for the web service + private static Map<String,Class<? extends KnowledgeSource>> knowledgeSourceMapping = new TreeMap<String,Class<? extends KnowledgeSource>>(); + private static Map<String,Class<? extends ReasonerComponent>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponent>>(); + private static Map<String,Class<? extends LearningProblem>> learningProblemMapping = new TreeMap<String,Class<? extends LearningProblem>>(); + private static Map<String,Class<? extends LearningAlgorithm>> learningAlgorithmMapping = new TreeMap<String,Class<? extends LearningAlgorithm>>(); + + public DLLearnerWS() { + knowledgeSourceMapping.put("owlfile", OWLFile.class); + knowledgeSourceMapping.put("sparql", SparqlEndpoint.class); + reasonerMapping.put("dig", DIGReasoner.class); + learningProblemMapping.put("posNegDefinition", PosNegDefinitionLP.class); + learningProblemMapping.put("posNegInclusion", PosNegInclusionLP.class); + learningAlgorithmMapping.put("refinement", ROLearner.class); + } + + /** + * Generates a unique ID for the client and initialises a session. + * Using the ID the client can call the other web service methods. + * Two calls to this method are guaranteed to return different results. + * + * @return A session ID. + */ + @WebMethod + public int generateID() { + int id; + do { + id = rand.nextInt(); + } while(clients.containsKey(id)); + clients.put(id, new ClientState()); + return id; + } + + // returns session state or throws client not known exception + private ClientState getState(int id) throws ClientNotKnownException { + ClientState state = clients.get(id); + if(state==null) + throw new ClientNotKnownException(id); + return state; + } + + // returns the class which is referred to by the string + @SuppressWarnings({"unused"}) + private Class<? extends Component> getComponent(String component) throws UnknownComponentException { + if(knowledgeSourceMapping.containsKey(component)) + return knowledgeSourceMapping.get(component); + else if(reasonerMapping.containsKey(component)) + return reasonerMapping.get(component); + else if(learningProblemMapping.containsKey(component)) + return learningProblemMapping.get(component); + else if(learningAlgorithmMapping.containsKey(component)) + return learningAlgorithmMapping.get(component); + else + throw new UnknownComponentException(component); + } + + /////////////////////////////////////// + // methods for basic component setup // + /////////////////////////////////////// + + /** + * Adds a knowledge source. + * + * @return An identifier for the component. + */ + @WebMethod + public int addKnowledgeSource(int id, String component, String url) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(id); + Class<? extends KnowledgeSource> ksClass = knowledgeSourceMapping.get(component); + if(ksClass == null) + throw new UnknownComponentException(component); + KnowledgeSource ks = cm.knowledgeSource(ksClass); + cm.applyConfigEntry(ks, "url", url); + return state.addKnowledgeSource(ks); + } + + @WebMethod + public void removeKnowledgeSource(int id, int componentID) throws ClientNotKnownException { + getState(id).removeKnowledgeSource(componentID); + } + + @WebMethod + public int setReasoner(int id, String component) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(id); + Class<? extends ReasonerComponent> rcClass = reasonerMapping.get(component); + if(rcClass == null) + throw new UnknownComponentException(component); + + ReasonerComponent rc = cm.reasoner(rcClass, state.getKnowledgeSources()); + return state.setReasonerComponent(rc); + } + + @WebMethod + public int setLearningProblem(int id, String component) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(id); + Class<? extends LearningProblem> lpClass = learningProblemMapping.get(component); + if(lpClass == null) + throw new UnknownComponentException(component); + + LearningProblem lp = cm.learningProblem(lpClass, state.getReasoningService()); + return state.setLearningProblem(lp); + } + + @WebMethod + public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(id); + Class<? extends LearningAlgorithm> laClass = learningAlgorithmMapping.get(component); + if(laClass == null) + throw new UnknownComponentException(component); + + LearningAlgorithm la = cm.learningAlgorithm(laClass, state.getLearningProblem(), state.getReasoningService()); + return state.setLearningAlgorithm(la); + } + + /** + * Initialise all components. + * @param id Session ID. + */ + @WebMethod + public void init(int id) throws ClientNotKnownException { + ClientState state = getState(id); + for(KnowledgeSource ks : state.getKnowledgeSources()) + ks.init(); + state.getReasonerComponent().init(); + state.getLearningProblem().init(); + state.getLearningAlgorithm().init(); + } + + /** + * Starts the learning algorithm and returns the best concept found. This + * method will block until learning is completed. + * + * @param id Session ID. + * @return The best solution found. + * @throws ClientNotKnownException + */ + @WebMethod + public String learn(int id) throws ClientNotKnownException { + ClientState state = getState(id); + state.getLearningAlgorithm().start(); + return state.getLearningAlgorithm().getBestSolution().toString(); + } + + /** + * Starts the learning algorithm and returns immediately. The learning + * algorithm is executed in its own thread and can be queried and + * controlled using other Web Service methods. + * + * @param id Session ID. + * @throws ClientNotKnownException + */ + @WebMethod + public void learnThreaded(int id) throws ClientNotKnownException { + final ClientState state = getState(id); + Thread learningThread = new Thread() { + @Override + public void run() { + state.setAlgorithmRunning(true); + state.getLearningAlgorithm().start(); + state.setAlgorithmRunning(false); + } + }; + learningThread.start(); + } + + @WebMethod + public String getCurrentlyBestConcept(int id) throws ClientNotKnownException { + ClientState state = getState(id); + return state.getLearningAlgorithm().getBestSolution().toString(); + } + + @WebMethod + public boolean isAlgorithmRunning(int id) throws ClientNotKnownException { + return getState(id).isAlgorithmRunning(); + } + + /** + * Stops the learning algorithm smoothly. + * @param id + * @throws ClientNotKnownException + */ + @WebMethod + public void stop(int id) throws ClientNotKnownException { + getState(id).getLearningAlgorithm().stop(); + } + + ///////////////////////////////////////// + // methods for component configuration // + ///////////////////////////////////////// + + @WebMethod + public void setPositiveExamples(int id, String[] positiveExamples) throws ClientNotKnownException { + ClientState state = getState(id); + Set<String> posExamples = new TreeSet<String>(Arrays.asList(positiveExamples)); + cm.applyConfigEntry(state.getLearningProblem(), "positiveExamples", posExamples); + } + + @WebMethod + public void setNegativeExamples(int id, String[] negativeExamples) throws ClientNotKnownException { + ClientState state = getState(id); + Set<String> negExamples = new TreeSet<String>(Arrays.asList(negativeExamples)); + cm.applyConfigEntry(state.getLearningProblem(), "negativeExamples", negExamples); + } + + @WebMethod + public void applyConfigEntryInt(int sessionID, int componentID, String optionName, Integer value) throws ClientNotKnownException, UnknownComponentException { + applyConfigEntry(sessionID, componentID,optionName,value); + } + + @WebMethod + public void applyConfigEntryString(int sessionID, int componentID, String optionName, String value) throws ClientNotKnownException, UnknownComponentException { + applyConfigEntry(sessionID, componentID,optionName,value); + } + + @WebMethod + public void applyConfigEntryStringArray(int sessionID, int componentID, String optionName, String[] value) throws ClientNotKnownException, UnknownComponentException { + Set<String> stringSet = new TreeSet<String>(Arrays.asList(value)); + applyConfigEntry(sessionID, componentID,optionName,stringSet); + } + + @WebMethod + public void applyConfigEntryBoolean(int sessionID, int componentID, String optionName, Boolean value) throws ClientNotKnownException, UnknownComponentException { + applyConfigEntry(sessionID, componentID,optionName,value); + } + + private void applyConfigEntry(int sessionID, int componentID, String optionName, Object value) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(sessionID); + Component component = state.getComponent(componentID); + cm.applyConfigEntry(component, optionName, value); + } + + //////////////////////////////////// + // reasoning and querying methods // + //////////////////////////////////// + + @WebMethod + public String[] getAtomicConcepts(int id) throws ClientNotKnownException { + Set<AtomicConcept> atomicConcepts = getState(id).getReasoningService().getAtomicConcepts(); + return Datastructures.sortedSet2StringListConcepts(atomicConcepts); + } + + @WebMethod + public String getSubsumptionHierarchy(int id) throws ClientNotKnownException { + return getState(id).getReasoningService().toString(); + } + + @WebMethod + public String[] retrieval(int id, String conceptString) throws ClientNotKnownException { + ClientState state = getState(id); + // call parser to parse atomic concept + Concept concept = null; + try { + concept = KBParser.parseConcept(conceptString); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Set<Individual> individuals = state.getReasoningService().retrieval(concept); + return Datastructures.sortedSet2StringListIndividuals(individuals); + } + + @WebMethod + public String[] getAtomicRoles(int id) throws ClientNotKnownException { + ClientState state = getState(id); + Set<AtomicRole> roles = state.getReasoningService().getAtomicRoles(); + return Datastructures.sortedSet2StringListRoles(roles); + } + + @WebMethod + public String[] getInstances(int id) throws ClientNotKnownException { + ClientState state = getState(id); + Set<Individual> individuals = state.getReasoningService().getIndividuals(); + return Datastructures.sortedSet2StringListIndividuals(individuals); + } + + @WebMethod + public String[] getIndividualsForARole(int id, String role) throws ClientNotKnownException { + ClientState state = getState(id); + Map<Individual,SortedSet<Individual>> m = state.getReasoningService().getRoleMembers(new AtomicRole(role)); + Set<Individual> individuals = m.keySet(); + return Datastructures.sortedSet2StringListIndividuals(individuals); + } +} Deleted: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java 2007-10-16 09:27:26 UTC (rev 226) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSNew.java 2007-10-16 09:32:08 UTC (rev 227) @@ -1,350 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.server; - -import java.util.Arrays; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import javax.jws.soap.SOAPBinding; - -import org.dllearner.algorithms.refinement.ROLearner; -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.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.kb.OWLFile; -import org.dllearner.kb.SparqlEndpoint; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegInclusionLP; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.utilities.Datastructures; - -/** - * DL-Learner web service interface. - * - * @author Jens Lehmann - * @author Sebastian Hellmann - * - */ -@WebService(name = "DLLearnerWebService") -@SOAPBinding(style = SOAPBinding.Style.RPC) -public class DLLearnerWSNew { - - private Map<Integer, State> clients = new TreeMap<Integer,State>(); - private Random rand=new Random(); - private static ComponentManager cm = ComponentManager.getInstance(); - - // defines the components, which are accessible for the web service - private static Map<String,Class<? extends KnowledgeSource>> knowledgeSourceMapping = new TreeMap<String,Class<? extends KnowledgeSource>>(); - private static Map<String,Class<? extends ReasonerComponent>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponent>>(); - private static Map<String,Class<? extends LearningProblem>> learningProblemMapping = new TreeMap<String,Class<? extends LearningProblem>>(); - private static Map<String,Class<? extends LearningAlgorithm>> learningAlgorithmMapping = new TreeMap<String,Class<? extends LearningAlgorithm>>(); - - public DLLearnerWSNew() { - knowledgeSourceMapping.put("owlfile", OWLFile.class); - knowledgeSourceMapping.put("sparql", SparqlEndpoint.class); - reasonerMapping.put("dig", DIGReasoner.class); - learningProblemMapping.put("posNegDefinition", PosNegDefinitionLP.class); - learningProblemMapping.put("posNegInclusion", PosNegInclusionLP.class); - learningAlgorithmMapping.put("refinement", ROLearner.class); - } - - /** - * Generates a unique ID for the client and initialises a session. - * Using the ID the client can call the other web service methods. - * Two calls to this method are guaranteed to return different results. - * - * @return A session ID. - */ - @WebMethod - public int generateID() { - int id; - do { - id = rand.nextInt(); - } while(clients.containsKey(id)); - clients.put(id, new State()); - return id; - } - - // returns session state or throws client not known exception - private State getState(int id) throws ClientNotKnownException { - State state = clients.get(id); - if(state==null) - throw new ClientNotKnownException(id); - return state; - } - - // returns the class which is referred to by the string - @SuppressWarnings({"unused"}) - private Class<? extends Component> getComponent(String component) throws UnknownComponentException { - if(knowledgeSourceMapping.containsKey(component)) - return knowledgeSourceMapping.get(component); - else if(reasonerMapping.containsKey(component)) - return reasonerMapping.get(component); - else if(learningProblemMapping.containsKey(component)) - return learningProblemMapping.get(component); - else if(learningAlgorithmMapping.containsKey(component)) - return learningAlgorithmMapping.get(component); - else - throw new UnknownComponentException(component); - } - - /////////////////////////////////////// - // methods for basic component setup // - /////////////////////////////////////// - - /** - * Adds a knowledge source. - * - * @return An identifier for the component. - */ - @WebMethod - public int addKnowledgeSource(int id, String component, String url) throws ClientNotKnownException, UnknownComponentException { - State state = getState(id); - Class<? extends KnowledgeSource> ksClass = knowledgeSourceMapping.get(component); - if(ksClass == null) - throw new UnknownComponentException(component); - KnowledgeSource ks = cm.knowledgeSource(ksClass); - cm.applyConfigEntry(ks, "url", url); - return state.addKnowledgeSource(ks); - } - - @WebMethod - public void removeKnowledgeSource(int id, int componentID) throws ClientNotKnownException { - getState(id).removeKnowledgeSource(componentID); - } - - @WebMethod - public int setReasoner(int id, String component) throws ClientNotKnownException, UnknownComponentException { - State state = getState(id); - Class<? extends ReasonerComponent> rcClass = reasonerMapping.get(component); - if(rcClass == null) - throw new UnknownComponentException(component); - - ReasonerComponent rc = cm.reasoner(rcClass, state.getKnowledgeSources()); - return state.setReasonerComponent(rc); - } - - @WebMethod - public int setLearningProblem(int id, String component) throws ClientNotKnownException, UnknownComponentException { - State state = getState(id); - Class<? extends LearningProblem> lpClass = learningProblemMapping.get(component); - if(lpClass == null) - throw new UnknownComponentException(component); - - LearningProblem lp = cm.learningProblem(lpClass, state.getReasoningService()); - return state.setLearningProblem(lp); - } - - @WebMethod - public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException { - State state = getState(id); - Class<? extends LearningAlgorithm> laClass = learningAlgorithmMapping.get(component); - if(laClass == null) - throw new UnknownComponentException(component); - - LearningAlgorithm la = cm.learningAlgorithm(laClass, state.getLearningProblem(), state.getReasoningService()); - return state.setLearningAlgorithm(la); - } - - /** - * Initialise all components. - * @param id Session ID. - */ - @WebMethod - public void init(int id) throws ClientNotKnownException { - State state = getState(id); - for(KnowledgeSource ks : state.getKnowledgeSources()) - ks.init(); - state.getReasonerComponent().init(); - state.getLearningProblem().init(); - state.getLearningAlgorithm().init(); - } - - /** - * Starts the learning algorithm and returns the best concept found. This - * method will block until learning is completed. - * - * @param id Session ID. - * @return The best solution found. - * @throws ClientNotKnownException - */ - @WebMethod - public String learn(int id) throws ClientNotKnownException { - State state = getState(id); - state.getLearningAlgorithm().start(); - return state.getLearningAlgorithm().getBestSolution().toString(); - } - - /** - * Starts the learning algorithm and returns immediately. The learning - * algorithm is executed in its own thread and can be queried and - * controlled using other Web Service methods. - * - * @param id Session ID. - * @throws ClientNotKnownException - */ - @WebMethod - public void learnThreaded(int id) throws ClientNotKnownException { - final State state = getState(id); - Thread learningThread = new Thread() { - @Override - public void run() { - state.setAlgorithmRunning(true); - state.getLearningAlgorithm().start(); - state.setAlgorithmRunning(false); - } - }; - learningThread.start(); - } - - @WebMethod - public String getCurrentlyBestConcept(int id) throws ClientNotKnownException { - State state = getState(id); - return state.getLearningAlgorithm().getBestSolution().toString(); - } - - @WebMethod - public boolean isAlgorithmRunning(int id) throws ClientNotKnownException { - return getState(id).isAlgorithmRunning(); - } - - /** - * Stops the learning algorithm smoothly. - * @param id - * @throws ClientNotKnownException - */ - @WebMethod - public void stop(int id) throws ClientNotKnownException { - getState(id).getLearningAlgorithm().stop(); - } - - ///////////////////////////////////////// - // methods for component configuration // - ///////////////////////////////////////// - - @WebMethod - public void setPositiveExamples(int id, String[] positiveExamples) throws ClientNotKnownException { - State state = getState(id); - Set<String> posExamples = new TreeSet<String>(Arrays.asList(positiveExamples)); - cm.applyConfigEntry(state.getLearningProblem(), "positiveExamples", posExamples); - } - - @WebMethod - public void setNegativeExamples(int id, String[] negativeExamples) throws ClientNotKnownException { - State state = getState(id); - Set<String> negExamples = new TreeSet<String>(Arrays.asList(negativeExamples)); - cm.applyConfigEntry(state.getLearningProblem(), "negativeExamples", negExamples); - } - - @WebMethod - public void applyConfigEntryInt(int sessionID, int componentID, String optionName, Integer value) throws ClientNotKnownException, UnknownComponentException { - applyConfigEntry(sessionID, componentID,optionName,value); - } - - @WebMethod - public void applyConfigEntryString(int sessionID, int componentID, String optionName, String value) throws ClientNotKnownException, UnknownComponentException { - applyConfigEntry(sessionID, componentID,optionName,value); - } - - @WebMethod - public void applyConfigEntryStringArray(int sessionID, int componentID, String optionName, String[] value) throws ClientNotKnownException, UnknownComponentException { - Set<String> stringSet = new TreeSet<String>(Arrays.asList(value)); - applyConfigEntry(sessionID, componentID,optionName,stringSet); - } - - @WebMethod - public void applyConfigEntryBoolean(int sessionID, int componentID, String optionName, Boolean value) throws ClientNotKnownException, UnknownComponentException { - applyConfigEntry(sessionID, componentID,optionName,value); - } - - private void applyConfigEntry(int sessionID, int componentID, String optionName, Object value) throws ClientNotKnownException, UnknownComponentException { - State state = getState(sessionID); - Component component = state.getComponent(componentID); - cm.applyConfigEntry(component, optionName, value); - } - - //////////////////////////////////// - // reasoning and querying methods // - //////////////////////////////////// - - @WebMethod - public String[] getAtomicConcepts(int id) throws ClientNotKnownException { - Set<AtomicConcept> atomicConcepts = getState(id).getReasoningService().getAtomicConcepts(); - return Datastructures.sortedSet2StringListConcepts(atomicConcepts); - } - - @WebMethod - public String getSubsumptionHierarchy(int id) throws ClientNotKnownException { - return getState(id).getReasoningService().toString(); - } - - @WebMethod - public String[] retrieval(int id, String conceptString) throws ClientNotKnownException { - State state = getState(id); - // call parser to parse atomic concept - Concept concept = null; - try { - concept = KBParser.parseConcept(conceptString); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Set<Individual> individuals = state.getReasoningService().retrieval(concept); - return Datastructures.sortedSet2StringListIndividuals(individuals); - } - - @WebMethod - public String[] getAtomicRoles(int id) throws ClientNotKnownException { - State state = getState(id); - Set<AtomicRole> roles = state.getReasoningService().getAtomicRoles(); - return Datastructures.sortedSet2StringListRoles(roles); - } - - @WebMethod - public String[] getInstances(int id) throws ClientNotKnownException { - State state = getState(id); - Set<Individual> individuals = state.getReasoningService().getIndividuals(); - return Datastructures.sortedSet2StringListIndividuals(individuals); - } - - @WebMethod - public String[] getIndividualsForARole(int id, String role) throws ClientNotKnownException { - State state = getState(id); - Map<Individual,SortedSet<Individual>> m = state.getReasoningService().getRoleMembers(new AtomicRole(role)); - Set<Individual> individuals = m.keySet(); - return Datastructures.sortedSet2StringListIndividuals(individuals); - } -} Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2007-10-16 09:27:26 UTC (rev 226) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2007-10-16 09:32:08 UTC (rev 227) @@ -32,7 +32,7 @@ System.out.print("Starting DL-Learner web service at http://" + isa.getHostName()+":"+isa.getPort()+ "/services ... "); - Endpoint endpoint = Endpoint.create(new DLLearnerWSNew()); + Endpoint endpoint = Endpoint.create(new DLLearnerWS()); //Endpoint endpoint = Endpoint.create(new CustomDataClass()); HttpContext context = server.createContext("/services"); endpoint.publish(context); Deleted: trunk/src/dl-learner/org/dllearner/server/State.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/State.java 2007-10-16 09:27:26 UTC (rev 226) +++ trunk/src/dl-learner/org/dllearner/server/State.java 2007-10-16 09:32:08 UTC (rev 227) @@ -1,209 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.server; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import org.dllearner.core.Component; -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.kb.OWLFile; -import org.dllearner.kb.SparqlEndpoint; - -/** - * Stores the state of a DL-Learner client session. - * - * @author Jens Lehmann - * - */ -public class State { - - // stores the mapping between component IDs and component - // (note that this allows us to keep all references to components even - // if they are note used anymore e.g. a deleted knowledge source) - private Map<Integer,Component> componentIDs = new HashMap<Integer,Component>(); - - private Set<KnowledgeSource> knowledgeSources = new HashSet<KnowledgeSource>(); - - private LearningProblem learningProblem; - - private ReasonerComponent reasonerComponent; - private ReasoningService reasoningService; - - private LearningAlgorithm learningAlgorithm; - - private Random rand=new Random(); - - private boolean isAlgorithmRunning = false; - - private int generateComponentID(Component component) { - int id; - do { - id = rand.nextInt(); - } while(componentIDs.keySet().contains(id)); - componentIDs.put(id, component); - return id; - } - - /** - * @return the isAlgorithmRunning - */ - public boolean isAlgorithmRunning() { - return isAlgorithmRunning; - } - - /** - * @param isAlgorithmRunning the isAlgorithmRunning to set - */ - public void setAlgorithmRunning(boolean isAlgorithmRunning) { - this.isAlgorithmRunning = isAlgorithmRunning; - } - -// public Component getComponent(Class<? extends Component> componentClass) throws UnknownComponentException { -// if(learningProblem.getClass().equals(componentClass)) -// return learningProblem; -// else if(learningAlgorithm.getClass().equals(componentClass)) -// return learningAlgorithm; -// else if(reasonerComponent.getClass().equals(componentClass)) -// return reasonerComponent; -// else if(KnowledgeSource.class.isAssignableFrom(componentClass)) { -// -// -// for(KnowledgeSource ks : knowledgeSources) { -// if(ks.getClass().equals(componentClass)) -// return ks; -// } -// throw new UnknownComponentException(componentClass.getName()); -// } else -// throw new UnknownComponentException(componentClass.getName()); -// } - - /** - * Removes a knowledge source with the given URL (independant of its type). - * @param url URL of the OWL file or SPARQL Endpoint. - * @return True if a knowledge source was deleted, false otherwise. - */ - public boolean removeKnowledgeSource(String url) { - Iterator<KnowledgeSource> it = knowledgeSources.iterator(); - while(it.hasNext()) { - KnowledgeSource source = it.next(); - if((source instanceof OWLFile && ((OWLFile)source).getURL().toString().equals(url)) - || (source instanceof SparqlEndpoint && ((SparqlEndpoint)source).getURL().toString().equals(url)) ) { - it.remove(); - return true; - } - } - return false; - } - - /** - * @return the learningProblem - */ - public LearningProblem getLearningProblem() { - return learningProblem; - } - - /** - * @param learningProblem the learningProblem to set - */ - public int setLearningProblem(LearningProblem learningProblem) { - this.learningProblem = learningProblem; - return generateComponentID(learningProblem); - } - - /** - * @return the reasonerComponent - */ - public ReasonerComponent getReasonerComponent() { - return reasonerComponent; - } - - /** - * Sets the reasoner component and creates the corresponding - * <code>ReasoningService</code> instance. - * - * @param reasonerComponent the reasonerComponent to set - */ - public int setReasonerComponent(ReasonerComponent reasonerComponent) { - this.reasonerComponent = reasonerComponent; - reasoningService = new ReasoningService(reasonerComponent); - return generateComponentID(reasonerComponent); - } - - /** - * @return the learningAlgorithm - */ - public LearningAlgorithm getLearningAlgorithm() { - return learningAlgorithm; - } - - /** - * @param learningAlgorithm the learningAlgorithm to set - */ - public int setLearningAlgorithm(LearningAlgorithm learningAlgorithm) { - this.learningAlgorithm = learningAlgorithm; - return generateComponentID(learningAlgorithm); - } - - /** - * @return the reasoningService - */ - public ReasoningService getReasoningService() { - return reasoningService; - } - - /** - * @param key - * @return - * @see java.util.Map#get(java.lang.Object) - */ - public Component getComponent(int id) { - return componentIDs.get(id); - } - - /** - * @param e - * @return - */ - public int addKnowledgeSource(KnowledgeSource ks) { - knowledgeSources.add(ks); - return generateComponentID(ks); - - } - - public boolean removeKnowledgeSource(int componentID) { - return knowledgeSources.remove(componentIDs.get(componentID)); - } - - /** - * @return the knowledgeSources - */ - public Set<KnowledgeSource> getKnowledgeSources() { - return knowledgeSources; - } -} Added: trunk/src/dl-learner/org/dllearner/server/jaxws/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/server/jaxws/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/jaxws/package.html 2007-10-16 09:32:08 UTC (rev 227) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Classes generated by JAXWS.</p> +</body> +</html> \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/server/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/server/package.html 2007-10-16 09:27:26 UTC (rev 226) +++ trunk/src/dl-learner/org/dllearner/server/package.html 2007-10-16 09:32:08 UTC (rev 227) @@ -2,8 +2,6 @@ <html> <head></head> <body bgcolor="white"> -<p>This package implements the DL-Learner server, which handles learning problems according to the "Ontology Class Learning Interface". - -TODO: So ein Interface muss natürlich erst spezifiziert werden ...</p> +<p>This package implements the DL-Learner web service.</p> </body> </html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-28 09:14:16
|
Revision: 262 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=262&view=rev Author: jenslehmann Date: 2007-10-28 02:14:13 -0700 (Sun, 28 Oct 2007) Log Message: ----------- - converted trains example to new structure - without imports empty backgroud knowledge is used Modified Paths: -------------- trunk/examples/trains/trains.conf trunk/src/dl-learner/org/dllearner/cli/Start.java Added Paths: ----------- trunk/examples/trains/trains.kb Modified: trunk/examples/trains/trains.conf =================================================================== --- trunk/examples/trains/trains.conf 2007-10-24 15:11:58 UTC (rev 261) +++ trunk/examples/trains/trains.conf 2007-10-28 09:14:13 UTC (rev 262) @@ -30,268 +30,19 @@ * Copyright (C) 2007, Jens Lehmann */ -useRetrievalForClassification = false; -refinement.useDIGMultiInstanceChecks = twoChecks; +// refinement.writeSearchTree = true; +// refinement.searchTreeFile = "log/searchTreeTrains.txt"; -/** background knowledge **/ -// TODO: more knowledge could be added here, e.g. that all classes are disjoint; -// shape can be described using nominals i.e. a fixed set of values; etc. +import("trains.kb"); -car(car_11). car(car_12). car(car_13). car(car_14). -car(car_21). car(car_22). car(car_23). -car(car_31). car(car_32). car(car_33). -car(car_41). car(car_42). car(car_43). car(car_44). -car(car_51). car(car_52). car(car_53). -car(car_61). car(car_62). -car(car_71). car(car_72). car(car_73). -car(car_81). car(car_82). -car(car_91). car(car_92). car(car_93). car(car_94). -car(car_101). car(car_102). - -train(east1). train(east2). train(east3). train(east4). train(east5). -train(west6). train(west7). train(west8). train(west9). train(west10). - -// eastbound train 1 -short(car_12). -closed(car_12). -long(car_11). -long(car_13). -short(car_14). -open_car(car_11). -open_car(car_13). -open_car(car_14). -shape(car_11,rectangle). -shape(car_12,rectangle). -shape(car_13,rectangle). -shape(car_14,rectangle). -load(car_11,rectangle). -load_count(car_11,three). -load(car_12,triangle). -load_count(car_12,one). -load(car_13,hexagon). -load_count(car_13,one). -load(car_14,circle). -load(car_14,one). -wheels(car_11,two). -wheels(car_12,two). -wheels(car_13,three). -wheels(car_14,two). -has_car(east1,car_11). -has_car(east1,car_12). -has_car(east1,car_13). -has_car(east1,car_14). - -// eastbound train 2 -has_car(east2,car_21). -has_car(east2,car_22). -has_car(east2,car_23). -short(car_21). -short(car_22). -short(car_23). -shape(car_21,u_shaped). -shape(car_22,u_shaped). -shape(car_23,rectangle). -open_car(car_21). -open_car(car_22). -closed(car_23). -load(car_21,triangle). -load_count(car_21,one). -load(car_22,rectangle). -load_count(car_22,one). -load(car_23,circle). -load_count(car_23,two). -wheels(car_21,two). -wheels(car_22,two). -wheels(car_23,two). - -// eastbound train 3 -has_car(east3,car_31). -has_car(east3,car_32). -has_car(east3,car_33). -short(car_31). -short(car_32). -long(car_33). -shape(car_31,rectangle). -shape(car_32,hexagon). -shape(car_33,rectangle). -open_car(car_31). -closed(car_32). -closed(car_33). -load(car_31,circle). -load_count(car_31,one). -load(car_32,triangle). -load_count(car_32,one). -load(car_33,triangle). -load_count(car_33,one). -wheels(car_31,two). -wheels(car_32,two). -wheels(car_33,three). - -// eastbound train 4 -has_car(east4,car_41). -has_car(east4,car_42). -has_car(east4,car_43). -has_car(east4,car_44). -short(car_41). -short(car_42). -short(car_43). -short(car_44). -shape(car_41,u_shaped). -shape(car_42,rectangle). -shape(car_43,elipse). -shape(car_44,rectangle). -double(car_42). -open_car(car_41). -open_car(car_42). -closed(car_43). -open_car(car_44). -load(car_41,triangle). -load_count(car_41,one). -load(car_42,triangle). -load_count(car_42,one). -load(car_43,rectangle). -load_count(car_43,one). -load(car_44,rectangle). -load_count(car_44,one). -wheels(car_41,two). -wheels(car_42,two). -wheels(car_43,two). -wheels(car_44,two). - -// eastbound train 5 -has_car(east5,car_51). -has_car(east5,car_52). -has_car(east5,car_53). -short(car_51). -short(car_52). -short(car_53). -shape(car_51,rectangle). -shape(car_52,rectangle). -shape(car_53,rectangle). -double(car_51). -open_car(car_51). -closed(car_52). -closed(car_53). -load(car_51,triangle). -load_count(car_51,one). -load(car_52,rectangle). -load_count(car_52,one). -load(car_53,circle). -load_count(car_53,one). -wheels(car_51,two). -wheels(car_52,three). -wheels(car_53,two). - -// westbound train 6 -has_car(west6,car_61). -has_car(west6,car_62). -long(car_61). -short(car_62). -shape(car_61,rectangle). -shape(car_62,rectangle). -closed(car_61). -open_car(car_62). -load(car_61,circle). -load_count(car_61,three). -load(car_62,triangle). -load_count(car_62,one). -wheels(car_61,two). -wheels(car_62,two). - -// westbound train 7 -has_car(west7,car_71). -has_car(west7,car_72). -has_car(west7,car_73). -short(car_71). -short(car_72). -long(car_73). -shape(car_71,rectangle). -shape(car_72,u_shaped). -shape(car_73,rectangle). -double(car_71). -open_car(car_71). -open_car(car_72). -jagged(car_73). -load(car_71,circle). -load_count(car_71,one). -load(car_72,triangle). -load_count(car_72,one). -// load(car_73,nil). -load_count(car_73,zero). -wheels(car_71,two). -wheels(car_72,two). -wheels(car_73,two). - -// westbound train 8 -has_car(west8,car_81). -has_car(west8,car_82). -long(car_81). -short(car_82). -shape(car_81,rectangle). -shape(car_82,u_shaped). -closed(car_81). -open_car(car_82). -load(car_81,rectangle). -load_count(car_81,one). -load(car_82,circle). -load_count(car_82,one). -wheels(car_81,three). -wheels(car_82,two). - -// westbound train 9 -has_car(west9,car_91). -has_car(west9,car_92). -has_car(west9,car_93). -has_car(west9,car_94). -short(car_91). -long(car_92). -short(car_93). -short(car_94). -shape(car_91,u_shaped). -shape(car_92,rectangle). -shape(car_93,rectangle). -shape(car_94,u_shaped). -open_car(car_91). -jagged(car_92). -open_car(car_93). -open_car(car_94). -load(car_91,circle). -load_count(car_91,one). -load(car_92,rectangle). -load_count(car_92,one). -load(car_93,rectangle). -load_count(car_93,one). -load(car_94,circle). -load_count(car_94,one). -wheels(car_91,two). -wheels(car_92,two). -wheels(car_93,two). -wheels(car_94,two). - -// westbound train 10 -has_car(west10,car_101). -has_car(west10,car_102). -short(car_101). -long(car_102). -shape(car_101,u_shaped). -shape(car_102,rectangle). -open_car(car_101). -open_car(car_102). -load(car_101,rectangle). -load_count(car_101,one). -load(car_102,rectangle). -load_count(car_102,two). -wheels(car_101,two). -wheels(car_102,two). - /** examples **/ -+eastbound(east1). -+eastbound(east2). -+eastbound(east3). -+eastbound(east4). -+eastbound(east5). --eastbound(west6). --eastbound(west7). --eastbound(west8). --eastbound(west9). --eastbound(west10). ++east1 ++east2 ++east3 ++east4 ++east5 +-west6 +-west7 +-west8 +-west9 +-west10 Added: trunk/examples/trains/trains.kb =================================================================== --- trunk/examples/trains/trains.kb (rev 0) +++ trunk/examples/trains/trains.kb 2007-10-28 09:14:13 UTC (rev 262) @@ -0,0 +1,251 @@ +/** background knowledge **/ +// TODO: more knowledge could be added here, e.g. that all classes are disjoint; +// shape can be described using nominals i.e. a fixed set of values; etc. + +car(car_11). car(car_12). car(car_13). car(car_14). +car(car_21). car(car_22). car(car_23). +car(car_31). car(car_32). car(car_33). +car(car_41). car(car_42). car(car_43). car(car_44). +car(car_51). car(car_52). car(car_53). +car(car_61). car(car_62). +car(car_71). car(car_72). car(car_73). +car(car_81). car(car_82). +car(car_91). car(car_92). car(car_93). car(car_94). +car(car_101). car(car_102). + +train(east1). train(east2). train(east3). train(east4). train(east5). +train(west6). train(west7). train(west8). train(west9). train(west10). + +// eastbound train 1 +short(car_12). +closed(car_12). +long(car_11). +long(car_13). +short(car_14). +open_car(car_11). +open_car(car_13). +open_car(car_14). +shape(car_11,rectangle). +shape(car_12,rectangle). +shape(car_13,rectangle). +shape(car_14,rectangle). +load(car_11,rectangle). +load_count(car_11,three). +load(car_12,triangle). +load_count(car_12,one). +load(car_13,hexagon). +load_count(car_13,one). +load(car_14,circle). +load(car_14,one). +wheels(car_11,two). +wheels(car_12,two). +wheels(car_13,three). +wheels(car_14,two). +has_car(east1,car_11). +has_car(east1,car_12). +has_car(east1,car_13). +has_car(east1,car_14). + +// eastbound train 2 +has_car(east2,car_21). +has_car(east2,car_22). +has_car(east2,car_23). +short(car_21). +short(car_22). +short(car_23). +shape(car_21,u_shaped). +shape(car_22,u_shaped). +shape(car_23,rectangle). +open_car(car_21). +open_car(car_22). +closed(car_23). +load(car_21,triangle). +load_count(car_21,one). +load(car_22,rectangle). +load_count(car_22,one). +load(car_23,circle). +load_count(car_23,two). +wheels(car_21,two). +wheels(car_22,two). +wheels(car_23,two). + +// eastbound train 3 +has_car(east3,car_31). +has_car(east3,car_32). +has_car(east3,car_33). +short(car_31). +short(car_32). +long(car_33). +shape(car_31,rectangle). +shape(car_32,hexagon). +shape(car_33,rectangle). +open_car(car_31). +closed(car_32). +closed(car_33). +load(car_31,circle). +load_count(car_31,one). +load(car_32,triangle). +load_count(car_32,one). +load(car_33,triangle). +load_count(car_33,one). +wheels(car_31,two). +wheels(car_32,two). +wheels(car_33,three). + +// eastbound train 4 +has_car(east4,car_41). +has_car(east4,car_42). +has_car(east4,car_43). +has_car(east4,car_44). +short(car_41). +short(car_42). +short(car_43). +short(car_44). +shape(car_41,u_shaped). +shape(car_42,rectangle). +shape(car_43,elipse). +shape(car_44,rectangle). +double(car_42). +open_car(car_41). +open_car(car_42). +closed(car_43). +open_car(car_44). +load(car_41,triangle). +load_count(car_41,one). +load(car_42,triangle). +load_count(car_42,one). +load(car_43,rectangle). +load_count(car_43,one). +load(car_44,rectangle). +load_count(car_44,one). +wheels(car_41,two). +wheels(car_42,two). +wheels(car_43,two). +wheels(car_44,two). + +// eastbound train 5 +has_car(east5,car_51). +has_car(east5,car_52). +has_car(east5,car_53). +short(car_51). +short(car_52). +short(car_53). +shape(car_51,rectangle). +shape(car_52,rectangle). +shape(car_53,rectangle). +double(car_51). +open_car(car_51). +closed(car_52). +closed(car_53). +load(car_51,triangle). +load_count(car_51,one). +load(car_52,rectangle). +load_count(car_52,one). +load(car_53,circle). +load_count(car_53,one). +wheels(car_51,two). +wheels(car_52,three). +wheels(car_53,two). + +// westbound train 6 +has_car(west6,car_61). +has_car(west6,car_62). +long(car_61). +short(car_62). +shape(car_61,rectangle). +shape(car_62,rectangle). +closed(car_61). +open_car(car_62). +load(car_61,circle). +load_count(car_61,three). +load(car_62,triangle). +load_count(car_62,one). +wheels(car_61,two). +wheels(car_62,two). + +// westbound train 7 +has_car(west7,car_71). +has_car(west7,car_72). +has_car(west7,car_73). +short(car_71). +short(car_72). +long(car_73). +shape(car_71,rectangle). +shape(car_72,u_shaped). +shape(car_73,rectangle). +double(car_71). +open_car(car_71). +open_car(car_72). +jagged(car_73). +load(car_71,circle). +load_count(car_71,one). +load(car_72,triangle). +load_count(car_72,one). +// load(car_73,nil). +load_count(car_73,zero). +wheels(car_71,two). +wheels(car_72,two). +wheels(car_73,two). + +// westbound train 8 +has_car(west8,car_81). +has_car(west8,car_82). +long(car_81). +short(car_82). +shape(car_81,rectangle). +shape(car_82,u_shaped). +closed(car_81). +open_car(car_82). +load(car_81,rectangle). +load_count(car_81,one). +load(car_82,circle). +load_count(car_82,one). +wheels(car_81,three). +wheels(car_82,two). + +// westbound train 9 +has_car(west9,car_91). +has_car(west9,car_92). +has_car(west9,car_93). +has_car(west9,car_94). +short(car_91). +long(car_92). +short(car_93). +short(car_94). +shape(car_91,u_shaped). +shape(car_92,rectangle). +shape(car_93,rectangle). +shape(car_94,u_shaped). +open_car(car_91). +jagged(car_92). +open_car(car_93). +open_car(car_94). +load(car_91,circle). +load_count(car_91,one). +load(car_92,rectangle). +load_count(car_92,one). +load(car_93,rectangle). +load_count(car_93,one). +load(car_94,circle). +load_count(car_94,one). +wheels(car_91,two). +wheels(car_92,two). +wheels(car_93,two). +wheels(car_94,two). + +// westbound train 10 +has_car(west10,car_101). +has_car(west10,car_102). +short(car_101). +long(car_102). +shape(car_101,u_shaped). +shape(car_102,rectangle). +open_car(car_101). +open_car(car_102). +load(car_101,rectangle). +load_count(car_101,one). +load(car_102,rectangle). +load_count(car_102,two). +wheels(car_101,two). +wheels(car_102,two). + Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-24 15:11:58 UTC (rev 261) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-28 09:14:13 UTC (rev 262) @@ -318,6 +318,7 @@ List<List<String>> imports = parser.getFunctionCalls().get("import"); Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); + if(imports != null) { for (List<String> arguments : imports) { // step 1: detect URL URL url = null; @@ -371,6 +372,7 @@ importedFiles.put(url, ksClass); } } + } return importedFiles; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-01 20:54:22
|
Revision: 294 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=294&view=rev Author: kurzum Date: 2007-12-01 12:54:13 -0800 (Sat, 01 Dec 2007) Log Message: ----------- ontology with config sets Added Paths: ----------- trunk/config/ trunk/config/config.owl Added: trunk/config/config.owl =================================================================== --- trunk/config/config.owl (rev 0) +++ trunk/config/config.owl 2007-12-01 20:54:13 UTC (rev 294) @@ -0,0 +1,172 @@ +<?xml version="1.0"?> +<!DOCTYPE rdf:RDF [ + <!ENTITY config "http://www.extraction.org/config#"> + <!ENTITY owl "http://www.w3.org/2002/07/owl#"> + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#"> + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#"> +]> +<rdf:RDF xml:base="http://www.extraction.org/config" xmlns:config="http://www.extraction.org/config#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> + <!-- Ontology Information --> + <owl:Ontology rdf:about=""> + <owl:versionInfo xml:lang="en">version 0.1</owl:versionInfo> + </owl:Ontology> + <!-- Classes --> + <owl:Class rdf:about="#Configuration"/> + <owl:Class rdf:about="#FilterSet"/> + <owl:Class rdf:about="#GETParameter"/> + <owl:Class rdf:about="#ObjectFilterSet"> + <rdfs:subClassOf rdf:resource="#FilterSet"/> + </owl:Class> + <owl:Class rdf:about="#PredicateFilterSet"> + <rdfs:subClassOf rdf:resource="#FilterSet"/> + </owl:Class> + <owl:Class rdf:about="#SparqlEndpoint"/> + <owl:Class rdf:about="#TypedQuery"/> + <!-- Annotation Properties --> + <owl:AnnotationProperty rdf:about="&rdfs;comment"/> + <owl:AnnotationProperty rdf:about="&owl;versionInfo"/> + <!-- Datatype Properties --> + <owl:DatatypeProperty rdf:about="#filtersURI"> + <rdfs:domain rdf:resource="#ObjectFilterSet"/> + <rdfs:domain rdf:resource="#PredicateFilterSet"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasAfterGET"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasHost"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasMode"> + <rdfs:domain rdf:resource="#TypedQuery"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasParameterContent"> + <rdfs:domain rdf:resource="#GETParameter"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasParameterName"> + <rdfs:domain rdf:resource="#GETParameter"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasPort"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasQueryParameter"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasRecursionDepth"> + <rdfs:domain rdf:resource="#Configuration"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#usesLiterals"> + <rdfs:domain rdf:resource="#TypedQuery"/> + </owl:DatatypeProperty> + <!-- Object Properties --> + <owl:ObjectProperty rdf:about="#hasGETParameter"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + <rdfs:range rdf:resource="#GETParameter"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasObjectFilterSet"> + <rdfs:domain rdf:resource="#TypedQuery"/> + <rdfs:range rdf:resource="#ObjectFilterSet"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasPredicateFilterSet"> + <rdfs:domain rdf:resource="#TypedQuery"/> + <rdfs:range rdf:resource="#PredicateFilterSet"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasSparqlEndpoint"> + <rdfs:domain rdf:resource="#Configuration"/> + <rdfs:range rdf:resource="#SparqlEndpoint"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasTypedQuery"> + <rdfs:domain rdf:resource="#Configuration"/> + <rdfs:range rdf:resource="#TypedQuery"/> + </owl:ObjectProperty> + <!-- Instances --> + <config:SparqlEndpoint rdf:about="#dbpediaEndpoint"> + <config:hasAfterGET rdf:datatype="&xsd;string">/sparql</config:hasAfterGET> + <config:hasGETParameter rdf:resource="#defaultgraphuri"/> + <config:hasGETParameter rdf:resource="#format"/> + <config:hasHost rdf:datatype="&xsd;string">dbpedia.openlinksw.com</config:hasHost> + <config:hasPort rdf:datatype="&xsd;string">80</config:hasPort> + <config:hasQueryParameter rdf:datatype="&xsd;string">query</config:hasQueryParameter> + <config:hasURL>dbpedia.openlinksw.com:80/sparql</config:hasURL> + </config:SparqlEndpoint> + <config:ObjectFilterSet rdf:about="#dbpediaGeneralObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Articles_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Wikipedia_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://upload.wikimedia.org/wikipedia/commons</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://upload.wikimedia.org/wikipedia</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www.geonames.org</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2006/03/wn/wn20/instances/synset</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www4.wiwiss.fu-berlin.de/flickrwrappr</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#dbpediaGeneralPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/reference</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/website</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/wikipage-</config:filtersURI> + </config:PredicateFilterSet> + <config:TypedQuery rdf:about="#dbpediaYago"> + <config:hasMode rdf:datatype="&xsd;string">forbid</config:hasMode> + <config:hasObjectFilterSet rdf:resource="#dbpediaGeneralObjectFilter"/> + <config:hasObjectFilterSet rdf:resource="#foafObjectFilter"/> + <config:hasObjectFilterSet rdf:resource="#yagoObjectFilter"/> + <config:hasPredicateFilterSet rdf:resource="#dbpediaGeneralPredicateFilter"/> + <config:hasPredicateFilterSet rdf:resource="#foafPredicateFilter"/> + <config:hasPredicateFilterSet rdf:resource="#sameAsFilter"/> + <config:hasPredicateFilterSet rdf:resource="#yagoPredicateFilter"/> + <config:usesLiterals rdf:datatype="&xsd;string">false</config:usesLiterals> + </config:TypedQuery> + <config:Configuration rdf:about="#dbpediatest" rdfs:comment="for first test"> + <config:hasRecursionDepth rdf:datatype="&xsd;string">2</config:hasRecursionDepth> + <config:hasSparqlEndpoint rdf:resource="#dbpediaEndpoint"/> + <config:hasTypedQuery rdf:resource="#dbpediaYago"/> + </config:Configuration> + <config:GETParameter rdf:about="#defaultgraphuri"> + <config:hasParameterContent rdf:datatype="&xsd;string">http://dbpedia.org</config:hasParameterContent> + <config:hasParameterName rdf:datatype="&xsd;string">default-graph-uri</config:hasParameterName> + </config:GETParameter> + <config:ObjectFilterSet rdf:about="#foafObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://xmlns.com/foaf/0.1/</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#foafPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://xmlns.com/foaf/0.1/</config:filtersURI> + </config:PredicateFilterSet> + <config:GETParameter rdf:about="#format"> + <config:hasParameterContent rdf:datatype="&xsd;string">application/sparql-results.xml</config:hasParameterContent> + <config:hasParameterName rdf:datatype="&xsd;string">format</config:hasParameterName> + </config:GETParameter> + <config:Configuration rdf:about="#localjoseki"> + <config:hasRecursionDepth rdf:datatype="&xsd;string">2</config:hasRecursionDepth> + <config:hasSparqlEndpoint rdf:resource="#localjosekiendpoint"/> + <config:hasTypedQuery rdf:resource="#localjosekitypedquery"/> + </config:Configuration> + <config:SparqlEndpoint rdf:about="#localjosekiendpoint"> + <config:hasAfterGET rdf:datatype="&xsd;string">/books</config:hasAfterGET> + <config:hasHost rdf:datatype="http://www.w3.org/2001/XMLSchema#string">localhost</config:hasHost> + <config:hasPort rdf:datatype="&xsd;string">2020</config:hasPort> + <config:hasQueryParameter rdf:datatype="&xsd;string">query</config:hasQueryParameter> + <config:hasURL>localhost:2020/books</config:hasURL> + </config:SparqlEndpoint> + <config:TypedQuery rdf:about="#localjosekitypedquery"> + <config:hasMode rdf:datatype="&xsd;string">forbid</config:hasMode> + <config:hasObjectFilterSet rdf:resource="#dbpediaGeneralObjectFilter"/> + <config:hasPredicateFilterSet rdf:resource="#dbpediaGeneralPredicateFilter"/> + <config:usesLiterals rdf:datatype="&xsd;string">false</config:usesLiterals> + </config:TypedQuery> + <config:PredicateFilterSet rdf:about="#sameAsFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2002/07/owl#sameAs</config:filtersURI> + </config:PredicateFilterSet> + <config:ObjectFilterSet rdf:about="#yagoObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Articles_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Wikipedia_</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#yagoPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2004/02/skos/core</config:filtersURI> + </config:PredicateFilterSet> + <rdf:Description rdf:about="#hasURL"> + <rdf:type> + <rdf:Description rdf:about="http://www.w3.org/2002/07/owl#DatatypeProperty"/> + </rdf:type> + <rdfs:domain> + <rdf:Description rdf:about="#SparqlEndpoint"/> + </rdfs:domain> + </rdf:Description> +</rdf:RDF> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-02 11:42:40
|
Revision: 295 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=295&view=rev Author: jenslehmann Date: 2007-12-02 03:42:36 -0800 (Sun, 02 Dec 2007) Log Message: ----------- added SparqlEndpointRestructured as component - prefix "sparql2" in CLI, use import(...,SPARQL2) in conf file Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/cli/Start.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-12-01 20:54:13 UTC (rev 294) +++ trunk/lib/components.ini 2007-12-02 11:42:36 UTC (rev 295) @@ -4,6 +4,7 @@ org.dllearner.kb.OWLFile org.dllearner.kb.KBFile org.dllearner.kb.SparqlEndpoint +org.dllearner.kb.SparqlEndpointRestructured # reasoners org.dllearner.reasoning.DIGReasoner org.dllearner.reasoning.FastRetrievalReasoner Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-01 20:54:13 UTC (rev 294) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-02 11:42:36 UTC (rev 295) @@ -60,6 +60,7 @@ import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.kb.SparqlEndpointRestructured; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -224,6 +225,7 @@ Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); // knowledge sources componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); + componentPrefixMapping.put(SparqlEndpointRestructured.class, "sparql2"); // reasoners componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); // learning problems - configured via + and - flags for examples @@ -370,6 +372,8 @@ ksClass = KBFile.class; else if (formatString.equals("SPARQL")) ksClass = SparqlEndpoint.class; + else if (formatString.equals("SPARQL2")) + ksClass = SparqlEndpointRestructured.class; else if (formatString.equals("NT")) ksClass = OWLFile.class; else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-02 11:52:08
|
Revision: 296 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=296&view=rev Author: jenslehmann Date: 2007-12-02 03:52:02 -0800 (Sun, 02 Dec 2007) Log Message: ----------- refactored and formatted new SPARQL component files Modified Paths: -------------- trunk/examples/dbpedia/sparql.conf trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/ Modified: trunk/examples/dbpedia/sparql.conf =================================================================== --- trunk/examples/dbpedia/sparql.conf 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/examples/dbpedia/sparql.conf 2007-12-02 11:52:02 UTC (rev 296) @@ -31,16 +31,16 @@ cli.showSubsumptionHierarchy = false; // SPARQL options -sparql.numberOfRecursions = 2; -sparql.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Philolaus","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; -sparql.filterMode = 0; -sparql.predList = {}; -sparql.objList = {}; -sparql.classList = {}; -sparql.format = "KB"; -sparql.dumpToFile = false; +sparql2.numberOfRecursions = 2; +sparql2.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Philolaus","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; +sparql2.filterMode = 0; +sparql2.predList = {}; +sparql2.objList = {}; +sparql2.classList = {}; +sparql2.format = "KB"; +sparql2.dumpToFile = false; -import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL"); +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); /** examples **/ +"http://dbpedia.org/resource/Pythagoras" Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 11:52:02 UTC (rev 296) @@ -41,9 +41,9 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.KB; -import org.dllearner.kb.extraction.Manager; -import org.dllearner.kb.extraction.SparqlEndpoint; -import org.dllearner.kb.extraction.SparqlQueryType; +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQueryType; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,202 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.OWLConstant; -import org.semanticweb.owl.model.OWLDataPropertyExpression; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLObjectPropertyExpression; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLOntologyManager; - -public class Configuration { - private SparqlEndpoint SparqlEndpoint; - private SparqlQueryType SparqlQueryType; - private Manipulator Manipulator; - - - private Configuration(){ - } - public Configuration(SparqlEndpoint SparqlEndpoint,SparqlQueryType SparqlQueryType){ - this.SparqlEndpoint=SparqlEndpoint; - this.SparqlQueryType=SparqlQueryType; - } - - - public static Configuration getConfiguration(URI uri){ - //public static String getTellsString(URL file, URI kbURI){//throws OWLOntologyCreationException{ - Configuration ret=new Configuration(); - try{ - String file="config/config.owl"; - - - File f= new File(file); - String fileURL="file:///"+f.getAbsolutePath(); - URL u=new URL(fileURL); - /* Load an ontology from a physical URI */ - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology ontology = manager.loadOntologyFromPhysicalURI(u.toURI()); - //System.out.println( ontology.containsIndividualReference(uri)); - //OWLIndividualImpl ind=new OWLIndividualImpl(); - //System.out.println(ontology.getReferencedIndividuals()); - Set<OWLIndividual> s=ontology.getReferencedIndividuals(); - //System.out.println(ontology.getReferencedClasses()); - //Set<OWLIndividualAxiom> s= ontology.getIndividualAxioms(); - Iterator<OWLIndividual> it=s.iterator(); - while (it.hasNext()){ - OWLIndividual tmp=(OWLIndividual)it.next(); - //tmp.getURI() - if(tmp.getURI().equals(uri)){ - OWLIndividual[] arr=getIndividualsForProperty("hasSparqlEndpoint",tmp.getObjectPropertyValues(ontology)); - OWLIndividual sEndpoint=arr[0]; - ret.SparqlEndpoint=makeEndpoint(sEndpoint, ontology); - arr=getIndividualsForProperty("hasTypedQuery",tmp.getObjectPropertyValues(ontology)); - OWLIndividual typedQuery=arr[0]; - ret.SparqlQueryType=makeSparqlQueryType(typedQuery, ontology); - - } - //{hasSparqlEndpoint=[dbpediaEndpoint]} - } - - ret.Manipulator=makeManipulator(); - }catch (Exception e) {e.printStackTrace();} - - return ret; - } - - - - - - public static OWLIndividual[] getIndividualsForProperty(String propertyname,Map<OWLObjectPropertyExpression, Set<OWLIndividual>> m){ - Set<OWLObjectPropertyExpression> s=m.keySet(); - - Iterator<OWLObjectPropertyExpression> it=s.iterator(); - while (it.hasNext()){ - OWLObjectPropertyExpression tmp=(OWLObjectPropertyExpression)it.next(); - //System.out.println(tmp); - //System.out.println(propertyname); - if(tmp.toString().equals(propertyname)) - { - Object[] arr=((Set<OWLIndividual>)m.get(tmp)).toArray() ; - OWLIndividual[] o=new OWLIndividual[arr.length]; - for (int i = 0; i < o.length; i++) { - o[i]=(OWLIndividual)arr[i]; - } - - return o;} - } - return null; - - } - - public static String getFirstValueForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ - return getValuesForDataProperty(propertyname, m)[0]; - } - - public static String[] getValuesForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ - Set<OWLDataPropertyExpression> s=m.keySet(); - - Iterator<OWLDataPropertyExpression> it=s.iterator(); - while (it.hasNext()){ - OWLDataPropertyExpression tmp=(OWLDataPropertyExpression)it.next(); - if(tmp.toString().equals(propertyname)) - { - Object[] arr=((Set<OWLConstant>)m.get(tmp)).toArray() ; - String[] str=new String[arr.length]; - for (int i = 0; i < str.length; i++) { - str[i]=((OWLConstant)arr[i]).getLiteral(); - } - return str;} - } - return null; - - } - - public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint,OWLOntology o){ - String host=getFirstValueForDataProperty("hasHost",sEndpoint.getDataPropertyValues(o)); - String port=getFirstValueForDataProperty("hasPort",sEndpoint.getDataPropertyValues(o)); - String hasAfterGET=getFirstValueForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); - String hasQueryParameter=getFirstValueForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); - OWLIndividual[] para=getIndividualsForProperty("hasGETParameter",sEndpoint.getObjectPropertyValues(o)); - //System.out.println("test"); - HashMap<String,String> parameters=new HashMap<String,String>(); - if(para==null)return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); - for (OWLIndividual p : para) { - //System.out.println("test2"); - String a1=getFirstValueForDataProperty("hasParameterName",p.getDataPropertyValues(o)); - String a2=getFirstValueForDataProperty("hasParameterContent",p.getDataPropertyValues(o)); - parameters.put(a1, a2); - } - //System.out.println("test2"); - //System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ parameters); - return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); - - - - } - - public static SparqlQueryType makeSparqlQueryType(OWLIndividual typedQuery,OWLOntology o){ - String useLiterals=getFirstValueForDataProperty("usesLiterals",typedQuery.getDataPropertyValues(o)); - String hasMode=getFirstValueForDataProperty("hasMode",typedQuery.getDataPropertyValues(o)); - //String hasAfterGET=getValuesForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); - //String hasQueryParameter=getValuesForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); - OWLIndividual[] objFilter=getIndividualsForProperty("hasObjectFilterSet",typedQuery.getObjectPropertyValues(o)); - OWLIndividual[] predFilter=getIndividualsForProperty("hasPredicateFilterSet",typedQuery.getObjectPropertyValues(o)); - - Set<String> objectFilter=new HashSet<String>(); - Set<String> predicateFilter=new HashSet<String>(); - - for (OWLIndividual of : objFilter) { - String[] tmp=getValuesForDataProperty("filtersURI",of.getDataPropertyValues(o)); - for (String s : tmp){ - objectFilter.add(s); - - } - } - - for (OWLIndividual pf : predFilter) { - String[] tmp=getValuesForDataProperty("filtersURI",pf.getDataPropertyValues(o)); - for (String s : tmp){ - predicateFilter.add(s); - - } - } - //System.out.println(predicateFilter); - //System.out.println(hasMode+objectFilter+predicateFilter+useLiterals); - return new SparqlQueryType(hasMode,objectFilter,predicateFilter,useLiterals); - - - - } - - public static Manipulator makeManipulator() { - return new Manipulator(); - } - - - public Manipulator getManipulator() { - return this.Manipulator; - } - - public SparqlEndpoint getSparqlEndpoint() { - return SparqlEndpoint; - } - - - - public SparqlQueryType getSparqlQueryType() { - return SparqlQueryType; - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,74 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.net.URI; -import java.util.Vector; - -import org.dllearner.kb.extraction.datastructures.InstanceNode; -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; - -public class ExtractionAlgorithm { - - private Configuration Configuration; - private Manipulator Manipulator; - private int recursiondepth=2; - private boolean getAllBackground=true; - - - - public ExtractionAlgorithm (Configuration Configuration){ - this.Configuration=Configuration; - this.Manipulator=Configuration.getManipulator(); - - } - - public Node getFirstNode(URI u){ - return new InstanceNode(u); - } - public Vector<Node> expandAll(URI[] u,TypedSparqlQuery tsp){ - Vector<Node> v=new Vector<Node>(); - for(URI one:u){ - v.add(expandNode(one, tsp)); - } - return v; - } - - - public Node expandNode(URI u, TypedSparqlQuery tsp){ - Node n=getFirstNode(u); - Vector<Node> v=new Vector<Node>(); - v.add(n); - System.out.println("StartVector: "+v); - // n.expand(tsp, this.Manipulator); - //Vector<Node> second= - for(int x=1;x<=this.recursiondepth;x++){ - - Vector<Node>tmp=new Vector<Node>(); - while (v.size()>0) { - Node tmpNode=v.remove(0); - System.out.println("Expanding "+tmpNode); - Vector<Node> tmpVec=tmpNode.expand(tsp, this.Manipulator); - - tmp.addAll(tmpVec); - } - v=tmp; - System.out.println("Rec: "+x+" with "+v); - } - if(this.getAllBackground){ - Vector<Node> classes=new Vector<Node>(); - for(Node one:v){ - if(one.isClass()) {classes.add(one);} - } - while(classes.size()>0){ - System.out.println(classes.size()); - classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); - } - - } - return n; - - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,67 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; - -public class Manager { - - private Configuration Configuration; - private TypedSparqlQuery TypedSparqlQuery; - private ExtractionAlgorithm ExtractionAlgorithm; - - - public void usePredefinedConfiguration(URI uri){ - - this.Configuration=org.dllearner.kb.extraction.Configuration.getConfiguration(uri); - this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); - } - - public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint){ - - this.Configuration=new Configuration(SparqlEndpoint,SparqlQueryType); - this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); - } - - public String extract(URI uri){ - //this.TypedSparqlQuery.query(uri); - //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - System.out.println("Start extracting"); - Node n=this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); - Set<String> s=n.toNTriple(); - String nt=""; - for(String str:s){ - nt+=str+"\n"; - } - return nt; - } - - public String extract(Set<String> instances){ - //this.TypedSparqlQuery.query(uri); - //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - System.out.println("Start extracting"); - Set<String> ret=new HashSet<String>(); - - - for(String one:instances){ - try{ - Node n=this.ExtractionAlgorithm.expandNode(new URI(one),this.TypedSparqlQuery); - ret.addAll(n.toNTriple()); - }catch (Exception e) {e.printStackTrace();} - } - - - String nt=""; - for(String str:ret){ - nt+=str+"\n"; - } - return nt; - } - - -} \ No newline at end of file Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,55 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.datastructures.Tupel; - -public class Manipulator { - public String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public String type="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - - String objectProperty="http://www.w3.org/2002/07/owl#ObjectProperty"; - String classns="http://www.w3.org/2002/07/owl#Class"; - String thing="http://www.w3.org/2002/07/owl#Thing"; - - Set<String> classproperties; - - - String[] defaultClasses={ - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Category:", - "http://dbpedia.org/resource/Template:", - "http://www.w3.org/2004/02/skos/core", - "http://dbpedia.org/class/"}; //TODO FEHLER hier fehlt yago - - public Manipulator(){ - Set<String> classproperties=new HashSet<String>(); - classproperties.add(subclass); - - } - - public Set<Tupel> check(Set<Tupel> s,Node node){ - Set<Tupel> toRemove=new HashSet<Tupel>(); - Iterator<Tupel> it=s.iterator(); - while(it.hasNext()){ - Tupel t=(Tupel)it.next(); - //all classes with owl:type class - if(t.a.equals(this.type) && t.b.equals(this.classns)&& node.isClass() ) - {toRemove.add(t);}; - // all with type class - if( t.b.equals(this.classns) && node.isClass() ) - {toRemove.add(t);}; - // all instances with owl:type thing - if(t.a.equals(this.type) && t.b.equals(this.thing)&& node.isInstance() ) - {toRemove.add(t);}; - - } - s.removeAll(toRemove); - - return s; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,69 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.HashMap; - -public class SparqlEndpoint { - - String host; - int port; - String hasAfterGET; - String hasQueryParameter; - String hasURL; - public HashMap<String,String> parameters=new HashMap<String,String>(); - public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, HashMap<String, String> parameters) { - super(); - this.host = host; - this.port = Integer.parseInt(port); - this.hasAfterGET = hasAfterGET; - this.hasQueryParameter = hasQueryParameter; - this.parameters = parameters; - } - - public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { - super(); - this.port=port; - this.host=host; - this.hasURL = hasURL; - this.hasQueryParameter = "query"; - this.parameters = parameters; - } - public String getHasAfterGET() { - return hasAfterGET; - } - public void setHasAfterGET(String hasAfterGET) { - this.hasAfterGET = hasAfterGET; - } - public String getHasQueryParameter() { - return hasQueryParameter; - } - public void setHasQueryParameter(String hasQueryParameter) { - this.hasQueryParameter = hasQueryParameter; - } - public String getHost() { - return host; - } - public void setHost(String host) { - this.host = host; - } - public HashMap<String, String> getParameters() { - return parameters; - } - public void setParameters(HashMap<String, String> parameters) { - this.parameters = parameters; - } - public int getPort() { - return port; - } - public void setPort(int port) { - this.port = port; - } - - - - - /*sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + - //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + - URLEncoder.encode(query, "UTF-8")+ - //query+// URLencode - "&format=application%2Fsparql-results%2Bxml*/ -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,68 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.Set; - -public class SparqlQueryType { - - private String mode="forbid"; - private String[] objectfilterlist={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/resource/Category", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - private String[] predicatefilterlist={ - "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - private boolean literals=false; - - public SparqlQueryType(String mode, String[] obectfilterlist, String[] predicatefilterlist, boolean literals) { - super(); - this.mode = mode; - this.objectfilterlist = obectfilterlist; - this.predicatefilterlist = predicatefilterlist; - this.literals = literals; - } - - public SparqlQueryType(String mode, Set<String> objectfilterlist, Set<String> predicatefilterlist, String literals) { - super(); - this.mode = mode; - this.literals = (literals.equals("true"))?true:false; - - Object[] arr=objectfilterlist.toArray(); - Object[] arr2=predicatefilterlist.toArray(); - this.objectfilterlist = new String[arr.length]; - this.predicatefilterlist = new String[arr2.length]; - for (int i = 0; i < arr.length; i++) { - this.objectfilterlist[i]=(String)arr[i]; - } - for (int i = 0; i < arr2.length; i++) { - this.predicatefilterlist[i]=(String)arr2[i]; - } - - - } - - public boolean isLiterals() { - return literals; - } - - public String getMode() { - return mode; - } - - public String[] getObjectfilterlist() { - return objectfilterlist; - } - - public String[] getPredicatefilterlist() { - return predicatefilterlist; - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,31 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.io.File; -import java.io.FileWriter; -import java.net.URI; - -public class Test { - - - public static void main(String[] args) { - System.out.println("Start"); - String test2="http://www.extraction.org/config#dbpediatest"; - String test="http://www.extraction.org/config#localjoseki"; - try{ - URI u=new URI(test); - Manager m=new Manager(); - m.usePredefinedConfiguration(u); - - - URI u2=new URI("http://dbpedia.org/resource/Angela_Merkel"); - - String filename=System.currentTimeMillis()+".nt"; - FileWriter fw=new FileWriter(new File(filename),true); - fw.write(m.extract(u2)); - fw.flush(); - fw.close(); - - }catch (Exception e) {e.printStackTrace();} - } - -} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,132 @@ +package org.dllearner.kb.sparql; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.net.URLEncoder; + +public class Cache implements Serializable { + // Object can be the cache itself + // or a cache object(one entry) + + final static long serialVersionUID = 104; + transient String basedir = ""; + transient String fileending = ".cache"; + long timestamp; + String content = ""; + long daysoffreshness = 15; + long multiplier = 24 * 60 * 60 * 1000;// h m s ms + String sparqlquery = ""; + + // constructor for the cache itself + public Cache(String path) { + this.basedir = path + File.separator; + if (!new File(path).exists()) { + System.out.println(new File(path).mkdir()); + ; + } + + } + + // constructor for single cache object(one entry) + public Cache(String c, String sparql) { + this.content = c; + this.sparqlquery = sparql; + this.timestamp = System.currentTimeMillis(); + } + + public String get(String key, String sparql) { + // System.out.println("get From "+key); + String ret = null; + try { + Cache c = readFromFile(makeFilename(key)); + if (c == null) + return null; + // System.out.println(" file found"); + if (!c.checkFreshness()) + return null; + // System.out.println("fresh"); + if (!c.validate(sparql)) + return null; + // System.out.println("valid"); + ret = c.content; + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + }; + + public void put(String key, String content, String sparql) { + // System.out.println("put into "+key); + Cache c = new Cache(content, sparql); + putIntoFile(makeFilename(key), c); + } + + String makeFilename(String key) { + String ret = ""; + try { + ret = basedir + URLEncoder.encode(key, "UTF-8") + fileending; + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + } + + boolean checkFreshness() { + if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) + // fresh + return true; + else + return false; + } + + boolean validate(String sparql) { + if (this.sparqlquery.equals(sparql)) + // valid + return true; + else + return false; + } + + public void checkFile(String Filename) { + if (!new File(Filename).exists()) { + try { + new File(Filename).createNewFile(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + } + + public void putIntoFile(String Filename, Cache content) { + try { + // FileWriter fw=new FileWriter(new File(Filename),true); + FileOutputStream fos = new FileOutputStream(Filename, false); + ObjectOutputStream o = new ObjectOutputStream(fos); + o.writeObject(content); + fos.flush(); + fos.close(); + } catch (Exception e) { + System.out.println("Not in cache creating: " + Filename); + } + } + + public Cache readFromFile(String Filename) { + Cache content = null; + try { + FileInputStream fos = new FileInputStream(Filename); + ObjectInputStream o = new ObjectInputStream(fos); + content = (Cache) o.readObject(); + // FileReader fr=new FileReader(new File(Filename,"r")); + // BufferedReader br=new BufferedReader(fr); + } catch (Exception e) { + } + return content; + + } +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,61 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +public class ClassNode extends Node { + Set<PropertyNode> properties = new HashSet<PropertyNode>(); + + public ClassNode(URI u) { + super(u); + this.type = "class"; + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { + Set<Tupel> s = tsq.query(this.URI); + s = m.check(s, this); + Vector<Node> Nodes = new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + try { + if (t.a.equals(m.type) || t.a.equals(m.subclass)) { + ClassNode tmp = new ClassNode(new URI(t.b)); + properties.add(new PropertyNode(new URI(m.subclass), this, tmp)); + Nodes.add(tmp); + } + } catch (Exception e) { + System.out.println(t); + e.printStackTrace(); + } + + } + return Nodes; + } + + @Override + public boolean isClass() { + return true; + } + + @Override + public Set<String> toNTriple() { + Set<String> s = new HashSet<String>(); + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + "http://www.w3.org/2002/07/owl#Class" + ">."); + + for (PropertyNode one : properties) { + s.add("<" + this.URI + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.addAll(one.getB().toNTriple()); + } + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,207 @@ +package org.dllearner.kb.sparql; + +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLConstant; +import org.semanticweb.owl.model.OWLDataPropertyExpression; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLObjectPropertyExpression; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyManager; + +public class Configuration { + private SparqlEndpoint SparqlEndpoint; + private SparqlQueryType SparqlQueryType; + private Manipulator Manipulator; + + private Configuration() { + } + + public Configuration(SparqlEndpoint SparqlEndpoint, SparqlQueryType SparqlQueryType) { + this.SparqlEndpoint = SparqlEndpoint; + this.SparqlQueryType = SparqlQueryType; + } + + public static Configuration getConfiguration(URI uri) { + // public static String getTellsString(URL file, URI kbURI){//throws + // OWLOntologyCreationException{ + Configuration ret = new Configuration(); + try { + String file = "config/config.owl"; + + File f = new File(file); + String fileURL = "file:///" + f.getAbsolutePath(); + URL u = new URL(fileURL); + /* Load an ontology from a physical URI */ + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(u.toURI()); + // System.out.println( ontology.containsIndividualReference(uri)); + // OWLIndividualImpl ind=new OWLIndividualImpl(); + // System.out.println(ontology.getReferencedIndividuals()); + Set<OWLIndividual> s = ontology.getReferencedIndividuals(); + // System.out.println(ontology.getReferencedClasses()); + // Set<OWLIndividualAxiom> s= ontology.getIndividualAxioms(); + Iterator<OWLIndividual> it = s.iterator(); + while (it.hasNext()) { + OWLIndividual tmp = (OWLIndividual) it.next(); + // tmp.getURI() + if (tmp.getURI().equals(uri)) { + OWLIndividual[] arr = getIndividualsForProperty("hasSparqlEndpoint", tmp + .getObjectPropertyValues(ontology)); + OWLIndividual sEndpoint = arr[0]; + ret.SparqlEndpoint = makeEndpoint(sEndpoint, ontology); + arr = getIndividualsForProperty("hasTypedQuery", tmp + .getObjectPropertyValues(ontology)); + OWLIndividual typedQuery = arr[0]; + ret.SparqlQueryType = makeSparqlQueryType(typedQuery, ontology); + + } + // {hasSparqlEndpoint=[dbpediaEndpoint]} + } + + ret.Manipulator = makeManipulator(); + } catch (Exception e) { + e.printStackTrace(); + } + + return ret; + } + + public static OWLIndividual[] getIndividualsForProperty(String propertyname, + Map<OWLObjectPropertyExpression, Set<OWLIndividual>> m) { + Set<OWLObjectPropertyExpression> s = m.keySet(); + + Iterator<OWLObjectPropertyExpression> it = s.iterator(); + while (it.hasNext()) { + OWLObjectPropertyExpression tmp = (OWLObjectPropertyExpression) it.next(); + // System.out.println(tmp); + // System.out.println(propertyname); + if (tmp.toString().equals(propertyname)) { + Object[] arr = ((Set<OWLIndividual>) m.get(tmp)).toArray(); + OWLIndividual[] o = new OWLIndividual[arr.length]; + for (int i = 0; i < o.length; i++) { + o[i] = (OWLIndividual) arr[i]; + } + + return o; + } + } + return null; + + } + + public static String getFirstValueForDataProperty(String propertyname, + Map<OWLDataPropertyExpression, Set<OWLConstant>> m) { + return getValuesForDataProperty(propertyname, m)[0]; + } + + public static String[] getValuesForDataProperty(String propertyname, + Map<OWLDataPropertyExpression, Set<OWLConstant>> m) { + Set<OWLDataPropertyExpression> s = m.keySet(); + + Iterator<OWLDataPropertyExpression> it = s.iterator(); + while (it.hasNext()) { + OWLDataPropertyExpression tmp = (OWLDataPropertyExpression) it.next(); + if (tmp.toString().equals(propertyname)) { + Object[] arr = ((Set<OWLConstant>) m.get(tmp)).toArray(); + String[] str = new String[arr.length]; + for (int i = 0; i < str.length; i++) { + str[i] = ((OWLConstant) arr[i]).getLiteral(); + } + return str; + } + } + return null; + + } + + public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint, OWLOntology o) { + String host = getFirstValueForDataProperty("hasHost", sEndpoint.getDataPropertyValues(o)); + String port = getFirstValueForDataProperty("hasPort", sEndpoint.getDataPropertyValues(o)); + String hasAfterGET = getFirstValueForDataProperty("hasAfterGET", sEndpoint + .getDataPropertyValues(o)); + String hasQueryParameter = getFirstValueForDataProperty("hasQueryParameter", sEndpoint + .getDataPropertyValues(o)); + OWLIndividual[] para = getIndividualsForProperty("hasGETParameter", sEndpoint + .getObjectPropertyValues(o)); + // System.out.println("test"); + HashMap<String, String> parameters = new HashMap<String, String>(); + if (para == null) + return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + for (OWLIndividual p : para) { + // System.out.println("test2"); + String a1 = getFirstValueForDataProperty("hasParameterName", p.getDataPropertyValues(o)); + String a2 = getFirstValueForDataProperty("hasParameterContent", p + .getDataPropertyValues(o)); + parameters.put(a1, a2); + } + // System.out.println("test2"); + // System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ + // parameters); + return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + + } + + public static SparqlQueryType makeSparqlQueryType(OWLIndividual typedQuery, OWLOntology o) { + String useLiterals = getFirstValueForDataProperty("usesLiterals", typedQuery + .getDataPropertyValues(o)); + String hasMode = getFirstValueForDataProperty("hasMode", typedQuery + .getDataPropertyValues(o)); + // String + // hasAfterGET=getValuesForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); + // String + // hasQueryParameter=getValuesForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); + OWLIndividual[] objFilter = getIndividualsForProperty("hasObjectFilterSet", typedQuery + .getObjectPropertyValues(o)); + OWLIndividual[] predFilter = getIndividualsForProperty("hasPredicateFilterSet", typedQuery + .getObjectPropertyValues(o)); + + Set<String> objectFilter = new HashSet<String>(); + Set<String> predicateFilter = new HashSet<String>(); + + for (OWLIndividual of : objFilter) { + String[] tmp = getValuesForDataProperty("filtersURI", of.getDataPropertyValues(o)); + for (String s : tmp) { + objectFilter.add(s); + + } + } + + for (OWLIndividual pf : predFilter) { + String[] tmp = getValuesForDataProperty("filtersURI", pf.getDataPropertyValues(o)); + for (String s : tmp) { + predicateFilter.add(s); + + } + } + // System.out.println(predicateFilter); + // System.out.println(hasMode+objectFilter+predicateFilter+useLiterals); + return new SparqlQueryType(hasMode, objectFilter, predicateFilter, useLiterals); + + } + + public static Manipulator makeManipulator() { + return new Manipulator(); + } + + public Manipulator getManipulator() { + return this.Manipulator; + } + + public SparqlEndpoint getSparqlEndpoint() { + return SparqlEndpoint; + } + + public SparqlQueryType getSparqlQueryType() { + return SparqlQueryType; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,68 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.Vector; + +public class ExtractionAlgorithm { + + private Configuration Configuration; + private Manipulator Manipulator; + private int recursiondepth = 2; + private boolean getAllBackground = true; + + public ExtractionAlgorithm(Configuration Configuration) { + this.Configuration = Configuration; + this.Manipulator = Configuration.getManipulator(); + + } + + public Node getFirstNode(URI u) { + return new InstanceNode(u); + } + + public Vector<Node> expandAll(URI[] u, TypedSparqlQuery tsp) { + Vector<Node> v = new Vector<Node>(); + for (URI one : u) { + v.add(expandNode(one, tsp)); + } + return v; + } + + public Node expandNode(URI u, TypedSparqlQuery tsp) { + Node n = getFirstNode(u); + Vector<Node> v = new Vector<Node>(); + v.add(n); + System.out.println("StartVector: " + v); + // n.expand(tsp, this.Manipulator); + // Vector<Node> second= + for (int x = 1; x <= this.recursiondepth; x++) { + + Vector<Node> tmp = new Vector<Node>(); + while (v.size() > 0) { + Node tmpNode = v.remove(0); + System.out.println("Expanding " + tmpNode); + Vector<Node> tmpVec = tmpNode.expand(tsp, this.Manipulator); + + tmp.addAll(tmpVec); + } + v = tmp; + System.out.println("Rec: " + x + " with " + v); + } + if (this.getAllBackground) { + Vector<Node> classes = new Vector<Node>(); + for (Node one : v) { + if (one.isClass()) { + classes.add(one); + } + } + while (classes.size() > 0) { + System.out.println(classes.size()); + classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); + } + + } + return n; + + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,78 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +public class InstanceNode extends Node { + + Set<ClassNode> classes = new HashSet<ClassNode>(); + Set<Tupel> datatypes = new HashSet<Tupel>(); + Set<PropertyNode> properties = new HashSet<PropertyNode>(); + + public InstanceNode(URI u) { + super(u); + this.type = "instance"; + + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { + + Set<Tupel> s = tsq.query(this.URI); + // Manipulation + m.check(s, this); + Vector<Node> Nodes = new Vector<Node>(); + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + + try { + if (t.a.equals(m.type)) { + ClassNode tmp = new ClassNode(new URI(t.b)); + classes.add(tmp); + Nodes.add(tmp); + } else { + InstanceNode tmp = new InstanceNode(new URI(t.b)); + properties.add(new PropertyNode(new URI(t.a), this, tmp)); + Nodes.add(tmp); + + } + } catch (Exception e) { + System.out.println("Problem with: " + t); + e.printStackTrace(); + } + + } + this.expanded = true; + return Nodes; + } + + @Override + public boolean isInstance() { + return true; + } + + @Override + public Set<String> toNTriple() { + Set<String> s = new HashSet<String>(); + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + "http://www.w3.org/2002/07/owl#Thing" + ">."); + for (ClassNode one : classes) { + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + one.getURI() + ">."); + s.addAll(one.toNTriple()); + } + for (PropertyNode one : properties) { + s.add("<" + this.URI + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.addAll(one.toNTriple()); + s.addAll(one.getB().toNTriple()); + } + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,62 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +public class Manager { + + private Configuration Configuration; + private TypedSparqlQuery TypedSparqlQuery; + private ExtractionAlgorithm ExtractionAlgorithm; + + public void usePredefinedConfiguration(URI uri) { + + this.Configuration = org.dllearner.kb.sparql.Configuration.getConfiguration(uri); + this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + } + + public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint) { + + this.Configuration = new Configuration(SparqlEndpoint, SparqlQueryType); + this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + } + + public String extract(URI uri) { + // this.TypedSparqlQuery.query(uri); + // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Node n = this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); + Set<String> s = n.toNTriple(); + String nt = ""; + for (String str : s) { + nt += str + "\n"; + } + return nt; + } + + public String extract(Set<String> instances) { + // this.TypedSparqlQuery.query(uri); + // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Set<String> ret = new HashSet<String>(); + + for (String one : instances) { + try { + Node n = this.ExtractionAlgorithm.expandNode(new URI(one), this.TypedSparqlQuery); + ret.addAll(n.toNTriple()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String nt = ""; + for (String str : ret) { + nt += str + "\n"; + } + return nt; + } + +} \ No newline at end of file Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,58 @@ +package org.dllearner.kb.sparql; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class Manipulator { + public String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + + String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + String classns = "http://www.w3.org/2002/07/owl#Class"; + String thing = "http://www.w3.org/2002/07/owl#Thing"; + + Set<String> classproperties; + + String[] defaultClasses = { "http://dbpedia.org/class/yago", + "http://dbpedia.org/resource/Category:", "http://dbpedia.org/resource/Template:", + "http://www.w3.org/2004/02/skos/core", "http://dbpedia.org/class/" }; // TODO + // FEHLER + // hier + // fehlt + // yago + + public Manipulator() { + Set<String> classproperties = new HashSet<String>(); + classproperties.add(subclass); + + } + + public Set<Tupel> check(Set<Tupel> s, Node node) { + Set<Tupel> toRemove = new HashSet<Tupel>(); + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + // all classes with owl:type class + if (t.a.equals(this.type) && t.b.equals(this.classns) && node.isClass()) { + toRemove.add(t); + } + ; + // all with type class + if (t.b.equals(this.classns) && node.isClass()) { + toRemove.add(t); + } + ; + // all instances with owl:type thing + if (t.a.equals(this.type) && t.b.equals(this.thing) && node.isInstance()) { + toRemove.add(t); + } + ; + + } + s.removeAll(toRemove); + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,54 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.Set; +import java.util.Vector; + +public abstract class Node { + URI URI; + protected String type; + protected boolean expanded = false; + + // Hashtable<String,Node> classes=new Hashtable<String,Node>(); + // Hashtable<String,Node> instances=new Hashtable<String,Node>();; + // Hashtable<String,Node> datatype=new Hashtable<String,Node>();; + + public Node(URI u) { + this.URI = u; + + } + + /* + * public void checkConsistency(){ if (type.equals("class") && ( + * instances.size()>0 || datatype.size()>0)){ System.out.println("Warning, + * inconsistent:"+this.toString()); } + * } + */ + + public abstract Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m); + + public abstract Set<String> toNTriple(); + + @Override + public String toString() { + return "Node: " + URI + ":" + type; + + } + + public boolean isClass() { + return false; + } + + public boolean isInstance() { + return false; + } + + public boolean isProperty() { + return false; + } + + public URI getURI() { + return URI; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,74 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +public class PropertyNode extends Node { + + private Node a; + private Node b; + private Set<String> SpecialTypes; + + public PropertyNode(URI u) { + super(u); + this.type = "property"; + + } + + public PropertyNode(URI u, Node a, Node b) { + super(u); + this.type = "property"; + this.a = a; + this.b = b; + this.SpecialTypes = new HashSet<String>(); + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { + Set<Tupel> s = tsq.query(this.URI); + Vector<Node> Nodes = new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + try { + if (t.a.equals(m.type)) { + SpecialTypes.add(t.b); + } + } catch (Exception e) { + System.out.println(t); + e.printStackTrace(); + } + + } + return Nodes; + } + + @Override + public boolean isProperty() { + return true; + } + + public Node getB() { + return this.b; + } + + @Override + public Set<String> toNTriple() { + Set<String> s = new HashSet<String>(); + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); + for (String one : SpecialTypes) { + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + one + ">."); + + } + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,128 @@ +package org.dllearner.kb.sparql; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URL; +import java.net.URLEncoder; + +public class SimpleHTTPRequest { + static final char value[] = { 13, 10 }; + static final String cut = new String(value); + private InetAddress ia; + private int port; + + public SimpleHTTPRequest(InetAddress ia, int port) { + super(); + this.ia = ia; + this.port = port; + + } + + public String sendAndReceive(String content) { + String retval = ""; + // + + byte resp[] = null; + + try { + Socket SparqlServer = new Socket(this.ia, this.port); + // String request=makeHeader(content); + // send request + (SparqlServer.getOutputStream()).write(content.getBytes()); + + // get Response + resp = readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval = new String(resp); + retval = subtractResponseHeader(retval); + // retval="||"+retval; + + SparqlServer.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + // System.out.println("got it"); + return retval; + + }// down + + public static byte[] readBuffer(InputStream IS) throws IOException { + byte buffer[] = new byte[0xffff]; + int nbytes = 0; + byte resp[] = new byte[0]; + while ((nbytes = IS.read(buffer)) != -1) { + byte tmp[] = new byte[resp.length + nbytes]; + int i = 0; + for (; i < resp.length; i++) { + tmp[i] = resp[i]; + } + for (int a = 0; a < nbytes; a++, i++) { + tmp[i] = buffer[a]; + } + resp = tmp; + } + return resp; + } + + public String subtractResponseHeader(String in) { + // System.out.println(in.indexOf(cut+""+cut)); + return in.substring(in.indexOf(cut + "" + cut) + 4); + + } + + private String sendAndReceive2(String sparql, URL url) throws IOException { + StringBuilder answer = new StringBuilder(); + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + + connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + + connection.addRequestProperty("Host", "dbpedia.openlinksw.com"); + connection.addRequestProperty("Connection", "close"); + connection + .addRequestProperty( + "Accept", + "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); + connection + .addRequestProperty( + "User-Agent", + "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + osw + .write("default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + URLEncoder.encode(sparql, "UTF-8") + + "&format=application%2Fsparql-results%2Bxml"); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if (line != null) + answer.append(line); + } while (line != null); + + br.close(); + + return answer.toString(); + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,79 @@ +package org.dllearner.kb.sparql; + +import java.util.HashMap; + +public class SparqlEndpoint { + + String host; + int port; + String hasAfterGET; + String hasQueryParameter; + String hasURL; + public HashMap<String, String> parameters = new HashMap<String, String>(); + + public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, + HashMap<String, String> parameters) { + super(); + this.host = host; + this.port = Integer.parseInt(port); + this.hasAfterGET = hasAfterGET; + this.hasQueryParameter = hasQueryParameter; + this.parameters = parameters; + } + + public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { + super(); + this.port = port; + this.host = host; + this.hasURL = hasURL; + this.hasQueryParameter = "query"; + this.parameters = parameters; + } + + public String getHasAfterGET() { + return hasAfterGET; + } + + public void setHasAfterGET(String hasAfterGET) { + this.hasAfterGET = hasAfterGET; + } + + public String getHasQueryParameter() { + return hasQueryParameter; + } + + public void setHasQueryParameter(String hasQueryParameter) { + this.hasQueryParameter = hasQueryParameter; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public HashMap<String, String> getParameters() { + return parameters; + } + + public void setParameters(HashMap<String, String> parameters) { + this.parameters = parameters; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + /* + * sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + * //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + + * URLEncoder.encode(query, "UTF-8")+ //query+// URLencode + * "&format=application%2Fsparql-results%2Bxml + */ +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,81 @@ +package org.dllearner.kb.sparql; + +import java.net.InetAddress; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Set; + +public class SparqlHTTPRequest { + static final char value[] = { 13, 10 }; + static final String cut = new String(value); + + private SparqlEndpoint SparqlEndpoint; + private SimpleHTTPRequest SimpleHTTPRequest; + + public SparqlHTTPRequest(SparqlEndpoint SparqlEndpoint) { + this.SparqlEndpoint = SparqlEndpoint; + InetAddress ia = null; + try { + ia = InetAddress.getByName(SparqlEndpoint.getHost()); + } catch (Exception e) { + e.printStackTrace(); + } + this.SimpleHTTPRequest = new SimpleHTTPRequest(ia, SparqlEndpoint.getPort()); + + } + + public String sendAndReceiveSPARQL(String sparql) { + + // System.out.println(sparql); + String content = makeContent(sparql); + // System.out.println(content); + String ret = this.SimpleHTTPRequest.sendAndReceive(content); + // System.out.println(ret); + + // this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); + + return ret; + + }// down + + public String makeContent(String query) { + + String RequestHeader = ""; + try { + + RequestHeader = "GET "; + RequestHeader += SparqlEndpoint.getHasAfterGET() + "?"; + // parameters + Set<String> s = SparqlEndpoint.getParameters().keySet(); + Iterator<String> it = s.iterator(); + while (it.hasNext()) { + String element = (String) it.next(); + RequestHeader += "" + URLEncoder.encode(element, "UTF-8") + "=" + + URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8") + + "&"; + } + RequestHeader += "" + SparqlEndpoint.getHasQueryParameter() + "=" + + URLEncoder.encode(query, "UTF-8"); + RequestHeader += " HTTP/1.1" + cut; + RequestHeader += "Host: " + SparqlEndpoint.getHost() + cut; + + RequestHeader += "Connection: close" + + cut + + + // "Accept-Encoding: gzip"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + + cut + + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" + + cut + + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + + cut + + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24" + + cut + cut; + } catch (Exception e) { + e.printStackTrace(); + } + return RequestHeader; + + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,37 @@ +package org.dllearner.kb.sparql; + +public class SparqlQueryMaker { + + private SparqlQueryType SparqlQueryType; + + public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { + this.SparqlQueryType = SparqlQu... [truncated message content] |
From: <ku...@us...> - 2007-12-02 19:53:13
|
Revision: 308 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=308&view=rev Author: kurzum Date: 2007-12-02 11:53:08 -0800 (Sun, 02 Dec 2007) Log Message: ----------- Manual settings work now. Filtermode=0 means all configurations have to be done manual filtermode 1 and above uses presets overriding almost all manual configurations made new example workingexamplemanual.conf changed workingexample.conf filtermode=1 uses yago and dbpedia Modified Paths: -------------- trunk/examples/dbpedia/newworking.conf trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java Added Paths: ----------- trunk/examples/dbpedia/newworkingManually.conf Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ Modified: trunk/examples/dbpedia/newworking.conf =================================================================== --- trunk/examples/dbpedia/newworking.conf 2007-12-02 17:40:55 UTC (rev 307) +++ trunk/examples/dbpedia/newworking.conf 2007-12-02 19:53:08 UTC (rev 308) @@ -35,7 +35,9 @@ sparql2.host = "dbpedia.openlinksw.com"; sparql2.getAllBackground=true; sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel"}; -sparql2.filterMode = 0; +sparql2.filterMode = 1; +//filtermode 1 and above uses a predefined setting +//0 means manual sparql2.predList = {}; sparql2.objList = {}; sparql2.classList = {}; Added: trunk/examples/dbpedia/newworkingManually.conf =================================================================== --- trunk/examples/dbpedia/newworkingManually.conf (rev 0) +++ trunk/examples/dbpedia/newworkingManually.conf 2007-12-02 19:53:08 UTC (rev 308) @@ -0,0 +1,64 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +sparql2.numberOfRecursions = 2; +sparql2.host = "dbpedia.openlinksw.com"; +sparql2.getAllBackground=true; +sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel"}; +sparql2.filterMode = 0; +//filtermode 1 and above uses a predefined setting +//0 means manual +sparql2.predList = {"http://www.w3.org/2004/02/skos/core", + "http://www.w3.org/2002/07/owl#sameAs", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/reference", + "http://dbpedia.org/property/website", + "http://dbpedia.org/property/wikipage"}; +sparql2.objList = {"http://dbpedia.org/resource/Category:Wikipedia_" + ,"http://dbpedia.org/resource/Category:Articles_" + ,"http://xmlns.com/foaf/0.1/" + ,"http://upload.wikimedia.org/wikipedia/commons" + ,"http://upload.wikimedia.org/wikipedia" + ,"http://www.geonames.org" + ,"http://www.w3.org/2006/03/wn/wn20/instances/synset" + ,"http://www4.wiwiss.fu-berlin.de/flickrwrappr" + ,"http://www.w3.org/2004/02/skos/core"}; +sparql2.classList = {}; +sparql2.format = "N-TRIPLES"; +sparql2.dumpToFile = true; + +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +/** examples **/ ++"http://dbpedia.org/resource/Angela_Merkel" +-"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 17:40:55 UTC (rev 307) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 19:53:08 UTC (rev 308) @@ -189,14 +189,16 @@ //new SparqlOntologyCollector(Datastructures.setToArray(instances), numberOfRecursions, filterMode, //Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format,url,useLits); Manager m=new Manager(); - if(filterMode==0){ - + if(filterMode>=1){ m.usePredefinedConfiguration(filterMode); } else{ SparqlQueryType sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); - SpecificSparqlEndpoint se=new SpecificSparqlEndpoint(url, host, new HashMap<String, String>()); + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + SpecificSparqlEndpoint se=new SpecificSparqlEndpoint(url, host, parameters); m.useConfiguration(sqt, se,numberOfRecursions,getAllBackground); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 17:40:55 UTC (rev 307) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 19:53:08 UTC (rev 308) @@ -49,7 +49,7 @@ tmp.addAll(tmpVec); } v = tmp; - System.out.println("Rec: " + x + " with " + v); + System.out.println("Recursion counter: " + x + " with " + v.size()+" Nodes remaining"); } if (this.getAllBackground) { Vector<Node> classes = new Vector<Node>(); @@ -59,9 +59,9 @@ } } while (classes.size() > 0) { - System.out.println(classes.size()); + System.out.println("Remaining classes: "+classes.size()); Node next=classes.remove(0); - System.out.println(next); + System.out.println("Expanding: "+next); classes.addAll(next.expand(tsp, manipulator)); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 17:40:55 UTC (rev 307) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 19:53:08 UTC (rev 308) @@ -10,7 +10,7 @@ public static Configuration get(int i) { switch (i) { - case 0: + case 1: return dbpediaYago(); } @@ -18,18 +18,18 @@ } public static Configuration dbpediaYago() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://dbpedia.org"); - m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - SpecificSparqlEndpoint sse = new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); + + SpecificSparqlEndpoint sse=dbpediaEndpoint(); // System.out.println(u); - Set<String> pred = new HashSet<String>(); + SparqlQueryType sqt = YagoFilter(); + + return new Configuration(sse, sqt, 2, true); + + } + + public static SparqlQueryType YagoFilter(){ + + Set<String> pred = new HashSet<String>(); pred.add("http://www.w3.org/2004/02/skos/core"); pred.add("http://www.w3.org/2002/07/owl#sameAs"); pred.add("http://xmlns.com/foaf/0.1/"); @@ -48,10 +48,21 @@ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); obj.add("http://www.w3.org/2004/02/skos/core"); - SparqlQueryType sqt = new SparqlQueryType("forbid", obj, pred, "false"); - - return new Configuration(sse, sqt, 2, true); - + return new SparqlQueryType("forbid", obj, pred, "false"); } + + + public static SpecificSparqlEndpoint dbpediaEndpoint(){ + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + m.put("default-graph-uri", "http://dbpedia.org"); + m.put("format", "application/sparql-results.xml"); + try { + u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-02 20:52:42
|
Revision: 309 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=309&view=rev Author: kurzum Date: 2007-12-02 12:52:38 -0800 (Sun, 02 Dec 2007) Log Message: ----------- changed some Options see examples/dbpedia/reference.conf Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java Added Paths: ----------- trunk/examples/dbpedia/reference.conf trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java Added: trunk/examples/dbpedia/reference.conf =================================================================== --- trunk/examples/dbpedia/reference.conf (rev 0) +++ trunk/examples/dbpedia/reference.conf 2007-12-02 20:52:38 UTC (rev 309) @@ -0,0 +1,81 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +//necessary: +sparql2.numberOfRecursions = 2; +sparql2.getAllBackground=true; +sparql2.format = "N-TRIPLES"; +sparql2.dumpToFile = true; +sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel","http://dbpedia.org/resource/Gerhard_Schr%C3%B6der"}; + + +//predefined Endpoint overrides host and it doesn't matter what the string in import below looks like +// 0 means nothing +// 1 means dbpedia +sparql2.predefinedEndpoint=1; +//sparql2.host = "dbpedia.openlinksw.com"; + + + +//predefined filter overrides predList and ObjList +sparql2.predefinedFilter = 1; +//filtermode 1 and above uses a predefined setting +// 0 means nothing (manual configuration) +// 1 means only yago classes + +/* +This is left here. It is the yago predefined Filter +sparql2.predList = {"http://www.w3.org/2004/02/skos/core", + "http://www.w3.org/2002/07/owl#sameAs", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/reference", + "http://dbpedia.org/property/website", + "http://dbpedia.org/property/wikipage"}; +sparql2.objList = {"http://dbpedia.org/resource/Category:Wikipedia_" + ,"http://dbpedia.org/resource/Category:Articles_" + ,"http://xmlns.com/foaf/0.1/" + ,"http://upload.wikimedia.org/wikipedia/commons" + ,"http://upload.wikimedia.org/wikipedia" + ,"http://www.geonames.org" + ,"http://www.w3.org/2006/03/wn/wn20/instances/synset" + ,"http://www4.wiwiss.fu-berlin.de/flickrwrappr" + ,"http://www.w3.org/2004/02/skos/core"}; +*/ + + + +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +/** examples **/ ++"http://dbpedia.org/resource/Angela_Merkel" +-"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 19:53:08 UTC (rev 308) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 20:52:38 UTC (rev 309) @@ -43,6 +43,8 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.KB; import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.PredefinedEndpoint; +import org.dllearner.kb.sparql.PredefinedFilter; import org.dllearner.kb.sparql.SparqlQueryType; import org.dllearner.kb.sparql.SpecificSparqlEndpoint; import org.dllearner.parser.KBParser; @@ -64,7 +66,8 @@ private Set<String> instances; private URL dumpFile; private int numberOfRecursions; - private int filterMode; + private int predefinedFilter=0; + private int predefinedEndpoint=0; private Set<String> predList; private Set<String> objList; private Set<String> classList; @@ -127,7 +130,9 @@ options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); options.add(new IntegerConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); - options.add(new IntegerConfigOption("filterMode","the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedFilter","the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint","the mode of the SPARQL Filter")); + options.add(new StringSetConfigOption("predList","a predicate list")); options.add(new StringSetConfigOption("objList","an object list")); options.add(new StringSetConfigOption("classList","a class list")); @@ -164,8 +169,10 @@ objList = (Set<String>) entry.getValue(); } else if(option.equals("classList")) { classList = (Set<String>) entry.getValue(); - } else if(option.equals("filterMode")){ - filterMode=(Integer)entry.getValue(); + } else if(option.equals("predefinedEndpoint")){ + predefinedEndpoint=(Integer)entry.getValue(); + } else if(option.equals("predefinedFilter")){ + predefinedFilter=(Integer)entry.getValue(); } else if(option.equals("format")){ format=(String)entry.getValue(); } else if(option.equals("dumpToFile")){ @@ -189,19 +196,32 @@ //new SparqlOntologyCollector(Datastructures.setToArray(instances), numberOfRecursions, filterMode, //Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format,url,useLits); Manager m=new Manager(); - if(filterMode>=1){ - m.usePredefinedConfiguration(filterMode); + SpecificSparqlEndpoint sse=null; + SparqlQueryType sqt=null; + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + + if(predefinedEndpoint>=1){ + sse=PredefinedEndpoint.getEndpoint(predefinedEndpoint); + + } + else{ + SpecificSparqlEndpoint se=new SpecificSparqlEndpoint(url, host, parameters); + + } + + if(predefinedFilter>=1){ + sqt=PredefinedFilter.getFilter(predefinedFilter); } else{ - SparqlQueryType sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); - SpecificSparqlEndpoint se=new SpecificSparqlEndpoint(url, host, parameters); - m.useConfiguration(sqt, se,numberOfRecursions,getAllBackground); + sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); + + + } - + m.useConfiguration(sqt, sse,numberOfRecursions,getAllBackground); try { String ont=m.extract(instances); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 19:53:08 UTC (rev 308) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 20:52:38 UTC (rev 309) @@ -10,20 +10,8 @@ private TypedSparqlQuery typedSparqlQuery; private ExtractionAlgorithm extractionAlgorithm; - /*public void usePredefinedConfiguration(URI uri) { - - this.Configuration = org.dllearner.kb.sparql.Configuration.getConfiguration(uri); - this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); - }*/ - public void usePredefinedConfiguration(int i) { - this.configuration = PredefinedConfigurations.get(i); - this.typedSparqlQuery = new TypedSparqlQuery(configuration); - this.extractionAlgorithm = new ExtractionAlgorithm(configuration); - } - public void useConfiguration(SparqlQueryType SparqlQueryType, SpecificSparqlEndpoint SparqlEndpoint, int recursiondepth,boolean getAllBackground) { this.configuration = new Configuration(SparqlEndpoint, SparqlQueryType,recursiondepth,getAllBackground); Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 19:53:08 UTC (rev 308) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 20:52:38 UTC (rev 309) @@ -1,68 +0,0 @@ -package org.dllearner.kb.sparql; - -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -public class PredefinedConfigurations { - - public static Configuration get(int i) { - - switch (i) { - case 1: - return dbpediaYago(); - - } - return null; - } - - public static Configuration dbpediaYago() { - - SpecificSparqlEndpoint sse=dbpediaEndpoint(); - // System.out.println(u); - SparqlQueryType sqt = YagoFilter(); - - return new Configuration(sse, sqt, 2, true); - - } - - public static SparqlQueryType YagoFilter(){ - - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - - Set<String> obj = new HashSet<String>(); - obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - 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 SpecificSparqlEndpoint dbpediaEndpoint(){ - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://dbpedia.org"); - m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); - } - -} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2007-12-02 20:52:38 UTC (rev 309) @@ -0,0 +1,29 @@ +package org.dllearner.kb.sparql; + +import java.net.URL; +import java.util.HashMap; + +public class PredefinedEndpoint { + public static SpecificSparqlEndpoint getEndpoint(int i) { + + switch (i) { + case 1: + return dbpediaEndpoint(); + + } + return null; + } + + public static SpecificSparqlEndpoint dbpediaEndpoint(){ + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + m.put("default-graph-uri", "http://dbpedia.org"); + m.put("format", "application/sparql-results.xml"); + try { + u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); +} +} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2007-12-02 20:52:38 UTC (rev 309) @@ -0,0 +1,42 @@ +package org.dllearner.kb.sparql; + +import java.util.HashSet; +import java.util.Set; + +public class PredefinedFilter { + + + public static SparqlQueryType getFilter(int i) { + + switch (i) { + case 1: + return YagoFilter(); + + } + return null; + } + + + public static SparqlQueryType YagoFilter(){ + Set<String> pred = new HashSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + + Set<String> obj = new HashSet<String>(); + obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + 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"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-03 17:58:29
|
Revision: 317 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=317&view=rev Author: jenslehmann Date: 2007-12-03 09:58:20 -0800 (Mon, 03 Dec 2007) Log Message: ----------- - changed some option names, added default values and explanations - created simple.conf example (simple entry example for learning on SPARQL endpoints) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Added Paths: ----------- trunk/examples/sparql/simple.conf Added: trunk/examples/sparql/simple.conf =================================================================== --- trunk/examples/sparql/simple.conf (rev 0) +++ trunk/examples/sparql/simple.conf 2007-12-03 17:58:20 UTC (rev 317) @@ -0,0 +1,49 @@ +/** + * Simple example for using a SPARQL Endpoint as background + * knowledge. + * + * solutions: + * http://dbpedia.org/class/yago/Adult109605289 + * http://dbpedia.org/class/yago/Female109619168 + * http://dbpedia.org/class/yago/Scientist110560637 + */ + +// recursion depth of extraction algorithm +sparql2.recursionDepth = 2; + +// list of ignored roles +sparql2.predList = { + "http://www.w3.org/2004/02/skos/core", + "http://www.w3.org/2002/07/owl#sameAs", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/reference", + "http://dbpedia.org/property/website", + "http://dbpedia.org/property/wikipage" +}; + +// list of ignored objects +sparql2.objList = { + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://dbpedia.org/resource/Category:Articles_", + "http://xmlns.com/foaf/0.1/", + "http://upload.wikimedia.org/wikipedia/commons", + "http://upload.wikimedia.org/wikipedia", + "http://www.geonames.org", + "http://www.w3.org/2006/03/wn/wn20/instances/synset", + "http://www4.wiwiss.fu-berlin.de/flickrwrappr", + "http://www.w3.org/2004/02/skos/core" +}; + +// use DBpedia endpoint +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +// the set of objects as starting point for fragment selection +// (should be identical to the set of examples) +sparql2.instances = { + "http://dbpedia.org/resource/Angela_Merkel", + "http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" +}; + +/** examples **/ ++"http://dbpedia.org/resource/Angela_Merkel" +-"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-03 16:55:16 UTC (rev 316) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-03 17:58:20 UTC (rev 317) @@ -53,11 +53,11 @@ import org.dllearner.reasoning.JenaOWLDIGConverter; /** - * Represents a SPARQL Endpoint. TODO: Is it necessary to create a class - * DBpediaSparqlEndpoint? + * Represents a SPARQL Endpoint. * * @author Jens Lehmann * @author Sebastian Knappe + * @author Sebastian Hellmann */ public class SparqlEndpointRestructured extends KnowledgeSource { @@ -66,16 +66,16 @@ String host; private Set<String> instances; private URL dumpFile; - private int numberOfRecursions; + private int recursionDepth = 2; private int predefinedFilter = 0; private int predefinedEndpoint = 0; private Set<String> predList; private Set<String> objList; private Set<String> classList; - private String format; - private boolean dumpToFile; + private String format = "N-TRIPLES"; + private boolean dumpToFile = true; private boolean useLits = false; - private boolean getAllBackground = false; + private boolean getAllSuperClasses = true; private boolean learnDomain = false; private String role; @@ -136,19 +136,19 @@ options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); options.add(new StringSetConfigOption("instances", "relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("numberOfRecursions", - "number of Recursions, the Sparql-Endpoint is asked")); + options.add(new IntegerConfigOption("recursionDepth", + "recursion depth of KB fragment selection", 2)); options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); - options.add(new StringSetConfigOption("predList", "a predicate list")); - options.add(new StringSetConfigOption("objList", "an object list")); - options.add(new StringSetConfigOption("classList", "a class list")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format")); + options.add(new StringSetConfigOption("predList", "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); options.add(new BooleanConfigOption("dumpToFile", - "wether Ontology from DBPedia is written to a file or not")); + "Specifies whether the extracted ontology is written to a file or not.", true)); options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllBackground", "get")); + options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); options.add(new StringConfigOption("role", "role to learn Domain from")); @@ -177,8 +177,8 @@ host = (String) entry.getValue(); } else if (option.equals("instances")) { instances = (Set<String>) entry.getValue(); - } else if (option.equals("numberOfRecursions")) { - numberOfRecursions = (Integer) entry.getValue(); + } else if (option.equals("recursionDepth")) { + recursionDepth = (Integer) entry.getValue(); } else if (option.equals("predList")) { predList = (Set<String>) entry.getValue(); } else if (option.equals("objList")) { @@ -195,8 +195,8 @@ dumpToFile = (Boolean) entry.getValue(); } else if (option.equals("useLits")) { useLits = (Boolean) entry.getValue(); - } else if (option.equals("getAllBackground")) { - getAllBackground = (Boolean) entry.getValue(); + } else if (option.equals("getAllSuperClasses")) { + getAllSuperClasses = (Boolean) entry.getValue(); } else if (option.equals("learnDomain")) { learnDomain = (Boolean) entry.getValue(); } else if (option.equals("role")) { @@ -244,7 +244,7 @@ sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); } // give everything to the manager - m.useConfiguration(sqt, sse, man, numberOfRecursions, getAllBackground); + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses); try { String ont = ""; // used to learn a domain of a role This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-03 21:49:05
|
Revision: 320 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=320&view=rev Author: jenslehmann Date: 2007-12-03 13:48:52 -0800 (Mon, 03 Dec 2007) Log Message: ----------- continued tuple list support Modified Paths: -------------- trunk/examples/sparql/simple.conf trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Modified: trunk/examples/sparql/simple.conf =================================================================== --- trunk/examples/sparql/simple.conf 2007-12-03 18:29:20 UTC (rev 319) +++ trunk/examples/sparql/simple.conf 2007-12-03 21:48:52 UTC (rev 320) @@ -44,6 +44,8 @@ "http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" }; +// sparql2.example = [(a,b),(c,d)]; + /** examples **/ +"http://dbpedia.org/resource/Angela_Merkel" -"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" Modified: trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-12-03 18:29:20 UTC (rev 319) +++ trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-12-03 21:48:52 UTC (rev 320) @@ -132,6 +132,14 @@ return doubleValue; } + public Set<String> getSetValues() { + return setValues; + } + + public List<StringTuple> getListTuples() { + return listTuples; + } + public Object getValue() { if(isIntegerOption) return intValue; @@ -199,10 +207,6 @@ else return completeOption + "=" + stringValue; } - - public Set<String> getSetValues() { - return setValues; - } public String getFullName() { if(containsSubOption) Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-03 18:29:20 UTC (rev 319) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-03 21:48:52 UTC (rev 320) @@ -53,6 +53,7 @@ import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; @@ -73,6 +74,7 @@ import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; +import org.dllearner.utilities.StringTuple; /** * Startup file for Command Line Interface. @@ -309,6 +311,12 @@ (StringSetConfigOption) configOption, option.getSetValues()); cm.applyConfigEntry(component, entry); + } else if (configOption instanceof StringTupleListConfigOption && option.isListOption()) { + + ConfigEntry<List<StringTuple>> entry = new ConfigEntry<List<StringTuple>>( + (StringTupleListConfigOption) configOption, option.getListTuples()); + cm.applyConfigEntry(component, entry); + } else { handleError("The type of conf file entry " + option + " is not correct."); } Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-03 18:29:20 UTC (rev 319) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-03 21:48:52 UTC (rev 320) @@ -41,6 +41,7 @@ import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.dl.KB; import org.dllearner.kb.sparql.Manager; import org.dllearner.kb.sparql.Manipulator; @@ -155,6 +156,8 @@ options.add(new StringConfigOption("blankNodeIdentifier", "used to identify blanknodes in Tripels")); + options.add(new StringTupleListConfigOption("example", "example")); + return options; } @@ -203,6 +206,8 @@ role = (String) entry.getValue(); } else if (option.equals("blankNodeIdentifier")) { blankNodeIdentifier = (String) entry.getValue(); + } else if (option.equals("example")) { + System.out.println(entry.getValue()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-03 22:06:34
|
Revision: 321 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=321&view=rev Author: jenslehmann Date: 2007-12-03 14:06:30 -0800 (Mon, 03 Dec 2007) Log Message: ----------- finished tuple list support syntax: component.option = [(a1,b1),(a2,b2),...] Modified Paths: -------------- trunk/examples/sparql/simple.conf trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj Modified: trunk/examples/sparql/simple.conf =================================================================== --- trunk/examples/sparql/simple.conf 2007-12-03 21:48:52 UTC (rev 320) +++ trunk/examples/sparql/simple.conf 2007-12-03 22:06:30 UTC (rev 321) @@ -44,7 +44,7 @@ "http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" }; -// sparql2.example = [(a,b),(c,d)]; +sparql2.example = [(a,b),(c,d)]; /** examples **/ +"http://dbpedia.org/resource/Angela_Merkel" Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-12-03 21:48:52 UTC (rev 320) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-12-03 22:06:30 UTC (rev 321) @@ -277,7 +277,7 @@ jj_la1[8] = jj_gen; if (jj_2_7(2147483647)) { jj_consume_token(26); - jj_consume_token(27); + jj_consume_token(31); isSet=true; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -303,7 +303,7 @@ throw new ParseException(); } values.add(tmp); - jj_consume_token(28); + jj_consume_token(29); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: @@ -318,19 +318,19 @@ throw new ParseException(); } values.add(tmp); - jj_consume_token(27); + jj_consume_token(31); isSet=true; break; default: jj_la1[9] = jj_gen; if (jj_2_8(2147483647)) { - jj_consume_token(31); + jj_consume_token(27); jj_consume_token(32); isList=true; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 31: - jj_consume_token(31); + case 27: + jj_consume_token(27); label_3: while (true) { if (jj_2_6(6)) { @@ -338,7 +338,7 @@ } else { break label_3; } - jj_consume_token(29); + jj_consume_token(28); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: tmp = String(); @@ -351,7 +351,7 @@ jj_consume_token(-1); throw new ParseException(); } - jj_consume_token(28); + jj_consume_token(29); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: tmp2 = String(); @@ -366,9 +366,9 @@ } jj_consume_token(30); tuples.add(new StringTuple(tmp,tmp2)); - jj_consume_token(28); + jj_consume_token(29); } - jj_consume_token(29); + jj_consume_token(28); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: tmp = String(); @@ -381,7 +381,7 @@ jj_consume_token(-1); throw new ParseException(); } - jj_consume_token(28); + jj_consume_token(29); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: tmp2 = String(); @@ -418,6 +418,8 @@ else if(isSet) confOption = new ConfFileOption(option,subOption,values); + else if(isList) + confOption = new ConfFileOption(option,subOption,tuples); else confOption = new ConfFileOption(option,subOption,value); } else { @@ -429,6 +431,8 @@ else if(isSet) confOption = new ConfFileOption(option,values); + else if(isList) + confOption = new ConfFileOption(option,tuples); else confOption = new ConfFileOption(option,value); } @@ -442,20 +446,20 @@ String s, s1, s2; List<String> list = new LinkedList<String>(); s1 = Id(); - jj_consume_token(29); + jj_consume_token(28); s2 = String(); list.add(s2); label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 28: + case 29: ; break; default: jj_la1[11] = jj_gen; break label_4; } - jj_consume_token(28); + jj_consume_token(29); s = String(); list.add(s); } @@ -584,64 +588,24 @@ finally { jj_save(7, xla); } } - final private boolean jj_3R_19() { - if (jj_3R_13()) return true; - return false; - } - - final private boolean jj_3_6() { - if (jj_scan_token(29)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_17()) { - jj_scanpos = xsp; - if (jj_3R_18()) return true; - } - if (jj_scan_token(28)) return true; - xsp = jj_scanpos; - if (jj_3R_19()) { - jj_scanpos = xsp; - if (jj_3R_20()) return true; - } - if (jj_scan_token(30)) return true; - if (jj_scan_token(28)) return true; - return false; - } - final private boolean jj_3_5() { Token xsp; xsp = jj_scanpos; - if (jj_3R_15()) { + if (jj_3R_13()) { jj_scanpos = xsp; - if (jj_3R_16()) return true; + if (jj_3R_14()) return true; } - if (jj_scan_token(28)) return true; + if (jj_scan_token(29)) return true; return false; } - final private boolean jj_3R_26() { - if (jj_3R_13()) return true; - return false; - } - - final private boolean jj_3R_23() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_26()) { - jj_scanpos = xsp; - if (jj_3R_27()) return true; - } - if (jj_scan_token(28)) return true; - return false; - } - - final private boolean jj_3R_21() { + final private boolean jj_3R_19() { if (jj_scan_token(NUMBER)) return true; return false; } final private boolean jj_3R_10() { - if (jj_3R_13()) return true; + if (jj_3R_11()) return true; return false; } @@ -651,7 +615,7 @@ return false; } - final private boolean jj_3R_18() { + final private boolean jj_3R_16() { if (jj_3R_5()) return true; return false; } @@ -666,51 +630,30 @@ return false; } - final private boolean jj_3R_12() { - if (jj_scan_token(26)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_23()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_24()) { - jj_scanpos = xsp; - if (jj_3R_25()) return true; - } - if (jj_scan_token(27)) return true; + final private boolean jj_3R_20() { + if (jj_scan_token(DOUBLE)) return true; return false; } - final private boolean jj_3R_25() { - if (jj_3R_5()) return true; - return false; - } - final private boolean jj_3_2() { if (jj_3R_5()) return true; - if (jj_scan_token(29)) return true; - if (jj_3R_13()) return true; + if (jj_scan_token(28)) return true; + if (jj_3R_11()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_14()) { jj_scanpos = xsp; break; } + if (jj_3R_12()) { jj_scanpos = xsp; break; } } if (jj_scan_token(30)) return true; if (jj_scan_token(CONF_END)) return true; return false; } - final private boolean jj_3R_16() { + final private boolean jj_3R_14() { if (jj_3R_5()) return true; return false; } - final private boolean jj_3R_22() { - if (jj_scan_token(DOUBLE)) return true; - return false; - } - final private boolean jj_3_1() { if (jj_3R_5()) return true; Token xsp; @@ -726,61 +669,54 @@ jj_scanpos = xsp; if (jj_3R_10()) { jj_scanpos = xsp; - if (jj_3R_11()) { + if (jj_scan_token(26)) { jj_scanpos = xsp; - if (jj_3R_12()) return true; + if (jj_scan_token(27)) return true; } } } } } - if (jj_scan_token(CONF_END)) return true; return false; } final private boolean jj_3R_9() { - if (jj_3R_22()) return true; + if (jj_3R_20()) return true; return false; } - final private boolean jj_3R_11() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; + final private boolean jj_3R_5() { + if (jj_scan_token(ID)) return true; return false; } - final private boolean jj_3R_24() { - if (jj_3R_13()) return true; + final private boolean jj_3R_15() { + if (jj_3R_11()) return true; return false; } - final private boolean jj_3R_17() { - if (jj_3R_13()) return true; - return false; - } - - final private boolean jj_3R_20() { + final private boolean jj_3R_18() { if (jj_3R_5()) return true; return false; } - final private boolean jj_3R_5() { - if (jj_scan_token(ID)) return true; + final private boolean jj_3R_13() { + if (jj_3R_11()) return true; return false; } - final private boolean jj_3R_15() { - if (jj_3R_13()) return true; + final private boolean jj_3R_8() { + if (jj_3R_19()) return true; return false; } - final private boolean jj_3R_8() { - if (jj_3R_21()) return true; + final private boolean jj_3R_11() { + if (jj_scan_token(STRING)) return true; return false; } final private boolean jj_3_8() { - if (jj_scan_token(31)) return true; + if (jj_scan_token(27)) return true; if (jj_scan_token(32)) return true; return false; } @@ -790,25 +726,39 @@ return false; } - final private boolean jj_3R_27() { - if (jj_3R_5()) return true; + final private boolean jj_3_7() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(31)) return true; return false; } - final private boolean jj_3R_13() { - if (jj_scan_token(STRING)) return true; + final private boolean jj_3R_12() { + if (jj_scan_token(29)) return true; + if (jj_3R_11()) return true; return false; } - final private boolean jj_3R_14() { - if (jj_scan_token(28)) return true; - if (jj_3R_13()) return true; + final private boolean jj_3R_17() { + if (jj_3R_11()) return true; return false; } - final private boolean jj_3_7() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; + final private boolean jj_3_6() { + if (jj_scan_token(28)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_15()) { + jj_scanpos = xsp; + if (jj_3R_16()) return true; + } + if (jj_scan_token(29)) return true; + xsp = jj_scanpos; + if (jj_3R_17()) { + jj_scanpos = xsp; + if (jj_3R_18()) return true; + } + if (jj_scan_token(30)) return true; + if (jj_scan_token(29)) return true; return false; } @@ -829,7 +779,7 @@ jj_la1_1(); } private static void jj_la1_0() { - jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x80000000,0x10000000,0x1001000,}; + jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x8000000,0x20000000,0x1001000,}; } private static void jj_la1_1() { jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java 2007-12-03 21:48:52 UTC (rev 320) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java 2007-12-03 22:06:30 UTC (rev 321) @@ -55,11 +55,11 @@ "<STRING>", "\"=\"", "\"{\"", - "\"}\"", + "\"[\"", + "\"(\"", "\",\"", - "\"(\"", "\")\"", - "\"[\"", + "\"}\"", "\"]\"", }; Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-12-03 21:48:52 UTC (rev 320) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-12-03 22:06:30 UTC (rev 321) @@ -58,13 +58,13 @@ switch(curChar) { case 40: - return jjStopAtPos(0, 29); + return jjStopAtPos(0, 28); case 41: return jjStopAtPos(0, 30); case 43: return jjStopAtPos(0, 10); case 44: - return jjStopAtPos(0, 28); + return jjStopAtPos(0, 29); case 45: return jjStopAtPos(0, 11); case 46: @@ -86,13 +86,13 @@ case 84: return jjMoveStringLiteralDfa1_0(0x8000L); case 91: - return jjStopAtPos(0, 31); + return jjStopAtPos(0, 27); case 93: return jjStopAtPos(0, 32); case 123: return jjStopAtPos(0, 26); case 125: - return jjStopAtPos(0, 27); + return jjStopAtPos(0, 31); default : return jjMoveNfa_0(0, 0); } @@ -619,8 +619,8 @@ public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, null, "\56", "\73", "\53", "\55", null, null, null, "\124\117\120", "\102\117\124\124\117\115", "\101\116\104", "\117\122", -null, null, null, "\76\75", "\74\75", null, "\75", "\173", "\175", "\54", "\50", -"\51", "\133", "\135", }; +null, null, null, "\76\75", "\74\75", null, "\75", "\173", "\133", "\50", "\54", +"\51", "\175", "\135", }; public static final String[] lexStateNames = { "DEFAULT", }; Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-12-03 21:48:52 UTC (rev 320) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-12-03 22:06:30 UTC (rev 321) @@ -277,8 +277,10 @@ { ( // bei Konfigurationsoption geht der Parser bis zum Semikolon durch, da das das einzige // sichere Unterscheidungsmerkmal ist + // LOOKAHEAD(Id() [ "." Id() ] "=" ( Id() | Integer() | Double() | String() + // | "{" "}" | "{" ( ( String() | Id() ) "," )* (String() | Id()) "}" | "[" ) <CONF_END>) confOption=ConfOption() LOOKAHEAD(Id() [ "." Id() ] "=" ( Id() | Integer() | Double() | String() - | "{" "}" | "{" ( ( String() | Id() ) "," )* (String() | Id()) "}" ) <CONF_END>) confOption=ConfOption() + | "{" | "[" )) confOption=ConfOption() { addConfOption(confOption); } | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar @@ -326,6 +328,8 @@ else if(isSet) confOption = new ConfFileOption(option,subOption,values); + else if(isList) + confOption = new ConfFileOption(option,subOption,tuples); else confOption = new ConfFileOption(option,subOption,value); } else { @@ -337,6 +341,8 @@ else if(isSet) confOption = new ConfFileOption(option,values); + else if(isList) + confOption = new ConfFileOption(option,tuples); else confOption = new ConfFileOption(option,value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-05 16:16:06
|
Revision: 329 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=329&view=rev Author: kurzum Date: 2007-12-05 08:15:59 -0800 (Wed, 05 Dec 2007) Log Message: ----------- some minor changes, role domain learning doesn't really work, because the instances have to be chosen in a smarter way. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java Added Paths: ----------- trunk/examples/sparql/role_domain_placeOfBirth_yago.conf trunk/examples/sparql/role_range_placeOfBirth_yago.conf Added: trunk/examples/sparql/role_domain_placeOfBirth_yago.conf =================================================================== --- trunk/examples/sparql/role_domain_placeOfBirth_yago.conf (rev 0) +++ trunk/examples/sparql/role_domain_placeOfBirth_yago.conf 2007-12-05 16:15:59 UTC (rev 329) @@ -0,0 +1,58 @@ +/** + * + * solutions: + * + */ + + +// recursion depth of extraction algorithm +sparql2.recursionDepth = 1; + +// list of ignored roles +sparql2.predList = { + "http://www.w3.org/2004/02/skos/core", + "http://www.w3.org/2002/07/owl#sameAs", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/reference", + "http://dbpedia.org/property/website", + "http://dbpedia.org/property/wikipage" +}; + +// list of ignored objects +sparql2.objList = { + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://dbpedia.org/resource/Category:Articles_", + "http://xmlns.com/foaf/0.1/", + "http://upload.wikimedia.org/wikipedia/commons", + "http://upload.wikimedia.org/wikipedia", + "http://www.geonames.org", + "http://www.w3.org/2006/03/wn/wn20/instances/synset", + "http://www4.wiwiss.fu-berlin.de/flickrwrappr", + "http://www.w3.org/2004/02/skos/core" +}; + +// use DBpedia endpoint +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +// the set of objects as starting point for fragment selection +// (should be identical to the set of examples) +sparql2.instances = { + "http://dbpedia.org/resource/Angela_Merkel", + "http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" +}; +sparql2.role = "http://dbpedia.org/property/placeOfBirth"; +sparql2.learnDomain=true; +sparql2.learnRange=false; + + +/** examples **/ ++"http://dbpedia.org/resource/Richard_Burton" ++"http://dbpedia.org/resource/Gregory_Bateson" ++"http://dbpedia.org/resource/Gennaro_Gattuso" ++"http://dbpedia.org/resource/Thomas_Bayes" ++"http://dbpedia.org/resource/W%C5%82adys%C5%82aw_Anders" +-"http://dbpedia.org/resource/Roman_Dacia" +-"http://dbpedia.org/resource/Petrovichi" +-"http://dbpedia.org/resource/Scotland" +-"http://dbpedia.org/resource/Lanuvium" +-"http://dbpedia.org/resource/Riga" \ No newline at end of file Added: trunk/examples/sparql/role_range_placeOfBirth_yago.conf =================================================================== --- trunk/examples/sparql/role_range_placeOfBirth_yago.conf (rev 0) +++ trunk/examples/sparql/role_range_placeOfBirth_yago.conf 2007-12-05 16:15:59 UTC (rev 329) @@ -0,0 +1,59 @@ +/** + * + * solutions: + *(http://dbpedia.org/class/yago/Isle109319456 OR http://dbpedia.org/class/yago/Location100027167) + */ + + +// recursion depth of extraction algorithm +sparql2.recursionDepth = 1; + +// list of ignored roles +sparql2.predList = { + "http://www.w3.org/2004/02/skos/core", + "http://www.w3.org/2002/07/owl#sameAs", + "http://xmlns.com/foaf/0.1/", + "http://dbpedia.org/property/reference", + "http://dbpedia.org/property/website", + "http://dbpedia.org/property/wikipage" +}; + +// list of ignored objects +sparql2.objList = { + "http://dbpedia.org/resource/Category:Wikipedia_", + "http://dbpedia.org/resource/Category:Articles_", + "http://xmlns.com/foaf/0.1/", + "http://upload.wikimedia.org/wikipedia/commons", + "http://upload.wikimedia.org/wikipedia", + "http://www.geonames.org", + "http://www.w3.org/2006/03/wn/wn20/instances/synset", + "http://www4.wiwiss.fu-berlin.de/flickrwrappr", + "http://www.w3.org/2004/02/skos/core" +}; + +// use DBpedia endpoint +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +// the set of objects as starting point for fragment selection +// (should be identical to the set of examples) +sparql2.instances = { + "http://dbpedia.org/resource/Angela_Merkel", + "http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" +}; + +sparql2.role = "http://dbpedia.org/property/placeOfBirth"; +sparql2.learnDomain=false; +sparql2.learnRange=true; + + +/** examples **/ ++"http://dbpedia.org/resource/Roman_Dacia" +//+"http://dbpedia.org/resource/Petrovichi" ++"http://dbpedia.org/resource/Scotland" ++"http://dbpedia.org/resource/Lanuvium" ++"http://dbpedia.org/resource/Riga" +-"http://dbpedia.org/resource/Richard_Burton" +-"http://dbpedia.org/resource/Gregory_Bateson" +-"http://dbpedia.org/resource/Gennaro_Gattuso" +-"http://dbpedia.org/resource/Thomas_Bayes" +-"http://dbpedia.org/resource/W%C5%82adys%C5%82aw_Anders" \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-05 16:15:59 UTC (rev 329) @@ -26,11 +26,11 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.Random; import java.util.Set; import org.dllearner.core.KnowledgeSource; @@ -83,6 +83,7 @@ private int breakSuperClassRetrievalAfter = 500; private boolean learnDomain = false; + private boolean learnRange = false; private String role; private String blankNodeIdentifier = "bnode"; @@ -160,7 +161,8 @@ options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain from")); + options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); + options.add(new StringConfigOption("role", "role to learn Domain/Range from")); options.add(new StringConfigOption("blankNodeIdentifier", "used to identify blanknodes in Tripels")); @@ -214,6 +216,8 @@ getAllSuperClasses = (Boolean) entry.getValue(); } else if (option.equals("learnDomain")) { learnDomain = (Boolean) entry.getValue(); + }else if (option.equals("learnRange")) { + learnRange = (Boolean) entry.getValue(); } else if (option.equals("role")) { role = (String) entry.getValue(); } else if (option.equals("blankNodeIdentifier")) { @@ -260,32 +264,76 @@ } // get Options for Filters - System.out.println("aaa"+predefinedFilter); + if (predefinedFilter >= 1) { sqt = PredefinedFilter.getFilter(predefinedFilter); } else { sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - System.out.println(sqt); + } // give everything to the manager m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses); try { String ont = ""; // used to learn a domain of a role - if (learnDomain) { - instances = m.getDomainInstancesForRole(role); + if (learnDomain || learnRange) { + Set<String> pos=new HashSet<String>(); + Set<String> neg=new HashSet<String>(); + if(learnDomain){ + pos = m.getDomainInstancesForRole(role); + neg = m.getRangeInstancesForRole(role); + }else if(learnRange){ + neg = m.getDomainInstancesForRole(role); + pos = m.getRangeInstancesForRole(role); + } + //choose 30 + + + Set<String> tmp=new HashSet<String>(); + for(String one:pos){ + tmp.add(one); + if(tmp.size()>=5)break; + } + pos=tmp; + System.out.println(pos.size()); + + tmp=new HashSet<String>(); + for(String one:neg){ + tmp.add(one); + if(tmp.size()>=5)break; + } + neg=tmp; + + instances=new HashSet<String>(); + instances.addAll( pos); + + instances.addAll(neg); + + for(String one:pos){ + System.out.println("+\""+one+"\""); + } + for(String one:neg){ + System.out.println("-\""+one+"\""); + } + + /*Random r= new Random(); + + + Object[] arr=instances.toArray(); + while(instances.size()>=30){ + + }*/ // add the role to the filter(a solution is always EXISTS // role.TOP) m.addPredicateFilter(role); //System.out.println(instances); // THIS is a workaround - for(String one:instances){ - System.out.println("+\""+one+"\""); - } + } // the actual extraction is started here ont = m.extract(instances); + System.out.println("Finished collecting Fragment"); if (dumpToFile) { String filename = System.currentTimeMillis() + ".nt"; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-05 16:15:59 UTC (rev 329) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.StringTuple; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-05 16:15:59 UTC (rev 329) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.StringTuple; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-05 16:15:59 UTC (rev 329) @@ -22,6 +22,8 @@ import java.net.URI; import java.util.HashSet; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.utilities.StringTuple; @@ -53,6 +55,7 @@ Set<StringTuple> t = this.typedSparqlQuery.getTupelsForRole(u); Set<String> ret = new HashSet<String>(); for (StringTuple one : t) { + ret.add(one.a); } return ret; @@ -68,6 +71,7 @@ Set<StringTuple> t = this.typedSparqlQuery.getTupelsForRole(u); Set<String> ret = new HashSet<String>(); for (StringTuple one : t) { + ret.add(one.b); } return ret; @@ -91,7 +95,7 @@ // this.TypedSparqlQuery.query(uri); // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); System.out.println("Start extracting"); - Set<String> ret = new HashSet<String>(); + SortedSet<String> ret = new TreeSet<String>(); for (String one : instances) { try { @@ -101,12 +105,26 @@ e.printStackTrace(); } } - - String nt = ""; - for (String str : ret) { + System.out.println("Finished extracting, start conversion"); + StringBuffer nt = new StringBuffer(); + Object[] arr=ret.toArray(); + for (int i = 0; i < arr.length; i++) { + nt.append((String) arr[i]+"\n"); + if(i%1000==0)System.out.println(i+" of "+arr.length+" triples done"); + } + /* + String tmp=""; + while ( ret.size() > 0) { + tmp=ret.first(); + nt+=tmp; + ret.remove(tmp); + System.out.println(ret.size()); + + } + /*for (String str : ret) { nt += str + "\n"; - } - return nt; + }*/ + return nt.toString(); } public void addPredicateFilter(String str) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2007-12-05 16:15:59 UTC (rev 329) @@ -76,6 +76,22 @@ } return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); } + + /* + * it only has 4 classes + public static SpecificSparqlEndpoint dblp() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + // m.put("default-graph-uri", "http://dbpedia.org"); + // m.put("format", "application/sparql-results.xml"); + try { + u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); + } + */ public static SpecificSparqlEndpoint govTrack() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); @@ -88,5 +104,55 @@ } return new SpecificSparqlEndpoint(u, "www.rdfabout.com", m); } + public static SpecificSparqlEndpoint revyu() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + // m.put("default-graph-uri", "http://dbpedia.org"); + // m.put("format", "application/sparql-results.xml"); + //http://revyu.com/sparql?query=SELECT DISTINCT * WHERE {[] a ?c} + try { + u = new URL("http://revyu.com/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "revyu.com", m); + } + // returns strange xml + /*public static SpecificSparqlEndpoint dbtune() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + // m.put("default-graph-uri", "http://dbpedia.org"); + // m.put("format", "application/sparql-results.xml"); + //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 + http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D + &resultFormat=xml + &resourceFormat=ns&entailment=none + http://dbtune.org:2020/evaluateQuery + ?repository=default&serialization=rdfxml&queryLanguage=SPARQL + &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D + &resultFormat=xml + &resourceFormat=ns&entailment=none + try { + u = new URL("http://dbtune.org:2020/sparql/"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "dbtune.org", m); + }*/ + + public static SpecificSparqlEndpoint myopenlink() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + m.put("default-graph-uri", "http://myopenlink.net/dataspace"); + m.put("format", "application/sparql-results.xml"); + //http://myopenlink.net:8890/sparql/?query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D + try { + u = new URL("http://myopenlink.net:8890/sparql/"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "myopenlink.net", m); + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-05 13:09:58 UTC (rev 328) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-05 16:15:59 UTC (rev 329) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.StringTuple; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-07 09:47:12
|
Revision: 347 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=347&view=rev Author: jenslehmann Date: 2008-01-07 01:47:05 -0800 (Mon, 07 Jan 2008) Log Message: ----------- continued OWL API reasoner Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2008-01-06 20:08:33 UTC (rev 346) +++ trunk/lib/components.ini 2008-01-07 09:47:05 UTC (rev 347) @@ -6,6 +6,7 @@ org.dllearner.kb.SparqlEndpoint org.dllearner.kb.SparqlEndpointRestructured # reasoners +org.dllearner.reasoning.OWLAPIReasoner org.dllearner.reasoning.DIGReasoner org.dllearner.reasoning.FastRetrievalReasoner org.dllearner.reasoning.KAON2Reasoner Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-06 20:08:33 UTC (rev 346) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-07 09:47:05 UTC (rev 347) @@ -110,6 +110,8 @@ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); StringConfigOption type = new StringConfigOption("reasonerType", "FaCT++ or Pellet", "FaCT++"); type.setAllowedValues(new String[] {"FaCT++", "Pellet"}); + // closure-Option? siehe: + // http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup options.add(type); return options; } @@ -170,6 +172,16 @@ // instantiate Pellet reasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); } + + // compute class hierarchy and types of individuals + // (done here to speed up later reasoner calls) + try { + reasoner.classify(); + reasoner.realise(); + } catch (OWLReasonerException e) { + e.printStackTrace(); + } + factory = manager.getOWLDataFactory(); // read in primitives @@ -303,19 +315,47 @@ } private TreeSet<Concept> getMoreGeneralConcepts(Concept concept) { - return null; + Set<Set<OWLClass>> classes = null; + try { + classes = reasoner.getSuperClasses(getOWLAPIDescription(concept)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstClasses(classes); } private TreeSet<Concept> getMoreSpecialConcepts(Concept concept) { - return null; + Set<Set<OWLClass>> classes = null; + try { + classes = reasoner.getSubClasses(getOWLAPIDescription(concept)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstClasses(classes); } private TreeSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { - return null; + Set<Set<OWLObjectProperty>> properties; + try { + properties = reasoner.getSuperProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstProperties(properties); } private TreeSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { - return null; + Set<Set<OWLObjectProperty>> properties; + try { + properties = reasoner.getSubProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstProperties(properties); } @Override @@ -330,6 +370,7 @@ } } + // TODO @Override public SortedSet<Individual> retrieval(Concept concept) { OWLDescription d = getOWLAPIDescription(concept); @@ -351,24 +392,10 @@ e.printStackTrace(); throw new Error("GetConcepts() reasoning error in OWL API."); } - // the OWL API returns a set of sets; each inner set consists of - // atomic classes - Set<AtomicConcept> concepts = new HashSet<AtomicConcept>(); - for(Set<OWLClass> classes : result) { - // take one element from the set and ignore the rest - // (TODO: we need to make sure we always ignore the same concepts) - OWLClass concept = classes.iterator().next(); - concepts.add(new AtomicConcept(concept.getURI().toString())); - } - return concepts; + return getFirstClassesNoTopBottom(result); } @Override - public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { - return null; - } - - @Override public boolean isSatisfiable() { try { return reasoner.isSatisfiable(factory.getOWLThing()); @@ -378,6 +405,49 @@ } } + // OWL API often returns a set of sets of classes, where each inner + // set consists of equivalent classes; this method picks one class + // from each inner set to flatten the set of sets + private TreeSet<Concept> getFirstClasses(Set<Set<OWLClass>> setOfSets) { + TreeSet<Concept> concepts = new TreeSet<Concept>(conceptComparator); + for(Set<OWLClass> innerSet : setOfSets) { + // take one element from the set and ignore the rest + // (TODO: we need to make sure we always ignore the same concepts) + OWLClass concept = innerSet.iterator().next(); + if(concept.isOWLThing()) { + concepts.add(new Top()); + } else if(concept.isOWLNothing()) { + concepts.add(new Bottom()); + } else { + concepts.add(new AtomicConcept(concept.getURI().toString())); + } + } + return concepts; + } + + private Set<AtomicConcept> getFirstClassesNoTopBottom(Set<Set<OWLClass>> setOfSets) { + Set<AtomicConcept> concepts = new HashSet<AtomicConcept>(); + for(Set<OWLClass> innerSet : setOfSets) { + // take one element from the set and ignore the rest + // (TODO: we need to make sure we always ignore the same concepts) + OWLClass concept = innerSet.iterator().next(); + if(!concept.isOWLThing() && !concept.isOWLNothing()) + concepts.add(new AtomicConcept(concept.getURI().toString())); + } + return concepts; + } + + private TreeSet<AtomicRole> getFirstProperties(Set<Set<OWLObjectProperty>> setOfSets) { + TreeSet<AtomicRole> roles = new TreeSet<AtomicRole>(roleComparator); + for(Set<OWLObjectProperty> innerSet : setOfSets) { + // take one element from the set and ignore the rest + // (TODO: we need to make sure we always ignore the same concepts) + OWLObjectProperty property = innerSet.iterator().next(); + roles.add(new AtomicRole(property.getURI().toString())); + } + return roles; + } + private Set<Concept> owlClassesToAtomicConcepts(Set<OWLClass> owlClasses) { Set<Concept> concepts = new HashSet<Concept>(); for(OWLClass owlClass : owlClasses) @@ -389,6 +459,10 @@ return new AtomicConcept(owlClass.getURI().toString()); } + public OWLObjectProperty getOWLAPIDescription(AtomicRole role) { + return factory.getOWLObjectProperty(URI.create(role.getName())); + } + public OWLDescription getOWLAPIDescription(Concept concept) { if (concept instanceof AtomicConcept) { return factory.getOWLClass(URI.create(((AtomicConcept)concept).getName())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-07 16:23:00
|
Revision: 349 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=349&view=rev Author: jenslehmann Date: 2008-01-07 08:22:54 -0800 (Mon, 07 Jan 2008) Log Message: ----------- - OWL API reasoner implemented but not recommended yet * Pellet 1.5.1 working but no performance improvement - maybe due to a lot System out calls (one for each instance check) * FaCT++ 1.10 buggy; wrote a sample case for wrong behaviour in FaCTBugDemo and send it to FaCT developer Dmitry Tsarkov - CLI adapted such that new reasoner interface can be used - various smaller fixes in code and examples Modified Paths: -------------- trunk/examples/father2.conf trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Added Paths: ----------- trunk/examples/uncle.owl trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java Modified: trunk/examples/father2.conf =================================================================== --- trunk/examples/father2.conf 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/examples/father2.conf 2008-01-07 16:22:54 UTC (rev 349) @@ -8,7 +8,6 @@ */ reasoner = dig; -digReasonerURL = "http://localhost:8081"; import("father.owl"); // do not display http://example.com/father# in concepts @@ -19,9 +18,9 @@ digProtocolFile = "log/father2_dig.txt"; /** examples **/ -+father("http://example.com/father#stefan"). -+father("http://example.com/father#markus"). -+father("http://example.com/father#martin"). --father("http://example.com/father#heinz"). --father("http://example.com/father#anna"). --father("http://example.com/father#michelle"). ++"http://example.com/father#stefan" ++"http://example.com/father#markus" ++"http://example.com/father#martin" +-"http://example.com/father#heinz" +-"http://example.com/father#anna" +-"http://example.com/father#michelle" Added: trunk/examples/uncle.owl =================================================================== --- trunk/examples/uncle.owl (rev 0) +++ trunk/examples/uncle.owl 2008-01-07 16:22:54 UTC (rev 349) @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE rdf:RDF [ + <!ENTITY owl 'http://www.w3.org/2002/07/owl#'> +]> + +<rdf:RDF + xml:base="http://localhost/foo" + xmlns:a="http://localhost/foo#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> + +<owl:Ontology rdf:about=""/> + +<owl:Class rdf:about="&owl;Nothing"> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <owl:Class rdf:about="#male"/> + <owl:Class rdf:about="#female"/> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> +</owl:Class> + +<owl:ObjectProperty rdf:ID="hasSibling"> + <rdf:type rdf:resource="&owl;SymmetricProperty"/> +</owl:ObjectProperty> + +<owl:ObjectProperty rdf:ID="married"> + <rdf:type rdf:resource="&owl;SymmetricProperty"/> + <rdf:type rdf:resource="&owl;FunctionalProperty"/> +</owl:ObjectProperty> + +<a:male rdf:ID="alex"/> + +<a:male rdf:ID="alfred"> + <a:hasChild rdf:resource="#hans"/> + <a:hasSibling rdf:resource="#heinz"/> + <a:hasSibling rdf:resource="#maria"/> + <a:married rdf:resource="#katrin"/> +</a:male> + +<a:female rdf:ID="anna"> + <a:hasChild rdf:resource="#alfred"/> + <a:hasChild rdf:resource="#heinz"/> + <a:hasChild rdf:resource="#maria"/> + <a:married rdf:resource="#jan"/> +</a:female> + +<a:female rdf:ID="hanna"> + <a:hasChild rdf:resource="#jan"/> + <a:hasSibling rdf:resource="#alex"/> +</a:female> + +<a:male rdf:ID="hans"> + <a:married rdf:resource="#johanna"/> +</a:male> + +<a:male rdf:ID="heinrich"> + <a:married rdf:resource="#susi"/> +</a:male> + +<a:male rdf:ID="heinz"> + <a:hasSibling rdf:resource="#maria"/> +</a:male> + +<a:male rdf:ID="jan"> + <a:hasChild rdf:resource="#alfred"/> + <a:hasChild rdf:resource="#heinz"/> + <a:hasChild rdf:resource="#maria"/> +</a:male> + +<a:female rdf:ID="johanna"> + <a:hasSibling rdf:resource="#mandy"/> +</a:female> + +<a:female rdf:ID="katrin"> + <a:hasChild rdf:resource="#hans"/> +</a:female> + +<a:female rdf:ID="mandy"> + <a:hasChild rdf:resource="#miriam"/> +</a:female> + +<a:female rdf:ID="maria"> + <a:hasChild rdf:resource="#markus"/> +</a:female> + +<a:male rdf:ID="markus"/> + +<a:female rdf:ID="miriam"/> + +<a:female rdf:ID="susi"> + <a:hasSibling rdf:resource="#anna"/> +</a:female> + +<owl:Class rdf:ID="female"/> + +<owl:Class rdf:ID="male"/> + +<owl:ObjectProperty rdf:ID="hasChild"/> + +</rdf:RDF> Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-07 16:22:54 UTC (rev 349) @@ -70,6 +70,7 @@ import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; @@ -132,6 +133,8 @@ // default value if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) reasonerClass = DIGReasoner.class; + else if(reasonerOption.getStringValue().equals("owlAPI")) + reasonerClass = OWLAPIReasoner.class; else { handleError("Unknown value " + reasonerOption.getStringValue() + "for option \"reasoner\"."); @@ -160,6 +163,7 @@ cm.applyConfigEntry(lp, "positiveExamples", posExamples); if(lpClass != PosOnlyDefinitionLP.class) cm.applyConfigEntry(lp, "negativeExamples", negExamples); + configureComponent(cm, lp, componentPrefixMapping, parser); initComponent(cm, lp); // step 4: detect learning algorithm @@ -230,7 +234,9 @@ componentPrefixMapping.put(SparqlEndpointRestructured.class, "sparql2"); // reasoners componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); + componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); // learning problems - configured via + and - flags for examples + componentPrefixMapping.put(PosNegDefinitionLP.class, "posNegDefinitionLP"); // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); componentPrefixMapping.put(GP.class, "gp"); Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -99,9 +99,9 @@ else return negAsPos.size(); } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { // two checks - if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); // if the concept is too weak, then do not query negative // examples @@ -172,13 +172,13 @@ } return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification - } else { + } else { SortedSet<Individual> posAsPos = new TreeSet<Individual>(); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); SortedSet<Individual> negAsPos = new TreeSet<Individual>(); SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, allExamples); SortedSet<Individual> negClassified = Helper.difference(allExamples, @@ -187,15 +187,20 @@ posAsNeg = Helper.intersection(positiveExamples, negClassified); negAsPos = Helper.intersection(negativeExamples, posClassified); negAsNeg = Helper.intersection(negativeExamples, negClassified); + + // System.out.println("pos classified: " + posClassified); + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); } else { - + System.out.println("TEST"); + for (Individual example : positiveExamples) { - if (reasoningService.instanceCheck(concept, example)) + if (reasoningService.instanceCheck(concept, example)) { posAsPos.add(example); - else - posAsNeg.add(example); + } else { + posAsNeg.add(example); System.out.println(concept + " " + example); + } } for (Individual example : negativeExamples) { if (reasoningService.instanceCheck(concept, example)) Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -124,9 +124,9 @@ SortedSet<Individual> negExInNegatedConcept = Helper.intersection(negativeExamples, inNegatedConcept); return (negativeExamples.size() - negExInNegatedConcept.size()); } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { // two checks - if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { Set<Individual> posExInNegatedConcept = reasoningService.instanceCheck(new Negation(concept), positiveExamples); if(posExInNegatedConcept.size()>0) { Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -32,6 +32,7 @@ import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; @@ -48,7 +49,7 @@ protected SortedSet<Individual> allExamples; protected boolean useRetrievalForClassification = false; - protected UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + protected UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; protected double percentPerLengthUnit = 0.05; /** @@ -90,6 +91,9 @@ options.add(new BooleanConfigOption("useRetrievalForClassficiation", "Specifies whether to use retrieval or instance checks for testing a concept.")); options.add(CommonConfigOptions.getPercentPerLenghtUnitOption(0.05)); + StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum."); + multiInstanceChecks.setAllowedValues(new String[] {"never", "twoChecks", "oneCheck"}); + options.add(multiInstanceChecks); return options; } @@ -112,6 +116,15 @@ useRetrievalForClassification = (Boolean) entry.getValue(); else if (name.equals("percentPerLengthUnit")) percentPerLengthUnit = (Double) entry.getValue(); + else if (name.equals("useMultiInstanceChecks")) { + String value = (String) entry.getValue(); + if(value.equals("oneCheck")) + useMultiInstanceChecks = UseMultiInstanceChecks.ONECHECK; + else if(value.equals("twoChecks")) + useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + else + useMultiInstanceChecks = UseMultiInstanceChecks.NEVER; + } } /* Added: trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-01-07 16:22:54 UTC (rev 349) @@ -0,0 +1,65 @@ +package org.dllearner.reasoning; + +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.io.File; + +public class FaCTBugDemo { + + public static void main(String[] args) { + + try { + URI uri = new File("examples/father.owl").toURI(); + + // Create our ontology manager in the usual way. + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // Load a copy of the pizza ontology. We'll load the ontology from the web. + OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); + + OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); + // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + + // seems to be needed for some reason although no ontology is imported + Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); + reasoner.loadOntologies(importsClosure); + + reasoner.classify(); + reasoner.realise(); + + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); + OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); + OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); + Set<OWLDescription> set = new HashSet<OWLDescription>(); + set.add(male); + set.add(hasSomeChild); + OWLDescription father = factory.getOWLObjectIntersectionOf(set); + OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); + + if(reasoner.hasType(martin, father, false)) + System.out.println("positive result"); // Pellet 1.5.1 (correct) + else + System.out.println("negative result"); // FaCT++ 1.10 + + } + catch(UnsupportedOperationException exception) { + System.out.println("Unsupported reasoner operation."); + } + catch(OWLReasonerException ex) { + System.out.println("Reasoner error: " + ex.getMessage()); + } + catch (OWLOntologyCreationException e) { + System.out.println("Could not load the pizza ontology: " + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-07 16:22:54 UTC (rev 349) @@ -19,6 +19,7 @@ */ package org.dllearner.reasoning; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -80,7 +81,7 @@ */ public class OWLAPIReasoner extends ReasonerComponent { - private String reasonerType = "FaCT++"; + private String reasonerType = "fact"; private Set<KnowledgeSource> sources; private OWLReasoner reasoner; @@ -109,7 +110,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); StringConfigOption type = new StringConfigOption("reasonerType", "FaCT++ or Pellet", "FaCT++"); - type.setAllowedValues(new String[] {"FaCT++", "Pellet"}); + type.setAllowedValues(new String[] {"fact", "pellet"}); // closure-Option? siehe: // http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup options.add(type); @@ -143,15 +144,29 @@ Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); Set<OWLIndividual> owlIndividuals = new TreeSet<OWLIndividual>(namedObjectComparator); + Set<OWLOntology> allImports = new HashSet<OWLOntology>(); + for(KnowledgeSource source : sources) { if(!(source instanceof OWLFile)) { System.out.println("Currently, only OWL files are supported. Ignoring knowledge source " + source + "."); } else { URL url = ((OWLFile)source).getURL(); + /* try { + url = new URL("http://www.co-ode.org/ontologies/pizza/2007/02/12/pizza.owl"); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + */ + try { OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); + allImports.addAll(manager.getImportsClosure(ontology)); classes.addAll(ontology.getReferencedClasses()); properties.addAll(ontology.getReferencedObjectProperties()); + // does not seem to work => workaround: query all instances of Top + // maybe one can also query for instances of OWLObjectProperty, + // OWLClass, OWLIndividual owlIndividuals.addAll(ontology.getReferencedIndividuals()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); @@ -162,7 +177,7 @@ } // create actual reasoner - if(reasonerType.equals("FaCT++")) { + if(reasonerType.equals("fact")) { try { reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); } catch (Exception e) { @@ -173,9 +188,24 @@ reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); } + /* + Set<OWLOntology> importsClosure = manager.getImportsClosure(ontology); + System.out.println("imports closure : " + importsClosure); + try { + reasoner.loadOntologies(importsClosure); + } catch (OWLReasonerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + + System.out.println(classes); + System.out.println(properties); + System.out.println(individuals); + // compute class hierarchy and types of individuals // (done here to speed up later reasoner calls) try { + reasoner.loadOntologies(allImports); reasoner.classify(); reasoner.realise(); } catch (OWLReasonerException e) { @@ -184,6 +214,18 @@ factory = manager.getOWLDataFactory(); + + + try { + if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) + System.out.println("DEFINED."); + else + System.out.println("NOT DEFINED."); + } catch (OWLReasonerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // read in primitives atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); for(OWLClass owlClass : classes) @@ -370,17 +412,20 @@ } } - // TODO @Override public SortedSet<Individual> retrieval(Concept concept) { OWLDescription d = getOWLAPIDescription(concept); + Set<OWLIndividual> individuals = null; try { - reasoner.getIndividuals(d, false); + individuals = reasoner.getIndividuals(d, false); } catch (OWLReasonerException e) { // TODO Auto-generated catch block e.printStackTrace(); } - return null; + SortedSet<Individual> inds = new TreeSet<Individual>(); + for(OWLIndividual ind : individuals) + inds.add(new Individual(ind.getURI().toString())); + return inds; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |