You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <jen...@us...> - 2007-10-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 08:31:03
|
Revision: 176 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=176&view=rev Author: jenslehmann Date: 2007-10-08 01:30:59 -0700 (Mon, 08 Oct 2007) Log Message: ----------- - preliminary adaption of all reasoning algorithms to new structure - refactored LearningAlgorithmNew to LearningAlgorithm and DIGReasonerNew to DIGReasoner Modified Paths: -------------- 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/gp/GP.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/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.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 Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -11,7 +11,7 @@ import org.dllearner.core.ConfigOption; import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -34,7 +34,7 @@ * @author Jens Lehmann * */ -public class BruteForceLearner extends LearningAlgorithmNew { +public class BruteForceLearner extends LearningAlgorithm { LearningProblem learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-08 08:30:59 UTC (rev 176) @@ -28,13 +28,13 @@ import org.dllearner.core.ConfigOption; import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -public class RandomGuesser extends LearningAlgorithmNew { +public class RandomGuesser extends LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 08:30:59 UTC (rev 176) @@ -50,7 +50,7 @@ import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; @@ -65,7 +65,7 @@ * @author Jens Lehmann * */ -public class GP extends LearningAlgorithmNew { +public class GP extends LearningAlgorithm { // NumberFormat f; DecimalFormat df = new DecimalFormat("0.00"); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -14,7 +14,7 @@ import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -28,7 +28,7 @@ import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; -public class ROLearner extends LearningAlgorithmNew { +public class ROLearner extends LearningAlgorithm { private boolean stop = false; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 08:30:59 UTC (rev 176) @@ -45,7 +45,7 @@ import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; @@ -67,7 +67,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; -import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.reasoning.DIGReasoner; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; @@ -121,7 +121,7 @@ Class<? extends ReasonerComponent> reasonerClass = null; // default value if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) - reasonerClass = DIGReasonerNew.class; + reasonerClass = DIGReasoner.class; else { handleError("Unknown value " + reasonerOption.getStringValue() + "for option \"reasoner\"."); @@ -139,8 +139,8 @@ // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - LearningAlgorithmNew la = null; - Class<? extends LearningAlgorithmNew> laClass = null; + LearningAlgorithm la = null; + Class<? extends LearningAlgorithm> laClass = null; if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; @@ -193,7 +193,7 @@ // knowledge sources componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); // reasoners - componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); + componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); // learning problems - configured via + and - flags for examples // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); @@ -446,8 +446,8 @@ String message = "OK"; if (component instanceof KBFile) message = ((KBFile) component).getURL().toString() + " read"; - else if (component instanceof DIGReasonerNew) { - DIGReasonerNew reasoner = (DIGReasonerNew) component; + else if (component instanceof DIGReasoner) { + DIGReasoner reasoner = (DIGReasoner) component; message = "using " + reasoner.getIdentifier() + " connected via DIG 1.1 at " + reasoner.getReasonerURL().toString(); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 08:30:59 UTC (rev 176) @@ -63,13 +63,13 @@ private static Set<Class<? extends KnowledgeSource>> knowledgeSources; private static Set<Class<? extends ReasonerComponent>> reasonerComponents; private static Set<Class<? extends LearningProblem>> learningProblems; - private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; + private static Set<Class<? extends LearningAlgorithm>> 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; + private static Map<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { @@ -89,8 +89,8 @@ knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); - learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); - algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>>( + learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithm>>(classComparator); + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>>( classComparator); // create classes from strings @@ -106,8 +106,8 @@ reasonerComponents.add((Class<? extends ReasonerComponent>) component); else if (LearningProblem.class.isAssignableFrom(component)) learningProblems.add((Class<? extends LearningProblem>) component); - else if (LearningAlgorithmNew.class.isAssignableFrom(component)) { - Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>) component; + else if (LearningAlgorithm.class.isAssignableFrom(component)) { + Class<? extends LearningAlgorithm> learningAlgorithmClass = (Class<? extends LearningAlgorithm>) component; learningAlgorithms.add(learningAlgorithmClass); Collection<Class<? extends LearningProblem>> problems = (Collection<Class<? extends LearningProblem>>) invokeStaticMethod( learningAlgorithmClass, "supportedLearningProblems"); @@ -297,7 +297,7 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem lp, ReasoningService rs) { + public <T extends LearningAlgorithm> 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."); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-08 08:30:59 UTC (rev 176) @@ -26,7 +26,7 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.reasoning.DIGReasoner; /** * Test for component based design. @@ -53,7 +53,7 @@ source.init(); // create DIG reasoning service with standard settings - ReasonerComponent reasoner = cm.reasoner(DIGReasonerNew.class, source); + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); ReasoningService rs = cm.reasoningService(reasoner); reasoner.init(); @@ -73,7 +73,7 @@ lp.init(); // create the learning algorithm - LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); la.init(); Copied: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java (from rev 166, trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2007-10-08 08:30:59 UTC (rev 176) @@ -0,0 +1,66 @@ +/** + * 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.Collection; +import java.util.LinkedList; + +import org.dllearner.core.dl.Concept; + +/** + * @author Jens Lehmann + * + */ +public abstract class LearningAlgorithm extends Component { + + /** + * Starts the algorithm. + * + */ + public abstract void start(); + + + /** + * Stops the algorithm gracefully. + * + */ + public abstract void stop(); + + /** + * Every algorithm must be able to return the score of the + * best solution found. + * @return Best score. + */ + public abstract Score getSolutionScore(); + + /** + * Returns the best solutions obtained so far. + * @return Best solution. + */ + public abstract Concept getBestSolution(); + + /** + * Returns all learning problems supported by this component. + */ + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + return new LinkedList<Class<? extends LearningProblem>>(); + } + +} Deleted: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,66 +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.core; - -import java.util.Collection; -import java.util.LinkedList; - -import org.dllearner.core.dl.Concept; - -/** - * @author Jens Lehmann - * - */ -public abstract class LearningAlgorithmNew extends Component { - - /** - * Starts the algorithm. - * - */ - public abstract void start(); - - - /** - * Stops the algorithm gracefully. - * - */ - public abstract void stop(); - - /** - * Every algorithm must be able to return the score of the - * best solution found. - * @return Best score. - */ - public abstract Score getSolutionScore(); - - /** - * Returns the best solutions obtained so far. - * @return Best solution. - */ - public abstract Concept getBestSolution(); - - /** - * Returns all learning problems supported by this component. - */ - public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { - return new LinkedList<Class<? extends LearningProblem>>(); - } - -} Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 08:30:59 UTC (rev 176) @@ -36,7 +36,6 @@ import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.DIGReasonerNew; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.SortedSetTuple; @@ -414,7 +413,7 @@ } else if (getReasonerType() == ReasonerType.DIG) { // DIG erzeugt momentan auch nur einen KAON2-Reasoner und // exportiert dann mit der obigen Funktion - ((DIGReasonerNew) reasoner).saveOntology(file, format); + ((DIGReasoner) reasoner).saveOntology(file, format); } } Deleted: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,110 +0,0 @@ -package org.dllearner.reasoning; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.Reasoner; -import org.dllearner.core.ReasoningMethodUnsupportedException; -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.core.dl.RoleHierarchy; -import org.dllearner.core.dl.SubsumptionHierarchy; -import org.dllearner.utilities.SortedSetTuple; - -public abstract class AbstractReasoner implements Reasoner { - - public boolean subsumes(Concept superConcept, Concept subConcept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) throws ReasoningMethodUnsupportedException { - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept subConcept : subConcepts) { - if(subsumes(superConcept,subConcept)) - returnSet.add(subConcept); - } - return returnSet; - } - - public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) throws ReasoningMethodUnsupportedException { - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept superConcept : superConcepts) { - if(subsumes(superConcept,subConcept)) - returnSet.add(superConcept); - } - return returnSet; - } - - public SortedSet<Individual> retrieval(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public boolean instanceCheck(Concept concept, Individual individual) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException { - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for(Individual individual : individuals) { - if(instanceCheck(concept,individual)) - returnSet.add(individual); - } - return returnSet; - } - - public SortedSetTuple<Individual> doubleRetrieval(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public boolean isSatisfiable() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - /* - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - */ - - public SubsumptionHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<AtomicConcept> getConcepts(Individual i) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,749 +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.reasoning; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import javax.xml.namespace.QName; - -import org.apache.xmlbeans.XmlCursor; -import org.dllearner.Config; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Bottom; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; -import org.dllearner.core.dl.RoleHierarchy; -import org.dllearner.core.dl.SubsumptionHierarchy; -import org.dllearner.core.dl.Top; -import org.dllearner.kb.OntologyFileFormat; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.RoleComparator; -import org.kr.dl.dig.v1_1.Concepts; -import org.kr.dl.dig.v1_1.Csynonyms; -import org.kr.dl.dig.v1_1.IdType; -import org.kr.dl.dig.v1_1.Named; -import org.kr.dl.dig.v1_1.ResponseDocument; -import org.kr.dl.dig.v1_1.ResponsesDocument; -import org.kr.dl.dig.v1_1.Roles; -import org.kr.dl.dig.v1_1.Rsynonyms; -import org.kr.dl.dig.v1_1.IndividualSetDocument.IndividualSet; - -/** - * DIG 1.1 implementation of the reasoner interface. - * - * @author Jens Lehmann - * - */ -public class DIGReasoner extends AbstractReasoner { - - // Variablen für Reasoner - DIGHTTPConnector connector; - String identifier; - URI kbURI; - private String asksPrefix; - Map<URL,OntologyFileFormat> imports; - KB kb; - // Cache für Konzepte, Rollen und Individuen - 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 - // unterschiedlich sind; - // alternativ wäre auch eine Indizierung über Strings möglich - ConceptComparator conceptComparator = new ConceptComparator(); - RoleComparator roleComparator = new RoleComparator(); - SubsumptionHierarchy subsumptionHierarchy; - RoleHierarchy roleHierarchy; - // enthält atomare Konzepte, sowie Top und Bottom - Set<Concept> allowedConceptsInSubsumptionHierarchy; - - /** - * Creates a DIG reasoner object. - * - * @param kb Internal knowledge base. - * @param url URL of the DIG reasoner e.g. http://localhost:8081. - * @param imports Files to import (format and physical location of each file). - */ - public DIGReasoner(KB kb, URL url, Map<URL,OntologyFileFormat> imports) { - this.imports = imports; - this.kb = kb; - connector = new DIGHTTPConnector(url); - 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+"\">"; - - // erzeuge tell-Anfrage für Knowledgebase - if(kb.getNumberOfAxioms()>0) { - 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(DIGConverter.getDIGString(kb)); - sb.append("</tells>"); - - ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } - } - - String importDIGString = ""; - - // Ontologien mit Hilfe von KAON2 importieren - direkt zur - // KB hinzufügen - for(URL file : imports.keySet()) { - /* - // System.out.println("Importing " + file + " using KAON2."); - Ontology ontology = KAON2Reasoner.importKB(file); - try { - KAON2Reasoner.importKAON2Ontology(kb, ontology); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ - - // mit Hilfe von Jena wird OWL zu DIG konvertiert - // (allein diese Funktion sorgt leider dafür, dass - // DL-Learner stark anwächst, da verschieden Jena-Bibliotheken - // eingebunden werden müssen) - long importStartTime = System.currentTimeMillis(); - - // if the ontology format is N-Triples then Jena is used, otherwise the OWL API - if(imports.get(file).equals(OntologyFileFormat.N_TRIPLES)) { - System.out.print("Converting import file " + file + " to DIG using Jena ... "); - - importDIGString = JenaOWLDIGConverter.getTellsString(file, imports.get(file), kbURI); - } else { - System.out.println("Converting import file " + file + " to DIG using OWL API:"); - - importDIGString = OWLAPIDIGConverter.getTellsString(file, imports.get(file), kbURI); - } - - ResponseDocument rdImport = connector.tells(importDIGString); - if(!rdImport.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } else { - long importTime = System.currentTimeMillis() - importStartTime; - if(imports.get(file).equals(OntologyFileFormat.N_TRIPLES)) - System.out.println("OK (" + importTime + " ms)"); - // (" + JenaOWLDIGConverter.nrOfStatementsLastConversion + " statements, "+ importTime + " ms)"); - - } - - } - - // es wird jetzt immer der DIG-Reasoner abgefragt (auch ohne Importe), - // da so gleich auch äquivalente Konzepte rausgefiltert werden - - - - // DIG-Abfragen nach Konzepten, Rollen, Individuals - atomicConcepts = getAtomicConceptsDIG(); - atomicRoles = getAtomicRolesDIG(); - individuals = getIndividualsDIG(); - - } - - /** - * 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.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); - - // Subsumptionhierarchy berechnen - // TODO: kann man effizienter auch in einer Abfrage machen - - // Refinements von 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) { - tmp = getMoreSpecialConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); - } - - 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. - */ - @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); - - // Refinement atomarer Konzepte - for(AtomicRole role : atomicRoles) { - roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); - roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); - } - - 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; - } - */ - 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) { - boolean topOrBottomFound = false; - 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) { - boolean nonAnonymousConceptFound = false; - AtomicConcept foundConcept = null; - Named[] catoms = concepts.getCatomArray(); - for(Named catom : catoms) { - String name = catom.getName(); - 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); - } - } - } - } - } - - 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) { - // 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); - } - - return digAtomicRoles; - } - - 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())); - - return digIndividuals; - } - - public ReasonerType getReasonerType() { - return ReasonerType.DIG; - } - - @Override - public boolean subsumes(Concept superConcept, Concept subConcept) { - // System.out.println("subsumes(" + superConcept + "," + subConcept + ")"); - String subsumesDIG = asksPrefix; - subsumesDIG += "<subsumes id=\"query_subsume\">"; - 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); - 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) { - 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); - 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) { - returnSet.add(queryMap.get(idType.getId())); - } - return returnSet; - } - - /* - // 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 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 - // ä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++) { - // es werden nur atomare Konzepte erwartet - Named[] atoms = conceptsArray[i].getCatomArray(); - - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - resultsSet.add(ac); - } - - // hinzufügen von Top, falls notwendig - 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 - // nicht erlaubte (von Jena erzeugte) Konzepte, die nicht äquivalent - // 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 - // (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++) { - Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - resultsSet.add(ac); - } - - // hinzufügen von Bottom, falls notwendig - if(conceptsArray[i].getBottomArray().length>0) - resultsSet.add(new Bottom()); - - 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++) { - Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { - AtomicRole ar = new AtomicRole(atom.getName()); - //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++) { - Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { - AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) - resultsSet.add(ar); - } - } - - return resultsSet; - } - - @Override - public boolean instanceCheck(Concept concept, Individual individual) { - String instanceCheckDIG = asksPrefix; - instanceCheckDIG += "<instance id= \"query_instance\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; - instanceCheckDIG += DIGConverter.getDIGString(concept); - instanceCheckDIG += "</instance></asks>"; - - return parseBooleanAnswer(instanceCheckDIG); - } - - @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()+"\"/>"; - 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) { - returnSet.add(new Individual(queryMap.get(idType.getId()))); - } - return returnSet; - } - - @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) - results.add(new Individual(individual.getName())); - return results; - } - - // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus - @Override - public Set<AtomicConcept> getConcepts(Individual individual) { - String typesDIG = asksPrefix; - typesDIG += "<types id=\"query_types\">"; - typesDIG += "<individual name=\"" + individual.getName() + "\" />"; - 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++) { - Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - 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 - public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { - String relatedIndividualsDIG = asksPrefix; - relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; - relatedIndividualsDIG += "<ratom name=\"" + atomicRole.getName() + "\" />"; - 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)) { - // Cursor steht jetzt bei einem IndividualPair - cursor.toFirstChild(); - // 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); - */ - - return resultMap; - } - - @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) - return true; - else - return false; - } - - public String getIdentifier() { - return identifier; - } - - public void releaseKB() { - connector.releaseKB(kbURI); - } - - public void saveOntology(File file, OntologyFileFormat format) { - // KAON2-Reasoner erzeugen und den die Ontologie speichern lassen - // (später könnte man das über Jena erledigen, allerdings funktioniert - // das mit KAON2 auch gut) - KAON2Reasoner kaon2Reasoner = new KAON2Reasoner(kb,imports); - kaon2Reasoner.saveOntology(file, format); - } -} Copied: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java (from rev 174, trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -0,0 +1,739 @@ +/** + * 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.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import javax.xml.namespace.QName; + +import org.apache.xmlbeans.XmlCursor; +import org.dllearner.Config; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; +import org.dllearner.core.dl.Top; +import org.dllearner.kb.OntologyFileFormat; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.RoleComparator; +import org.kr.dl.dig.v1_1.Concepts; +import org.kr.dl.dig.v1_1.Csynonyms; +import org.kr.dl.dig.v1_1.IdType; +import org.kr.dl.dig.v1_1.Named; +import org.kr.dl.dig.v1_1.ResponseDocument; +import org.kr.dl.dig.v1_1.ResponsesDocument; +import org.kr.dl.dig.v1_1.Roles; +import org.kr.dl.dig.v1_1.Rsynonyms; +import org.kr.dl.dig.v1_1.IndividualSetDocument.IndividualSet; + +/** + * 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; + URI kbURI; + private String asksPrefix; + // Cache für Konzepte, Rollen und Individuen + 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 + // unterschiedlich sind; + // alternativ wäre auch eine Indizierung über Strings möglich + ConceptComparator conceptComparator = new ConceptComparator(); + RoleComparator roleComparator = new RoleComparator(); + SubsumptionHierarchy subsumptionHierarchy; + RoleHierarchy roleHierarchy; + // enthält atomare Konzepte, sowie Top und Bottom + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + public DIGReasoner(Set<KnowledgeSource> sources) { + this.sources = sources; + try { + reasonerURL = new URL("http://localhost:8081"); + } catch (MalformedURLException e) { } + } + + @Override + public void init() { + 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+"\">"; + + // 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(source.toDIG(kbURI)); + + ResponseDocument rd = connector.tells(sb.toString()); + if(!rd.getResponse().isSetOk()) { + System.err.println("DIG-Reasoner cannot read knowledgebase."); + System.exit(0); + } + } +// sb.append("</tells>"); + + // DIG-Abfragen nach Konzepten, Rollen, Individuals + atomicConcepts = getAtomicConceptsDIG(); + atomicRoles = getAtomicRolesDIG(); + 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")); + return options; + } + + /* (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 s = (String) entry.getValue(); + try { + reasonerURL = new URL(s); + } catch (MalformedURLException e) { + // e.printStackTrace(); + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); + } + } + } + + + /** + * 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.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); + + // Subsumptionhierarchy berechnen + // TODO: kann man effizienter auch in einer Abfrage machen + + // Refinements von 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) { + tmp = getMoreSpecialConceptsDIG(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyDown.put(atom, tmp); + + tmp = getMoreGeneralConceptsDIG(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyUp.put(atom, tmp); + } + + 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. + */ + @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); + + // Refinement atomarer Konzepte + for(AtomicRole role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); + } + + 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; + } + */ + 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.getResponse... [truncated message content] |
From: <jen...@us...> - 2007-10-08 08:17:39
|
Revision: 175 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=175&view=rev Author: jenslehmann Date: 2007-10-08 01:17:31 -0700 (Mon, 08 Oct 2007) Log Message: ----------- old learning algorithm interface removed Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java Deleted: trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-07 18:00:21 UTC (rev 174) +++ trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-08 08:17:31 UTC (rev 175) @@ -1,44 +0,0 @@ -package org.dllearner.algorithms; - -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; - -/** - * TODO: Es gibt 3 Sachen, die eine Loesung ausmachen: die Loesung selbst, - * also z.B. male AND EXISTS hasChild.TOP; die Score und die Fitness; - * man kann das also vielleicht alles noch sinnvoller integrieren, also - * z.B. die Score-Klasse so gestalten, dass Sie ein Node entgegennimmt und - * dort alles berechnet; beim Vergleich mehererer Algorithmen darf es dann - * z.B. nicht passieren, dass unterschiedliche Fitnessmessungen die Statistik - * verfaelschen; mit ADC wird das Ganze dann noch komplexer - * - * @author jl - * - */ -public interface LearningAlgorithm { - - /** - * Starts the algorithm. - * - */ - public void start(); - - /** - * Every algorithm must be able to return the score of the - * best solution found. - * @return Best score. - */ - public Score getSolutionScore(); - - /** - * Gibt beste L�sung zur�ck. - * @return - */ - public Concept getBestSolution(); - - /** - * Stops the algorithm gracefully. - * - */ - public void stop(); -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-07 18:00:21 UTC (rev 174) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-08 08:17:31 UTC (rev 175) @@ -34,7 +34,7 @@ import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { +public class RandomGuesser extends LearningAlgorithmNew { private Concept bestDefinition = null; private Score bestScore; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-07 18:00:21 UTC (rev 174) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 08:17:31 UTC (rev 175) @@ -46,7 +46,6 @@ import java.util.Map.Entry; import org.dllearner.Config; -import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; @@ -66,7 +65,7 @@ * @author Jens Lehmann * */ -public class GP extends LearningAlgorithmNew implements LearningAlgorithm { +public class GP extends LearningAlgorithmNew { // NumberFormat f; DecimalFormat df = new DecimalFormat("0.00"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-07 18:00:23
|
Revision: 174 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=174&view=rev Author: jenslehmann Date: 2007-10-07 11:00:21 -0700 (Sun, 07 Oct 2007) Log Message: ----------- transition from old command line interface completed Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/modules/TestModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/Main.java Deleted: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-07 18:00:21 UTC (rev 174) @@ -1,1379 +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; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.text.DecimalFormat; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.Config.Algorithm; -import org.dllearner.algorithms.BruteForceLearner; -import org.dllearner.algorithms.LearningAlgorithm; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.cli.ConfFileOption; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.LearningAlgorithmNew; -import org.dllearner.core.LearningProblem; -import org.dllearner.core.Reasoner; -import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.AssertionalAxiom; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.ConceptAssertion; -import org.dllearner.core.dl.FlatABox; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; -import org.dllearner.core.dl.Negation; -import org.dllearner.core.dl.RoleAssertion; -import org.dllearner.kb.OntologyFileFormat; -import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.modules.ModuleInvocator; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.dllearner.parser.TokenMgrError; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastRetrievalReasoner; -import org.dllearner.reasoning.KAON2Reasoner; -import org.dllearner.reasoning.ReasonerType; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.ConceptTransformation; -import org.dllearner.utilities.Files; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.RoleComparator; -import org.dllearner.utilities.Stat; - -/** - * Stellt die Verbindung zwischen Parser und den anderen Programmteilen her. - * Startet den Algorithmus. - * - * TODO: Die Hauptmethode sollte noch in kleinere Einheiten zerlegt werden zur - * besseren Lesbarkeit. - * - * TODO: einige Errors können durch RuntimeException ersetzt werden (kein throws - * und Exception-Handling notwendig) - * - * @author Jens Lehmann - * - */ -public class Main { - - private static FlatABox abox; - - private static ConfigurationManager confMgr; - - private Reasoner reasoner; - private ReasoningService rs; - private PosNegLP learningProblem; - // es werden jeweils die Dateien mit dem zugehörigen Format abgelegt - Map<URL, OntologyFileFormat> importedFiles; - Map<File, OntologyFileFormat> exportedFiles; - KB kb; - SortedSet<Individual> posExamples; - SortedSet<Individual> negExamples; - List<File> loadedJars; - List<String> preprocessingModules; - - private static long algorithmStartTime = 0; - - private String baseDir; - - // neuer Hauptkonstruktor - public Main(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, - Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfFileOption> confOptions, List<List<String>> functionCalls, - String baseDir, boolean useQueryMode) { - - this.kb = kb; - this.baseDir = baseDir; - - // Konfigurationsmanager erstellen - confMgr = new ConfigurationManager(confOptions); - if (!confMgr.checkConsistency()) { - throw new Error( - "inconsistent/unsupported combination of configuration options"); - } - - // Funktionsaufrufe in Klassenvariablen laden - parseFunctionCalls(functionCalls); - - - - // verwandte Individuen entfernen - /* - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#nonnie")); - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#beatrice")); - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#ann")); - */ - - // momentan keine Unterst�tzung f�r das gleichzeitige Lernen mehrerer - // Konzepte - // TODO: irgendwann lernen mehrerer Konzepte eventuell unterst�tzen - // (momentan keine hohe Priorit�t) - if (positiveExamples.size() > 1 || negativeExamples.size() > 1) { - throw new Error("Currently only one target concept is supported."); - } - - // Jar-Dateien laden - List<URL> urls = new LinkedList<URL>(); - // for (List<String> call : functionCalls) { - // if (call.get(0).equals("loadJarFile")) { - for(File f : loadedJars) { - // base dir wird hier nicht verwendet, da die Module eher - // relativ zum DL-Learner als zu den Beispielen liegen - // File f = new File(baseDir,call.get(1)); - // File f = new File(call.get(1)); - System.out.println("Loading jar file \"" + f.getAbsolutePath() + "\"."); - try { - urls.add(new URL("file", "localhost", f.getAbsolutePath())); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - // } - //} - } - - URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[] {})); - - // confMgr.applyOptions(); - - // Preprocessing-Modul aufrufen, falls notwendig - for (String module : preprocessingModules) { - //if (!Config.preprocessingModule.equals("")) { - System.out.println("Invoking preprocessing module main class " + module + "."); - ModuleInvocator mi = new ModuleInvocator(loader, module); - mi.invokePreprocessingModule(kb, positiveExamples, negativeExamples, confOptions, functionCalls, baseDir, useQueryMode); - //} - } - - // Funktionsaufrufe nochmal in Klassenvariablen laden, falls sie sich - // geändert haben - parseFunctionCalls(functionCalls); - - // Konfigurationsoptionen anwenden (könnten auch von einem Modul - // gesetzt werden) - confMgr.applyOptions(); - - // Beispiele werden in eine Menge gebracht - posExamples = new TreeSet<Individual>(); - negExamples = new TreeSet<Individual>(); - - for (AtomicConcept target : positiveExamples.keySet()) - posExamples = positiveExamples.get(target); - - for (AtomicConcept target : negativeExamples.keySet()) - negExamples = negativeExamples.get(target); - - // File-Objekte an function calls binden - /* - * boolean importKB = functionCalls.containsKey("import"); importedFiles = - * new LinkedList<File>(); if (importKB) { Set<String> - * importedFilesStr = functionCalls.get("import"); for (String - * importFileStr : importedFilesStr) { importedFiles.add(new - * File(baseDir, importFileStr)); } } - */ - /* - importedFiles = new HashMap<File, OntologyFileFormat>(); - for (List<String> call : functionCalls) { - if (call.get(0).equals("import")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - importedFiles.put(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - importedFiles.put(f, format); - } - } - } - */ - - // DIG-Reasoner testen - // new DIGReasonerTest(kb); - // System.exit(0); - - reasoner = createReasoner(kb, importedFiles); - ReasoningService rs = new ReasoningService(reasoner); - // commented out during changes - // learningProblem = new LearningProblem(rs, posExamples, negExamples); - - // export function - /* - * if (functionCalls.containsKey("export")) { for (String export : - * functionCalls.get("export")) { rs.saveOntology(export, baseDir); } } - */ - /* - for (List<String> call : functionCalls) { - if (call.get(0).equals("export")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - rs.saveOntology(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - rs.saveOntology(f, format); - } - } - } - */ - for(File f : exportedFiles.keySet()) { - rs.saveOntology(f, exportedFiles.get(f)); - } - - // Satisfiability Check - if (Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - 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); - } - - autoDetectConceptsAndRoles(rs); - - // Subsumptionhierarchie vorbereiten - System.out.print("Preparing Subsumption Hierarchy ... "); - long subHierTimeStart = System.nanoTime(); - reasoner.prepareSubsumptionHierarchy(); - long subHierTime = System.nanoTime() - subHierTimeStart; - System.out.println("OK (" - + Helper.prettyPrintNanoSeconds(subHierTime, true, false) + ")"); - - // prepare role hierarchy - System.out.print("Preparing Role Hierarchy ... "); - long roleHierTimeStart = System.nanoTime(); - try { - reasoner.prepareRoleHierarchy(); - // System.out.println(); - // System.out.println(reasoner.getRoleHierarchy()); - } catch (ReasoningMethodUnsupportedException e1) { - System.out.println("Tried to construct the role hierarchy, but the reasoner " - + "does not support it. Currently only DIG reasoners support this feature."); - } - long roleHierTime = System.nanoTime() - roleHierTimeStart; - System.out.println("OK (" - + Helper.prettyPrintNanoSeconds(roleHierTime, true, false) + ")"); - - // Beispiele anzeigen - boolean oneLineExampleInfo = true; - int maxExampleStringLength = posExamples.toString().length(); - maxExampleStringLength = Math.max(maxExampleStringLength, 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 (Individual ex : posExamples) - System.out.println(" " + ex); - System.out.println("negative examples[" + negExamples.size() + "]: "); - for (Individual ex : negExamples) - System.out.println(" " + ex); - } - - // Individuals - if (Config.showIndividuals) { - int stringLength = reasoner.getIndividuals().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("individuals[" + reasoner.getIndividuals().size() - + "]: "); - for (Individual ind : reasoner.getIndividuals()) - System.out.println(" " + ind); - } else - System.out.println("individuals[" + reasoner.getIndividuals().size() - + "]: " + reasoner.getIndividuals()); - } - - // Konzepte - if (Config.showConcepts) { - int stringLength = reasoner.getAtomicConcepts().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("concepts[" + reasoner.getAtomicConcepts().size() - + "]: "); - for (AtomicConcept ac : reasoner.getAtomicConcepts()) - System.out.println(" " + ac); - } else - System.out.println("concepts[" + reasoner.getAtomicConcepts().size() - + "]: " + reasoner.getAtomicConcepts()); - } - - // Rollen - if (Config.showRoles) { - int stringLength = reasoner.getAtomicRoles().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("roles[" + reasoner.getAtomicRoles().size() + "]: "); - for (AtomicRole r : reasoner.getAtomicRoles()) - System.out.println(" " + r); - } else - System.out.println("roles[" + reasoner.getAtomicRoles().size() + "]: " - + reasoner.getAtomicRoles()); - } - - // Anzeige der Subsumptionhierarchie - if (Config.showSubsumptionHierarchy) { - System.out.println("Subsumption Hierarchy:"); - try { - System.out.println(reasoner.getSubsumptionHierarchy()); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - // Anzeige der Wissensbasis - if (Config.showInternalKB) { - System.out.println(kb); - } - - - // Vergleichsreasoner erstellen zum Testen - // Reasoner reasoner2 = null; - // try { - // URL dig2URL = new URL("http://localhost:8081"); - // reasoner2 = new DIGReasoner(kb, dig2URL); - // reasoner2 = new KAON2Reasoner(kb, importedFiles); - // } catch (MalformedURLException e) { - // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // ReasoningService rs2 = new ReasoningService(reasoner2); - // LearningProblem learningProblem2 = new LearningProblem(rs2, - // posExamples, negExamples); - - // test(learningProblem); - // test2(learningProblem); - - // createStatisticsMLDMPaper(learningProblem, baseDir); - // System.exit(0); - - if (useQueryMode) { - processQueryMode(reasoner); - } else { - if (Config.statisticMode) - ; // createStatistics(learningProblem, baseDir); - else { - - rs.resetStatistics(); - algorithmStartTime = System.nanoTime(); - - if (Config.algorithm == Algorithm.BRUTE_FORCE) { - LearningAlgorithmNew la = new BruteForceLearner(learningProblem, null); - la.start(); - } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { - // new RandomGuesser(learningProblem, 10000, 10); - } else if (Config.algorithm == Algorithm.GP - || Config.algorithm == Algorithm.HYBRID_GP) { - //LearningAlgorithm la = new GP(learningProblem); - //la.start(); - } else { - if (Config.Refinement.improveSubsumptionHierarchy) { - // if(Config.reasonerType == ReasonerType.DIG) { - System.out - .println("Subsumption Hierarchy is improved for Refinement Operator Based Algorithm"); - - - try { - reasoner.getSubsumptionHierarchy() - .improveSubsumptionHierarchy(); - // System.out.println(reasoner.getSubsumptionHierarchy()); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - // ((DIGReasoner)reasoner).improveSubsumptionHierarchy(); - // ((DIGReasoner)reasoner).printSubsumptionHierarchies(); - // } else { - // System.out.println("Subsumption Hierarchy not - // improved (support for selected reasoner not - // implemented)"); - // } - } - LearningAlgorithmNew la = new ROLearner(learningProblem, null); - la.start(); - // new ROLearner(learningProblem, learningProblem2); - } - - long algorithmDuration = System.nanoTime() - algorithmStartTime; - - if (rs.getNrOfRetrievals() > 0) { - System.out.println("number of retrievals: " + rs.getNrOfRetrievals()); - System.out.println("retrieval reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getRetrievalReasoningTimeNs()) + " ( " - + Helper.prettyPrintNanoSeconds(rs.getTimePerRetrievalNs()) - + " per retrieval)"); - } - if (rs.getNrOfInstanceChecks() > 0) { - System.out.println("number of instance checks: " - + rs.getNrOfInstanceChecks() + " (" - + rs.getNrOfMultiInstanceChecks() + " multiple)"); - System.out.println("instance check reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getInstanceCheckReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerInstanceCheckNs()) - + " per instance check)"); - } - if (rs.getNrOfSubsumptionHierarchyQueries() > 0) { - System.out.println("subsumption hierarchy queries: " - + rs.getNrOfSubsumptionHierarchyQueries()); - /* - * System.out.println("subsumption hierarchy reasoning time: " + - * Helper.prettyPrintNanoSeconds(rs - * .getSubsumptionHierarchyTimeNs()) + " ( " + - * Helper.prettyPrintNanoSeconds(rs - * .getTimePerSubsumptionHierarchyQueryNs()) + " per - * subsumption hierachy query)"); - */ - } - if (rs.getNrOfSubsumptionChecks() > 0) { - System.out.println("(complex) subsumption checks: " - + rs.getNrOfSubsumptionChecks() + " (" - + rs.getNrOfMultiSubsumptionChecks() + " multiple)"); - System.out.println("subsumption reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getSubsumptionReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerSubsumptionCheckNs()) - + " per subsumption check)"); - } - DecimalFormat df = new DecimalFormat(); - double reasoningPercentage = 100 * rs.getOverallReasoningTimeNs() - / (double) algorithmDuration; - System.out - .println("overall reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getOverallReasoningTimeNs()) + " (" - + df.format(reasoningPercentage) - + "% of overall runtime)"); - System.out.println("overall algorithm runtime: " - + Helper.prettyPrintNanoSeconds(algorithmDuration)); - } - } - - // Aufräumarbeiten (TODO: das fehlt für KAON2 noch) - if (reasoner instanceof DIGReasoner) - ((DIGReasoner) reasoner).releaseKB(); - } - - // parst Funktionsaufrufe in Klassenvariablen - private void parseFunctionCalls(List<List<String>> functionCalls) { - // Funktionsaufrufe parsen - importedFiles = new HashMap<URL, OntologyFileFormat>(); - exportedFiles = new HashMap<File, OntologyFileFormat>(); - loadedJars = new LinkedList<File>(); - preprocessingModules = new LinkedList<String>(); - for (List<String> call : functionCalls) { - if(call.get(0).equals("import")) { - // alte Methode mit file statt URI - // File f = new File(baseDir, call.get(1)); - - URL url = null; - try { - String fileString = call.get(1); - if(fileString.startsWith("http:")) { - url = new URL(fileString); - } else { - File f = new File(baseDir, call.get(1)); - url = f.toURI().toURL(); - } - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - importedFiles.put(url, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - importedFiles.put(url, format); - } - } else if(call.get(0).equals("export")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - exportedFiles.put(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - exportedFiles.put(f, format); - } - } else if(call.get(0).equals("loadJarFile")) { - loadedJars.add(new File(call.get(1))); - } else if(call.get(0).equals("runPreprocessingModule")) { - preprocessingModules.add(call.get(1)); - } else { - System.out.println("Unknown function \"" + call.get(0) + "\". Exiting."); - System.exit(0); - } - } - } - - // Reasoning-Service erstellen - // TODO: überlegen, ob man die Methode nicht ev. auslagert, da sich Klassenvariablen - // mit Parametern überlappen - public static Reasoner createReasoner(KB kb, Map<URL, OntologyFileFormat> importedFiles) { - Reasoner reasoner = null; - if (Config.reasonerType == ReasonerType.KAON2) { - reasoner = new KAON2Reasoner(kb, importedFiles); - System.out.println("Reasoner: KAON2 (over Java API)"); - } else if (Config.reasonerType == ReasonerType.DIG) { - reasoner = new DIGReasoner(kb, Config.digReasonerURL, importedFiles); - System.out.println("Reasoner: " + ((DIGReasoner) reasoner).getIdentifier() - + " - connected via DIG 1.1 at " + Config.digReasonerURL); - } else if (Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - // erst KAON2-Reasoner erstellen um FlatABox zu erzeugen - if (Config.startUpReasoningType == ReasonerType.KAON2) { - Reasoner startUpReasoner = new KAON2Reasoner(kb, importedFiles); - // FlatABox abox; - try { - abox = createFlatABox(startUpReasoner); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - throw new Error( - "StartUpReasoner does not support all necessary reasoning methods."); - } - reasoner = new FastRetrievalReasoner(abox); - } else - throw new Error("Unsupported startup reasoner."); - } else { - throw new Error("Unsupported Reasoner"); - } - - // Reasoner.initializeReasoner(ReasonerType.KAON2,kb,importedFiles); - // ReasoningService reasoner = new ReasoningService(Config.reasonerType, - // Config.startUpReasoningType, kb, importedFiles); - // ReasoningService - // return new ReasoningService(reasoner); - return reasoner; - } - - /** - * Computes the set of allowed concepts based on configuration settings (also - * ignores anonymous and standard RDF, RDFS, OWL concept produces by Jena). - * - */ - public static void autoDetectConceptsAndRoles(ReasoningService rs) { - // einige Sachen, die momentan nur vom Refinement-Algorithmus - // unterstützt werden (später ev. auch von anderen Algorithmen) - //if (Config.algorithm == Algorithm.REFINEMENT) { - - // berechnen der verwendbaren Konzepte - if (Config.Refinement.allowedConceptsAutoDetect) { - // TODO: Code aus DIG-Reasoner-Klasse einfügen - - Set<AtomicConcept> allowedConceptsTmp = new TreeSet<AtomicConcept>( - new ConceptComparator()); - allowedConceptsTmp.addAll(rs.getAtomicConcepts()); - Iterator<AtomicConcept> it = allowedConceptsTmp.iterator(); - while (it.hasNext()) { - String conceptName = it.next().getName(); - // System.out.println(conceptName); - // seltsame anon-Konzepte, die von Jena erzeugt werden - // löschen - if (conceptName.startsWith("anon")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (probably an anonymous concept produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName - .startsWith("http://www.w3.org/1999/02/22-rdf-syntax-ns#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (RDF construct produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName - .startsWith("http://www.w3.org/2000/01/rdf-schema#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (RDF Schema construct produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName.startsWith("http://www.w3.org/2002/07/owl#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (OWL construct produced by Jena when reading in OWL file)."); - it.remove(); - } - } - - // hier werden jetzt noch die zu ignorierenden Konzepte entfernt - if(Config.Refinement.ignoredConcepts != null) { - - - for(AtomicConcept ac : Config.Refinement.ignoredConcepts) { - boolean success = allowedConceptsTmp.remove(ac); - if(!success) { - System.out.println("Ignored concept " + ac + " does not exist in knowledge base."); - System.exit(0); - } - - } - } - - - Config.Refinement.allowedConcepts = allowedConceptsTmp; - } else { - // prüfen, ob nur verfügbare Konzepte vom Nutzer gewählt worden - Set<AtomicConcept> allowed = new HashSet<AtomicConcept>(); - allowed.addAll(Config.Refinement.allowedConcepts); - allowed.removeAll(rs.getAtomicConcepts()); - if (allowed.size() > 0) { - System.out - .println("Some of the concepts you told the learner to use in the definition, " - + "do not exist in the background knowledge: " - + allowed); - System.out.println("Please correct this problem and restart."); - System.exit(0); - } - } - - if (Config.Refinement.allowedRolesAutoDetect) { - Set<AtomicRole> allowedRolesTmp = rs.getAtomicRoles(); - - // hier werden jetzt noch die zu ignorierenden Rollen entfernt - if(Config.Refinement.ignoredRoles != null) { - - - for(AtomicRole ar : Config.Refinement.ignoredRoles) { - boolean success = allowedRolesTmp.remove(ar); - if(!success) { - System.out.println("Ignored role " + ar + " does not exist in knowledge base."); - System.exit(0); - } - - } - } - - Config.Refinement.allowedRoles = allowedRolesTmp; - - } else { - Set<AtomicRole> allowedR = new HashSet<AtomicRole>(); - allowedR.addAll(Config.Refinement.allowedRoles); - - Set<AtomicRole> existingR = new TreeSet<AtomicRole>(new RoleComparator()); - existingR.addAll(rs.getAtomicRoles()); - - // allowedR.removeAll(rs.getAtomicRoles()); - allowedR.removeAll(existingR); - - if (allowedR.size() > 0) { - System.out - .println("Some of the roles you told the learner to use in the definition, " - + "do not exist in the background knowledge: " - + allowedR); - System.out.println("Please correct this problem and restart."); - System.out.println(rs.getAtomicRoles()); - System.out.println(Config.Refinement.allowedRoles); - System.exit(0); - } - - } - } - - // Statistikerzeugung wird ausgelagert, damit im "normalen" Programm - // nichts ge�ndert werden muss -// 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()); -// } - - // erzeugt Statistiken für MLDM-Paper zur Verarbeitung mit GnuPlot - // Vorsicht: Laufzeit von mehreren Stunden - @SuppressWarnings("unused") - private void createStatisticsMLDMPaper(PosNegDefinitionLP learningProblem, String baseDir) { - // Algorithmus 1: hybrid GP (100% refinement) - // Algorithmus 2: 50% refinement, 40% crossover, 1% mutation - // Algorithmus 3: 80% crossover, 2% mutation - - // Diagramm 1: Prozentzahl richtig klassifiziert - // Diagramm 2: Konzeptlänge - // Diagramm 3: Laufzeit - - int runs = 9; - GP gp; - int nrOfExamples = learningProblem.getPositiveExamples().size() - + learningProblem.getNegativeExamples().size(); - - Stat[][] statAr = new Stat[4][3]; - File[][] fileAr = new File[4][3]; - StringBuilder[][] exportString = new StringBuilder[4][3]; - // initialise export strings - for (int j = 0; j < 4; j++) { - for (int k = 0; k < 3; k++) { - exportString[j][k] = new StringBuilder(); - } - } - - fileAr[0][0] = new File(baseDir, "gnuplot/hybrid100classification.data"); - fileAr[0][1] = new File(baseDir, "gnuplot/hybrid100length.data"); - fileAr[0][2] = new File(baseDir, "gnuplot/hybrid100runtime.data"); - fileAr[1][0] = new File(baseDir, "gnuplot/hybrid50classification.data"); - fileAr[1][1] = new File(baseDir, "gnuplot/hybrid50length.data"); - fileAr[1][2] = new File(baseDir, "gnuplot/hybrid50runtime.data"); - fileAr[2][0] = new File(baseDir, "gnuplot/gpclassification.data"); - fileAr[2][1] = new File(baseDir, "gnuplot/gplength.data"); - fileAr[2][2] = new File(baseDir, "gnuplot/gpruntime.data"); - - // Extra-Test - fileAr[3][0] = new File(baseDir, "gnuplot/extraclassification.data"); - 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 - // Config.GP.elitism = true; - - for (int i = 700; i <= 700; i += 100) { - // initialise statistics array - for (int j = 0; j < 4; j++) { - for (int k = 0; k < 3; k++) { - statAr[j][k] = new Stat(); - } - } - - for (int run = 0; run < runs; run++) { - System.out.println("============="); - System.out.println("i " + i + " run " + run); - System.out.println("============="); - - // nur ein Test durchlaufen - for (int j = 0; j < 3; j++) { - - // Reasoner neu erstellen um Speicherprobleme zu vermeiden - reasoner = new DIGReasoner(kb, Config.digReasonerURL, importedFiles); - reasoner.prepareSubsumptionHierarchy(); - rs = new ReasoningService(reasoner); - // learningProblem = new LearningProblem(rs, posExamples, negExamples); - learningProblem = cm.learningProblem(PosNegDefinitionLP.class, rs); - cm.applyConfigEntry(learningProblem, "positiveExamples", posExamples); - cm.applyConfigEntry(learningProblem, "negativeExamples", negExamples); - - if (j == 0) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.85; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.05; - Config.GP.hillClimbingProbability = 0; - } else if (j == 1) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.4; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.4; - Config.GP.hillClimbingProbability = 0; - } else if (j == 2) { - Config.algorithm = Algorithm.GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; - } else if (j == 3) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.7; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.1; - Config.GP.hillClimbingProbability = 0; - } - - algorithmStartTime = System.nanoTime(); - gp = new GP(learningProblem); - long algorithmTime = System.nanoTime() - algorithmStartTime; - long algorithmTimeSeconds = algorithmTime / 1000000000; - - // Release, damit Pellet (hoffentlich) Speicher wieder - // freigibt - ((DIGReasoner) reasoner).releaseKB(); - - int conceptLength = gp.getBestSolution().getLength(); - Score bestScore = gp.getSolutionScore(); - int misClassifications = bestScore.getCoveredNegatives().size() - + bestScore.getNotCoveredPositives().size(); - double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); - - statAr[j][0].addNumber(classificationRatePercent); - statAr[j][1].addNumber(conceptLength); - statAr[j][2].addNumber(algorithmTimeSeconds); - - } - } - - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - exportString[j][k].append(i + " " + statAr[j][k].getMean() + " " - + statAr[j][k].getStandardDeviation() + "\n"); - } - } - - // Daten werden nach jeder Populationserhöhung geschrieben, nicht - // nur - // am Ende => man kann den Test also auch zwischendurch abbrechen - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - Files.createFile(fileAr[j][k], exportString[j][k].toString()); - } - } - } - - long overallTime = System.nanoTime() - overallTimeStart; - System.out.println("\noverall time: " - + Helper.prettyPrintNanoSeconds(overallTime)); - } - - // TODO: query mode umschreiben - private void processQueryMode(Reasoner reasoner) { - - System.out - .println("Entering query mode. Enter a concept for performing retrieval or q to quit."); - String queryStr = ""; - do { - - System.out.print("enter query: "); // String einlesen - BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); - - // Eingabestring einlesen - try { - queryStr = input.readLine(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - if (!queryStr.equals("q")) { - - // Konzept parsen - Concept concept = null; - boolean parsedCorrectly = true; - - try { - concept = KBParser.parseConcept(queryStr); - } catch (ParseException e1) { - e1.printStackTrace(); - System.err - .println("The concept you entered could not be parsed. Please try again."); - parsedCorrectly = false; - } catch (TokenMgrError e) { - e.printStackTrace(); - System.err - .println("An error occured during parsing. Please enter a syntactically valid concept."); - parsedCorrectly = false; - } - - if (parsedCorrectly) { - // berechne im Konzept vorkommende atomare Rollen und - // Konzepte - SortedSet<AtomicConcept> occurringConcepts = new TreeSet<AtomicConcept>( - new ConceptComparator()); - occurringConcepts.addAll(Helper.getAtomicConcepts(concept)); - SortedSet<AtomicRole> occurringRoles = new TreeSet<AtomicRole>( - new RoleComparator()); - occurringRoles.addAll(Helper.getAtomicRoles(concept)); - - // ziehe davon die existierenden ab => die resultierenden - // Mengen - // sollten leer sein, ansonsten Fehler (der DIG-Reasoner - // fängt das - // leider nicht selbst ab) - // => momentan etwas umständlich gelöst, da es in Java bei - // removeAll darauf - // ankommt, dass die Argumentmenge den Comparator - // implementiert hat, was hier - // (noch) nicht der Fall ist - for (AtomicConcept ac : rs.getAtomicConcepts()) - occurringConcepts.remove(ac); - for (AtomicRole ar : rs.getAtomicRoles()) - occurringRoles.remove(ar); - - boolean nonExistingConstructs = false; - if (occurringConcepts.size() != 0 || occurringRoles.size() != 0) { - System.out - .println("You used non-existing atomic concepts or roles. Please correct your query."); - if (occurringConcepts.size() > 0) - System.out.println("non-existing concepts: " - + occurringConcepts); - if (occurringRoles.size() > 0) - System.out.println("non-existing roles: " + occurringRoles); - nonExistingConstructs = true; - } - - if (!nonExistingConstructs) { - // Retrieval stellen - Set<Individual> result = null; - try { - result = reasoner.retrieval(concept); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - System.out.println(result); - - Score score = learningProblem.computeScore(concept); - System.out.println(score); - - // feststellen, was zur Lösung noch fehlt - // Set<String> notCoveredPositives - } - } - } - - } while (!queryStr.equals("q")); - - /* - * String queryStr = ""; - * - * do { - * - * System.out.print("enter query: "); // String einlesen BufferedReader - * input = new BufferedReader(new InputStreamReader(System.in)); - * - * try { queryStr = input.readLine(); // queryStr.trim(); } catch - * (IOException e) { e.printStackTrace(); } - * - * if (!queryStr.equals("q")) { - * - * Predicate queryPredicate = null; boolean parseError = false; boolean - * showRole = false; ASTConcept conceptNode = null; // testen, ob es - * einem Rollennamen entspricht if (roles.containsKey(queryStr)) { - * queryPredicate = roles.get(queryStr); showRole = true; } else { // zu - * einer Konzeptbeschreibung vervollst�ndigen queryStr = "query = " + - * queryStr + "."; // String parsen SimpleNode queryNode = null; try { - * queryNode = DLLearner.parseString(queryStr); conceptNode = - * (ASTConcept) queryNode.jjtGetChild(0).jjtGetChild(1); queryPredicate = - * parseConcept(conceptNode); } catch (ParseException e) { - * System.out.println(e); // e.printStackTrace(); System.out - * .println("Exception encountered. Please enter a valid concept - * description or a role name."); parseError = true; } catch - * (TokenMgrError e2) { System.out.println(e2); System.out - * .println("Error encountered. Please enter a valid concept description - * or a role name."); parseError = true; } } - * - * if (!parseError) { // Kind ermitteln (Kind 0 ist "query", Kind 1 // - * "=", Kind // 2 Konzept) // Node conceptNode = // - * queryNode.jjtGetChild(0).jjtGetChild(1); // if (conceptNode - * instanceof ASTConcept) { // Description d = parseConcept((ASTConcept) // // - * conceptNode); // Query stellen List<String> results = new // - * LinkedList<String>(); Map<String, List<String>> resultMap = new - * HashMap<String, List<String>>(); try { query = - * reasoner.createQuery(queryPredicate); Object[] tupleBuffer = null; - * - * query.open(); while (!query.afterLast()) { tupleBuffer = - * query.tupleBuffer(); // .toString(); if (tupleBuffer.length == 1) - * results.add(tupleBuffer[0].toString()); else { String ind1 = - * tupleBuffer[0].toString(); String ind2 = tupleBuffer[1].toString(); - * List<String> l; if (!resultMap.containsKey(ind1)) l = new LinkedList<String>(); - * else l = resultMap.get(ind1); - * - * l.add(ind2); resultMap.put(ind1, l); } query.next(); } // Query an - * eigenen Algorithmus stellen if(!showRole) { org.dllearner.dl.Concept - * conceptOwn = parseConceptOwn(conceptNode); // Score score = - * conceptOwn.computeScore(); Score score = new Score(conceptOwn); - * System.out.println(score); System.out.println("positive (own - * algorithm): " + score.getDefPosSet()); System.out.println("negative - * (own algorithm): " + score.getDefNegSet()); } - * - * if (tupleBuffer == null || tupleBuffer.length <= 1) { - * System.out.println("KAON2: " + results); } else - * System.out.println(resultMap); query.close(); query.dispose(); } - * catch (KAON2Exception e) { e.printStackTrace(); } catch - * (InterruptedException e) { e.printStackTrace(); } // } else { // - * System.out.println("Please enter a concept."); // } } // String - * einlesen, String parsen => SimpleNode, falls // einzigstes Kind // - * kein Konzept ist, dann Abbruch; falls doch dann parsen // und // // - * zur�ckerhaltene // Description an Reasoner geben } } while - * (!queryStr.equals("q")); - */ - - /* - * String queryStr = ""; Query query; - * - * do { - * - * System.out.print("enter query: "); // String einlesen BufferedReader - * input = new BufferedReader(new InputStreamReader(System.in)); - * - * try { queryStr = input.readLine(); // queryStr.trim(); } catch - * (IOException e) { e.printStackTrace(); } - * - * if (!queryStr.equals("q")) { - * - * Predicate queryPredicate = null; boolean parseError = false; boolean - * showRole = false; ASTConcept conceptNode = null; // testen, ob es - * einem Rollennamen entspricht if (roles.containsKey(queryStr)) { - * queryPredicate = roles.get(queryStr); showRole = true; } else { // zu - * einer Konzeptbeschreibung vervollst�ndigen queryStr = "query = " + - * queryStr + "."; // String parsen SimpleNode queryNode = null; try { - * queryNode = DLLearner.parseString(queryStr); conceptNode = - * (ASTConcept) queryNode.jjtGetChild(0).jjtGetChild(1); queryPredicate = - * parseConcept(conceptNode); } catch (ParseException e) { - * System.out.println(e); // e.printStackTrace(); System.out - * .println("Exception encountered. Please enter a valid concept - * description or a role name."); parseError = true; } catch - * (TokenMgrError e2) { System.out.println(e2); System.out - * .println("Error encountered. Please enter a valid concept description - * or a role name."); parseError = true; } } - * - * if (!parseError) { // Kind ermitteln (Kind 0 ist "query", Kind 1 "=", - * Kind // 2 Konzept) // Node conceptNode = // - * queryNode.jjtGetChild(0).jjtGetChild(1); // if (conceptNode - * instanceof ASTConcept) { // Description d = parseConcept((ASTConcept) // - * conceptNode); // Query stellen List<String> results = new LinkedList<String>(); - * Map<String, List<String>> resultMap = new HashMap<String, List<String>>(); - * try { query = reasoner.createQuery(queryPredicate); Object[] - * tupleBuffer = null; - * - * query.open(); while (!query.afterLast()) { tupleBuffer = - * query.tupleBuffer(); // .toString(); if (tupleBuffer.length == 1) - * results.add(tupleBuffer[0].toString()); else { String ind1 = - * tupleBuffer[0].toString(); String ind2 = tupleBuffer[1].toString(); - * List<String> l; if (!resultMap.containsKey(ind1)) l = new LinkedList<String>(); - * else l = resultMap.get(ind1); - * - * l.add(ind2); resultMap.put(ind1, l); } query.next(); } // Query an - * eigenen Algorithmus stellen if(!showRole) { org.dllearner.dl.Concept - * conceptOwn = parseConceptOwn(conceptNode); // Score score = - * conceptOwn.computeScore(); Score score = new Score(conceptOwn); - * System.out.println(score); System.out.println("positive (own - * algorithm): " + score.getDefPosSet()); System.out.println("negative - * (own algorithm): " + score.getDefNegSet()); } - * - * if (tupleBuffer == null || tupleBuffer.length <= 1) { - * System.out.println("KAON2: " + results); } else - * System.out.println(resultMap); query.close(); query.dispose(); } - * catch (KAON2Exception e) { e.printStackTrace(); } catch - * (InterruptedException e) { e.printStackTrace(); } // } else { // - * System.out.println("Please enter a concept."); // } } // String - * einlesen, String parsen => SimpleNode, falls // einzigstes Kind // - * kein Konzept ist, dann Abbruch; falls doch dann parsen // und // - * zur�ckerhaltene // Description an Reasoner geben } } while - * (!queryStr.equals("q")); - */ - } - - // Funktion wird nicht mehr ben�tigt - /* - * private File searchImports(Node rootNode, String baseDir) { // es wird - * zuerst nach einer import-Anweisung gesucht // boolean importKB = false; - * File importedFile = null; for (int i = 0; i < - * rootNode.jjtGetNumChildren(); i++) { if (rootNode.jjtGetChild(i) - * instanceof ASTFunctionCall) { Node functionCall = (ASTFunctionCall) - * rootNode.jjtGetChild(i); String function = ((ASTId) - * functionCall.jjtGetChild(0)).getId(); if (function.equals("import")) { - * String importFile = ""; importFile = ((ASTString) - * functionCall.jjtGetChild(1)).getId(); // Anf�hrungszeichen im String - * wegschneiden importFile = importFile.substring(1, importFile.length() - - * 1); importedFile = new File(baseDir, importFile); // importKB = true; } } } - * return importedFile; } - */ - - // VERALTET - /* - * private void handleReturnType(Ontology ontology) { // es wird eine Regel: - * "zielkonzept SUBCLASS r�ckgabetyp" zur Ontologie // hinzugef�gt // TODO: - * es muss noch gepr�ft werden was bei Inkosistenz mit pos. bzw. // - * negativen Beispiel passiert // Problem: diese Implementierungsvariante - * bringt leider nichts, da der // einfache DL-Algorithmus daraus keinen - * Nutzen zieht (au�erdem kann ein // Nutzer falls er m�chte einfach so eine - * Regel in die Konf.datei // schreiben) FlatABox abox = - * FlatABox.getInstance(); String subClass = abox.getTargetConcept() + " - * SUBCLASS " + Config.returnType; Description d2 = null; try { d2 = - * parseConcept((ASTConcept) - * DLLearner.parseString(subClass).jjtGetChild(1)); } catch (ParseException - * e) { System.err.println("Cannot parse return type."); - * e.printStackTrace(); System.exit(0); } Description d1 = - * getConcept(abox.getTargetConcept()); - * - * List<OntologyChangeEvent> changes = new ArrayList<OntologyChangeEvent>(); - * changes.add(new OntologyChangeEvent(KAON2Manager.factory().subClassOf(d1, - * d2), OntologyChangeEvent.ChangeType.ADD)); - * - * try { ontology.applyChanges(changes); } catch (KAON2Exception e) { - * System.err.println("Error in handling return type " + Config.returnType + - * "."); e.printStackTrace(); System.exit(0); } } - */ - - /* - * private static OWLClass getConcept(String name) { if - * (!concepts.containsKey(name)) { concepts.put(name, - * KAON2Manager.factory().owlClass(name)); } return concepts.get(name); } - * - * private static ObjectProperty getRole(String name) { if - * (!roles.containsKey(name)) { roles.put(name, - * KAON2Manager.factory().objectProperty(name)); } return roles.get(name); } - * - * public static Individual getIndividual(String name) { if - * (!individuals.containsKey(name)) { individuals.put(name, - * KAON2Manager.factory().individual(name)); } return individuals.get(name); } - */ - - // die Methode muss private bleiben - private static FlatABox createFlatABox(Reasoner reasoner) - throws ReasoningMethodUnsupportedException { - long dematStartTime = System.currentTimeMillis(); - - FlatABox aBox = new FlatABox(); // FlatABox.getInstance(); - for (AtomicConcept atomicConcept : reasoner.getAtomicConcepts()) { - aBox.atomicConceptsPos.put(atomicConcept.getName(), Helper - .getStringSet(reasoner.retrieval(atomicConcept))); - Negation negatedAtomicConcept = new Negation(atomicConcept); - aBox.atomicConceptsNeg.put(atomicConcept.getName(), Helper - .getStringSet(reasoner.retrieval(negatedAtomicConcept))); - aBox.concepts.add(atomicConcept.getName()); - } - - for (AtomicRole atomicRole : reasoner.getAtomicRoles()) { - aBox.rolesPos.put(atomicRole.getName(), Helper.getStringMap(reasoner - .getRoleMembers(atomicRole))); - aBox.roles.add(atomicRole.getName()); - } - - aBox.domain = Helper.getStringSet(reasoner.getIndividuals()); - aBox.top = aBox.domain; - // ab hier keine �nderungen mehr an FlatABox - aBox.prepare(); - - // System.out.println(aBox); - - long dematDuration = System.currentTimeMillis() - dematStartTime; - System.out.println("OK (" + dematDuration + " ms)"); - return aBox; - } - - // gibt M�glickeit flat Abox zu bekommen, falls eine erzeugt wurde - // (wird momentan nur f�r hill climbing ben�tigt und es ist sauberer diese - // hier - // zu erzeugen und bekommen als die ReasoningService-Klasse zu hacken) - public static FlatABox getFlatAbox() { - return abox; - } - - // generiert sibling aus Forte-Daten - @SuppressWarnings("unused") - private void test2(PosNegLP learningProblem) { - // Set<AtomicRole> roles = reasoner.getAtomicRoles(); - // for(AtomicRole role : roles) { - // System.out.println(rs.getRoleMembers(role)); - // } - /* - * AtomicRole sibling = new AtomicRole("sibling"); Map<String,SortedSet<String>> - * members = rs.getRoleMembers(sibling); for(String name : - * members.keySet()) { SortedSet<String> fillers = members.get(name); - * for(String filler : fillers) { - * System.out.println("sibling("+name+","+filler+")."); } } - */ - Concept c = null; - try { - c = KBParser.parseConcept("EXISTS uncle.TOP"); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Set<Individual> uncles = rs.retrieval(c); - Set<Individual> inds = rs.getIndividuals(); - for (Individual ind : uncles) - System.out.println("+isUncle(" + ind + ")."); - inds.removeAll(uncles); - for (Individual ind : inds) - System.out.println("-isUncle(" + ind + ")."); - - System.exit(0); - } - - public static long getAlgorithmStartTime() { - return algorithmStartTime; - } - - // die Methode soll alle Konzeptzusicherungen und Rollenzusicherungen von - // Individuen entfernen, die mit diesem Individuum verbunden sind - @SuppressWarnings("unused") - private void removeIndividualSubtree(KB kb, Individual individual) { - System.out.println(); - // erster Schritt: alle verbundenen Individuen finden - Set<Individual> connectedIndividuals = kb.findRelatedIndividuals(individual); - System.out.println("connected individuals: " + connectedIndividuals); - // Individual selbst auch entfernen - connectedIndividuals.add(individual); - - // zweiter Schritt: entfernen von Rollen- und Konzeptzusicherungen - Set<AssertionalAxiom> abox = kb.getAbox(); - Iterator<AssertionalAxiom> it = abox.iterator(); - while (it.hasNext()) { - AssertionalAxiom a = it.next(); - if (a instanceof RoleAssertion) { - RoleAssertion ra = (RoleAssertion) a; - if (connectedIndividuals.contains(ra.getIndividual1()) - || connectedIndividuals.contains(ra.getIndividual2())) { - System.out.println("remove " + ra); - it.remove(); - } - } else if (a instanceof ConceptAssertion) { - if (connectedIndividuals.contains(((ConceptAssertion) a).getIndividual())) { - System.out.println("remove " + a); - it.remove(); - } - } else - throw new RuntimeException(); - } - - Set<Individual> inds = kb.findAllIndividuals(); - System.out.println("remaining individuals: " + inds); - System.out.println(); - } - - public static ConfigurationManager getConfMgr() { - return confMgr; - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-07 18:00:21 UTC (rev 174) @@ -8,8 +8,8 @@ import java.util.TreeMap; import org.dllearner.Config; -import org.dllearner.Main; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -340,7 +340,14 @@ Score tmpScore; SortedSetTuple<String> tmp, tmp2; // FlatABox abox = ((FastRetrievalReasoner)learningProblem.getReasoner().getFastRetrieval().getAbox(); - FlatABox abox = Main.getFlatAbox(); + // FlatABox abox = Main.getFlatAbox(); + FlatABox abox = null; + try { + abox = Helper.createFlatABox(learningProblem.getReasoningService()); + } catch (ReasoningMethodUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } // TODO: testen, ob aktuelles Konzept zu speziell bzw. allgemein ist; // dann kann man das effizienter implementieren Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-07 18:00:21 UTC (rev 174) @@ -11,7 +11,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.Main; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; @@ -243,7 +242,7 @@ @Override public void init() { // TODO: this needs to be changed - Main.autoDetectConceptsAndRoles(rs); + Helper.autoDetectConceptsAndRoles(rs); // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm rs.prepareSubsumptionHierarchy(); Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-07 18:00:21 UTC (rev 174) @@ -19,15 +19,20 @@ */ package org.dllearner.cli; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.text.DecimalFormat; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; @@ -42,22 +47,31 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; 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.KBFile; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.parser.ConfParser; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; +import org.dllearner.utilities.RoleComparator; /** * Startup file for Command Line Interface. @@ -140,6 +154,9 @@ initComponent(cm, lp); initComponent(cm, la); + // perform file exports + performExports(parser, baseDir, rs); + // show examples (display each one if they do not take up much space, // otherwise just show the number of examples) boolean oneLineExampleInfo = true; @@ -163,7 +180,11 @@ processCLIOptions(cm, parser, rs); // start algorithm + long algStartTime = System.nanoTime(); la.start(); + long algDuration = System.nanoTime() - algStartTime; + + printConclusions(rs, algDuration); } // creates a mapping from components to option prefix strings @@ -180,6 +201,10 @@ return componentPrefixMapping; } + // convenience method + // basically every prefix (e.g. "refinement" in "refinement.horizontalExpFactor) + // corresponds to a specific component - this way the CLI will automatically + // support any configuration options supported by the component private static void configureComponent(ComponentManager cm, Component component, Map<Class<? extends Component>, String> componentPrefixMapping, ConfParser parser) { String prefix = componentPrefixMapping.get(component.getClass()); @@ -187,6 +212,7 @@ configureComponent(cm, component, parser.getConfOptionsByPrefix(prefix)); } + // convenience method - see above method private static void configureComponent(ComponentManager cm, Component component, List<ConfFileOption> options) { if (options != null) @@ -19... [truncated message content] |
From: <jen...@us...> - 2007-10-07 16:35:14
|
Revision: 173 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=173&view=rev Author: jenslehmann Date: 2007-10-07 09:35:12 -0700 (Sun, 07 Oct 2007) Log Message: ----------- build script now generates startup files pointing to the new CLI (org.dllearner.cli.Start and org.dllearner.cli.QuickStart) Modified Paths: -------------- trunk/build.xml Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-10-07 16:32:12 UTC (rev 172) +++ trunk/build.xml 2007-10-07 16:35:12 UTC (rev 173) @@ -185,11 +185,11 @@ <map from="${removeprefix}" to="."/> </pathconvert> - <echo file="bin/quickstart.bat" message="java -cp ${pathStringWin} org.dllearner.QuickStart"/> - <echo file="bin/dllearner.bat" message="java -cp ${pathStringWin} org.dllearner.parser.DLLearner %*"/> + <echo file="bin/quickstart.bat" message="java -cp ${pathStringWin} org.dllearner.cli.QuickStart"/> + <echo file="bin/dllearner.bat" message="java -cp ${pathStringWin} org.dllearner.cli.Start %*"/> <echo file="bin/ws.bat" message="java -cp ${pathStringWin} org.dllearner.server.DLLearnerWSStart %*"/> - <echo file="bin/quickstart" message="java -cp ${pathStringUnix} org.dllearner.QuickStart"/> - <echo file="bin/dllearner" message="java -cp ${pathStringUnix} org.dllearner.parser.DLLearner $@"/> + <echo file="bin/quickstart" message="java -cp ${pathStringUnix} org.dllearner.cli.QuickStart"/> + <echo file="bin/dllearner" message="java -cp ${pathStringUnix} org.dllearner.cli.start $@"/> <echo file="bin/ws" message="java -cp ${pathStringUnix} org.dllearner.server.DLLearnerWSStart $@"/> </target> 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-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-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-04 15:08:35
|
Revision: 169 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=169&view=rev Author: jenslehmann Date: 2007-10-04 08:08:33 -0700 (Thu, 04 Oct 2007) Log Message: ----------- extended config option access Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-04 15:07:40 UTC (rev 168) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-04 15:08:33 UTC (rev 169) @@ -33,6 +33,7 @@ // conf file options private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); + private Map<String,List<ConfFileOption>> confOptionsByPrefix = new HashMap<String,List<ConfFileOption>>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) @@ -56,6 +57,19 @@ } } + private void addConfOption(ConfFileOption confOption) { + confOptions.add(confOption); + confOptionsByName.put(confOption.getFullName(), confOption); + String prefix = confOption.getOption(); + if(confOptionsByPrefix.containsKey(prefix)) + confOptionsByPrefix.get(prefix).add(confOption); + else { + LinkedList<ConfFileOption> optionList = new LinkedList<ConfFileOption>(); + optionList.add(confOption); + confOptionsByPrefix.put(prefix,optionList); + } + } + public SortedSet<Individual> getPositiveExamples() { return positiveExamples; } @@ -72,6 +86,18 @@ return confOptionsByName; } + public ConfFileOption getConfOptionsByName(String name) { + return confOptionsByName.get(name); + } + + public Map<String,List<ConfFileOption>> getConfOptionsByPrefix() { + return confOptionsByPrefix; + } + + public List<ConfFileOption> getConfOptionsByPrefix(String prefix) { + return confOptionsByPrefix.get(prefix); + } + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -198,7 +224,7 @@ } if (jj_2_1(2147483647)) { confOption = ConfOption(); - confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); + addConfOption(confOption); } else if (jj_2_2(2147483647)) { FunctionCall(); } else if (jj_2_3(2147483647)) { @@ -464,64 +490,6 @@ finally { jj_save(5, xla); } } - final private boolean jj_3R_8() { - if (jj_3R_17()) return true; - return false; - } - - final private boolean jj_3R_10() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - final private boolean jj_3R_19() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_17() { - if (jj_scan_token(DOUBLE)) return true; - return false; - } - - final private boolean jj_3R_14() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_7() { - if (jj_3R_16()) return true; - return false; - } - - final private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; - return false; - } - - final private boolean jj_3R_6() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_22() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_13() { - if (jj_scan_token(28)) return true; - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3_6() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - final private boolean jj_3_5() { Token xsp; xsp = jj_scanpos; @@ -647,6 +615,64 @@ return false; } + final private boolean jj_3R_8() { + if (jj_3R_17()) return true; + return false; + } + + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_19() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_7() { + if (jj_3R_16()) return true; + return false; + } + + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; + return false; + } + + final private boolean jj_3R_6() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_22() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_13() { + if (jj_scan_token(28)) return true; + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_6() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + public ConfParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-04 15:07:43
|
Revision: 168 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=168&view=rev Author: jenslehmann Date: 2007-10-04 08:07:40 -0700 (Thu, 04 Oct 2007) Log Message: ----------- continued to implement command line interface (with numerous related changes) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java trunk/src/dl-learner/org/dllearner/parser/conf.jj Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-04 15:07:40 UTC (rev 168) @@ -22,6 +22,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.RoleComparator; /** @@ -188,15 +189,15 @@ // alle Strings erlaubt) String[] possibleValuesArray = strOptions.get(optionString); List<String> possibleValues = Arrays.asList(possibleValuesArray); - if (!possibleValues.contains(option.getStrValue()) && possibleValues.size() != 0) { + if (!possibleValues.contains(option.getStringValue()) && possibleValues.size() != 0) { System.out.println("Error: The configuration option \"" + optionString - + "\" must not have value \"" + option.getStrValue() + + "\" must not have value \"" + option.getStringValue() + "\". The value must be one of " + possibleValues + "."); System.exit(0); } // alles OK, Option kann angewandt werden - applyStringOptions(optionString,option.getStrValue()); + applyStringOptions(optionString,option.getStringValue()); // Option existiert nicht => Fehlerbehandlung } else { @@ -421,17 +422,17 @@ private void applyStringOptions(String option, String value) { if (option.equals("penalizeNeutralExamples")) - Config.penalizeNeutralExamples = strToBool(value); + Config.penalizeNeutralExamples = Datastructures.strToBool(value); else if (option.equals("showCorrectClassifications")) - Config.showCorrectClassifications = strToBool(value); + Config.showCorrectClassifications = Datastructures.strToBool(value); else if (option.equals("statMode")) - Config.statisticMode = strToBool(value); + Config.statisticMode = Datastructures.strToBool(value); else if (option.equals("una")) - Config.una = strToBool(value); + Config.una = Datastructures.strToBool(value); else if (option.equals("owa")) - Config.owa = strToBool(value); + Config.owa = Datastructures.strToBool(value); else if (option.equals("gp.useFixedNumberOfGenerations")) - Config.GP.useFixedNumberOfGenerations = strToBool(value); + Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); else if (option.equals("scoreMethod")) { if (value.equals("full")) Config.scoreMethod = ScoreMethod.FULL; @@ -459,17 +460,17 @@ } else if(option.equals("hidePrefix")) { Config.hidePrefixes.add(value); } else if (option.equals("showIndividuals")) { - Config.showIndividuals = strToBool(value); + Config.showIndividuals = Datastructures.strToBool(value); } else if (option.equals("showConcepts")) { - Config.showConcepts = strToBool(value); + Config.showConcepts = Datastructures.strToBool(value); } else if (option.equals("showRoles")) { - Config.showRoles = strToBool(value); + Config.showRoles = Datastructures.strToBool(value); } else if (option.equals("showInternalKB")) { - Config.showInternalKB = strToBool(value); + Config.showInternalKB = Datastructures.strToBool(value); } else if (option.equals("showSubsumptionHierarchy")) { - Config.showSubsumptionHierarchy = strToBool(value); + Config.showSubsumptionHierarchy = Datastructures.strToBool(value); } else if (option.equals("writeDIGProtocol")) { - Config.writeDIGProtocol = strToBool(value); + Config.writeDIGProtocol = Datastructures.strToBool(value); } else if (option.equals("digProtocolFile")) { Config.digProtocolFile = new File(value); // } else if (option.equals("preprocessingModule")) { @@ -487,34 +488,34 @@ else Config.GP.algorithmType = AlgorithmType.GENERATIONAL; } else if (option.equals("gp.adc")) { - Config.GP.adc = strToBool(value); + Config.GP.adc = Datastructures.strToBool(value); } else if (option.equals("refinement.heuristic")) { if(value.equals("lexicographic")) Config.Refinement.heuristic = Config.Refinement.Heuristic.LEXICOGRAPHIC; else Config.Refinement.heuristic = Config.Refinement.Heuristic.FLEXIBLE; } else if (option.equals("refinement.quiet")) - Config.Refinement.quiet = strToBool(value); + Config.Refinement.quiet = Datastructures.strToBool(value); else if (option.equals("refinement.writeSearchTree")) - Config.Refinement.writeSearchTree = strToBool(value); + Config.Refinement.writeSearchTree = Datastructures.strToBool(value); else if (option.equals("refinement.searchTreeFile")) { Config.Refinement.searchTreeFile = new File(value); } else if (option.equals("refinement.applyAllFilter")) - Config.Refinement.applyAllFilter = strToBool(value); + Config.Refinement.applyAllFilter = Datastructures.strToBool(value); else if (option.equals("refinement.applyExistsFilter")) - Config.Refinement.applyExistsFilter = strToBool(value); + Config.Refinement.applyExistsFilter = Datastructures.strToBool(value); else if (option.equals("refinement.useTooWeakList")) - Config.Refinement.useTooWeakList = strToBool(value); + Config.Refinement.useTooWeakList = Datastructures.strToBool(value); else if (option.equals("refinement.useOverlyGeneralList")) - Config.Refinement.useOverlyGeneralList = strToBool(value); + Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); else if (option.equals("refinement.useShortConceptConstruction")) - Config.Refinement.useShortConceptConstruction = strToBool(value); + Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); else if (option.equals("refinement.useAllConstructor")) - Config.Refinement.useAllConstructor = strToBool(value); + Config.Refinement.useAllConstructor = Datastructures.strToBool(value); else if (option.equals("refinement.useExistsConstructor")) - Config.Refinement.useExistsConstructor = strToBool(value); + Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); else if (option.equals("refinement.useNegation")) - Config.Refinement.useNegation = strToBool(value); + Config.Refinement.useNegation = Datastructures.strToBool(value); else if (option.equals("reasoner")) { if(value.equals("dig")) Config.reasonerType = ReasonerType.DIG; @@ -531,7 +532,7 @@ System.exit(0); } } else if (option.equals("useRetrievalForClassification")) - Config.useRetrievalForClassification = strToBool(value); + Config.useRetrievalForClassification = Datastructures.strToBool(value); // else if (option.equals("refinement.useDIGMultiInstanceChecks")) { // if(value.equals("never")) // Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.NEVER; @@ -567,15 +568,6 @@ } } - private static boolean strToBool(String str) { - if (str.equals("true")) - return true; - else if (str.equals("false")) - return false; - else - throw new Error("Cannot convert to boolean."); - } - public void addDoubleOption(String option, Double[] range) { doubleOptions.put(option, range); } Modified: trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -33,11 +33,12 @@ private boolean containsSubOption = true; private boolean isIntegerOption = false; - private boolean isNumeric = false; + private boolean isDoubleOption = false; + private boolean isStringOption = false; private boolean isSetOption = false; private String option; private String subOption; - private String strValue; + private String stringValue; private int intValue; private double doubleValue; private Set<String> setValues; @@ -50,7 +51,8 @@ public ConfFileOption(String option, String subOption, String value) { this.option = option; this.subOption = subOption; - strValue = value; + stringValue = value; + isStringOption = true; } public ConfFileOption(String option, int value) { @@ -63,7 +65,6 @@ this.subOption = subOption; intValue = value; isIntegerOption = true; - isNumeric = true; } public ConfFileOption(String option, double value) { @@ -75,8 +76,7 @@ this.option = option; this.subOption = subOption; doubleValue = value; - // isIntegerOption = false; - isNumeric = true; + isDoubleOption = false; } public ConfFileOption(String option, Set<String> values) { @@ -98,17 +98,13 @@ public int getIntValue() { return intValue; } - - public boolean isIntegerOption() { - return isIntegerOption; - } - + public String getOption() { return option; } - public String getStrValue() { - return strValue; + public String getStringValue() { + return stringValue; } public String getSubOption() { @@ -119,8 +115,46 @@ return doubleValue; } + public Object getValue() { + if(isIntegerOption) + return intValue; + else if(isDoubleOption) + return doubleValue; + else if(isStringOption) + return stringValue; + else + return setValues; + } + + /** + * + * @return The class of the value of the conf file option; + */ + public Class<?> getType() { + if(isIntegerOption) + return Integer.class; + else if(isDoubleOption) + return Double.class; + else if(isStringOption) + return String.class; + else + return Set.class; + } + + public boolean isIntegerOption() { + return isIntegerOption; + } + + public boolean isDoubleOption() { + return isDoubleOption; + } + public boolean isNumeric() { - return isNumeric; + return (isIntegerOption || isDoubleOption); + } + + public boolean isStringOption() { + return isStringOption; } public boolean isSetOption() { @@ -134,13 +168,13 @@ completeOption += option + "." + subOption; else completeOption += option; - if(isNumeric) + if(isNumeric()) if(isIntegerOption) return completeOption + "=" + intValue; else return completeOption + "=" + doubleValue; else - return completeOption + "=" + strValue; + return completeOption + "=" + stringValue; } public Set<String> getSetValues() { Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-04 15:07:40 UTC (rev 168) @@ -28,22 +28,35 @@ import java.util.Map; import java.util.Set; +import org.dllearner.algorithms.gp.GP; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; +import org.dllearner.core.DoubleConfigOption; +import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.StringSetConfigOption; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.parser.ConfParser; +import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.utilities.Datastructures; /** * Startup file for Command Line Interface. * * @author Jens Lehmann - * + * */ public class Start { @@ -51,50 +64,169 @@ * @param args */ public static void main(String[] args) { - File file = new File(args[args.length-1]); + File file = new File(args[args.length - 1]); String baseDir = file.getParentFile().getPath(); - + // create component manager instance ComponentManager cm = ComponentManager.getInstance(); - + + // create a mapping between components and prefixes in the conf file + Map<Class<? extends Component>, String> componentPrefixMapping = createComponentPrefixMapping(); + // parse conf file ConfParser parser = ConfParser.parseFile(file); - -// try { - + + // 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()) { + 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())); + // ConfigOption<?> urlOption = cm.getConfigOption(entry.getValue(), + // "url"); + // cm.applyConfigEntry(ks, new ConfigEntry<String>(urlOption, + // entry.getValue())); cm.applyConfigEntry(ks, "url", entry.getKey().toString()); // TODO: SPARQL-specific settings - + // ks.applyConfigEntry(new ConfigEntry) - + } - + + // step 2: detect used reasoner + ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); + ReasoningService rs = null; + // default value + if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) + rs = cm.reasoningService(DIGReasonerNew.class, sources); + else { + handleError("Unknown value " + reasonerOption.getStringValue() + + "for option \"reasoner\"."); + } + + // step 3: detect learning problem (no options yet) + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + + // step 4: detect learning algorithm + ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); + LearningAlgorithmNew la = null; + Class<? extends LearningAlgorithmNew> laClass = null; + if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) + laClass = ROLearner.class; + + la = cm.learningAlgorithm(ROLearner.class, lp); + + configureComponent(cm, la, parser.getConfOptionsByPrefix(componentPrefixMapping + .get(la))); + + // start algorithm + la.start(); + // use parsed values to configure components - -// } catch (InvalidConfigOptionValueException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } + + // 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(); + // } } - private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, String baseDir) { + // 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>(); + 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); + } + + 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(); + + ConfigOption<?> configOption = cm.getConfigOption(component.getClass(), optionName); + // check whether such an option exists + if (configOption != null) { + + // 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()) { + + ConfigEntry<Integer> entry = new ConfigEntry<Integer>( + (IntegerConfigOption) configOption, option.getIntValue()); + cm.applyConfigEntry(component, entry); + + } else if(configOption instanceof DoubleConfigOption && (option.isIntegerOption() || option.isDoubleOption())) { + + double value; + 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()) { + + ConfigEntry<Boolean> entry = new ConfigEntry<Boolean>( + (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); + + } else { + handleError("The type of conf file entry " + option + " is not correct."); + } + + } catch (InvalidConfigOptionValueException e) { + // e.printStackTrace(); + System.exit(0); + } + + } else + handleError("Unknow option " + option + "."); + } + + // detects all imported files and their format + private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, + String baseDir) { List<List<String>> imports = parser.getFunctionCalls().get("import"); Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); - - for(List<String> arguments : imports) { + + for (List<String> arguments : imports) { // step 1: detect URL URL url = null; - try { + try { String fileString = arguments.get(0); - if(fileString.startsWith("http:")) { + if (fileString.startsWith("http:")) { url = new URL(fileString); } else { File f = new File(baseDir, arguments.get(0)); @@ -103,45 +235,52 @@ } catch (MalformedURLException e) { e.printStackTrace(); } - + // step 2: detect format Class<? extends KnowledgeSource> ksClass; if (arguments.size() == 1) { String filename = url.getPath(); String ending = filename.substring(filename.lastIndexOf(".")); - - if(ending.equals("rdf") || ending.equals("owl")) + + if (ending.equals("rdf") || ending.equals("owl")) ksClass = OWLFile.class; - else if(ending.equals("nt")) + else if (ending.equals("nt")) ksClass = OWLFile.class; - else if(ending.equals("kb")) + else if (ending.equals("kb")) ksClass = KBFile.class; else { - System.err.println("Warning: no format fiven for " + arguments.get(0) + " and could not detect it. Chosing RDF/XML."); + System.err.println("Warning: no format fiven for " + arguments.get(0) + + " and could not detect it. Chosing RDF/XML."); ksClass = OWLFile.class; } - + importedFiles.put(url, ksClass); } else { String formatString = arguments.get(1); - + if (formatString.equals("RDF/XML")) ksClass = OWLFile.class; - else if(formatString.equals("KB")) + else if (formatString.equals("KB")) ksClass = KBFile.class; - else if(formatString.equals("SPARQL")) + else if (formatString.equals("SPARQL")) ksClass = SparqlEndpoint.class; - else if(formatString.equals("NT")) + else if (formatString.equals("NT")) ksClass = OWLFile.class; else { - throw new RuntimeException("Unsupported knowledge source format " + formatString + ". Exiting."); + throw new RuntimeException("Unsupported knowledge source format " + + formatString + ". Exiting."); } - + importedFiles.put(url, ksClass); } } - + return importedFiles; } - + + private static void handleError(String message) { + System.err.println(message); + System.exit(0); + } + } Added: trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -0,0 +1,85 @@ +/** + * 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; + +/** + * Represents a configuration option with values of type value. Similar + * to the integer option a minimum and a maximum value can specified. + * + * @author Jens Lehmann + * + */ +public class DoubleConfigOption extends ConfigOption<Double> { + + private double lowerLimit = Double.MIN_VALUE; + private double upperLimit = Double.MAX_VALUE; + + public DoubleConfigOption(String name, String description) { + super(name, description); + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(Double value) { + if(value >= lowerLimit && value <= upperLimit) + return true; + else + return false; + } + + /** + * @return the The lowest possible value for this configuration option. + */ + public double getLowerLimit() { + return lowerLimit; + } + + /** + * @param lowerLimit The lowest possible value for this configuration option. + */ + public void setLowerLimit(double lowerLimit) { + this.lowerLimit = lowerLimit; + } + + /** + * @return the The highest possible value for this configuration option. + */ + public double getUpperLimit() { + return upperLimit; + } + + /** + * @param upperLimit The highest possible value for this configuration option. + */ + public void setUpperLimit(double upperLimit) { + this.upperLimit = upperLimit; + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) + */ + @Override + public boolean checkType(Object object) { + return (object instanceof Double); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -38,23 +38,6 @@ /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ - /* - public boolean isValidValue(Object value) { - if(!(value instanceof Integer)) - return false; - - int intValue = (Integer) value; - - if(intValue >= lowerLimit && intValue <= upperLimit) - return true; - else - return false; - } - */ - - /* (non-Javadoc) - * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) - */ @Override public boolean isValidValue(Integer value) { if(value >= lowerLimit && value <= upperLimit) @@ -99,10 +82,4 @@ return (object instanceof Integer); } - - - - - - } Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-04 15:07:40 UTC (rev 168) @@ -84,7 +84,7 @@ for (int i = 0; i < confOptions.size(); i++) { if(confOptions.get(i).getOption().equals("hidePrefix")){ - prefix=confOptions.get(i).getStrValue(); + prefix=confOptions.get(i).getStringValue(); } System.out.println(confOptions.get(i).getOption()); if(confOptions.get(i).getOption().equals("gp")) Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-04 15:07:40 UTC (rev 168) @@ -34,6 +34,7 @@ import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; import org.dllearner.modules.PreprocessingModule; +import org.dllearner.utilities.Datastructures; /** @@ -97,7 +98,7 @@ for (int i = 0; i < confOptions.size(); i++) { if(confOptions.get(i).getOption().equals("hidePrefix")){ - prefix=confOptions.get(i).getStrValue(); + prefix=confOptions.get(i).getStringValue(); } //sparqlModule options if(confOptions.get(i).getOption().equals("sparqlModule")){ @@ -136,7 +137,7 @@ this.fw=new FileWriter(new File(baseDir+File.separator+filename),true); System.out.println("SparqlModul: Collecting Ontology"); OntologyCollector oc=new OntologyCollector(subjectList, numberOfRecursions, - filterMode, Util.setToArray(predList),Util.setToArray( objList),Util.setToArray(classList)); + filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList)); String ont=oc.collectOntology(); fw.write(ont); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-10-04 15:07:40 UTC (rev 168) @@ -21,12 +21,10 @@ import java.util.HashSet; import java.util.Iterator; -import java.util.Set; /** * mainly converts datatypes * - * TODO: move to org.dllearner.utilities * * @author Sebastian Hellmann * @@ -35,25 +33,6 @@ /** - * easy conversion - * - * @param s - * @return - */ - public static String[] setToArray(Set<String> s){ - if(s==null)return null; - String[] ret=new String[s.size()]; - int i=0; - for (Iterator<String> iter = s.iterator(); iter.hasNext();) { - ret[i] = iter.next(); - i++; - - } - return ret; - - } - - /** * Warning use only for visualization * @param s * @return String without certain namespaces Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-04 15:07:40 UTC (rev 168) @@ -62,6 +62,7 @@ // conf file options private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); + private Map<String,List<ConfFileOption>> confOptionsByPrefix = new HashMap<String,List<ConfFileOption>>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) @@ -85,6 +86,19 @@ } } + private void addConfOption(ConfFileOption confOption) { + confOptions.add(confOption); + confOptionsByName.put(confOption.getFullName(), confOption); + String prefix = confOption.getOption(); + if(confOptionsByPrefix.containsKey(prefix)) + confOptionsByPrefix.get(prefix).add(confOption); + else { + LinkedList<ConfFileOption> optionList = new LinkedList<ConfFileOption>(); + optionList.add(confOption); + confOptionsByPrefix.put(prefix,optionList); + } + } + public SortedSet<Individual> getPositiveExamples() { return positiveExamples; } @@ -100,7 +114,19 @@ public Map<String,ConfFileOption> getConfOptionsByName() { return confOptionsByName; } + + public ConfFileOption getConfOptionsByName(String name) { + return confOptionsByName.get(name); + } + public Map<String,List<ConfFileOption>> getConfOptionsByPrefix() { + return confOptionsByPrefix; + } + + public List<ConfFileOption> getConfOptionsByPrefix(String prefix) { + return confOptionsByPrefix.get(prefix); + } + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -254,7 +280,7 @@ // sichere Unterscheidungsmerkmal ist LOOKAHEAD(Id() [ "." Id() ] "=" ( Id() | Integer() | Double() | String() | "{" "}" | "{" ( ( String() | Id() ) "," )* (String() | Id()) "}" ) <CONF_END>) confOption=ConfOption() - { confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } + { addConfOption(confOption); } | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar | LOOKAHEAD(<POS_EX>) PosExample() Added: trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java 2007-10-04 15:07:40 UTC (rev 168) @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities; + +import java.util.Iterator; +import java.util.Set; + +/** + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ +public class Datastructures { + + public static boolean strToBool(String str) { + if (str.equals("true")) + return true; + else if (str.equals("false")) + return false; + else + throw new Error("Cannot convert to boolean."); + } + + /** + * easy conversion + * + * @param s + * @return + */ + public static String[] setToArray(Set<String> s){ + if(s==null)return null; + String[] ret=new String[s.size()]; + int i=0; + for (Iterator<String> iter = s.iterator(); iter.hasNext();) { + ret[i] = iter.next(); + i++; + + } + return ret; + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-03 14:54:52
|
Revision: 167 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=167&view=rev Author: jenslehmann Date: 2007-10-03 07:54:46 -0700 (Wed, 03 Oct 2007) Log Message: ----------- command line interface started Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/cli/QuickStart.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/kb/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java trunk/src/dl-learner/org/dllearner/modules/TestModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/ConfigurationOption.java Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -15,6 +15,7 @@ import org.dllearner.Config.Algorithm; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; @@ -44,7 +45,7 @@ */ public class ConfigurationManager { - private Collection<ConfigurationOption> options; + private Collection<ConfFileOption> options; // verfuegbare Optionen // Problemfall: double-Optionen, die auch int-Optionen sein können; @@ -56,10 +57,10 @@ private List<String> setOptions; public ConfigurationManager() { - this(new LinkedList<ConfigurationOption>()); + this(new LinkedList<ConfFileOption>()); } - public ConfigurationManager(Collection<ConfigurationOption> confOptions) { + public ConfigurationManager(Collection<ConfFileOption> confOptions) { // options = new HashSet<ConfigurationOption>(); options = confOptions; strOptions = new HashMap<String, String[]>(); @@ -73,7 +74,7 @@ } public void applyOptions() { - for(ConfigurationOption option : options) { + for(ConfFileOption option : options) { // System.out.println(option); applyConfigurationOption(option); } @@ -101,7 +102,7 @@ // TODO: bei Fehlerbehandlungen müsste man jetzt noch berücksichtigen, dass // Mengen als 4. Optionstyp (neben int, double, string) dazugekommen sind - public void applyConfigurationOption(ConfigurationOption option) { + public void applyConfigurationOption(ConfFileOption option) { String optionString; if(option.containsSubOption()) optionString = option.getOption() + "." + option.getSubOption(); Deleted: trunk/src/dl-learner/org/dllearner/ConfigurationOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationOption.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/ConfigurationOption.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,129 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -/** - * Repraesentiert eine Konfigurationsoption. Es werden verschiedene Optionen angeboten. - * - * @author jl - * - */ -public class ConfigurationOption { - - private boolean containsSubOption = true; - private boolean isIntegerOption = false; - private boolean isNumeric = false; - private boolean isSetOption = false; - private String option; - private String subOption; - private String strValue; - private int intValue; - private double doubleValue; - private Set<String> setValues; - - public ConfigurationOption(String option, String value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, String value) { - this.option = option; - this.subOption = subOption; - strValue = value; - } - - public ConfigurationOption(String option, int value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, int value) { - this.option = option; - this.subOption = subOption; - intValue = value; - isIntegerOption = true; - isNumeric = true; - } - - public ConfigurationOption(String option, double value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, double value) { - this.option = option; - this.subOption = subOption; - doubleValue = value; - // isIntegerOption = false; - isNumeric = true; - } - - public ConfigurationOption(String option, Set<String> values) { - this(option, null, values); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, Set<String> values) { - this.option = option; - this.subOption = subOption; - isSetOption = true; - setValues = values; - } - - public boolean containsSubOption() { - return containsSubOption; - } - - public int getIntValue() { - return intValue; - } - - public boolean isIntegerOption() { - return isIntegerOption; - } - - public String getOption() { - return option; - } - - public String getStrValue() { - return strValue; - } - - public String getSubOption() { - return subOption; - } - - public double getDoubleValue() { - return doubleValue; - } - - public boolean isNumeric() { - return isNumeric; - } - - public boolean isSetOption() { - return isSetOption; - } - - @Override - public String toString() { - String completeOption = "Configuration Option: "; - if(containsSubOption) - completeOption += option + "." + subOption; - else - completeOption += option; - if(isNumeric) - if(isIntegerOption) - return completeOption + "=" + intValue; - else - return completeOption + "=" + doubleValue; - else - return completeOption + "=" + strValue; - } - - public Set<String> getSetValues() { - return setValues; - } - -} Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 14:54:46 UTC (rev 167) @@ -43,6 +43,7 @@ import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; @@ -117,7 +118,7 @@ // neuer Hauptkonstruktor public Main(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { this.kb = kb; Added: trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-03 14:54:46 UTC (rev 167) @@ -0,0 +1,157 @@ +/** + * 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.cli; + +import java.util.Set; + +/** + * Represents one configuration option in a conf file, e.g. + * refinement.horizontalExpansionFactor = 0.6. + * + * @author Jens Lehmann + * + */ +public class ConfFileOption { + + private boolean containsSubOption = true; + private boolean isIntegerOption = false; + private boolean isNumeric = false; + private boolean isSetOption = false; + private String option; + private String subOption; + private String strValue; + private int intValue; + private double doubleValue; + private Set<String> setValues; + + public ConfFileOption(String option, String value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, String value) { + this.option = option; + this.subOption = subOption; + strValue = value; + } + + public ConfFileOption(String option, int value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, int value) { + this.option = option; + this.subOption = subOption; + intValue = value; + isIntegerOption = true; + isNumeric = true; + } + + public ConfFileOption(String option, double value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, double value) { + this.option = option; + this.subOption = subOption; + doubleValue = value; + // isIntegerOption = false; + isNumeric = true; + } + + public ConfFileOption(String option, Set<String> values) { + this(option, null, values); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, Set<String> values) { + this.option = option; + this.subOption = subOption; + isSetOption = true; + setValues = values; + } + + public boolean containsSubOption() { + return containsSubOption; + } + + public int getIntValue() { + return intValue; + } + + public boolean isIntegerOption() { + return isIntegerOption; + } + + public String getOption() { + return option; + } + + public String getStrValue() { + return strValue; + } + + public String getSubOption() { + return subOption; + } + + public double getDoubleValue() { + return doubleValue; + } + + public boolean isNumeric() { + return isNumeric; + } + + public boolean isSetOption() { + return isSetOption; + } + + @Override + public String toString() { + String completeOption = "Configuration Option: "; + if(containsSubOption) + completeOption += option + "." + subOption; + else + completeOption += option; + if(isNumeric) + if(isIntegerOption) + return completeOption + "=" + intValue; + else + return completeOption + "=" + doubleValue; + else + return completeOption + "=" + strValue; + } + + public Set<String> getSetValues() { + return setValues; + } + + public String getFullName() { + if(containsSubOption) + return option + "." + subOption; + else + return option; + } + +} Modified: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.cli; import java.io.BufferedReader; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 14:54:46 UTC (rev 167) @@ -20,7 +20,25 @@ package org.dllearner.cli; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OntologyFileFormat; +import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.parser.ConfParser; + /** * Startup file for Command Line Interface. * @@ -34,10 +52,96 @@ */ public static void main(String[] args) { File file = new File(args[args.length-1]); + String baseDir = file.getParentFile().getPath(); + // create component manager instance + ComponentManager cm = ComponentManager.getInstance(); + // 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())); + cm.applyConfigEntry(ks, "url", entry.getKey().toString()); + + // TODO: SPARQL-specific settings + + // ks.applyConfigEntry(new ConfigEntry) + + } + // use parsed values to configure components + +// } catch (InvalidConfigOptionValueException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } } + private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, String baseDir) { + List<List<String>> imports = parser.getFunctionCalls().get("import"); + Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); + + for(List<String> arguments : imports) { + // step 1: detect URL + URL url = null; + try { + String fileString = arguments.get(0); + if(fileString.startsWith("http:")) { + url = new URL(fileString); + } else { + File f = new File(baseDir, arguments.get(0)); + url = f.toURI().toURL(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + // step 2: detect format + Class<? extends KnowledgeSource> ksClass; + if (arguments.size() == 1) { + String filename = url.getPath(); + String ending = filename.substring(filename.lastIndexOf(".")); + + if(ending.equals("rdf") || ending.equals("owl")) + ksClass = OWLFile.class; + else if(ending.equals("nt")) + ksClass = OWLFile.class; + else if(ending.equals("kb")) + ksClass = KBFile.class; + else { + System.err.println("Warning: no format fiven for " + arguments.get(0) + " and could not detect it. Chosing RDF/XML."); + ksClass = OWLFile.class; + } + + importedFiles.put(url, ksClass); + } else { + String formatString = arguments.get(1); + + if (formatString.equals("RDF/XML")) + ksClass = OWLFile.class; + else if(formatString.equals("KB")) + ksClass = KBFile.class; + else if(formatString.equals("SPARQL")) + ksClass = SparqlEndpoint.class; + else if(formatString.equals("NT")) + ksClass = OWLFile.class; + else { + throw new RuntimeException("Unsupported knowledge source format " + formatString + ". Exiting."); + } + + importedFiles.put(url, ksClass); + } + } + + return importedFiles; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -398,5 +398,9 @@ return null; } + + public ConfigOption<?> getConfigOption(Class<? extends Component> component, String name) { + return componentOptionsByName.get(component).get(name); + } } Modified: trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-03 14:54:46 UTC (rev 167) @@ -2,10 +2,19 @@ public enum OntologyFileFormat { - // RDF-Triples in XML file + /** + * RDF-Triples in XML file + */ RDF_XML, - // N-Triple format (subformat of N3) - N_TRIPLES + /** + * N-Triple format (subformat of N3) + */ + N_TRIPLES, + /** + * internal KB format + */ + KB, + } Modified: trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java 2007-10-03 14:54:46 UTC (rev 167) @@ -6,7 +6,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -24,7 +24,7 @@ @SuppressWarnings({"unchecked"}) public void invokePreprocessingModule(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { try { // Config.preprocessingModule = "org.dllearner.algorithms.gp.GP"; Modified: trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -4,7 +4,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -13,7 +13,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode); public String getModuleName(); Modified: trunk/src/dl-learner/org/dllearner/modules/TestModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/TestModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/TestModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -4,8 +4,8 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -15,7 +15,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Main.getConfMgr().addStringOption("bla", new String[] {"test"}); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 14:54:46 UTC (rev 167) @@ -29,7 +29,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -70,7 +70,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -28,8 +28,8 @@ import java.util.Set; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -69,7 +69,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,6 +1,7 @@ /* Generated By:JavaCC: Do not edit this line. ConfParser.java */ package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -20,36 +21,40 @@ import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public @SuppressWarnings("all") class ConfParser implements ConfParserConstants { + // examples private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - // Konfigurationsoptionen - private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + // conf file options + private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); + private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante - // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es - // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal - // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit - // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - // private static boolean constructorCalled = false; + private Map<String,List<List<String>>> functionCalls = new HashMap<String,List<List<String>>>(); - // Wissensbasis - // private KB kb = new KB(); - // public static final String internalNamespace = "http://localhost/foo#"; + private void addFunctionCall(String name, List<String> arguments) { + if(functionCalls.containsKey(name)) + functionCalls.get(name).add(arguments); + else { + List<List<String>> calls = new LinkedList<List<String>>(); + calls.add(arguments); + functionCalls.put(name,calls); + } + } public SortedSet<Individual> getPositiveExamples() { return positiveExamples; @@ -59,11 +64,15 @@ return negativeExamples; } - public List<ConfigurationOption> getConfOptions() { + public List<ConfFileOption> getConfOptions() { return confOptions; } - public List<List<String>> getFunctionCalls() { + public Map<String,ConfFileOption> getConfOptionsByName() { + return confOptionsByName; + } + + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -89,7 +98,7 @@ } */ - public static ConfParser parseFile(String filename) { + public static ConfParser parseFile(File filename) { ConfParser learner = null; try { learner = new ConfParser(new FileInputStream(filename)); @@ -174,7 +183,7 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; - ConfigurationOption confOption; + ConfFileOption confOption; label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -189,7 +198,7 @@ } if (jj_2_1(2147483647)) { confOption = ConfOption(); - confOptions.add(confOption); + confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } else if (jj_2_2(2147483647)) { FunctionCall(); } else if (jj_2_3(2147483647)) { @@ -204,12 +213,12 @@ jj_consume_token(0); } - final public ConfigurationOption ConfOption() throws ParseException { + final public ConfFileOption ConfOption() throws ParseException { boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; String option="", subOption="", value="", tmp=""; int number = 0; double numberDouble = 0; - ConfigurationOption confOption; + ConfFileOption confOption; Set<String> values = new HashSet<String>(); option = Id(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -297,25 +306,25 @@ if(containsSubOption) { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,subOption,numberDouble); + confOption = new ConfFileOption(option,subOption,numberDouble); else - confOption = new ConfigurationOption(option,subOption,number); + confOption = new ConfFileOption(option,subOption,number); else if(isSet) - confOption = new ConfigurationOption(option,subOption,values); + confOption = new ConfFileOption(option,subOption,values); else - confOption = new ConfigurationOption(option,subOption,value); + confOption = new ConfFileOption(option,subOption,value); } else { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,numberDouble); + confOption = new ConfFileOption(option,numberDouble); else - confOption = new ConfigurationOption(option,number); + confOption = new ConfFileOption(option,number); else if(isSet) - confOption = new ConfigurationOption(option,values); + confOption = new ConfFileOption(option,values); else - confOption = new ConfigurationOption(option,value); + confOption = new ConfFileOption(option,value); } {if (true) return confOption;} // confOptions.add(confOption); @@ -329,7 +338,7 @@ s1 = Id(); jj_consume_token(29); s2 = String(); - list.add(s1); list.add(s2); + list.add(s2); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -346,7 +355,7 @@ } jj_consume_token(30); jj_consume_token(CONF_END); - functionCalls.add(list); + addFunctionCall(s1,list); } final public void PosExample() throws ParseException { @@ -455,6 +464,96 @@ finally { jj_save(5, xla); } } + final private boolean jj_3R_8() { + if (jj_3R_17()) return true; + return false; + } + + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_19() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_7() { + if (jj_3R_16()) return true; + return false; + } + + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; + return false; + } + + final private boolean jj_3R_6() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_22() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_13() { + if (jj_scan_token(28)) return true; + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_6() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3_5() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) { + jj_scanpos = xsp; + if (jj_3R_15()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3R_12() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3R_21() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_18() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_21()) { + jj_scanpos = xsp; + if (jj_3R_22()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + final private boolean jj_3R_9() { if (jj_3R_12()) return true; return false; @@ -548,96 +647,6 @@ return false; } - final private boolean jj_3R_8() { - if (jj_3R_17()) return true; - return false; - } - - final private boolean jj_3R_10() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - final private boolean jj_3R_19() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_17() { - if (jj_scan_token(DOUBLE)) return true; - return false; - } - - final private boolean jj_3R_14() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_7() { - if (jj_3R_16()) return true; - return false; - } - - final private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; - return false; - } - - final private boolean jj_3R_6() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_22() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_13() { - if (jj_scan_token(28)) return true; - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3_6() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - final private boolean jj_3_5() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_14()) { - jj_scanpos = xsp; - if (jj_3R_15()) return true; - } - if (jj_scan_token(28)) return true; - return false; - } - - final private boolean jj_3R_12() { - if (jj_scan_token(STRING)) return true; - return false; - } - - final private boolean jj_3R_21() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_18() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_21()) { - jj_scanpos = xsp; - if (jj_3R_22()) return true; - } - if (jj_scan_token(28)) return true; - return false; - } - public ConfParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,5 +1,6 @@ /* Generated By:JavaCC: Do not edit this line. ConfParserTokenManager.java */ package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -16,7 +17,7 @@ import org.dllearner.Main; import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public @SuppressWarnings("all") class ConfParserTokenManager implements ConfParserConstants Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 14:54:46 UTC (rev 167) @@ -30,6 +30,7 @@ PARSER_BEGIN(ConfParser) package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -49,36 +50,40 @@ import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public class ConfParser { + // examples private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - // Konfigurationsoptionen - private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + // conf file options + private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); + private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante - // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es - // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal - // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit - // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - // private static boolean constructorCalled = false; + private Map<String,List<List<String>>> functionCalls = new HashMap<String,List<List<String>>>(); - // Wissensbasis - // private KB kb = new KB(); - // public static final String internalNamespace = "http://localhost/foo#"; + private void addFunctionCall(String name, List<String> arguments) { + if(functionCalls.containsKey(name)) + functionCalls.get(name).add(arguments); + else { + List<List<String>> calls = new LinkedList<List<String>>(); + calls.add(arguments); + functionCalls.put(name,calls); + } + } public SortedSet<Individual> getPositiveExamples() { return positiveExamples; @@ -88,11 +93,15 @@ return negativeExamples; } - public List<ConfigurationOption> getConfOptions() { + public List<ConfFileOption> getConfOptions() { return confOptions; } - public List<List<String>> getFunctionCalls() { + public Map<String,ConfFileOption> getConfOptionsByName() { + return confOptionsByName; + } + + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -118,7 +127,7 @@ } */ - public static ConfParser parseFile(String filename) { + public static ConfParser parseFile(File filename) { ConfParser learner = null; try { learner = new ConfParser(new FileInputStream(filename)); @@ -238,14 +247,14 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; - ConfigurationOption confOption; + ConfFileOption confOption; } { ( // 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() - { confOptions.add(confOption); } + { confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar | LOOKAHEAD(<POS_EX>) PosExample() @@ -254,13 +263,13 @@ <EOF> } -ConfigurationOption ConfOption() : +ConfFileOption ConfOption() : { boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; String option="", subOption="", value="", tmp=""; int number = 0; double numberDouble = 0; - ConfigurationOption confOption; + ConfFileOption confOption; Set<String> values = new HashSet<String>(); } { @@ -278,25 +287,25 @@ if(containsSubOption) { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,subOption,numberDouble); + confOption = new ConfFileOption(option,subOption,numberDouble); else - confOption = new ConfigurationOption(option,subOption,number); + confOption = new ConfFileOption(option,subOption,number); else if(isSet) - confOption = new ConfigurationOption(option,subOption,values); + confOption = new ConfFileOption(option,subOption,values); else - confOption = new ConfigurationOption(option,subOption,value); + confOption = new ConfFileOption(option,subOption,value); } else { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,numberDouble); + confOption = new ConfFileOption(option,numberDouble); else - confOption = new ConfigurationOption(option,number); + confOption = new ConfFileOption(option,number); else if(isSet) - confOption = new ConfigurationOption(option,values); + confOption = new ConfFileOption(option,values); else - confOption = new ConfigurationOption(option,value); + confOption = new ConfFileOption(option,value); } return confOption; // confOptions.add(confOption); @@ -309,9 +318,9 @@ List<String> list = new LinkedList<String>(); } { - s1=Id() "(" s2=String() { list.add(s1); list.add(s2); } + s1=Id() "(" s2=String() { list.add(s2); } ("," s=String() { list.add(s); } )* ")" <CONF_END> - { functionCalls.add(list); } + { addFunctionCall(s1,list); } } void PosExample() : { Individual i; } Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-03 14:54:46 UTC (rev 167) @@ -15,9 +15,9 @@ import org.dllearner.Config; import org.dllearner.ConfigurationManager; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; @@ -63,13 +63,13 @@ public void setStatus(String status) {this.status = status;} ConfigurationManager confMgr; - public void addOption(ConfigurationOption c){confMgr.applyConfigurationOption(c);} + public void addOption(ConfFileOption c){confMgr.applyConfigurationOption(c);} ROLearner ROL; public ClientState() { - TreeSet<ConfigurationOption> s=new TreeSet<ConfigurationOption>(); + TreeSet<ConfFileOption> s=new TreeSet<ConfFileOption>(); //s.add(new ConfigurationOption("refinement","quiet","true")); /*s.add(new ConfigurationOption()); s.add(new ConfigurationOption()); @@ -79,7 +79,7 @@ s.add(new ConfigurationOption());*/ confMgr = new ConfigurationManager(s); - addOption(new ConfigurationOption("refinement","quiet","true")); + addOption(new ConfFileOption("refinement","quiet","true")); //confMgr.applyOptions(); } @@ -460,7 +460,7 @@ public void learnMonitored(){ - addOption(new ConfigurationOption("refinement","ignoredConcepts",ignoredConcept)); + addOption(new ConfFileOption("refinement","ignoredConcepts",ignoredConcept)); this.lm=new LearnMonitor(this); this.lm.start(); //this.lm.learn(this); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-03 14:54:46 UTC (rev 167) @@ -156,7 +156,7 @@ for(int exampleNr=startExampleNr; exampleNr < examples.length; exampleNr++) { // parse current conf file - ConfParser learner = ConfParser.parseFile(confFiles[exampleNr].toString()); + ConfParser learner = ConfParser.parseFile(confFiles[exampleNr]); // read which files were imported (internal KB is ignored) and initialise reasoner Map<URL, OntologyFileFormat> imports = getImports(learner.getFunctionCalls(), confFiles[exampleNr]); @@ -302,15 +302,17 @@ } - private static Map<URL, OntologyFileFormat> getImports(List<List<String>> functionCalls, File confFile) { + private static Map<URL, OntologyFileFormat> getImports(Map<String,List<List<String>>> functionCalls, File confFile) { Map<URL, OntologyFileFormat> importedFiles = new HashMap<URL, OntologyFileFormat>(); OntologyFileFormat format = null; URL url = null; - for (List<String> call : functionCalls) { + List<List<String>> imports = functionCalls.get("import"); + + for (List<String> call : imports) { - if(call.get(0).equals("import")) { + //if(call.get(0).equals("import")) { try { String fileString = call.get(1); @@ -336,7 +338,7 @@ format = OntologyFileFormat.N_TRIPLES; importedFiles.put(url, format); } - } + // } } return importedFiles; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-03 11:13:09
|
Revision: 165 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=165&view=rev Author: jenslehmann Date: 2007-10-03 02:53:38 -0700 (Wed, 03 Oct 2007) Log Message: ----------- - added learning problem structure - partially implemented learning problems Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.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/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 09:53:38 UTC (rev 165) @@ -12,7 +12,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.learningproblems.PosNegLP.UseMultiInstanceChecks; import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.reasoning.ReasonerType; Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 09:53:38 UTC (rev 165) @@ -12,7 +12,7 @@ import org.dllearner.core.dl.Negation; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; +import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; import org.dllearner.utilities.SortedSetTuple; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 09:53:38 UTC (rev 165) @@ -60,7 +60,7 @@ import org.dllearner.core.dl.RoleAssertion; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -821,7 +821,7 @@ // erzeugt Statistiken für MLDM-Paper zur Verarbeitung mit GnuPlot // Vorsicht: Laufzeit von mehreren Stunden @SuppressWarnings("unused") - private void createStatisticsMLDMPaper(DefinitionLP learningProblem, String baseDir) { + private void createStatisticsMLDMPaper(PosNegDefinitionLP learningProblem, String baseDir) { // Algorithmus 1: hybrid GP (100% refinement) // Algorithmus 2: 50% refinement, 40% crossover, 1% mutation // Algorithmus 3: 80% crossover, 2% mutation @@ -888,7 +888,7 @@ reasoner.prepareSubsumptionHierarchy(); rs = new ReasoningService(reasoner); // learningProblem = new LearningProblem(rs, posExamples, negExamples); - learningProblem = cm.learningProblem(DefinitionLPTwoValued.class, rs); + learningProblem = cm.learningProblem(PosNegDefinitionLP.class, rs); cm.applyConfigEntry(learningProblem, "positiveExamples", posExamples); cm.applyConfigEntry(learningProblem, "negativeExamples", negExamples); Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 09:53:38 UTC (rev 165) @@ -34,25 +34,25 @@ import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.DefinitionLPThreeValued; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLPStrict; +import org.dllearner.learningproblems.PosNegDefinitionLP; public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private DefinitionLP learningProblem; + private LearningProblemNew learningProblem; private int numberOfTrees; private int maxDepth; - public RandomGuesser(DefinitionLP learningProblem) { + public RandomGuesser(LearningProblemNew 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); + problems.add(LearningProblemNew.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -58,6 +58,7 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; /** @@ -116,7 +117,7 @@ private Score bestScore; private Concept bestConcept; - private DefinitionLP learningProblem; + private PosNegLP learningProblem; // private GeneticRefinementOperator psi; private Psi psi; @@ -128,13 +129,13 @@ * 1.0 and a probability of mutation of 0.01. * */ - public GP(DefinitionLP learningProblem) { + public GP(PosNegLP 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); + problems.add(PosNegLP.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 09:53:38 UTC (rev 165) @@ -25,8 +25,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.learningproblems.PosNegDefinitionLPStrict; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; @@ -57,7 +57,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(DefinitionLP learningProblem, Concept hypothesis) { + private static Score calculateFitness(LearningProblemNew 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(DefinitionLP learningProblem, Concept hypothesis, Concept adc) { + private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis, Concept adc) { Concept extendedHypothesis; if (!Config.returnType.equals("")) { @@ -89,7 +89,9 @@ Score score; if(Config.GP.adc) - score = learningProblem.computeScore(extendedHypothesis, adc); + // TODO: ADC-Support + // score = learningProblem.computeScore(extendedHypothesis, adc); + throw new RuntimeException("ADC not supported"); else score = learningProblem.computeScore(extendedHypothesis); @@ -121,11 +123,11 @@ return score; } - public static Program createProgram(DefinitionLP learningProblem, Concept mainTree) { + public static Program createProgram(LearningProblemNew learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); } - private static Program createProgram(DefinitionLP learningProblem, Concept mainTree, Concept adc) { + private static Program createProgram(LearningProblemNew learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); } @@ -133,7 +135,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(DefinitionLP learningProblem, Program p) { + public static Program mutation(LearningProblemNew learningProblem, Program p) { mutation++; if(Config.GP.adc) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -157,7 +159,7 @@ } } - private static Concept mutation(DefinitionLP learningProblem, Concept tree, boolean useADC) { + private static Concept mutation(LearningProblemNew 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 +228,7 @@ * @param p2 Second parent. * @return A two-element array containing the offpsring. */ - public static Program[] crossover(DefinitionLP learningProblem, Program p1, Program p2) { + public static Program[] crossover(LearningProblemNew learningProblem, Program p1, Program p2) { crossover++; if(Config.GP.adc) { Concept[] pt; @@ -302,7 +304,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(DefinitionLP learningProblem, Program p) { + public static Program hillClimbing(LearningProblemNew learningProblem, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -325,7 +327,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(DefinitionLP learningProblem, Concept node, ScoreThreeValued score) { + private static Concept hillClimbing(LearningProblemNew 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,15 +442,15 @@ } } - private static ScoreThreeValued getScore(int conceptLength, DefinitionLP learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, LearningProblemNew 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); // learningProblem.getReasoner().getIndividuals(); // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); - - return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, learningProblem.getPositiveExamples(),((DefinitionLPThreeValued)learningProblem).getNeutralExamples(),learningProblem.getNegativeExamples()); + PosNegDefinitionLPStrict lp = (PosNegDefinitionLPStrict)learningProblem; + return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); } // aktualisiert die besten Knoten @@ -477,7 +479,7 @@ return returnMap; } - private static Concept pickTerminalSymbol(DefinitionLP learningProblem, boolean useADC) { + private static Concept pickTerminalSymbol(LearningProblemNew learningProblem, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size(); @@ -607,7 +609,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(DefinitionLP learningProblem, int depth) { + public static Program createFullRandomProgram(LearningProblemNew learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), @@ -617,7 +619,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false)); } - private static Concept createFullRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { + private static Concept createFullRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size(); @@ -668,7 +670,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(DefinitionLP learningProblem, int depth) { + public static Program createGrowRandomProgram(LearningProblemNew learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), @@ -678,7 +680,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false)); } - private static Concept createGrowRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { + private static Concept createGrowRandomTree(LearningProblemNew 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-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 09:53:38 UTC (rev 165) @@ -11,6 +11,7 @@ import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -18,7 +19,7 @@ PsiUp pu; PsiDown pd; - DefinitionLP learningProblem; + PosNegLP learningProblem; int nrOfPositiveExamples; int nrOfNegativeExamples; Random random; @@ -48,7 +49,7 @@ private long someTimeStart = 0; public long someTime = 0; - public Psi(DefinitionLP learningProblem) { //, PsiUp pu, PsiDown pd) { + public Psi(PosNegLP 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-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 09:53:38 UTC (rev 165) @@ -22,6 +22,7 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; /** @@ -40,12 +41,12 @@ ConceptComparator conceptComparator = new ConceptComparator(); - DefinitionLP learningProblem; + PosNegLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> topSet; - public PsiDown(DefinitionLP learningProblem) { + public PsiDown(PosNegLP 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-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 09:53:38 UTC (rev 165) @@ -22,18 +22,19 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; public class PsiUp implements RefinementOperator { ConceptComparator conceptComparator = new ConceptComparator(); - DefinitionLP learningProblem; + PosNegLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> bottomSet; - public PsiUp(DefinitionLP learningProblem) { + public PsiUp(PosNegLP learningProblem) { this.learningProblem = learningProblem; reasoningService = learningProblem.getReasoningService(); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 09:53:38 UTC (rev 165) @@ -25,7 +25,7 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.reasoning.DIGReasonerNew; /** @@ -57,7 +57,7 @@ rs.init(); // create a learning problem and set positive and negative examples - LearningProblemNew lp = cm.learningProblem(DefinitionLPTwoValued.class, rs); + LearningProblemNew lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Set<String> positiveExamples = new TreeSet<String>(); positiveExamples.add("http://example.com/father#stefan"); positiveExamples.add("http://example.com/father#markus"); Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 09:53:38 UTC (rev 165) @@ -19,8 +19,10 @@ */ package org.dllearner.core; +import org.dllearner.core.dl.Concept; + /** - * Marker interface for all learning problems (the "New" at the end of the name + * Base class for all learning problems (the "New" at the end of the name * is temporary for the restructuring process). * * @author Jens Lehmann @@ -34,4 +36,12 @@ this.reasoningService = reasoningService; } + public abstract Score computeScore(Concept concept); + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public ReasoningService getReasoningService() { + return reasoningService; + } + } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -19,75 +19,12 @@ */ package org.dllearner.learningproblems; -import java.util.SortedSet; - -import org.dllearner.core.LearningProblemNew; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; - /** - * The definition learning problem. + * Marker interface for definition learning problems. * * @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(); - +public interface DefinitionLP { + } Deleted: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-03 09:53:38 UTC (rev 165) @@ -1,114 +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.learningproblems; - -import java.util.SortedSet; - -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; - -/** - * @author Jens Lehmann - * - */ -public class DefinitionLPThreeValued extends DefinitionLP { - - public DefinitionLPThreeValued(ReasoningService reasoningService) { - super(reasoningService); - } - - /* (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 - - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - - } - - /* (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(); - } -} Deleted: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-03 09:53:38 UTC (rev 165) @@ -1,274 +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.learningproblems; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.BooleanConfigOption; -import org.dllearner.core.CommonConfigMappings; -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.ConfigOption; -import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.StringSetConfigOption; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.utilities.Helper; - -/** - * 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 SortedSet<Individual> positiveExamples; - private SortedSet<Individual> negativeExamples; - 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", - "positive examples")); - options.add(new StringSetConfigOption("negativeExamples", - "negative examples")); - options.add(new BooleanConfigOption("useRetrievalForClassficiation", - "Specifies whether to use retrieval or instance checks for testing a concept.")); - return options; - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @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(); - } - - /* - * (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() { - 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 - * examples otherwise. - */ - @Override - public int coveredNegativeExamplesOrTooWeak(Concept concept) { - - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - - // the set is constructed piecewise to avoid expensive set - // operations - // on a large number of individuals - for (Individual posExample : positiveExamples) { - if (!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - - // too weak - if (posAsNeg.size() > 0) - return -1; - // number of covered negatives - else - return negAsPos.size(); - } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - // two checks - if (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()) - return -1; - else { - s = reasoningService.instanceCheck(concept, negativeExamples); - return s.size(); - } - // one check - } else { - Set<Individual> s = reasoningService.instanceCheck(concept, posNegExamples); - // test whether all positive examples are covered - if (s.containsAll(positiveExamples)) - return s.size() - positiveExamples.size(); - else - return -1; - } - } else { - // SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - - for (Individual example : positiveExamples) { - if (!reasoningService.instanceCheck(concept, example)) - return -1; - // posAsNeg.add(example); - } - for (Individual example : negativeExamples) { - if (reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - } - - return negAsPos.size(); - } - } - } - - /** - * Computes score of a given concept using the reasoner. Either retrieval or - * instance check are used. For the latter, this method treats - * <code>UseMultiInstanceChecks.TWO_CHECKS</code> as if it were - * <code>UseMultiInstanceChecks.ONE_CHECKS</code> (it does not make much sense - * to implement TWO_CHECKS in this function, because we have to test all - * examples to create a score object anyway). - * - * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks - * @param concept - * The concept to test. - * @return Corresponding Score object. - */ - @Override - public Score computeScore(Concept concept) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - - // piecewise set construction - for (Individual posExample : positiveExamples) { - if (!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for (Individual negExample : negativeExamples) { - if (!posClassified.contains(negExample)) - negAsNeg.add(negExample); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); - // instance checks for classification - } 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) { - SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, - posNegExamples); - SortedSet<Individual> negClassified = Helper.difference(posNegExamples, - posClassified); - posAsPos = Helper.intersection(positiveExamples, posClassified); - posAsNeg = Helper.intersection(positiveExamples, negClassified); - negAsPos = Helper.intersection(negativeExamples, posClassified); - negAsNeg = Helper.intersection(negativeExamples, negClassified); - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, - negAsNeg); - } else { - - for (Individual example : positiveExamples) { - if (reasoningService.instanceCheck(concept, example)) - posAsPos.add(example); - else - posAsNeg.add(example); - } - for (Individual example : negativeExamples) { - if (reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - else - negAsNeg.add(example); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, - negAsNeg); - } - } - } - - @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; - } -} Added: trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +/** + * Marker interface for inclusion learning problems. + * + * @author Jens Lehmann + * + */ +public interface InclusionLP { + +} Copied: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java (from rev 162, trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,230 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.CommonConfigMappings; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; +import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; + +/** + * 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 PosNegDefinitionLP extends PosNegLP implements DefinitionLP { + + public PosNegDefinitionLP(ReasoningService reasoningService) { + super(reasoningService); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "two valued definition learning problem"; + } + + /** + * 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 + * examples otherwise. + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + + if (useRetrievalForClassification) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + + // the set is constructed piecewise to avoid expensive set + // operations + // on a large number of individuals + for (Individual posExample : positiveExamples) { + if (!posClassified.contains(posExample)) + posAsNeg.add(posExample); + } + + // too weak + if (posAsNeg.size() > 0) + return -1; + // number of covered negatives + else + return negAsPos.size(); + } else { + if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + // two checks + if (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()) + return -1; + else { + s = reasoningService.instanceCheck(concept, negativeExamples); + return s.size(); + } + // one check + } else { + Set<Individual> s = reasoningService.instanceCheck(concept, allExamples); + // test whether all positive examples are covered + if (s.containsAll(positiveExamples)) + return s.size() - positiveExamples.size(); + else + return -1; + } + } else { + // SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + SortedSet<Individual> negAsPos = new TreeSet<Individual>(); + + for (Individual example : positiveExamples) { + if (!reasoningService.instanceCheck(concept, example)) + return -1; + // posAsNeg.add(example); + } + for (Individual example : negativeExamples) { + if (reasoningService.instanceCheck(concept, example)) + negAsPos.add(example); + } + + return negAsPos.size(); + } + } + } + + /** + * Computes score of a given concept using the reasoner. Either retrieval or + * instance check are used. For the latter, this method treats + * <code>UseMultiInstanceChecks.TWO_CHECKS</code> as if it were + * <code>UseMultiInstanceChecks.ONE_CHECKS</code> (it does not make much sense + * to implement TWO_CHECKS in this function, because we have to test all + * examples to create a score object anyway). + * + * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks + * @param concept + * The concept to test. + * @return Corresponding Score object. + */ + @Override + public Score computeScore(Concept concept) { + if (useRetrievalForClassification) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + + // piecewise set construction + for (Individual posExample : positiveExamples) { + if (!posClassified.contains(posExample)) + posAsNeg.add(posExample); + } + SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + for (Individual negExample : negativeExamples) { + if (!posClassified.contains(negExample)) + negAsNeg.add(negExample); + } + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); + // instance checks for classification + } 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) { + SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, + allExamples); + SortedSet<Individual> negClassified = Helper.difference(allExamples, + posClassified); + posAsPos = Helper.intersection(positiveExamples, posClassified); + posAsNeg = Helper.intersection(positiveExamples, negClassified); + negAsPos = Helper.intersection(negativeExamples, posClassified); + negAsNeg = Helper.intersection(negativeExamples, negClassified); + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, + negAsNeg); + } else { + + for (Individual example : positiveExamples) { + if (reasoningService.instanceCheck(concept, example)) + posAsPos.add(example); + else + posAsNeg.add(example); + } + for (Individual example : negativeExamples) { + if (reasoningService.instanceCheck(concept, example)) + negAsPos.add(example); + else + negAsNeg.add(example); + } + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, + negAsNeg); + } + } + } + + @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; + } +} Copied: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java (from rev 162, trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,114 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.SortedSet; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; + +/** + * @author Jens Lehmann + * + */ +public class PosNegDefinitionLPStrict extends PosNegLP implements DefinitionLP { + + public PosNegDefinitionLPStrict(ReasoningService reasoningService) { + super(reasoningService); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "three valued definition learning problem"; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + // TODO Auto-generated method stub + + } + + /* (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(); + } +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +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.LearningProblemNew; +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; + +/** + * @author Jens Lehmann + * + */ +public class PosNegInclusionLP extends PosNegLP implements InclusionLP { + + private SortedSet<Individual> positiveExamples; + private SortedSet<Individual> negativeExamples; + private SortedSet<Individual> posNegExamples; + + public PosNegInclusionLP(ReasoningService reasoningService) { + super(reasoningService); + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @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(); + } + + /* + * (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 + + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.PosNegLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.dl.Concept) + */ + @Override + public Score computeScore(Concept concept) { + // TODO Auto-generated method stub + return null; + } + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,132 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.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.LearningProblemNew; +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; + +/** + * @author Jens Lehmann + * + */ +public abstract class PosNegLP extends LearningProblemNew { + + protected SortedSet<Individual> positiveExamples; + protected SortedSet<Individual> negativeExamples; + protected SortedSet<Individual> allExamples; + + 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 PosNegLP(ReasoningService reasoningService) { + super(reasoningService); + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dlle... [truncated message content] |
From: <jen...@us...> - 2007-10-03 10:45:36
|
Revision: 166 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=166&view=rev Author: jenslehmann Date: 2007-10-03 03:45:34 -0700 (Wed, 03 Oct 2007) Log Message: ----------- all parts of DL-Learner moved to the new learning problem structure Modified Paths: -------------- 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/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/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.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/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.List; import java.util.Set; -import org.dllearner.LearningProblem.LearningProblemType; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; @@ -32,7 +31,7 @@ public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; + // public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; public static boolean penalizeNeutralExamples = false; Deleted: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,282 +0,0 @@ -package org.dllearner; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.Config.Refinement; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.Negation; -import org.dllearner.learningproblems.ScoreThreeValued; -import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; -import org.dllearner.reasoning.ReasonerType; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.SortedSetTuple; - -/** - * Der Score-Calculator nimmt Konzepte (= m�gliche L�sungen des Lernproblems) - * entgegen und gibt Score-Objekte zur�ck. - * - * @author jl - * - */ -public class LearningProblem { - - public enum LearningProblemType {POSITIVE_ONLY, TWO_VALUED, THREE_VALUED}; - - private ReasoningService reasoningService; - - private SortedSet<Individual> positiveExamples; - private SortedSet<Individual> negativeExamples; - private SortedSet<Individual> neutralExamples; - // positive and negative examples - private SortedSet<Individual> posNegExamples; - - public LearningProblem(ReasoningService reasoningService, - SortedSet<Individual> positiveExamples, - SortedSet<Individual> negativeExamples) { - this.reasoningService = reasoningService; - this.positiveExamples = positiveExamples; - this.negativeExamples = negativeExamples; - - posNegExamples = Helper.union(positiveExamples, negativeExamples); - - // neutrale Beispiele berechnen (nur bei three valued interessant) - // auch hier aufpassen, dass man die Mengen immer kopiert - neutralExamples = Helper.intersection(reasoningService.getIndividuals(),positiveExamples); - neutralExamples.retainAll(negativeExamples); - - // System.out.println(positiveExamples); - // System.out.println(negativeExamples); - } - - // gibt -1 zurück, falls Konzept too weak; - // ansonsten die negativen Beispiele, die aus Konzept folgen - // wird verwendet für top-down-approach - // TODO: hier sind vielleicht noch Effizienzverbesserungen gegenüber dem reinen berechnen - // mit computeScore() drin [ist bis jetzt noch mehr oder weniger rüberkopiert] - public int coveredNegativeExamplesOrTooWeak(Concept concept) { - if(!Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - throw new RuntimeException("Can use this method only for two valued learning problem."); - - if(Config.useRetrievalForClassification) { - //if(Config.reasonerType == ReasonerType.KAON2 || Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - // die Menge wird schrittweise konstruiert um Operationen mit der potentiell - // großen Menge aller Individuals zu vermeiden - for(Individual posExample : positiveExamples) { - if(!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - - // es werden nicht alle positiven Beispiele auch positiv klassifiziert - if(posAsNeg.size()>0) - return -1; - else - return negAsPos.size(); - //} else - // throw new Error("LP not completely implemented"); - } else { - 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 == 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()) - return -1; - else { - s = reasoningService.instanceCheck(concept, negativeExamples); - return s.size(); - } - // one check - } else { - Set<Individual> s = reasoningService.instanceCheck(concept, posNegExamples); - // test whether all positive examples are covered - if(s.containsAll(positiveExamples)) - return s.size() - positiveExamples.size(); - else - return -1; - } - } - } - - if(Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - for(Individual example : positiveExamples) { - if(!reasoningService.instanceCheck(concept, example)) - posAsNeg.add(example); - } - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - } - - if(posAsNeg.size()>0) - return -1; - else - return negAsPos.size(); - } - } - throw new Error("LP not completely implemented"); - } - - public Score computeScore(Concept concept) { - if(Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - return computeScoreTwoValued(concept); - else - return computeScoreThreeValued(concept); - } - - public Score computeScore(Concept concept, Concept adc) { - if(Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - throw new Error("LP not completely implemented"); - else - return computeScoreThreeValued(concept, adc); - } - - private Score computeScoreTwoValued(Concept concept) { - if(Config.useRetrievalForClassification) { - if(Config.reasonerType == ReasonerType.DIG || Config.reasonerType == ReasonerType.KAON2 || Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - // die Menge wird schrittweise konstruiert um Operationen mit der potentiell - // großen Menge aller Individuals zu vermeiden - for(Individual posExample : positiveExamples) { - if(!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for(Individual negExample : negativeExamples) { - if(!posClassified.contains(negExample)) - negAsNeg.add(negExample); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); - } else - throw new Error("LP not completely implemented"); - // instance checks zur Klassifikation - } else { - if(Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(concept, example)) - posAsPos.add(example); - else - posAsNeg.add(example); - } - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - else - negAsNeg.add(example); - } - return new ScoreTwoValued(concept.getLength(),posAsPos, posAsNeg, negAsPos, negAsNeg); - } else - throw new Error("LP not completely implemented"); - } - } - - private Score computeScoreThreeValued(Concept concept) { - // Anfragen an Reasoner - if(Config.useRetrievalForClassification) { - if(Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSetTuple<Individual> tuple = reasoningService.doubleRetrieval(concept); - // this.defPosSet = tuple.getPosSet(); - // this.defNegSet = tuple.getNegSet(); - SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); - } else if(Config.reasonerType == ReasonerType.KAON2) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); - SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); - neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); - } else - throw new Error("score cannot be computed in this configuration"); - } else { - if(Config.reasonerType == ReasonerType.KAON2) { - if(Config.penalizeNeutralExamples) - throw new Error("It does not make sense to use single instance checks when" + - "neutral examples are penalized. Use Retrievals instead."); - - // TODO: umschreiben in instance checks - SortedSet<Individual> posClassified = new TreeSet<Individual>(); - SortedSet<Individual> negClassified = new TreeSet<Individual>(); - // Beispiele durchgehen - // TODO: Implementierung ist ineffizient, da man hier schon in Klassen wie - // posAsNeut, posAsNeg etc. einteilen k�nnte; so wird das extra in der Score-Klasse - // gemacht; bei wichtigen Benchmarks des 3-wertigen Lernproblems m�sste man das - // umstellen - // pos => pos - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(concept, example)) - posClassified.add(example); - } - // neg => pos - for(Individual example: negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - posClassified.add(example); - } - // pos => neg - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(new Negation(concept), example)) - negClassified.add(example); - } - // neg => neg - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(new Negation(concept), example)) - negClassified.add(example); - } - - SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); - neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); - } else - throw new Error("score cannot be computed in this configuration"); - } - } - - private Score computeScoreThreeValued(Concept concept, Concept adc) { - if(!Config.useRetrievalForClassification && - Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - throw new Error("Computing score for concept with ADC" - + " is currently only supported by retrivals " - + " using the fast retrieval algorithm"); - } else { - // SortedSetTuple tuple = reasoner.doubleRetrieval(concept,adc); - // this.defPosSet = tuple.getPosSet(); - // this.defNegSet = tuple.getNegSet(); - // deriveStatistics(); - } - throw new Error("LP not completely implemented"); - } - - public SortedSet<Individual> getNegativeExamples() { - return negativeExamples; - } - - public SortedSet<Individual> getNeutralExamples() { - return neutralExamples; - } - - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - - public ReasoningService getReasoningService() { - return reasoningService; - } -} Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 10:45:34 UTC (rev 166) @@ -44,6 +44,8 @@ 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.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; @@ -61,6 +63,7 @@ import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -97,7 +100,7 @@ private Reasoner reasoner; private ReasoningService rs; - private LearningProblem learningProblem; + private PosNegLP learningProblem; // es werden jeweils die Dateien mit dem zugehörigen Format abgelegt Map<URL, OntologyFileFormat> importedFiles; Map<File, OntologyFileFormat> exportedFiles; @@ -235,7 +238,8 @@ reasoner = createReasoner(kb, importedFiles); ReasoningService rs = new ReasoningService(reasoner); - learningProblem = new LearningProblem(rs, posExamples, negExamples); + // commented out during changes + // learningProblem = new LearningProblem(rs, posExamples, negExamples); // export function /* @@ -412,7 +416,7 @@ algorithmStartTime = System.nanoTime(); if (Config.algorithm == Algorithm.BRUTE_FORCE) { - LearningAlgorithm la = new BruteForceLearner(learningProblem); + LearningAlgorithmNew la = new BruteForceLearner(learningProblem); la.start(); } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { // new RandomGuesser(learningProblem, 10000, 10); @@ -444,7 +448,7 @@ // implemented)"); // } } - LearningAlgorithm la = new ROLearner(learningProblem); + LearningAlgorithmNew la = new ROLearner(learningProblem); la.start(); // new ROLearner(learningProblem, learningProblem2); } @@ -1293,95 +1297,9 @@ return abox; } - // irgendwelche Sachen testen - @SuppressWarnings("unused") - private void test(LearningProblem learningProblem) { - System.out.println("=== starting test method ==="); - // Concept concept = DLLearner.parseConcept("NOT EXISTS hasChild.NOT - // male"); - // System.out.println("testing: " + concept); - /* - * PsiDown pd = new PsiDown(learningProblem); concept = - * ConceptTransformation.transformToMulti(concept); - * - * Set<Concept> r = pd.refine(concept); System.out.println(r); - */ - /* - * Concept result = - * ConceptTransformation.transformToNegationNormalForm(concept); - * System.out.println(result); - * - */ - - /* - * Concept male = new - * AtomicConcept("http://www.csc.liv.ac.uk/~luigi/ontologies/basicFamily#Male"); - * AtomicRole hasChild = new - * AtomicRole("http://www.csc.liv.ac.uk/~luigi/ontologies/basicFamily#hasChild"); - * Concept exists = new Exists(hasChild, new Top()); MultiConjunction mc = - * new MultiConjunction(); mc.addChild(male); mc.addChild(exists); - * - * SortedSet<String> result = rs.retrieval(mc); for(String s : result) - * System.out.println(s); - * - * SortedSet<String> result2 = Helper.intersection(result, - * learningProblem.getPositiveExamples()); - * - * Score score = learningProblem.computeScore(mc); - * System.out.println("==="); - * System.out.println(score.getCoveredPositives()); - * System.out.println(score.getCoveredNegatives()); - * - * Concept top = new Top(); RhoDown rd = new RhoDown(learningProblem); - * Set<Concept> result3 = rd.refine(top, 3, null); for(Concept c : - * result3) System.out.println(c); - * - * System.out.println(rs.getMoreSpecialConcepts(top)); - * - * Concept container = new - * AtomicConcept("http://www.w3.org/2000/01/rdf-schema#Resource"); - * System.out.println(((DIGReasoner)reasoner).getMoreSpecialConceptsDIG(container)); - */ - - /* - * for(int i=0; i<10; i++) { Program p = - * GPUtilities.createGrowRandomProgram(learningProblem, 3); // - * System.out.println("concept: " + p.getTree()); // - * System.out.println("fitness: " + p.getFitness()); // - * System.out.println("length of concept: " + p.getTree().getLength()); // - * System.out.println(p.getScore()); - * - * System.out.println("##"); boolean ok = GPUtilities.checkProgram(p); // - * if(!ok) System.out.println(p.getTree()); } - * - * System.out.println("==="); // Concept male = new - * AtomicConcept("male"); Concept male = - * rs.getAtomicConceptsList().get(0); // Concept male = null; // - * for(Concept c : rs.getAtomicConcepts()) // male = c; - * GPUtilities.checkTree(male, true); System.out.println(male); - * System.out.println(male.getParent()); - */ - - Concept c = null; - try { - c = KBParser.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - ConceptTransformation.transformToMulti(c); - // Concept cMod = - // ConceptTransformation.transformToNegationNormalForm(c); - Concept cMod = ConceptTransformation.applyEquivalenceRules(c); - System.out.println(c); - System.out.println(cMod); - - System.exit(0); - } - // generiert sibling aus Forte-Daten @SuppressWarnings("unused") - private void test2(LearningProblem learningProblem) { + private void test2(PosNegLP learningProblem) { // Set<AtomicRole> roles = reasoner.getAtomicRoles(); // for(AtomicRole role : roles) { // System.out.println(rs.getRoleMembers(role)); Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,12 +1,18 @@ package org.dllearner.algorithms; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.dllearner.Config; -import org.dllearner.LearningProblem; +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.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -27,7 +33,7 @@ * @author Jens Lehmann * */ -public class BruteForceLearner implements LearningAlgorithm { +public class BruteForceLearner extends LearningAlgorithmNew { LearningProblem learningProblem; @@ -48,10 +54,37 @@ public BruteForceLearner(LearningProblem learningProblem) { this.learningProblem = learningProblem; - - } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(LearningProblem.class); + return problems; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); + options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); + 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() { // FlatABox abox = FlatABox.getInstance(); int maxLength = Config.maxLength; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 10:45:34 UTC (rev 166) @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.ConfigEntry; @@ -30,29 +29,26 @@ import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; -import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.PosNegDefinitionLPStrict; -import org.dllearner.learningproblems.PosNegDefinitionLP; public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private LearningProblemNew learningProblem; + private LearningProblem learningProblem; private int numberOfTrees; private int maxDepth; - public RandomGuesser(LearningProblemNew learningProblem) { + public RandomGuesser(LearningProblem learningProblem) { this.learningProblem = learningProblem; } - public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { - Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); - problems.add(LearningProblemNew.class); + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(LearningProblem.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 10:45:34 UTC (rev 166) @@ -46,18 +46,16 @@ import java.util.Map.Entry; import org.dllearner.Config; -import org.dllearner.LearningProblem; 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.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; @@ -133,8 +131,8 @@ this.learningProblem = learningProblem; } - public static Collection<Class<? extends LearningProblemNew>> supportedLearningAlgorithms() { - Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); + public static Collection<Class<? extends LearningProblem>> supportedLearningAlgorithms() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 10:45:34 UTC (rev 166) @@ -9,7 +9,7 @@ import org.dllearner.Config; import org.dllearner.Main; -import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -57,7 +57,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis) { + private static Score calculateFitness(LearningProblem 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(LearningProblemNew learningProblem, Concept hypothesis, Concept adc) { + private static Score calculateFitness(LearningProblem learningProblem, Concept hypothesis, Concept adc) { Concept extendedHypothesis; if (!Config.returnType.equals("")) { @@ -123,11 +123,11 @@ return score; } - public static Program createProgram(LearningProblemNew learningProblem, Concept mainTree) { + public static Program createProgram(LearningProblem learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); } - private static Program createProgram(LearningProblemNew learningProblem, Concept mainTree, Concept adc) { + private static Program createProgram(LearningProblem learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); } @@ -135,7 +135,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(LearningProblemNew learningProblem, Program p) { + public static Program mutation(LearningProblem learningProblem, Program p) { mutation++; if(Config.GP.adc) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -159,7 +159,7 @@ } } - private static Concept mutation(LearningProblemNew learningProblem, Concept tree, boolean useADC) { + private static Concept mutation(LearningProblem 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) @@ -228,7 +228,7 @@ * @param p2 Second parent. * @return A two-element array containing the offpsring. */ - public static Program[] crossover(LearningProblemNew learningProblem, Program p1, Program p2) { + public static Program[] crossover(LearningProblem learningProblem, Program p1, Program p2) { crossover++; if(Config.GP.adc) { Concept[] pt; @@ -304,7 +304,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(LearningProblemNew learningProblem, Program p) { + public static Program hillClimbing(LearningProblem learningProblem, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -327,7 +327,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(LearningProblemNew learningProblem, Concept node, ScoreThreeValued score) { + private static Concept hillClimbing(LearningProblem 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(); @@ -442,7 +442,7 @@ } } - private static ScoreThreeValued getScore(int conceptLength, LearningProblemNew learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, LearningProblem 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); @@ -479,7 +479,7 @@ return returnMap; } - private static Concept pickTerminalSymbol(LearningProblemNew learningProblem, boolean useADC) { + private static Concept pickTerminalSymbol(LearningProblem learningProblem, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size(); @@ -609,7 +609,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(LearningProblemNew learningProblem, int depth) { + public static Program createFullRandomProgram(LearningProblem learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), @@ -619,7 +619,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false)); } - private static Concept createFullRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { + private static Concept createFullRandomTree(LearningProblem learningProblem, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size(); @@ -670,7 +670,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(LearningProblemNew learningProblem, int depth) { + public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), @@ -680,7 +680,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false)); } - private static Concept createGrowRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { + private static Concept createGrowRandomTree(LearningProblem 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-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 10:45:34 UTC (rev 166) @@ -5,12 +5,9 @@ import java.util.SortedMap; import java.util.TreeMap; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.gp.Program; -import org.dllearner.core.LearningProblemNew; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; @@ -21,7 +20,6 @@ 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.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; @@ -21,7 +20,6 @@ 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.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,6 +1,7 @@ package org.dllearner.algorithms.refinement; import java.text.DecimalFormat; +import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; @@ -10,19 +11,26 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.LearningAlgorithm; +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.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; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; -public class ROLearner implements LearningAlgorithm { +public class ROLearner extends LearningAlgorithmNew { private boolean stop = false; @@ -31,7 +39,7 @@ private ConceptComparator conceptComparator = new ConceptComparator(); DecimalFormat df = new DecimalFormat(); - private LearningProblem learningProblem; + private PosNegLP learningProblem; // private LearningProblem learningProblem2; // Menge von Kandidaten für Refinement @@ -103,7 +111,7 @@ // soll später einen Operator und eine Heuristik entgegennehmen // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { - public ROLearner(LearningProblem learningProblem) { + public ROLearner(PosNegLP learningProblem) { this.learningProblem = learningProblem; // this.learningProblem2 = learningProblem2; operator = new RhoDown(learningProblem); @@ -203,7 +211,36 @@ // start(); } + + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(PosNegDefinitionLP.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 { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + // Kernalgorithmus @SuppressWarnings("unchecked") public void start() { @@ -826,4 +863,6 @@ stop = true; } + + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-03 10:45:34 UTC (rev 166) @@ -30,7 +30,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -46,6 +45,7 @@ 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 +62,7 @@ */ public class RhoDown implements RefinementOperator { - private LearningProblem learningProblem; + private PosNegLP learningProblem; private ReasoningService rs; // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts @@ -91,7 +91,7 @@ // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(LearningProblem learningProblem) { + public RhoDown(PosNegLP learningProblem) { this.learningProblem = learningProblem; rs = learningProblem.getReasoningService(); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 10:45:34 UTC (rev 166) @@ -62,13 +62,13 @@ 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 LearningProblem>> 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 LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { @@ -87,9 +87,9 @@ 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); + learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); - algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblemNew>>>( + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>>( classComparator); // create classes from strings @@ -103,12 +103,12 @@ 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 (LearningProblem.class.isAssignableFrom(component)) + learningProblems.add((Class<? extends LearningProblem>) component); else if (LearningAlgorithmNew.class.isAssignableFrom(component)) { Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>) component; learningAlgorithms.add(learningAlgorithmClass); - Collection<Class<? extends LearningProblemNew>> problems = (Collection<Class<? extends LearningProblemNew>>) invokeStaticMethod( + Collection<Class<? extends LearningProblem>> problems = (Collection<Class<? extends LearningProblem>>) invokeStaticMethod( learningAlgorithmClass, "supportedLearningProblems"); algorithmProblemsMapping.put(learningAlgorithmClass, problems); } @@ -265,7 +265,7 @@ return new ReasoningService(reasonerInstance); } - public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasoningService reasoner) { + public <T extends LearningProblem> 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."); @@ -275,15 +275,15 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblemNew lp) { + public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem 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)) { + Class<? extends LearningProblem> constructorArgument = null; + for (Class<? extends LearningProblem> problemClass : algorithmProblemsMapping.get(la)) { if (problemClass.isAssignableFrom(lp.getClass())) constructorArgument = problemClass; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 10:45:34 UTC (rev 166) @@ -57,7 +57,7 @@ rs.init(); // create a learning problem and set positive and negative examples - LearningProblemNew lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Set<String> positiveExamples = new TreeSet<String>(); positiveExamples.add("http://example.com/father#stefan"); positiveExamples.add("http://example.com/father#markus"); Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-03 10:45:34 UTC (rev 166) @@ -59,8 +59,8 @@ /** * Returns all learning problems supported by this component. */ - public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { - return new LinkedList<Class<? extends LearningProblemNew>>(); + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + return new LinkedList<Class<? extends LearningProblem>>(); } } Copied: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java (from rev 165, trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2007-10-03 10:45:34 UTC (rev 166) @@ -0,0 +1,46 @@ +/** + * 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 org.dllearner.core.dl.Concept; + +/** + * Base class for all learning problems. + * + * @author Jens Lehmann + * + */ +public abstract class LearningProblem extends Component { + + protected ReasoningService reasoningService; + + public LearningProblem(ReasoningService reasoningService) { + this.reasoningService = reasoningService; + } + + public abstract Score computeScore(Concept concept); + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public ReasoningService getReasoningService() { + return reasoningService; + } + +} Deleted: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,47 +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.core; - -import org.dllearner.core.dl.Concept; - -/** - * Base class for all learning problems (the "New" at the end of the name - * is temporary for the restructuring process). - * - * @author Jens Lehmann - * - */ -public abstract class LearningProblemNew extends Component { - - protected ReasoningService reasoningService; - - public LearningProblemNew(ReasoningService reasoningService) { - this.reasoningService = reasoningService; - } - - public abstract Score computeScore(Concept concept); - - // TODO: remove? reasoning service should probably not be accessed via - // learning problem - public ReasoningService getReasoningService() { - return reasoningService; - } - -} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 10:45:34 UTC (rev 166) @@ -211,20 +211,4 @@ } } - @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/learningproblems/PosNegDefinitionLPStrict.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 10:45:34 UTC (rev 166) @@ -19,14 +19,22 @@ */ package org.dllearner.learningproblems; +import java.util.Collection; import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.core.BooleanConfigOption; 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.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.Negation; +import org.dllearner.reasoning.ReasonerType; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.SortedSetTuple; /** * @author Jens Lehmann @@ -34,6 +42,9 @@ */ public class PosNegDefinitionLPStrict extends PosNegLP implements DefinitionLP { + private SortedSet<Individual> neutralExamples; + private boolean penaliseNeutralExamples = false; + public PosNegDefinitionLPStrict(ReasoningService reasoningService) { super(reasoningService); } @@ -45,22 +56,37 @@ return "three valued definition learning problem"; } - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = PosNegLP.createConfigOptions(); + options.add(new BooleanConfigOption("penaliseNeutralExamples", "if set to true neutral examples are penalised")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override - public void init() { - // TODO Auto-generated method stub - + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + super.applyConfigEntry(entry); + String name = entry.getOptionName(); + if(name.equals("penaliseNeutralExamples")) + penaliseNeutralExamples = (Boolean) entry.getValue(); } - + /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + * @see org.dllearner.core.Component#init() */ @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - + public void init() { + super.init(); + // compute neutral examples, i.e. those which are neither positive + // nor negative (we have to take care to copy sets instead of + // modifying them) + neutralExamples = Helper.intersection(reasoningService.getIndividuals(),positiveExamples); + neutralExamples.retainAll(negativeExamples); } /* (non-Javadoc) @@ -68,8 +94,62 @@ */ @Override public Score computeScore(Concept concept) { - // TODO Auto-generated method stub - return null; + if(useRetrievalForClassification) { + if(reasoningService.getReasonerType() == ReasonerType.FAST_RETRIEVAL) { + SortedSetTuple<Individual> tuple = reasoningService.doubleRetrieval(concept); + // this.defPosSet = tuple.getPosSet(); + // this.defNegSet = tuple.getNegSet(); + SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); + return new ScoreThreeValued(concept.getLength(),tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + } else if(reasoningService.getReasonerType() == ReasonerType.KAON2) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); + SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); + neutClassified.retainAll(negClassified); + return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + } else + throw new Error("score cannot be computed in this configuration"); + } else { + if(reasoningService.getReasonerType() == ReasonerType.KAON2) { + if(penaliseNeutralExamples) + throw new Error("It does not make sense to use single instance checks when" + + "neutral examples are penalized. Use Retrievals instead."); + + // TODO: umschreiben in instance checks + SortedSet<Individual> posClassified = new TreeSet<Individual>(); + SortedSet<Individual> negClassified = new TreeSet<Individual>(); + // Beispiele durchgehen + // TODO: Implementierung ist ineffizient, da man hier schon in Klassen wie + // posAsNeut, posAsNeg etc. einteilen k�nnte; so wird das extra in der Score-Klasse + // gemacht; bei wichtigen Benchmarks des 3-wertigen Lernproblems m�sste man das + // umstellen + // pos => pos + for(Individual example : positiveExamples) { + if(reasoningService.instanceCheck(concept, example)) + posClassified.add(example); + } + // neg => pos + for(Individual example: negativeExamples) { + if(reasoningService.instanceCheck(concept, example)) + posClassified.add(example); + } + // pos => neg + for(Individual example : positiveExamples) { + if(reasoningService.instanceCheck(new Negation(concept), example)) + negClassified.add(example); + } + // neg => neg + for(Individual example : negativeExamples) { + if(reasoningService.instanceCheck(new Negation(concept), example)) + negClassified.add(example); + } + + SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); + neutClassified.retainAll(negClassified); + return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + } else + throw new Error("score cannot be computed in this configuration"); + } } /* (non-Javadoc) @@ -77,38 +157,10 @@ */ @Override public int coveredNegativeExamplesOrTooWeak(Concept concept) { - // TODO Auto-generated method stub - return 0; + throw new UnsupportedOperationException("Method not implemented for three valued definition learning problem."); } - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#getNegativeExamples() - */ - @Override - public SortedSet<Individual> getNegativeExamples() { - // TODO Auto-generated method stub - return null; - } - - /* (n... [truncated message content] |
From: <jen...@us...> - 2007-10-03 07:46:56
|
Revision: 164 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=164&view=rev Author: jenslehmann Date: 2007-10-03 00:46:54 -0700 (Wed, 03 Oct 2007) Log Message: ----------- move from JJTree to standard JavaCC parsing completed (this is done because JJTree features are not needed anymore) Added Paths: ----------- trunk/src/dl-learner/org/dllearner/parser/ParseException.java trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java trunk/src/dl-learner/org/dllearner/parser/Token.java trunk/src/dl-learner/org/dllearner/parser/TokenMgrError.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/parser/kb.jj Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/parser/confttest.jj trunk/src/dl-learner/org/dllearner/parser/kbtest.jj Added: trunk/src/dl-learner/org/dllearner/parser/ParseException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ParseException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/ParseException.java 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,192 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ +package org.dllearner.parser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public @SuppressWarnings("all") class ParseException extends Exception { + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. The boolean + * flag "specialConstructor" is also set to true to indicate that + * this constructor was used to create this object. + * This constructor calls its super class with the empty string + * to force the "toString" method of parent class "Throwable" to + * print the error message in the form: + * ParseException: <result of getMessage> + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(""); + specialConstructor = true; + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + specialConstructor = false; + } + + public ParseException(String message) { + super(message); + specialConstructor = false; + } + + /** + * This variable determines which constructor was used to create + * this object and thereby affects the semantics of the + * "getMessage" method (see below). + */ + protected boolean specialConstructor; + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * This method has the standard behavior when this object has been + * created using the standard constructors. Otherwise, it uses + * "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser), then this method is called during the printing + * of the final stack trace, and hence the correct error message + * gets displayed. + */ + public String getMessage() { + if (!specialConstructor) { + return super.getMessage(); + } + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += add_escapes(tok.image); + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + protected String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} Added: trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,439 @@ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ +package org.dllearner.parser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public @SuppressWarnings("all") class SimpleCharStream +{ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, + bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, + available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + public int getEndLine() { + return bufline[bufpos]; + } + + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + public int getBeginLine() { + return bufline[tokenBegin]; + } + + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public SimpleCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + public SimpleCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && + bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} Added: trunk/src/dl-learner/org/dllearner/parser/Token.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/Token.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/Token.java 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,81 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ +package org.dllearner.parser; + +/** + * Describes the input token stream. + */ + +public @SuppressWarnings("all") class Token { + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** + * beginLine and beginColumn describe the position of the first character + * of this token; endLine and endColumn describe the position of the + * last character of this token. + */ + public int beginLine, beginColumn, endLine, endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simlpy add something like : + * + * case MyParserConstants.ID : return new IDToken(); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use it in your lexical actions. + */ + public static final Token newToken(int ofKind) + { + switch(ofKind) + { + default : return new Token(); + } + } + +} Added: trunk/src/dl-learner/org/dllearner/parser/TokenMgrError.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/TokenMgrError.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/TokenMgrError.java 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,133 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ +package org.dllearner.parser; + +public @SuppressWarnings("all") class TokenMgrError extends Error +{ + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + public TokenMgrError() { + } + + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} Copied: trunk/src/dl-learner/org/dllearner/parser/conf.jj (from rev 163, trunk/src/dl-learner/org/dllearner/parser/confttest.jj) =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,386 @@ +/** + * 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/>. + * + */ + +/** + * Conf file parser. + */ + +options { + JDK_VERSION = "1.5"; + STATIC = false; +} + +PARSER_BEGIN(ConfParser) +package org.dllearner.parser; + +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.TreeMap; +import java.util.Set; +import java.util.HashSet; +import java.util.SortedSet; +import java.util.TreeSet; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; + +import org.dllearner.Main; +import org.dllearner.Info; + +import org.dllearner.core.dl.*; +import org.dllearner.ConfigurationOption; +import org.dllearner.utilities.*; + +public class ConfParser { + + private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); + private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + + // Konfigurationsoptionen + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + + // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen + // Argumenten aufgerufen werden) + // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); + // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe + // werden in einer Liste gespeichert + private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // => irgendwie Funktionsname + Argumente speichern + // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element + // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante + + // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es + // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal + // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit + // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser + // private static boolean constructorCalled = false; + + // Wissensbasis + // private KB kb = new KB(); + // public static final String internalNamespace = "http://localhost/foo#"; + + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } + + public SortedSet<Individual> getNegativeExamples() { + return negativeExamples; + } + + public List<ConfigurationOption> getConfOptions() { + return confOptions; + } + + public List<List<String>> getFunctionCalls() { + return functionCalls; + } + + /* + private static void addFunctionCall(String functionName, String argument) { + if(functionCalls.containsKey(functionName)) { + functionCalls.get(functionName).add(argument); + } else { + Set<String> newFunction = new TreeSet<String>(); + newFunction.add(argument); + functionCalls.put(functionName,newFunction); + } + } + */ + + + /* + public static SimpleNode parseString(String str) throws ParseException { + StringReader sr = new StringReader(str); + DLLearner learner = new DLLearner(sr); + SimpleNode n = learner.Start(); + return n; + } + */ + + public static ConfParser parseFile(String filename) { + ConfParser learner = null; + try { + learner = new ConfParser(new FileInputStream(filename)); + learner.Start(); + } catch(FileNotFoundException e) { + e.printStackTrace(); + } catch(ParseException e) { + e.printStackTrace(); + } + return learner; + } + + public static void main(String args[]) { + + if(args.length==0) { + System.out.println("Please specify an input file."); + System.exit(0); + } + + System.out.println("Starting DL-Learner (Build " + Info.build + ")"); + // System.out.println(args); + + // System.out.println(args[0]); + // System.out.println(args[1]); + // System.out.println(args.length); + + File f = new File(args[args.length-1]); + String baseDir = ""; + + System.out.print("Parsing " + f.getName() + " ... "); + long parseStartTime = System.currentTimeMillis(); + + // SimpleNode n = null; + ConfParser learner = null; + try { + learner = new ConfParser(new FileInputStream(args[args.length-1])); + baseDir = f.getParentFile().getPath(); + } catch(IOException e) { + System.err.println(e); + System.exit(0); + } + try { + learner.Start(); + // n.dump(""); + // System.out.println("Thank you."); + } catch (Exception e) { + System.out.println("\nParse exception occurred. Please follow the advise given below."); + System.out.println(e.getMessage()); + e.printStackTrace(); + System.exit(0); + } + + long parseDuration = System.currentTimeMillis() - parseStartTime; + System.out.println("OK (" + parseDuration + " ms)"); + + boolean queryMode = false; + // solution test mode wird nicht unbedingt gebraucht, da man die covers + // gleich standardmäßig beim query mit anzeigen kann + // boolean solutionTestMode = false; + + if(args.length>1 && args[0].equals("-q")) + queryMode = true; + + //if(args.length>1 && args[0].equals("-qt")) { + // queryMode = true; + // solutionTestMode = true; + //} + + // new Main(n, baseDir, queryMode); + // Parser erstmal Standalone testen + // n.dump(""); + + // neuer Aufruf des Hauptprogramms + // TODO: remove (in the future, the parser will be called from whatever method + // needs it, instead of starting the learning process itself) + // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); + } +} +PARSER_END(ConfParser) + +SKIP : +{ + " " +| "\t" +| "\n" +| "\r" +| <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> +| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +} + +TOKEN : +{ + < COMMAND_END: "." > + | < CONF_END: ";" > + | < POS_EX: "+" > + | < NEG_EX: "-" > + | < ID: ["a"-"z"] (["_","a"-"z","A"-"Z","0"-"9"])* > + | < NUMBER: (["1"-"9"] (["0"-"9"])* | "0") > + | < DOUBLE: (["1"-"9"] (["0"-"9"])* | "0") "." (["0"-"9"])* > + | <TOP: "TOP" > + | <BOTTOM: "BOTTOM" > + | <AND: "AND" > + | <OR: "OR" > + | <EXISTS: "EXISTS" | "SOME" > + | <ALL: "ALL" | "FORALL" > + | <NOT: "NEG" | "NOT" > + | <GE: ">=" > + | <LE: "<=" > + | <STRING: "\"" (~["\"","\\","\n","\r"])* "\""> +} + +void Start() : +{ + ConceptAssertion conceptAssertion; + RoleAssertion roleAssertion; + RBoxAxiom rBoxAxiom; + Equality equality; + Inclusion inclusion; + ConfigurationOption confOption; +} +{ + ( // 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() + { confOptions.add(confOption); } + | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() + // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar + | LOOKAHEAD(<POS_EX>) PosExample() + | LOOKAHEAD(<NEG_EX>) NegExample() + )* + <EOF> +} + +ConfigurationOption ConfOption() : +{ + boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; + String option="", subOption="", value="", tmp=""; + int number = 0; + double numberDouble = 0; + ConfigurationOption confOption; + Set<String> values = new HashSet<String>(); +} +{ + option=Id() [ "." subOption=Id() {containsSubOption=true;} ] + "=" ( value=Id() + | value=String() + | number=Integer() {isNumeric=true;} + | numberDouble=Double() {isNumeric=true; isDouble=true;} + | LOOKAHEAD("{" "}") "{" "}" {isSet=true;} // leere Menge + | "{" ( LOOKAHEAD(2) ( tmp=String() | tmp=Id() ) {values.add(tmp);} "," )* + (tmp=String() | tmp=Id()) {values.add(tmp);} "}" {isSet=true;} + // eine Liste von ein oder mehr Elementen in Mengenschreibweise + ) <CONF_END> + { + if(containsSubOption) { + if(isNumeric) + if(isDouble) + confOption = new ConfigurationOption(option,subOption,numberDouble); + else + confOption = new ConfigurationOption(option,subOption,number); + else + if(isSet) + confOption = new ConfigurationOption(option,subOption,values); + else + confOption = new ConfigurationOption(option,subOption,value); + } else { + if(isNumeric) + if(isDouble) + confOption = new ConfigurationOption(option,numberDouble); + else + confOption = new ConfigurationOption(option,number); + else + if(isSet) + confOption = new ConfigurationOption(option,values); + else + confOption = new ConfigurationOption(option,value); + } + return confOption; + // confOptions.add(confOption); + } +} + +void FunctionCall() : +{ + String s, s1, s2; + List<String> list = new LinkedList<String>(); +} +{ + s1=Id() "(" s2=String() { list.add(s1); list.add(s2); } + ("," s=String() { list.add(s); } )* ")" <CONF_END> + { functionCalls.add(list); } +} + +void PosExample() : { Individual i; } +{ + <POS_EX> i=Individual() + { positiveExamples.add(i); } +} + +void NegExample() : { Individual i; } +{ + <NEG_EX> i=Individual() + { negativeExamples.add(i); } +} + +Individual Individual() : +{ + String name; +} +{ + (name=Id() | name=String()) + { + return new Individual(KBParser.getInternalURI(name)); + } +} + +String Id() : +{ + Token t; +} +{ + t=<ID> + { + return t.image; + } +} + +double Double() : +{ + Token t; +} +{ + t=<DOUBLE> + { + return new Double(t.image); + } +} + +int Integer() : +{ + Token t; +} +{ + t=<NUMBER> + { + return new Integer(t.image); + } +} + +String String() : +{ + Token t; + String s; +} +{ + t=<STRING> + { + // enclosing "" are removed + s = t.image; + s = s.substring(1, s.length() - 1); + return s; + } +} Deleted: trunk/src/dl-learner/org/dllearner/parser/confttest.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/confttest.jj 2007-10-03 07:41:53 UTC (rev 163) +++ trunk/src/dl-learner/org/dllearner/parser/confttest.jj 2007-10-03 07:46:54 UTC (rev 164) @@ -1,386 +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/>. - * - */ - -/** - * Conf file parser. - */ - -options { - JDK_VERSION = "1.5"; - STATIC = false; -} - -PARSER_BEGIN(ConfParser) -package org.dllearner.parser; - -import java.util.List; -import java.util.LinkedList; -import java.util.Map; -import java.util.TreeMap; -import java.util.Set; -import java.util.HashSet; -import java.util.SortedSet; -import java.util.TreeSet; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.StringReader; - -import org.dllearner.Main; -import org.dllearner.Info; - -import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; -import org.dllearner.utilities.*; - -public class ConfParser { - - private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); - private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - - // Konfigurationsoptionen - private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); - - // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen - // Argumenten aufgerufen werden) - // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); - // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe - // werden in einer Liste gespeichert - private List<List<String>> functionCalls = new LinkedList<List<String>>(); - // => irgendwie Funktionsname + Argumente speichern - // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element - // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante - - // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es - // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal - // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit - // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - // private static boolean constructorCalled = false; - - // Wissensbasis - // private KB kb = new KB(); - // public static final String internalNamespace = "http://localhost/foo#"; - - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - - public SortedSet<Individual> getNegativeExamples() { - return negativeExamples; - } - - public List<ConfigurationOption> getConfOptions() { - return confOptions; - } - - public List<List<String>> getFunctionCalls() { - return functionCalls; - } - - /* - private static void addFunctionCall(String functionName, String argument) { - if(functionCalls.containsKey(functionName)) { - functionCalls.get(functionName).add(argument); - } else { - Set<String> newFunction = new TreeSet<String>(); - newFunction.add(argument); - functionCalls.put(functionName,newFunction); - } - } - */ - - - /* - public static SimpleNode parseString(String str) throws ParseException { - StringReader sr = new StringReader(str); - DLLearner learner = new DLLearner(sr); - SimpleNode n = learner.Start(); - return n; - } - */ - - public static ConfParser parseFile(String filename) { - ConfParser learner = null; - try { - learner = new ConfParser(new FileInputStream(filename)); - learner.Start(); - } catch(FileNotFoundException e) { - e.printStackTrace(); - } catch(ParseException e) { - e.printStackTrace(); - } - return learner; - } - - public static void main(String args[]) { - - if(args.length==0) { - System.out.println("Please specify an input file."); - System.exit(0); - } - - System.out.println("Starting DL-Learner (Build " + Info.build + ")"); - // System.out.println(args); - - // System.out.println(args[0]); - // System.out.println(args[1]); - // System.out.println(args.length); - - File f = new File(args[args.length-1]); - String baseDir = ""; - - System.out.print("Parsing " + f.getName() + " ... "); - long parseStartTime = System.currentTimeMillis(); - - // SimpleNode n = null; - ConfParser learner = null; - try { - learner = new ConfParser(new FileInputStream(args[args.length-1])); - baseDir = f.getParentFile().getPath(); - } catch(IOException e) { - System.err.println(e); - System.exit(0); - } - try { - learner.Start(); - // n.dump(""); - // System.out.println("Thank you."); - } catch (Exception e) { - System.out.println("\nParse exception occurred. Please follow the advise given below."); - System.out.println(e.getMessage()); - e.printStackTrace(); - System.exit(0); - } - - long parseDuration = System.currentTimeMillis() - parseStartTime; - System.out.println("OK (" + parseDuration + " ms)"); - - boolean queryMode = false; - // solution test mode wird nicht unbedingt gebraucht, da man die covers - // gleich standardmäßig beim query mit anzeigen kann - // boolean solutionTestMode = false; - - if(args.length>1 && args[0].equals("-q")) - queryMode = true; - - //if(args.length>1 && args[0].equals("-qt")) { - // queryMode = true; - // solutionTestMode = true; - //} - - // new Main(n, baseDir, queryMode); - // Parser erstmal Standalone testen - // n.dump(""); - - // neuer Aufruf des Hauptprogramms - // TODO: remove (in the future, the parser will be called from whatever method - // needs it, instead of starting the learning process itself) - // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); - } -} -PARSER_END(ConfParser) - -SKIP : -{ - " " -| "\t" -| "\n" -| "\r" -| <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> -| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> -| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> -} - -TOKEN : -{ - < COMMAND_END: "." > - | < CONF_END: ";" > - | < POS_EX: "+" > - | < NEG_EX: "-" > - | < ID: ["a"-"z"] (["_","a"-"z","A"-"Z","0"-"9"])* > - | < NUMBER: (["1"-"9"] (["0"-"9"])* | "0") > - | < DOUBLE: (["1"-"9"] (["0"-"9"])* | "0") "." (["0"-"9"])* > - | <TOP: "TOP" > - | <BOTTOM: "BOTTOM" > - | <AND: "AND" > - | <OR: "OR" > - | <EXISTS: "EXISTS" | "SOME" > - | <ALL: "ALL" | "FORALL" > - | <NOT: "NEG" | "NOT" > - | <GE: ">=" > - | <LE: "<=" > - | <STRING: "\"" (~["\"","\\","\n","\r"])* "\""> -} - -void Start() : -{ - ConceptAssertion conceptAssertion; - RoleAssertion roleAssertion; - RBoxAxiom rBoxAxiom; - Equality equality; - Inclusion inclusion; - ConfigurationOption confOption; -} -{ - ( // 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() - { confOptions.add(confOption); } - | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() - // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar - | LOOKAHEAD(<POS_EX>) PosExample() - | LOOKAHEAD(<NEG_EX>) NegExample() - )* - <EOF> -} - -ConfigurationOption ConfOption() : -{ - boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; - String option="", subOption="", value="", tmp=""; - int number = 0; - double numberDouble = 0; - ConfigurationOption confOption; - Set<String> values = new HashSet<String>(); -} -{ - option=Id() [ "." subOption=Id() {containsSubOption=true;} ] - "=" ( value=Id() - | value=String() - | number=Integer() {isNumeric=true;} - | numberDouble=Double() {isNumeric=true; isDouble=true;} - | LOOKAHEAD("{" "}") "{" "}" {isSet=true;} // leere Menge - | "{" ( LOOKAHEAD(2) ( tmp=String() | tmp=Id() ) {values.add(tmp);} "," )* - (tmp=String() | tmp=Id()) {values.add(tmp);} "}" {isSet=true;} - // eine Liste von ein oder mehr Elementen in Mengenschreibweise - ) <CONF_END> - { - if(containsSubOption) { - if(isNumeric) - if(isDouble) - confOption = new ConfigurationOption(option,subOption,numberDouble); - else - confOption = new ConfigurationOption(option,subOption,number); - else - if(isSet) - confOption = new ConfigurationOption(option,subOption,values); - else - confOption = new ConfigurationOption(option,subOption,value); - } else { - if(isNumeric) - if(isDouble) - confOption = new ConfigurationOption(option,numberDouble); - else - confOption = new ConfigurationOption(option,number); - else - if(isSet) - confOption = new ConfigurationOption(option,values); - else - confOption = new ConfigurationOption(option,value); - } - return confOption; - // confOptions.add(confOption); - } -} - -void FunctionCall() : -{ - String s, s1, s2; - List<String> list = new LinkedList<String>(); -} -{ - s1=Id() "(" s2=String() { list.add(s1); list.add(s2); } - ("," s=String() { list.add(s); } )* ")" <CONF_END> - { functionCalls.add(list); } -} - -void PosExample() : { Individual i; } -{ - <POS_EX> i=Individual() - { positiveExamples.add(i); } -} - -void NegExample() : { Individual i; } -{ - <NEG_EX> i=Individual() - { negativeExamples.add(i); } -} - -Individual Individual() : -{ - String name; -} -{ - (name=Id() | name=String()) - { - return new Individual(KBParser.getInternalURI(name)); - } -} - -String Id() : -{ - Token t; -} -{ - t=<ID> - { - return t.image; - } -} - -double Double() : -{ - Token t; -} -{ - t=<DOUBLE> - { - return new Double(t.image); - } -} - -int Integer() : -{ - Token t; -} -{ - t=<NUMBER> - { - return new Integer(t.image); - } -} - -String String() : -{ - Token t; - String s; -} -{ - t=<STRING> - { - // enclosing "" are removed - s = t.image; - s = s.substring(1, s.length() - 1); - return s; - } -} Copied: trunk/src/dl-learner/org/dllearner/parser/kb.jj (from rev 163, trunk/src/dl-learner/org/dllearner/parser/kbtest.jj) =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2007-10-03 07:46:54 UTC (rev 164) @@ -0,0 +1,326 @@ +/** + * 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/>. + * + */ + +/** + * KB file parser. + */ + +options { + JDK_VERSION = "1.5"; + STATIC = false; +} + +PARSER_BEGIN(KBParser) +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; + +public class KBParser { + + public static final String internalNamespace = "http://localhost/foo#"; + + // method to give all internal stuff an URI (not necessary for DLs, but for OWL ontologies + // and it should be possible to represent the internal KB as OWL ontology) + public static String getInternalURI(String name) { + if(name.startsWith("http://")) + return name; + else + return internalNamespace + name; + } + + public static Concept parseConcept(String string) throws ParseException { + KBParser parser = new KBParser(new StringReader(string)); + return parser.Concept(); + } + + public static KB parseKBFile(File file) throws FileNotFoundException, ParseException { + KBParser parser = new KBParser(new FileInputStream(file)); + return parser.KB(); + } + +} +PARSER_END(KBParser) + +SKIP : +{ + " " +| "\t" +| "\n" +| "\r" +| <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> +| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +} + +TOKEN : +{ + < COMMAND_END: "." > + | < ID: ["a"-"z"] (["_","a"-"z","A"-"Z","0"-"9"])* > + | < NUMBER: (["1"-"9"] (["0"-"9"])* | "0") > + | < DOUBLE: (["1"-"9"] (["0"-"9"])* | "0") "." (["0"-"9"])* > + | < TOP: "TOP" > + | < BOTTOM: "BOTTOM" > + | < AND: "AND" > + | < OR: "OR" > + | < EXISTS: "EXISTS" | "SOME" > + | < ALL: "ALL" | "FORALL" > + | < NOT: "NEG" | "NOT" > + | < GE: ">=" > + | < LE: "<=" > + | < STRING: "\"" (~["\"","\\","\n","\r"])* "\""> +} + +KB KB() : +{ + ConceptAssertion conceptAssertion; + RoleAssertion roleAssertion; + RBoxAxiom rBoxAxiom; + Equality equality; + Inclusion inclusion; + KB kb = new KB(); +} +{ + ( LOOKAHEAD(Concept() "(" Individual() ")" <COMMAND_END>) conceptAssertion=ABoxConcept() + { kb.addABoxAxiom(conceptAssertion); } + | LOOKAHEAD([Not()] AtomicRole() "(" Individual() ",") roleAssertion = ABoxRole() + { kb.addABoxAxiom(roleAssertion); } + | rBoxAxiom = Transitive() + { kb.addRBoxAxiom(rBoxAxiom); } + | rBoxAxiom = Functional() + { kb.addRBoxAxiom(rBoxAxiom); } + | rBoxAxiom = Symmetric() + { kb.addRBoxAxiom(rBoxAxiom); } + | rBoxAxiom = Inverse() + { kb.addRBoxAxiom(rBoxAxiom); } + | rBoxAxiom = Subrole() + { kb.addRBoxAxiom(rBoxAxiom); } + // da Konfigurationsoptionen ausgeschlossen sind, reicht es bis zum "=" zu suchen + | LOOKAHEAD(Concept() "=") equality = TBoxEquiv() + { kb.addTBoxAxiom(equality); } + | LOOKAHEAD(Concept() ("SUBCLASSOF" | "SUB" )) inclusion = TBoxSub() + { kb.addTBoxAxiom(inclusion); } + )* + <EOF> + { return kb; } +} + +ConceptAssertion ABoxConcept() : {Concept c; Individual i;} +{ + c=Concept() "(" i=Individual() ")" <COMMAND_END> + { return new ConceptAssertion(c,i); } +} + +RoleAssertion ABoxRole() : +{ + boolean isNegated=false; + AtomicRole ar; + Individual i1,i2; +} +{ + [Not() {isNegated=true;}] ar=AtomicRole() "(" i1=Individual() "," i2=Individual() ")" <COMMAND_END> + { + if(isNegated) + throw new Error("negated role assertions not supported yet"); + else + return new RoleAssertion(ar,i1,i2); + } +} + +TransitiveRoleAxiom Transitive() : {AtomicRole ar;} +{ + "Transitive" "(" ar=AtomicRole() ")" <COMMAND_END> + { return new TransitiveRoleAxiom(ar); } +} + +FunctionalRoleAxiom Functional() : {AtomicRole ar;} +{ + "Functional" "(" ar=AtomicRole() ")" <COMMAND_END> + { return new FunctionalRoleAxiom(ar); } + +} + +SymmetricRoleAxiom Symmetric() : {AtomicRole ar;} +{ + "Symmetric" "(" ar=AtomicRole() ")" <COMMAND_END> + { return new SymmetricRoleAxiom(ar); } +} + +InverseRoleAxiom Inverse() : {AtomicRole ar1,ar2;} +{ + "Inverse" "(" ar1=AtomicRole() "," ar2=AtomicRole() ")" <COMMAND_END> + { return new InverseRoleAxiom(ar1,ar2); } +} + +SubRoleAxiom Subrole() : {AtomicRole ar1,ar2;} +{ + "Subrole" "(" ar1=AtomicRole() "," ar2=AtomicRole() ")" <COMMAND_END> + { return new SubRoleAxiom(ar1,ar2);} +} + +Equality TBoxEquiv() : {Concept c1,c2;} +{ + c1=Concept() "=" c2=Concept() <COMMAND_END> + { return new Equality(c1,c2); } +} + +Inclusion TBoxSub() : {Concept c1,c2;} +{ + c1=Concept() ("SUBCLASSOF" | "SUB" | "SUBCONCEPTOF") c2=Concept() <COMMAND_END> + { return new Inclusion(c1,c2);} +} + +Concept Concept() : +{ + Concept c,c1,c2; + AtomicConcept ac; + AtomicRole ar; + String s; + int i; +} +{ + Top() {return new Top();} + | Bottom() {return new Bottom();} + | ac = AtomicConcept() {return ac;} + // | s=Id() {return new AtomicConcept(s);} + // | s=String() {return new AtomicConcept(s);} + // Parser geht bis zum n�chsten AND oder OR + | LOOKAHEAD( "(" Concept() And()) "(" c1=Concept() And() c2=Concept() ")" + {return new Conjunction(c1,c2);} + | LOOKAHEAD( "(" Concept() Or()) "(" c1=Concept() Or() c2=Concept() ")" + {return new Disjunction(c1,c2);} + // EXISTS oder ALL reicht aus um richtigen Zweig zu w�hlen + // | Exists() s=Id() "." c=Concept() + // {return new Exists(new AtomicRole(s),c); } + | Exists() ar=AtomicRole() "." c=Concept() + {return new Exists(ar,c); } + // | All() s=Id() "." c=Concept() + // {return new All(new AtomicRole(s),c); } + | All() ar=AtomicRole() "." c=Concept() + {return new All(ar,c); } + | Not() c=Concept() + {return new Negation(c); } + // | GE() i=Integer() s=Id() "." c=Concept() + // {return new GreaterEqual(i,new AtomicRole(s),c);} + | GE() i=Integer() ar=AtomicRole() "." c=Concept() + {return new GreaterEqual(i,ar,c);} + // | LE() i=Integer() s=Id() "." c=Concept() + // {return new LessEqual(i,new AtomicRole(s),c);} + | LE() i=Integer() ar=AtomicRole() "." c=Concept() + {return new LessEqual(i,ar,c);} +} + +void Or() : {} { <OR> } +void And() : {} { <AND> } +void Top() : {} { <TOP> } +void Bottom() : {} { <BOTTOM> } +void Exists() : {} { <EXISTS> } +void All() : {} { <ALL> } +void Not() : {} { <NOT> } +void GE() : {} { <GE> } +void LE() : {} { <LE> } + +AtomicConcept AtomicConcept() : +{ + String name; +} +{ + (name=Id() | name=String()) + { + return new AtomicConcept(getInternalURI(name)); + } +} + +AtomicRole AtomicRole() : +{ + String name; +} +{ + (name=Id() | name=String()) + { + return new AtomicRole(getInternalURI(name)); + } +} + +Individual Individual() : +{ + String name; +} +{ + (name=Id() | name=String()) + { + return new Individual(getInternalURI(name)); + } +} + +String Id() : +{ + Token t; +} +{ + t=<ID> + { + // jjtThis.setId(t.image); + return t.image; + } +} + +double Double() : +{ + Token t; +} +{ + t=<DOUBLE> + { + return new Double(t.image); + } +} + +int Integer() : +{ + Token t; +} +{ + t=<NUMBER> + { + // jjtThis.setId(t.image); + // muss noch in Integer umgewandelt werden + return new Integer(t.image); + } +} + +String String() : +{ + Token t; + String s; +} +{ + t=<STRING> + { + // jjtThis.setId(t.image); + // es werden sofort die Anfuehrungszeichen abgeschnitten + s = t.image; + s = s.substring(1, s.length() - 1); + return s; + } +} \ No newline at end of file Deleted: trunk/src/dl-learner/org/dllearner/parser/kbtest.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kbtest.jj 2007-10-03 07:41:53 UTC (rev 163) +++ trunk/src/dl-learner/org/dllearner/parser/kbtest.jj 2007-10-03 07:46:54 UTC (rev 164) @@ -1,326 +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/>. - * - */ - -/** - * KB file parser. - */ - -options { - JDK_VERSION = "1.5"; - STATIC = false; -} - -PARSER_BEGIN(KBParser) -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; - -public class KBParser { - - public static final String internalNamespace = "http://localhost/foo#"; - - // method to give all internal stuff an URI (not necessary for DLs, but for OWL ontologies - // and it should be possible to represent the internal KB as OWL ontology) - public static String getInternalURI(String name) { - if(name.startsWith("http://")) - return name; - else - return internalNamespace + name; - } - - public static Concept parseConcept(String string) throws ParseException { - KBParser parser = new KBParser(new StringReader(string)); - return parser.Concept(); - } - - public static KB parseKBFile(File file) throws FileNotFoundException, ParseException { - KBParser parser = new KBParser(new FileInputStream(file)); - return parser.KB(); - } - -} -PARSER_END(KBParser) - -SKIP : -{ - " " -| "\t" -| "\n" -| "\r" -| <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> -| <FORMAL_COMMENT: "... [truncated message content] |
From: <jen...@us...> - 2007-10-03 07:41:56
|
Revision: 163 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=163&view=rev Author: jenslehmann Date: 2007-10-03 00:41:53 -0700 (Wed, 03 Oct 2007) Log Message: ----------- further parser changes Modified Paths: -------------- 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/KBParser.java trunk/src/dl-learner/org/dllearner/parser/KBParserConstants.java trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/parser/confttest.jj trunk/src/dl-learner/org/dllearner/parser/kbtest.jj Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/parser/ConfParserTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/JJTConfParserState.java trunk/src/dl-learner/org/dllearner/parser/JJTKBParserState.java trunk/src/dl-learner/org/dllearner/parser/KBParserTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/Node.java trunk/src/dl-learner/org/dllearner/parser/ParseException.java trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java trunk/src/dl-learner/org/dllearner/parser/Token.java trunk/src/dl-learner/org/dllearner/parser/TokenMgrError.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/parser/conf.jjt trunk/src/dl-learner/org/dllearner/parser/dllearner.jj trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/parser/kb.jjt Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,4 +1,4 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParser.java */ +/* Generated By:JavaCC: Do not edit this line. ConfParser.java */ package org.dllearner.parser; import java.util.List; @@ -23,8 +23,8 @@ import org.dllearner.ConfigurationOption; import org.dllearner.utilities.*; -public @SuppressWarnings("all") class ConfParser/*@bgen(jjtree)*/implements ConfParserTreeConstants, ConfParserConstants {/*@bgen(jjtree)*/ - protected JJTConfParserState jjtree = new JJTConfParserState(); +public @SuppressWarnings("all") class ConfParser implements ConfParserConstants { + private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); @@ -122,7 +122,7 @@ System.out.print("Parsing " + f.getName() + " ... "); long parseStartTime = System.currentTimeMillis(); - SimpleNode n = null; + // SimpleNode n = null; ConfParser learner = null; try { learner = new ConfParser(new FileInputStream(args[args.length-1])); @@ -132,7 +132,7 @@ System.exit(0); } try { - n = learner.Start(); + learner.Start(); // n.dump(""); // System.out.println("Thank you."); } catch (Exception e) { @@ -168,138 +168,92 @@ // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); } - final public SimpleNode Start() throws ParseException { - /*@bgen(jjtree) Start */ - SimpleNode jjtn000 = new SimpleNode(JJTSTART); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);ConceptAssertion conceptAssertion; + final public void Start() throws ParseException { + ConceptAssertion conceptAssertion; RoleAssertion roleAssertion; RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; ConfigurationOption confOption; - try { - label_1: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case POS_EX: - case NEG_EX: - case ID: - ; - break; - default: - jj_la1[0] = jj_gen; - break label_1; - } - if (jj_2_1(2147483647)) { - confOption = ConfOption(); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case POS_EX: + case NEG_EX: + case ID: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + if (jj_2_1(2147483647)) { + confOption = ConfOption(); confOptions.add(confOption); - } else if (jj_2_2(2147483647)) { - FunctionCall(); - } else if (jj_2_3(2147483647)) { - PosExample(); - } else if (jj_2_4(2147483647)) { - NegExample(); - } else { - jj_consume_token(-1); - throw new ParseException(); - } + } else if (jj_2_2(2147483647)) { + FunctionCall(); + } else if (jj_2_3(2147483647)) { + PosExample(); + } else if (jj_2_4(2147483647)) { + NegExample(); + } else { + jj_consume_token(-1); + throw new ParseException(); } - jj_consume_token(0); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return jjtn000;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); + jj_consume_token(0); } final public ConfigurationOption ConfOption() throws ParseException { - /*@bgen(jjtree) ConfOption */ - SimpleNode jjtn000 = new SimpleNode(JJTCONFOPTION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; + boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; String option="", subOption="", value="", tmp=""; int number = 0; double numberDouble = 0; ConfigurationOption confOption; Set<String> values = new HashSet<String>(); - try { - option = Id(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMAND_END: - jj_consume_token(COMMAND_END); - subOption = Id(); + option = Id(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMAND_END: + jj_consume_token(COMMAND_END); + subOption = Id(); containsSubOption=true; - break; - default: - jj_la1[1] = jj_gen; - ; - } - jj_consume_token(25); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - value = Id(); - break; - case STRING: - value = String(); - break; - case NUMBER: - number = Integer(); + break; + default: + jj_la1[1] = jj_gen; + ; + } + jj_consume_token(25); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + value = Id(); + break; + case STRING: + value = String(); + break; + case NUMBER: + number = Integer(); isNumeric=true; - break; - case DOUBLE: - numberDouble = Double(); + break; + case DOUBLE: + numberDouble = Double(); isNumeric=true; isDouble=true; - break; - default: - jj_la1[4] = jj_gen; - if (jj_2_6(2147483647)) { - jj_consume_token(26); - jj_consume_token(27); + break; + default: + jj_la1[4] = jj_gen; + if (jj_2_6(2147483647)) { + jj_consume_token(26); + jj_consume_token(27); isSet=true; - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 26: - jj_consume_token(26); - label_2: - while (true) { - if (jj_2_5(2)) { - ; - } else { - break label_2; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp = String(); - break; - case ID: - tmp = Id(); - break; - default: - jj_la1[2] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - values.add(tmp); - jj_consume_token(28); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 26: + jj_consume_token(26); + label_2: + while (true) { + if (jj_2_5(2)) { + ; + } else { + break label_2; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: @@ -309,24 +263,37 @@ tmp = Id(); break; default: - jj_la1[3] = jj_gen; + jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - values.add(tmp); - jj_consume_token(27); - isSet=true; + values.add(tmp); + jj_consume_token(28); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); break; + case ID: + tmp = Id(); + break; default: - jj_la1[5] = jj_gen; + jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } + values.add(tmp); + jj_consume_token(27); + isSet=true; + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } } - jj_consume_token(CONF_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + } + jj_consume_token(CONF_END); if(containsSubOption) { if(isNumeric) if(isDouble) @@ -353,259 +320,96 @@ {if (true) return confOption;} // confOptions.add(confOption); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public void FunctionCall() throws ParseException { - /*@bgen(jjtree) FunctionCall */ - SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONCALL); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);String s, s1, s2; + String s, s1, s2; List<String> list = new LinkedList<String>(); - try { - s1 = Id(); - jj_consume_token(29); - s2 = String(); + s1 = Id(); + jj_consume_token(29); + s2 = String(); list.add(s1); list.add(s2); - label_3: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 28: - ; - break; - default: - jj_la1[6] = jj_gen; - break label_3; - } - jj_consume_token(28); - s = String(); - list.add(s); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 28: + ; + break; + default: + jj_la1[6] = jj_gen; + break label_3; } - jj_consume_token(30); - jj_consume_token(CONF_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - functionCalls.add(list); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } + jj_consume_token(28); + s = String(); + list.add(s); } + jj_consume_token(30); + jj_consume_token(CONF_END); + functionCalls.add(list); } final public void PosExample() throws ParseException { - /*@bgen(jjtree) PosExample */ - SimpleNode jjtn000 = new SimpleNode(JJTPOSEXAMPLE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Individual i; - try { - jj_consume_token(POS_EX); - i = Individual(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Individual i; + jj_consume_token(POS_EX); + i = Individual(); positiveExamples.add(i); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } } final public void NegExample() throws ParseException { - /*@bgen(jjtree) NegExample */ - SimpleNode jjtn000 = new SimpleNode(JJTNEGEXAMPLE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Individual i; - try { - jj_consume_token(NEG_EX); - i = Individual(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Individual i; + jj_consume_token(NEG_EX); + i = Individual(); negativeExamples.add(i); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } } final public Individual Individual() throws ParseException { - /*@bgen(jjtree) Individual */ - SimpleNode jjtn000 = new SimpleNode(JJTINDIVIDUAL); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);String name; - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - name = Id(); - break; - case STRING: - name = String(); - break; - default: - jj_la1[7] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return new Individual(KBParser.getInternalURI(name));} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } + String name; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + name = Id(); + break; + case STRING: + name = String(); + break; + default: + jj_la1[7] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } + {if (true) return new Individual(KBParser.getInternalURI(name));} throw new Error("Missing return statement in function"); } final public String Id() throws ParseException { - /*@bgen(jjtree) Id */ - SimpleNode jjtn000 = new SimpleNode(JJTID); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token t; - try { - t = jj_consume_token(ID); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Token t; + t = jj_consume_token(ID); {if (true) return t.image;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public double Double() throws ParseException { - /*@bgen(jjtree) Double */ - SimpleNode jjtn000 = new SimpleNode(JJTDOUBLE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token t; - try { - t = jj_consume_token(DOUBLE); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Token t; + t = jj_consume_token(DOUBLE); {if (true) return new Double(t.image);} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public int Integer() throws ParseException { - /*@bgen(jjtree) Integer */ - SimpleNode jjtn000 = new SimpleNode(JJTINTEGER); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token t; - try { - t = jj_consume_token(NUMBER); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Token t; + t = jj_consume_token(NUMBER); {if (true) return new Integer(t.image);} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public String String() throws ParseException { - /*@bgen(jjtree) String */ - SimpleNode jjtn000 = new SimpleNode(JJTSTRING); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token t; + Token t; String s; - try { - t = jj_consume_token(STRING); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + t = jj_consume_token(STRING); // enclosing "" are removed s = t.image; s = s.substring(1, s.length() - 1); {if (true) return s;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } @@ -688,13 +492,13 @@ return false; } - final private boolean jj_3R_16() { - if (jj_scan_token(NUMBER)) return true; + final private boolean jj_3R_20() { + if (jj_3R_4()) return true; return false; } - final private boolean jj_3R_20() { - if (jj_3R_4()) return true; + final private boolean jj_3R_16() { + if (jj_scan_token(NUMBER)) return true; return false; } @@ -755,13 +559,13 @@ return false; } - final private boolean jj_3R_17() { - if (jj_scan_token(DOUBLE)) return true; + final private boolean jj_3R_19() { + if (jj_3R_12()) return true; return false; } - final private boolean jj_3R_19() { - if (jj_3R_12()) return true; + final private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; return false; } @@ -790,18 +594,18 @@ return false; } - final private boolean jj_3_6() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - final private boolean jj_3R_13() { if (jj_scan_token(28)) return true; if (jj_3R_12()) return true; return false; } + final private boolean jj_3_6() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + final private boolean jj_3_5() { Token xsp; xsp = jj_scanpos; @@ -876,7 +680,6 @@ token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; - jjtree.reset(); jj_gen = 0; for (int i = 0; i < 8; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); @@ -897,7 +700,6 @@ token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; - jjtree.reset(); jj_gen = 0; for (int i = 0; i < 8; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); @@ -916,7 +718,6 @@ token_source = tm; token = new Token(); jj_ntk = -1; - jjtree.reset(); jj_gen = 0; for (int i = 0; i < 8; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); @@ -993,7 +794,7 @@ return (jj_ntk = jj_nt.kind); } - private java.util.Vector jj_expentries = new java.util.Vector(); + private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -1055,7 +856,7 @@ jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.elementAt(i); + exptokseq[i] = jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,4 +1,4 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParserConstants.java */ +/* Generated By:JavaCC: Do not edit this line. ConfParserConstants.java */ package org.dllearner.parser; public @SuppressWarnings("all") interface ConfParserConstants { Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,4 +1,4 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParserTokenManager.java */ +/* Generated By:JavaCC: Do not edit this line. ConfParserTokenManager.java */ package org.dllearner.parser; import java.util.List; import java.util.LinkedList; Deleted: trunk/src/dl-learner/org/dllearner/parser/ConfParserTreeConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTreeConstants.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTreeConstants.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,31 +0,0 @@ -/* Generated By:JJTree: Do not edit this line. ./ConfParserTreeConstants.java */ - -package org.dllearner.parser; - -public @SuppressWarnings("all") interface ConfParserTreeConstants -{ - public int JJTSTART = 0; - public int JJTCONFOPTION = 1; - public int JJTFUNCTIONCALL = 2; - public int JJTPOSEXAMPLE = 3; - public int JJTNEGEXAMPLE = 4; - public int JJTINDIVIDUAL = 5; - public int JJTID = 6; - public int JJTDOUBLE = 7; - public int JJTINTEGER = 8; - public int JJTSTRING = 9; - - - public String[] jjtNodeName = { - "Start", - "ConfOption", - "FunctionCall", - "PosExample", - "NegExample", - "Individual", - "Id", - "Double", - "Integer", - "String", - }; -} Deleted: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,75 +0,0 @@ -/* Generated By:JJTree: Do not edit this line. ./DLLearnerTreeConstants.java */ - -package org.dllearner.parser; - -public @SuppressWarnings("all") interface DLLearnerTreeConstants -{ - public int JJTSTART = 0; - public int JJTPARSEKB = 1; - public int JJTCONFOPTION = 2; - public int JJTFUNCTIONCALL = 3; - public int JJTPOSEXAMPLE = 4; - public int JJTNEGEXAMPLE = 5; - public int JJTABOXCONCEPT = 6; - public int JJTABOXROLE = 7; - public int JJTTRANSITIVE = 8; - public int JJTFUNCTIONAL = 9; - public int JJTSYMMETRIC = 10; - public int JJTINVERSE = 11; - public int JJTSUBROLE = 12; - public int JJTTBOXEQUIV = 13; - public int JJTTBOXSUB = 14; - public int JJTCONCEPT = 15; - public int JJTOR = 16; - public int JJTAND = 17; - public int JJTTOP = 18; - public int JJTBOTTOM = 19; - public int JJTEXISTS = 20; - public int JJTALL = 21; - public int JJTNOT = 22; - public int JJTGE = 23; - public int JJTLE = 24; - public int JJTATOMICCONCEPT = 25; - public int JJTATOMICROLE = 26; - public int JJTINDIVIDUAL = 27; - public int JJTID = 28; - public int JJTDOUBLE = 29; - public int JJTINTEGER = 30; - public int JJTSTRING = 31; - - - public String[] jjtNodeName = { - "Start", - "parseKB", - "ConfOption", - "FunctionCall", - "PosExample", - "NegExample", - "ABoxConcept", - "ABoxRole", - "Transitive", - "Functional", - "Symmetric", - "Inverse", - "Subrole", - "TBoxEquiv", - "TBoxSub", - "Concept", - "Or", - "And", - "Top", - "Bottom", - "Exists", - "All", - "Not", - "GE", - "LE", - "AtomicConcept", - "AtomicRole", - "Individual", - "Id", - "Double", - "Integer", - "String", - }; -} Deleted: trunk/src/dl-learner/org/dllearner/parser/JJTConfParserState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/JJTConfParserState.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/JJTConfParserState.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,123 +0,0 @@ -/* Generated By:JJTree: Do not edit this line. ./JJTConfParserState.java */ - -package org.dllearner.parser; - -@SuppressWarnings("all") class JJTConfParserState { - private java.util.Stack nodes; - private java.util.Stack marks; - - private int sp; // number of nodes on stack - private int mk; // current mark - private boolean node_created; - - JJTConfParserState() { - nodes = new java.util.Stack(); - marks = new java.util.Stack(); - sp = 0; - mk = 0; - } - - /* Determines whether the current node was actually closed and - pushed. This should only be called in the final user action of a - node scope. */ - boolean nodeCreated() { - return node_created; - } - - /* Call this to reinitialize the node stack. It is called - automatically by the parser's ReInit() method. */ - void reset() { - nodes.removeAllElements(); - marks.removeAllElements(); - sp = 0; - mk = 0; - } - - /* Returns the root node of the AST. It only makes sense to call - this after a successful parse. */ - Node rootNode() { - return (Node)nodes.elementAt(0); - } - - /* Pushes a node on to the stack. */ - void pushNode(Node n) { - nodes.push(n); - ++sp; - } - - /* Returns the node on the top of the stack, and remove it from the - stack. */ - Node popNode() { - if (--sp < mk) { - mk = ((Integer)marks.pop()).intValue(); - } - return (Node)nodes.pop(); - } - - /* Returns the node currently on the top of the stack. */ - Node peekNode() { - return (Node)nodes.peek(); - } - - /* Returns the number of children on the stack in the current node - scope. */ - int nodeArity() { - return sp - mk; - } - - - void clearNodeScope(Node n) { - while (sp > mk) { - popNode(); - } - mk = ((Integer)marks.pop()).intValue(); - } - - - void openNodeScope(Node n) { - marks.push(new Integer(mk)); - mk = sp; - n.jjtOpen(); - } - - - /* A definite node is constructed from a specified number of - children. That number of nodes are popped from the stack and - made the children of the definite node. Then the definite node - is pushed on to the stack. */ - void closeNodeScope(Node n, int num) { - mk = ((Integer)marks.pop()).intValue(); - while (num-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, num); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } - - - /* A conditional node is constructed if its condition is true. All - the nodes that have been pushed since the node was opened are - made children of the conditional node, which is then pushed - on to the stack. If the condition is false the node is not - constructed and they are left on the stack. */ - void closeNodeScope(Node n, boolean condition) { - if (condition) { - int a = nodeArity(); - mk = ((Integer)marks.pop()).intValue(); - while (a-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, a); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } else { - mk = ((Integer)marks.pop()).intValue(); - node_created = false; - } - } -} Deleted: trunk/src/dl-learner/org/dllearner/parser/JJTKBParserState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/JJTKBParserState.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/JJTKBParserState.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,123 +0,0 @@ -/* Generated By:JJTree: Do not edit this line. ./JJTKBParserState.java */ - -package org.dllearner.parser; - -@SuppressWarnings("all") class JJTKBParserState { - private java.util.Stack<Node> nodes; - private java.util.Stack<Integer> marks; - - private int sp; // number of nodes on stack - private int mk; // current mark - private boolean node_created; - - JJTKBParserState() { - nodes = new java.util.Stack<Node>(); - marks = new java.util.Stack<Integer>(); - sp = 0; - mk = 0; - } - - /* Determines whether the current node was actually closed and - pushed. This should only be called in the final user action of a - node scope. */ - boolean nodeCreated() { - return node_created; - } - - /* Call this to reinitialize the node stack. It is called - automatically by the parser's ReInit() method. */ - void reset() { - nodes.removeAllElements(); - marks.removeAllElements(); - sp = 0; - mk = 0; - } - - /* Returns the root node of the AST. It only makes sense to call - this after a successful parse. */ - Node rootNode() { - return nodes.elementAt(0); - } - - /* Pushes a node on to the stack. */ - void pushNode(Node n) { - nodes.push(n); - ++sp; - } - - /* Returns the node on the top of the stack, and remove it from the - stack. */ - Node popNode() { - if (--sp < mk) { - mk = marks.pop(); - } - return nodes.pop(); - } - - /* Returns the node currently on the top of the stack. */ - Node peekNode() { - return nodes.peek(); - } - - /* Returns the number of children on the stack in the current node - scope. */ - int nodeArity() { - return sp - mk; - } - - - void clearNodeScope(Node n) { - while (sp > mk) { - popNode(); - } - mk = marks.pop(); - } - - - void openNodeScope(Node n) { - marks.push(mk); - mk = sp; - n.jjtOpen(); - } - - - /* A definite node is constructed from a specified number of - children. That number of nodes are popped from the stack and - made the children of the definite node. Then the definite node - is pushed on to the stack. */ - void closeNodeScope(Node n, int num) { - mk = marks.pop(); - while (num-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, num); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } - - - /* A conditional node is constructed if its condition is true. All - the nodes that have been pushed since the node was opened are - made children of the conditional node, which is then pushed - on to the stack. If the condition is false the node is not - constructed and they are left on the stack. */ - void closeNodeScope(Node n, boolean condition) { - if (condition) { - int a = nodeArity(); - mk = marks.pop(); - while (a-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, a); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } else { - mk = marks.pop(); - node_created = false; - } - } -} Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-02 17:42:58 UTC (rev 162) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2007-10-03 07:41:53 UTC (rev 163) @@ -1,4 +1,4 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. KBParser.java */ +/* Generated By:JavaCC: Do not edit this line. KBParser.java */ package org.dllearner.parser; import org.dllearner.core.dl.*; @@ -7,8 +7,8 @@ import java.io.FileNotFoundException; import java.io.StringReader; -public @SuppressWarnings("all") class KBParser/*@bgen(jjtree)*/implements KBParserTreeConstants, KBParserConstants {/*@bgen(jjtree)*/ - protected JJTKBParserState jjtree = new JJTKBParserState(); +public @SuppressWarnings("all") class KBParser implements KBParserConstants { + public static final String internalNamespace = "http://localhost/foo#"; // method to give all internal stuff an URI (not necessary for DLs, but for OWL ontologies @@ -31,923 +31,421 @@ } final public KB KB() throws ParseException { - /*@bgen(jjtree) KB */ - SimpleNode jjtn000 = new SimpleNode(JJTKB); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);ConceptAssertion conceptAssertion; + ConceptAssertion conceptAssertion; RoleAssertion roleAssertion; RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; KB kb = new KB(); - try { - label_1: - while (true) { + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + case TOP: + case BOTTOM: + case EXISTS: + case ALL: + case NOT: + case GE: + case LE: + case STRING: + case 22: + case 28: + case 29: + case 30: + case 31: + case 32: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + if (jj_2_1(2147483647)) { + conceptAssertion = ABoxConcept(); + kb.addABoxAxiom(conceptAssertion); + } else if (jj_2_2(2147483647)) { + roleAssertion = ABoxRole(); + kb.addABoxAxiom(roleAssertion); + } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - case TOP: - case BOTTOM: - case EXISTS: - case ALL: - case NOT: - case GE: - case LE: - case STRING: - case 22: case 28: + rBoxAxiom = Transitive(); + kb.addRBoxAxiom(rBoxAxiom); + break; case 29: + rBoxAxiom = Functional(); + kb.addRBoxAxiom(rBoxAxiom); + break; case 30: + rBoxAxiom = Symmetric(); + kb.addRBoxAxiom(rBoxAxiom); + break; case 31: + rBoxAxiom = Inverse(); + kb.addRBoxAxiom(rBoxAxiom); + break; case 32: - ; + rBoxAxiom = Subrole(); + kb.addRBoxAxiom(rBoxAxiom); break; default: - jj_la1[0] = jj_gen; - break label_1; - } - if (jj_2_1(2147483647)) { - conceptAssertion = ABoxConcept(); - kb.addABoxAxiom(conceptAssertion); - } else if (jj_2_2(2147483647)) { - roleAssertion = ABoxRole(); - kb.addABoxAxiom(roleAssertion); - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 28: - rBoxAxiom = Transitive(); - kb.addRBoxAxiom(rBoxAxiom); - break; - case 29: - rBoxAxiom = Functional(); - kb.addRBoxAxiom(rBoxAxiom); - break; - case 30: - rBoxAxiom = Symmetric(); - kb.addRBoxAxiom(rBoxAxiom); - break; - case 31: - rBoxAxiom = Inverse(); - kb.addRBoxAxiom(rBoxAxiom); - break; - case 32: - rBoxAxiom = Subrole(); - kb.addRBoxAxiom(rBoxAxiom); - break; - default: - jj_la1[1] = jj_gen; - if (jj_2_3(2147483647)) { - equality = TBoxEquiv(); + jj_la1[1] = jj_gen; + if (jj_2_3(2147483647)) { + equality = TBoxEquiv(); kb.addTBoxAxiom(equality); - } else if (jj_2_4(2147483647)) { - inclusion = TBoxSub(); + } else if (jj_2_4(2147483647)) { + inclusion = TBoxSub(); kb.addTBoxAxiom(inclusion); - } else { - jj_consume_token(-1); - throw new ParseException(); - } + } else { + jj_consume_token(-1); + throw new ParseException(); } } } - jj_consume_token(0); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return kb;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } + jj_consume_token(0); + {if (true) return kb;} throw new Error("Missing return statement in function"); } final public ConceptAssertion ABoxConcept() throws ParseException { - /*@bgen(jjtree) ABoxConcept */ - SimpleNode jjtn000 = new SimpleNode(JJTABOXCONCEPT); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Concept c; Individual i; - try { - c = Concept(); - jj_consume_token(22); - i = Individual(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Concept c; Individual i; + c = Concept(); + jj_consume_token(22); + i = Individual(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new ConceptAssertion(c,i);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public RoleAssertion ABoxRole() throws ParseException { - /*@bgen(jjtree) ABoxRole */ - SimpleNode jjtn000 = new SimpleNode(JJTABOXROLE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);boolean isNegated=false; + boolean isNegated=false; AtomicRole ar; Individual i1,i2; - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NOT: - Not(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case NOT: + Not(); isNegated=true; - break; - default: - jj_la1[2] = jj_gen; - ; - } - ar = AtomicRole(); - jj_consume_token(22); - i1 = Individual(); - jj_consume_token(24); - i2 = Individual(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + default: + jj_la1[2] = jj_gen; + ; + } + ar = AtomicRole(); + jj_consume_token(22); + i1 = Individual(); + jj_consume_token(24); + i2 = Individual(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); if(isNegated) {if (true) throw new Error("negated role assertions not supported yet");} else {if (true) return new RoleAssertion(ar,i1,i2);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public TransitiveRoleAxiom Transitive() throws ParseException { - /*@bgen(jjtree) Transitive */ - SimpleNode jjtn000 = new SimpleNode(JJTTRANSITIVE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);AtomicRole ar; - try { - jj_consume_token(28); - jj_consume_token(22); - ar = AtomicRole(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + AtomicRole ar; + jj_consume_token(28); + jj_consume_token(22); + ar = AtomicRole(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new TransitiveRoleAxiom(ar);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public FunctionalRoleAxiom Functional() throws ParseException { - /*@bgen(jjtree) Functional */ - SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONAL); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);AtomicRole ar; - try { - jj_consume_token(29); - jj_consume_token(22); - ar = AtomicRole(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + AtomicRole ar; + jj_consume_token(29); + jj_consume_token(22); + ar = AtomicRole(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new FunctionalRoleAxiom(ar);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public SymmetricRoleAxiom Symmetric() throws ParseException { - /*@bgen(jjtree) Symmetric */ - SimpleNode jjtn000 = new SimpleNode(JJTSYMMETRIC); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);AtomicRole ar; - try { - jj_consume_token(30); - jj_consume_token(22); - ar = AtomicRole(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + AtomicRole ar; + jj_consume_token(30); + jj_consume_token(22); + ar = AtomicRole(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new SymmetricRoleAxiom(ar);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public InverseRoleAxiom Inverse() throws ParseException { - /*@bgen(jjtree) Inverse */ - SimpleNode jjtn000 = new SimpleNode(JJTINVERSE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);AtomicRole ar1,ar2; - try { - jj_consume_token(31); - jj_consume_token(22); - ar1 = AtomicRole(); - jj_consume_token(24); - ar2 = AtomicRole(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + AtomicRole ar1,ar2; + jj_consume_token(31); + jj_consume_token(22); + ar1 = AtomicRole(); + jj_consume_token(24); + ar2 = AtomicRole(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new InverseRoleAxiom(ar1,ar2);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public SubRoleAxiom Subrole() throws ParseException { - /*@bgen(jjtree) Subrole */ - SimpleNode jjtn000 = new SimpleNode(JJTSUBROLE); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);AtomicRole ar1,ar2; - try { - jj_consume_token(32); - jj_consume_token(22); - ar1 = AtomicRole(); - jj_consume_token(24); - ar2 = AtomicRole(); - jj_consume_token(23); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + AtomicRole ar1,ar2; + jj_consume_token(32); + jj_consume_token(22); + ar1 = AtomicRole(); + jj_consume_token(24); + ar2 = AtomicRole(); + jj_consume_token(23); + jj_consume_token(COMMAND_END); {if (true) return new SubRoleAxiom(ar1,ar2);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public Equality TBoxEquiv() throws ParseException { - /*@bgen(jjtree) TBoxEquiv */ - SimpleNode jjtn000 = new SimpleNode(JJTTBOXEQUIV); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Concept c1,c2; - try { - c1 = Concept(); - jj_consume_token(25); - c2 = Concept(); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + Concept c1,c2; + c1 = Concept(); + jj_consume_token(25); + c2 = Concept(); + jj_consume_token(COMMAND_END); {if (true) return new Equality(c1,c2);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } throw new Error("Missing return statement in function"); } final public Inclusion TBoxSub() throws ParseException { - /*@bgen(jjtree) TBoxSub */ - SimpleNode jjtn000 = new SimpleNode(JJTTBOXSUB); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Concept c1,c2; - try { - c1 = Concept(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 26: - jj_consume_token(26); - break; - case 27: - jj_consume_token(27); - break; - case 33: - jj_consume_token(33); - break; - default: - jj_la1[3] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - c2 = Concept(); - jj_consume_token(COMMAND_END); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return new Inclusion(c1,c2);} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } + Concept c1,c2; + c1 = Concept(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 26: + jj_consume_token(26); + break; + case 27: + jj_consume_token(27); + break; + case 33: + jj_consume_token(33); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } + c2 = Concept(); + jj_consume_token(COMMAND_END); + {if (true) return new Inclusion(c1,c2);} throw new Error("Missing return statement in function"); } final public Concept Concept() throws ParseException { - /*@bgen(jjtree) Concept */ - SimpleNode jjtn000 = new SimpleNode(JJTCONCEPT); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Concept c,c1,c2; + Concept c,c1,c2; AtomicConcept ac; AtomicRole ar; String s; int i; - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TOP: - Top(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TOP: + Top(); {if (true) return new Top();} - break; - case BOTTOM: - Bottom(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case BOTTOM: + Bottom(); {if (true) return new Bottom();} - break; - case ID: - case STRING: - ac = AtomicConcept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case ID: + case STRING: + ac = AtomicConcept(); {if (true) return ac;} - break; - default: - jj_la1[4] = jj_gen; - if (jj_2_5(2147483647)) { - jj_consume_token(22); - c1 = Concept(); - And(); - c2 = Concept(); - jj_consume_token(23); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + default: + jj_la1[4] = jj_gen; + if (jj_2_5(2147483647)) { + jj_consume_token(22); + c1 = Concept(); + And(); + c2 = Concept(); + jj_consume_token(23); {if (true) return new Conjunction(c1,c2);} - } else if (jj_2_6(2147483647)) { - jj_consume_token(22); - c1 = Concept(); - Or(); - c2 = Concept(); - jj_consume_token(23); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + } else if (jj_2_6(2147483647)) { + jj_consume_token(22); + c1 = Concept(); + Or(); + c2 = Concept(); + jj_consume_token(23); {if (true) return new Disjunction(c1,c2);} - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXISTS: - Exists(); - ar = AtomicRole(); - jj_consume_token(COMMAND_END); - c = Concept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case EXISTS: + Exists(); + ar = AtomicRole(); + jj_consume_token(COMMAND_END); + c = Concept(); {if (true) return new Exists(ar,c);} - break; - case ALL: - All(); - ar = AtomicRole(); - jj_consume_token(COMMAND_END); - c = Concept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case ALL: + All(); + ar = AtomicRole(); + jj_consume_token(COMMAND_END); + c = Concept(); {if (true) return new All(ar,c);} - break; - case NOT: - Not(); - c = Concept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case NOT: + Not(); + c = Concept(); {if (true) return new Negation(c);} - break; - case GE: - GE(); - i = Integer(); - ar = AtomicRole(); - jj_consume_token(COMMAND_END); - c = Concept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case GE: + GE(); + i = Integer(); + ar = AtomicRole(); + jj_consume_token(COMMAND_END); + c = Concept(); {if (true) return new GreaterEqual(i,ar,c);} - break; - case LE: - LE(); - i = Integer(); - ar = AtomicRole(); - jj_consume_token(COMMAND_END); - c = Concept(); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; + break; + case LE: + LE(); + i = Integer(); + ar = AtomicRole(); + jj_consume_token(COMMAND_END); + c = Concept(); {if (true) return new LessEqual(i,ar,c);} - break; - default: - jj_la1[5] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } } - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } } throw new Error("Missing return statement in function"); } final public void Or() throws ParseException { - /*@bgen(jjtree) Or */ - SimpleNode jjtn000 = new SimpleNode(JJTOR); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); - try { - jj_consume_token(OR); - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } + jj_consume_token(OR); } final public void And() throws ParseException { - /*@bgen(jjtree) And */ - SimpleNode jjtn000 = new SimpleNode(JJTAND); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); - try { - jj_consume_token(AND); - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } + jj_consume_token(AND); } final public void Top() throws ParseException { - /*@bgen(jjtree) Top */ - SimpleNode jjtn000 = new SimpleNo... [truncated message content] |
From: <jen...@us...> - 2007-10-02 17:43:00
|
Revision: 162 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=162&view=rev Author: jenslehmann Date: 2007-10-02 10:42:58 -0700 (Tue, 02 Oct 2007) Log Message: ----------- - parser improvements - made alle necessary changes to reflect parser modifications - implemented knowledge source KBFile - started SPARQL Endpoint knowledge source - started CLI package - moved some classes to appropriate packages Modified Paths: -------------- 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/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.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/gp/Program.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.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/modules/sparql/Util.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/conf.jjt trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/parser/kb.jjt trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/reasoning/JenaOWLDIGConverter.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDIGConverter.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/cli/ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/Score.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/QuickStart.java trunk/src/dl-learner/org/dllearner/Score.java trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-02 17:42:58 UTC (rev 162) @@ -8,12 +8,12 @@ import java.util.Set; import org.dllearner.LearningProblem.LearningProblemType; -import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; 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.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.reasoning.ReasonerType; public class Config { Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-02 17:42:58 UTC (rev 162) @@ -13,12 +13,12 @@ import java.util.TreeSet; import org.dllearner.Config.Algorithm; -import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; -import org.dllearner.parser.DLLearner; +import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; +import org.dllearner.parser.KBParser; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.RoleComparator; @@ -90,7 +90,7 @@ } // der parserinterne Namespace wird immer ausgeblendet - Config.hidePrefixes.add(DLLearner.internalNamespace); + Config.hidePrefixes.add(KBParser.internalNamespace); } @@ -549,20 +549,20 @@ Config.Refinement.allowedConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); for(String s : setValues) // es wird die gleiche Funktion wie im Parser genommen um Namen auf URIs zu mappen - Config.Refinement.allowedConcepts.add(new AtomicConcept(DLLearner.getInternalURI(s))); + Config.Refinement.allowedConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.allowedRoles")) { Config.Refinement.allowedRolesAutoDetect = false; Config.Refinement.allowedRoles = new TreeSet<AtomicRole>(new RoleComparator()); for(String s : setValues) - Config.Refinement.allowedRoles.add(new AtomicRole(DLLearner.getInternalURI(s))); + Config.Refinement.allowedRoles.add(new AtomicRole(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.ignoredConcepts")) { Config.Refinement.ignoredConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); for(String s : setValues) - Config.Refinement.ignoredConcepts.add(new AtomicConcept(DLLearner.getInternalURI(s))); + Config.Refinement.ignoredConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.ignoredRoles")) { Config.Refinement.ignoredRoles = new TreeSet<AtomicRole>(new RoleComparator()); for(String s : setValues) - Config.Refinement.ignoredRoles.add(new AtomicRole(DLLearner.getInternalURI(s))); + Config.Refinement.ignoredRoles.add(new AtomicRole(KBParser.getInternalURI(s))); } } Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-02 17:42:58 UTC (rev 162) @@ -6,9 +6,12 @@ import org.dllearner.Config.Refinement; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.Negation; +import org.dllearner.learningproblems.ScoreThreeValued; +import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-02 17:42:58 UTC (rev 162) @@ -47,6 +47,7 @@ import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.AssertionalAxiom; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -57,10 +58,11 @@ import org.dllearner.core.dl.KB; import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.RoleAssertion; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPTwoValued; import org.dllearner.modules.ModuleInvocator; -import org.dllearner.parser.DLLearner; +import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasoner; @@ -990,7 +992,7 @@ boolean parsedCorrectly = true; try { - concept = DLLearner.parseConcept(queryStr); + concept = KBParser.parseConcept(queryStr); } catch (ParseException e1) { e1.printStackTrace(); System.err @@ -1362,7 +1364,7 @@ Concept c = null; try { - c = DLLearner.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); + c = KBParser.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -1393,7 +1395,7 @@ */ Concept c = null; try { - c = DLLearner.parseConcept("EXISTS uncle.TOP"); + c = KBParser.parseConcept("EXISTS uncle.TOP"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); Deleted: trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,11 +0,0 @@ -package org.dllearner; - -public enum OntologyFileFormat { - - // RDF-Triples in XML-Datei - RDF_XML, - - // N-Triple-Format (Subformat von N3) - N_TRIPLES - -} Deleted: trunk/src/dl-learner/org/dllearner/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/QuickStart.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/QuickStart.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,182 +0,0 @@ -package org.dllearner; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; -import java.io.InputStreamReader; -import java.io.RandomAccessFile; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; - -import org.dllearner.parser.DLLearner; - -/** - * A tool to quickly start a learning exampe. It detects all conf files in - * the examples directory and offers the user to start one of them. - * - * @author Sebastian Hellmann - * @author Jens Lehmann - */ -public class QuickStart { - - static HashMap<String, ArrayList<String>> hm = null; - static String pm = ".";// pathmodifier - - public static void main(String[] args) { - - String lastused = readit(); - String tab = " "; - int the_Number = 0; - ArrayList<String> FinalSelection = new ArrayList<String>(); - FinalSelection.add("na"); - - hm = new HashMap<String, ArrayList<String>>(); - String path = pm + File.separator + "examples"; - File f = new File(path); - getAllConfs(f, path); - - // System.out.println(hm.size()); - Iterator<String> i = hm.keySet().iterator(); - Object[] sort = new Object[hm.size()]; - int count = 0; - while (i.hasNext()) - sort[count++] = i.next(); - Arrays.sort(sort); - Object s; - String s1 = ""; - // String tmp=""; - for (int aa = 0; aa < sort.length; aa++) - // while (i.hasNext()) - { - s = sort[aa]; - s1 = (String) s; - if (s1.startsWith(pm + "\\examples\\") || s1.startsWith(pm + "/examples/")) - System.out.println(s1.substring(10).toUpperCase()); - else - System.out.println(s); - - ArrayList<String> al = hm.get(s); - String[] files = new String[al.size()]; - for (int j = 0; j < al.size(); j++) { - files[j] = al.get(j); - } - Arrays.sort(files); - for (int j = 0; j < files.length; j++) { - the_Number++; - FinalSelection.add(the_Number, s + files[j] + ".conf");// tmp=the_Number+":"+tab+files[j]; - System.out.println(" " + the_Number + ":" + tab + files[j] + ""); - - } - // System.out.println(FinalSelection.get(1)); - - }// end while - System.out.println("Last Used: " + lastused + "\n" - + "->press enter to use it again, else choose number:"); - boolean number = false; - try { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int target = 0; - String Selected = ""; - while (true) { - String cmd = br.readLine(); - try { - if (cmd.length() == 0) { - number = false; - break; - } - target = Integer.parseInt(cmd); - number = true; - break; - } catch (Exception e) { - System.out.println("Not a number"); - } - ; - }// end while - if (number) { - try { - Selected = FinalSelection.get(target); - } catch (Exception e) { - System.out.println("number does not exist"); - } - ; - writeit(Selected); - System.out.println(Selected); - } else if (!number) { - Selected = lastused; - } - - DLLearner.main(new String[] { Selected }); - - } catch (Exception e) { - e.printStackTrace(); - }// System.out.println(s+" : "+hm.get(s).get(0)); - - // System.out.println(f.isDirectory()+f.getAbsolutePath()); - } - - public static void getAllConfs(File f, String path) { - path = path + File.separator; - // System.out.println(path); - String[] act = f.list(); - for (int i = 0; i < act.length; i++) { - // System.out.println(act[i]); - - if (new File(path + act[i]).isDirectory()) { - - getAllConfs(new File(path + act[i]), path + act[i]); - // al.add(new File(act[i])); - } else if (act[i].endsWith(".conf")) { - if (hm.get(path) == null) { - hm.put(path, new ArrayList<String>()); - } - hm.get(path).add(act[i].substring(0, act[i].length() - 5)); - // System.out.println(act[i].substring(0,act[i].length()-5)); - // System.out.println(hm.get(path).size()); - // hm.put(new - // File(act[i]).getAbsolutePath(),act[i].substring(0,act[i].length()-4)); - } - }// end for - - } - - static void writeit(String lastused) { - try { - FileWriter fw = new FileWriter(".lastUsedExample"); - fw.write(lastused); - fw.flush(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - static String readit() { - String lu = ""; - try { - RandomAccessFile raf = new RandomAccessFile(".lastUsedExample", "r"); - String line = ""; - while ((line = raf.readLine()) != null) { - lu = line; - } - } catch (Exception e) { - writeit("na"); - } - return lu; - } - - static String readCP() { - String lu = ""; - try { - RandomAccessFile raf = new RandomAccessFile("classpath.start", "r"); - String line = ""; - while ((line = raf.readLine()) != null) { - lu += line; - } - } catch (Exception e) { - e.printStackTrace(); - } - return lu; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Score.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Score.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,28 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -import org.dllearner.core.dl.Individual; - -public abstract class Score { - public abstract double getScore(); - - /** - * The score of a concept depends on how good it classifies the - * examples of a learning problem and the length of the concept - * itself. If a given concept is known to have equal classification - * properties than the concept this score object is based on, then - * this method can be used to calculate its score value by using the - * length of this concept as parameter. - * - * @param newLength Length of the concept. - * @return Score. - */ - public abstract Score getModifiedLengthScore(int newLength); - - public abstract Set<Individual> getCoveredPositives(); - public abstract Set<Individual> getCoveredNegatives(); - public abstract Set<Individual> getNotCoveredPositives(); - - // public abstract int getNrOfMiss -} Deleted: trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,198 +0,0 @@ -package org.dllearner; - -import java.text.DecimalFormat; -import java.util.Set; -import java.util.SortedSet; - -import org.dllearner.core.dl.Individual; -import org.dllearner.utilities.Helper; - -/** - * Berechnet die Punktzahl (negativ), indem es die Ergebnisse einer Definition - * mit den Soll-Ergebnissen vergleicht. - * - * TODO: die Implementierung ist momentan dahingehend unguenstig, dass viele Sachen - * nur fuer die optische Aufbereitung berechnet werden; effizienter waere es - * nur die Klassifikationsfehler zu beruecksichtigen und andere statistische Werte nur - * dann wenn sie benoetigt werden - * - * @author Jens Lehmann - * - */ -public class ScoreThreeValued extends Score { - - public enum ScoreMethod {POSITIVE, FULL}; - - private SortedSet<Individual> posClassified; - private SortedSet<Individual> neutClassified; - private SortedSet<Individual> negClassified; - private SortedSet<Individual> posExamples; - private SortedSet<Individual> neutExamples; - private SortedSet<Individual> negExamples; - - private Set<Individual> posAsNeg; - private Set<Individual> negAsPos; - private Set<Individual> posAsNeut; - private Set<Individual> neutAsPos; - private Set<Individual> neutAsNeg; - private Set<Individual> negAsNeut; - private Set<Individual> posAsPos; - private Set<Individual> negAsNeg; - private Set<Individual> neutAsNeut; - - private double score; - private double accuracy; - private double accuracyOnExamples; - private double accuracyOnPositiveExamples; - private double errorRate; - - private int nrOfExamples; - private int conceptLength; - - public ScoreThreeValued(int conceptLength, - SortedSet<Individual> posClassified, - SortedSet<Individual> neutClassified, - SortedSet<Individual> negClassified, - SortedSet<Individual> posExamples, - SortedSet<Individual> neutExamples, - SortedSet<Individual> negExamples) { - this.conceptLength = conceptLength; - this.posClassified = posClassified; - this.neutClassified = neutClassified; - this.negClassified = negClassified; - this.posExamples = posExamples; - this.neutExamples = neutExamples; - this.negExamples = negExamples; - nrOfExamples = posExamples.size()+negExamples.size(); - computeClassificationMatrix(); - computeStatistics(); - } - - private void computeClassificationMatrix() { - posAsNeg = Helper.intersection(posExamples,negClassified); - negAsPos = Helper.intersection(negExamples,posClassified); - posAsNeut = Helper.intersection(posExamples,neutClassified); - neutAsPos = Helper.intersection(neutExamples,posClassified); - neutAsNeg = Helper.intersection(neutExamples,negClassified); - negAsNeut = Helper.intersection(negExamples,neutClassified); - // die 3 Berechnungen sind nicht so wichtig f�r die Punktzahl, d.h. falls - // es Performance bringt, dann kann man sie auch ausgliedern - posAsPos = Helper.intersection(posExamples,posClassified); - negAsNeg = Helper.intersection(negExamples,negClassified); - neutAsNeut = Helper.intersection(neutExamples,neutClassified); - } - - private void computeStatistics() { - score = - posAsNeg.size()*Config.errorPenalty - - negAsPos.size()*Config.errorPenalty - - posAsNeut.size()*Config.accuracyPenalty; - - if(Config.scoreMethod==ScoreMethod.FULL) - score -= negAsNeut.size()*Config.accuracyPenalty; - - if(Config.penalizeNeutralExamples) - score -= (neutAsPos.size()*Config.accuracyPenalty - + neutAsNeg.size()*Config.accuracyPenalty); - - // TODO: man könnte hier statt error penality auch accuracy penalty - // nehmen - double worstValue = nrOfExamples * Config.errorPenalty; - // ergibt Zahl zwischen -1 und 0 - score = score / worstValue; - score -= Config.percentPerLengthUnit * conceptLength; - - // die folgenden Berechnungen k�nnten aus Performancegr�nden auch - // ausgegliedert werden - // int domainSize = abox.domain.size(); - int numberOfExamples = posExamples.size()+negExamples.size(); - int domainSize = numberOfExamples + neutExamples.size(); - int correctlyClassified = posAsPos.size() + negAsNeg.size() + neutAsNeut.size(); - int correctOnExamples = posAsPos.size() + negAsNeg.size(); - int errors = posAsNeg.size() + negAsPos.size(); - - // Accuracy = Quotient von richtig klassifizierten durch Anzahl Domainelemente - accuracy = (double) correctlyClassified/domainSize; - - // Accuracy on Examples = Quotient von richtig klassifizierten durch Anzahl pos. - // und neg. Beispiele - accuracyOnExamples = (double) correctOnExamples/numberOfExamples; - - accuracyOnPositiveExamples = (double) posAsPos.size()/posExamples.size(); - - // Error = Quotient von komplett falsch klassifizierten durch Anzahl pos. - // und neg. Beispiele - errorRate = (double) errors/numberOfExamples; - } - - @Override - public double getScore() { - return score; - } - - @Override - public String toString() { - DecimalFormat df = new DecimalFormat("0.00"); - String str = ""; - str += "score method "; - if(Config.scoreMethod == ScoreMethod.FULL) - str += "full"; - else - str += "positive"; - if(!Config.penalizeNeutralExamples) - str += " (neutral examples not penalized)"; - str += "\n"; - if(Config.showCorrectClassifications) { - str += "Correctly classified:\n"; - str += " positive --> positive: " + posAsPos + "\n"; - str += " neutral --> neutral: " + neutAsNeut + "\n"; - str += " negative --> negative: " + negAsNeg + "\n"; - } - str += "Inaccurately classified (penalty of " + df.format(Config.accuracyPenalty) + " per instance):\n"; - str += " positive --> neutral: " + posAsNeut + "\n"; - if(Config.penalizeNeutralExamples) { - str += " neutral --> positive: " + neutAsPos + "\n"; - str += " neutral --> negative: " + neutAsNeg + "\n"; - } - if(Config.scoreMethod == ScoreMethod.FULL) - str += " negative --> neutral: " + negAsNeut + "\n"; - str += "Classification errors (penalty of " + df.format(Config.errorPenalty) + " per instance):\n"; - str += " positive --> negative: " + posAsNeg + "\n"; - str += " negative --> positive: " + negAsPos + "\n"; - str += "Statistics:\n"; - str += " Score: " + df.format(score) + "\n"; - str += " Accuracy: " + df.format(accuracy*100) + "%\n"; - str += " Accuracy on examples: " + df.format(accuracyOnExamples*100) + "%\n"; - str += " Accuracy on positive examples: " + df.format(accuracyOnPositiveExamples*100) + "%\n"; - str += " Error rate: " + df.format(errorRate*100) + "%\n"; - return str; - } - - public SortedSet<Individual> getNegClassified() { - return negClassified; - } - - public SortedSet<Individual> getPosClassified() { - return posClassified; - } - - @Override - public Set<Individual> getCoveredNegatives() { - return negAsPos; - } - - @Override - public Set<Individual> getCoveredPositives() { - return posAsPos; - } - - @Override - public Set<Individual> getNotCoveredPositives() { - return posAsNeg; - } - - @Override - public Score getModifiedLengthScore(int newLength) { - return new ScoreThreeValued(newLength, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,85 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -import org.dllearner.core.dl.Individual; - -/** - * - * TODO: accuracy-Berechnung (positive+negative Beispiele muessen dafuer bekannt sein) - * - * @author jl - * - */ -public class ScoreTwoValued extends Score { - - private Set<Individual> posAsPos; - private Set<Individual> posAsNeg; - private Set<Individual> negAsPos; - private Set<Individual> negAsNeg; - private double score; - private double classificationScore; - private int nrOfExamples; - private int conceptLength; - - public ScoreTwoValued(int conceptLength, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { - this.conceptLength = conceptLength; - this.posAsPos = posAsPos; - this.posAsNeg = posAsNeg; - this.negAsPos = negAsPos; - this.negAsNeg = negAsNeg; - nrOfExamples = posAsPos.size()+posAsNeg.size()+negAsPos.size()+negAsNeg.size(); - computeScore(); - } - - private void computeScore() { - // - Anzahl falscher Klassifikationen - classificationScore = - posAsNeg.size() - negAsPos.size(); - // Anteil falscher Klassifikationen (Zahl zwischen -1 und 0) - classificationScore = classificationScore / (double) nrOfExamples; - // Berücksichtigung des Längenfaktors - score = classificationScore - Config.percentPerLengthUnit * conceptLength; - } - - @Override - public double getScore() { - return score; - } - - @Override - public String toString() { - String str = ""; - str += "score: " + score + "\n"; - str += "posAsPos: " + posAsPos + "\n"; - str += "positive examples classified as negative: " + posAsNeg + "\n"; - str += "negative examples classified as positive: " + negAsPos + "\n"; - return str; - } - - @Override - public Set<Individual> getCoveredNegatives() { - return negAsPos; - } - - @Override - public Set<Individual> getCoveredPositives() { - return posAsPos; - } - - @Override - public Set<Individual> getNotCoveredPositives() { - return posAsNeg; - } - - /* - @Override - public double getModifiedLengthScore(int newLength) { - return classificationScore - Config.percentPerLengthUnit * newLength; - } - */ - - @Override - public Score getModifiedLengthScore(int newLength) { - return new ScoreTwoValued(newLength, posAsPos, posAsNeg, negAsPos, negAsNeg); - } -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-02 17:42:58 UTC (rev 162) @@ -7,7 +7,7 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; Modified: trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,6 +1,6 @@ package org.dllearner.algorithms; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-02 17:42:58 UTC (rev 162) @@ -23,7 +23,6 @@ import java.util.LinkedList; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.ConfigEntry; @@ -32,6 +31,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPThreeValued; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-02 17:42:58 UTC (rev 162) @@ -47,7 +47,6 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.ConfigEntry; @@ -55,6 +54,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-02 17:42:58 UTC (rev 162) @@ -9,9 +9,8 @@ import org.dllearner.Config; import org.dllearner.Main; -import org.dllearner.Score; -import org.dllearner.ScoreThreeValued; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -28,6 +27,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPThreeValued; +import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-10-02 17:42:58 UTC (rev 162) @@ -20,7 +20,7 @@ package org.dllearner.algorithms.gp; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-02 17:42:58 UTC (rev 162) @@ -6,9 +6,9 @@ import java.util.TreeMap; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-02 17:42:58 UTC (rev 162) @@ -11,8 +11,8 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; Copied: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java (from rev 160, trunk/src/dl-learner/org/dllearner/QuickStart.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,181 @@ +package org.dllearner.cli; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; + +/** + * A tool to quickly start a learning example. It detects all conf files in + * the examples directory and offers the user to start one of them. + * + * @author Sebastian Hellmann + * @author Jens Lehmann + */ +public class QuickStart { + + static HashMap<String, ArrayList<String>> hm = null; + static String pm = ".";// pathmodifier + + public static void main(String[] args) { + + String lastused = readit(); + String tab = " "; + int the_Number = 0; + ArrayList<String> FinalSelection = new ArrayList<String>(); + FinalSelection.add("na"); + + hm = new HashMap<String, ArrayList<String>>(); + String path = pm + File.separator + "examples"; + File f = new File(path); + getAllConfs(f, path); + + // System.out.println(hm.size()); + Iterator<String> i = hm.keySet().iterator(); + Object[] sort = new Object[hm.size()]; + int count = 0; + while (i.hasNext()) + sort[count++] = i.next(); + Arrays.sort(sort); + Object s; + String s1 = ""; + // String tmp=""; + for (int aa = 0; aa < sort.length; aa++) + // while (i.hasNext()) + { + s = sort[aa]; + s1 = (String) s; + if (s1.startsWith(pm + "\\examples\\") || s1.startsWith(pm + "/examples/")) + System.out.println(s1.substring(10).toUpperCase()); + else + System.out.println(s); + + ArrayList<String> al = hm.get(s); + String[] files = new String[al.size()]; + for (int j = 0; j < al.size(); j++) { + files[j] = al.get(j); + } + Arrays.sort(files); + for (int j = 0; j < files.length; j++) { + the_Number++; + FinalSelection.add(the_Number, s + files[j] + ".conf");// tmp=the_Number+":"+tab+files[j]; + System.out.println(" " + the_Number + ":" + tab + files[j] + ""); + + } + // System.out.println(FinalSelection.get(1)); + + }// end while + System.out.println("Last Used: " + lastused + "\n" + + "->press enter to use it again, else choose number:"); + boolean number = false; + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int target = 0; + String Selected = ""; + while (true) { + String cmd = br.readLine(); + try { + if (cmd.length() == 0) { + number = false; + break; + } + target = Integer.parseInt(cmd); + number = true; + break; + } catch (Exception e) { + System.out.println("Not a number"); + } + ; + }// end while + if (number) { + try { + Selected = FinalSelection.get(target); + } catch (Exception e) { + System.out.println("number does not exist"); + } + ; + writeit(Selected); + System.out.println(Selected); + } else if (!number) { + Selected = lastused; + } + + System.out.println("ToDo: start commandline interface with selected conf file"); + // DLLearner.main(new String[] { Selected }); + + } catch (Exception e) { + e.printStackTrace(); + }// System.out.println(s+" : "+hm.get(s).get(0)); + + // System.out.println(f.isDirectory()+f.getAbsolutePath()); + } + + public static void getAllConfs(File f, String path) { + path = path + File.separator; + // System.out.println(path); + String[] act = f.list(); + for (int i = 0; i < act.length; i++) { + // System.out.println(act[i]); + + if (new File(path + act[i]).isDirectory()) { + + getAllConfs(new File(path + act[i]), path + act[i]); + // al.add(new File(act[i])); + } else if (act[i].endsWith(".conf")) { + if (hm.get(path) == null) { + hm.put(path, new ArrayList<String>()); + } + hm.get(path).add(act[i].substring(0, act[i].length() - 5)); + // System.out.println(act[i].substring(0,act[i].length()-5)); + // System.out.println(hm.get(path).size()); + // hm.put(new + // File(act[i]).getAbsolutePath(),act[i].substring(0,act[i].length()-4)); + } + }// end for + + } + + static void writeit(String lastused) { + try { + FileWriter fw = new FileWriter(".lastUsedExample"); + fw.write(lastused); + fw.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + static String readit() { + String lu = ""; + try { + RandomAccessFile raf = new RandomAccessFile(".lastUsedExample", "r"); + String line = ""; + while ((line = raf.readLine()) != null) { + lu = line; + } + } catch (Exception e) { + writeit("na"); + } + return lu; + } + + static String readCP() { + String lu = ""; + try { + RandomAccessFile raf = new RandomAccessFile("classpath.start", "r"); + String line = ""; + while ((line = raf.readLine()) != null) { + lu += line; + } + } catch (Exception e) { + e.printStackTrace(); + } + return lu; + } + +} Added: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-02 17:42:58 UTC (rev 162) @@ -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.cli; + +import java.io.File; + +/** + * Startup file for Command Line Interface. + * + * @author Jens Lehmann + * + */ +public class Start { + + /** + * @param args + */ + public static void main(String[] args) { + File file = new File(args[args.length-1]); + + // parse conf file + + // use parsed values to configure components + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-02 17:42:58 UTC (rev 162) @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-02 17:42:58 UTC (rev 162) @@ -28,13 +28,13 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.OntologyFileFormat; 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.core.dl.RoleHierarchy; import org.dllearner.core.dl.SubsumptionHierarchy; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; Added: trunk/src/dl-learner/org/dllearner/core/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Score.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/Score.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,28 @@ +package org.dllearner.core; + +import java.util.Set; + +import org.dllearner.core.dl.Individual; + +public abstract class Score { + public abstract double getScore(); + + /** + * The score of a concept depends on how good it classifies the + * examples of a learning problem and the length of the concept + * itself. If a given concept is known to have equal classification + * properties than the concept this score object is based on, then + * this method can be used to calculate its score value by using the + * length of this concept as parameter. + * + * @param newLength Length of the concept. + * @return Score. + */ + public abstract Score getModifiedLengthScore(int newLength); + + public abstract Set<Individual> getCoveredPositives(); + public abstract Set<Individual> getCoveredNegatives(); + public abstract Set<Individual> getNotCoveredPositives(); + + // public abstract int getNrOfMiss +} Added: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,94 @@ +/** + * 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.kb; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URI; +import java.util.Collection; +import java.util.LinkedList; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.dl.KB; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.DIGConverter; + +/** + * @author Jens Lehmann + * + */ +public class KBFile extends KnowledgeSource { + + private File file; + private KB kb; + + public static String getName() { + return "KB file"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("filename", "pointer to the KB file")); + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("filename")) { + file = new File((String)entry.getValue()); + } + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + try { + kb = KBParser.parseKBFile(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + return DIGConverter.getDIGString(kb).toString(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-02 17:42:58 UTC (rev 162) @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.OntologyFileFormat; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; Copied: trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java (from rev 160, trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,11 @@ +package org.dllearner.kb; + +public enum OntologyFileFormat { + + // RDF-Triples in XML file + RDF_XML, + + // N-Triple format (subformat of N3) + N_TRIPLES + +} Added: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,101 @@ +/** + * 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.kb; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.StringSetConfigOption; + +/** + * Represents a SPARQL Endpoint. + * TODO: move org.dllearner.modules.sparql to this package and + * integrate its classes + * TODO: Is it necessary to create a class DBpediaSparqlEndpoint? + * + * @author Jens Lehmann + * + */ +public class SparqlEndpoint extends KnowledgeSource { + + private URL url; + private Set<String> instances; + + public static String getName() { + return "SPARQL Endpoint"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings({"unchecked"}) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); + } //catch (URISyntaxException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + //} + } else if(option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO add code for downloading data from SPARQL endpoint + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + return null; + } + +} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-02 17:42:58 UTC (rev 162) @@ -21,9 +21,9 @@ import java.util.SortedSet; -import org.dllearner.Score; import org.dllearner.core.LearningProblemNew; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -21,10 +21,10 @@ 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.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -25,14 +25,13 @@ 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.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; Copied: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java (from rev 160, trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,200 @@ +package org.dllearner.learningproblems; + +import java.text.DecimalFormat; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.Config; +import org.dllearner.core.Score; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; + +/** + * Berechnet die Punktzahl (negativ), indem es die Ergebnisse einer Definition + * mit den Soll-Ergebnissen vergleicht. + * + * TODO: die Implementierung ist momentan dahingehend unguenstig, dass viele Sachen + * nur fuer die optische Aufbereitung berechnet werden; effizienter waere es + * nur die Klassifikationsfehler zu beruecksichtigen und andere statistische Werte nur + * dann wenn sie benoetigt werden + * + * @author Jens Lehmann + * + */ +public class ScoreThreeValued extends Score { + + public enum ScoreMethod {POSITIVE, FULL}; + + private SortedSet<Individual> posClassified; + private SortedSet<Individual> neutClassified; + private SortedSet<Individual> negClassified; + private SortedSet<Individual> posExamples; + private SortedSet<Individual> neutExamples; + private SortedSet<Individual> negExamples; + + private Set<Individual> posAsNeg; + private Set<Individual> negAsPos; + private Set<Individual> posAsNeut; + private Set<Individual> neutAsPos; + private Set<Individual> neutAsNeg; + private Set<Individual> negAsNeut; + private Set<Individual> posAsPos; + private Set<Individual> negAsNeg; + private Set<Individual> neutAsNeut; + + private double score; + private double accuracy; + private double accuracyOnExamples; + private double accuracyOnPositiveExamples; + private double errorRate; + + private int nrOfExamples; + private int conceptLength; + + public ScoreThreeValued(int conceptLength, + SortedSet<Individual> posClassified, + SortedSet<Individual> neutClassified, + SortedSet<Individual> negClassified, + SortedSet<Individual> posExamples, + SortedSet<Individual> neutExamples, + SortedSet<Individual> negExamples) { + this.conceptLength = conceptLength; + this.posClassified = posClassified; + this.neutClassified = neutClassified; + this.negClassified = negClassified; + this.posExamples = posExamples; + this.neutExamples = neutExamples; + this.negExamples = negExamples; + nrOfExamples = posExamples.size()+negExamples.size(); + computeClassificationMatrix(); + computeStatistics(); + } + + private void computeClassificationMatrix() { + posAsNeg = Helper.intersection(posExamples,negClassified); + negAsPos = Helper.intersection(negExamples,posClassified); + posAsNeut = Helper.intersection(posExamples,neutClassified); + neutAsPos = Helper.intersection(neutExamples,posClassified); + neutAsNeg = Helper.intersection(neutExamples,negClassified); + negAsNeut = Helper.intersection(negExamples,neutClassified); + // die 3 Berechnungen sind nicht so wichtig f�r die Punktzahl, d.h. falls + // es Performance bringt, dann kann man sie auch ausgliedern + posAsPos = Helper.intersection(posExamples,posClassified); + negAsNeg = Helper.intersection(negExamples,negClassified); + neutAsNeut = Helper.intersection(neutExamples,neutClassified); + } + + private void computeStatistics() { + score = - posAsNeg.size()*Config.errorPenalty + - negAsPos.size()*Config.errorPenalty + - posAsNeut.size()*Config.accuracyPenalty; + + if(Config.scoreMethod==ScoreMethod.FULL) + score -= negAsNeut.size()*Config.accuracyPenalty; + + if(Config.penalizeNeutralExamples) + score -= (neutAsPos.size()*Config.accuracyPenalty + + neutAsNeg.size()*Config.accuracyPenalty); + + // TODO: man könnte hier statt error penality auch accuracy penalty + // nehmen + double worstValue = nrOfExamples * Config.errorPenalty; + // ergibt Zahl zwischen -1 und 0 + score = score / worstValue; + score -= Config.percentPerLengthUnit * conceptLength; + + // die folgenden Berechnungen k�nnten aus Performancegr�nden auch + // ausgegliedert werden + // int domainSize = abox.domain.size(); + int numberOfExamples = posExamples.size()+negExamples.size(); + int domainSize = numberOfExamples + neutExamples.size(); + int correctlyClassified = posAsPos.size() + negAsNeg.size() + neutAsNeut.size(); + int correctOnExamples = posAsPos.size() + negAsNeg.size(); + int errors = posAsNeg.size() + negAsPos.size(); + + // Accuracy = Quotient von richtig klassifizierten durch Anzahl Domainelemente + accuracy = (double) correctlyClassified/domainSize; + + // Accuracy on Examples = Quotient von richtig klassifizierten durch Anzahl pos. + // und neg. Beispiele + accuracyOnExamples = (double) correctOnExamples/numberOfExamples; + + accuracyOnPositiveExamples = (double) posAsPos.size()/posExamples.size(); + + // Error = Quotient von komplett falsch klassifizierten durch Anzahl pos. + // und neg. Beispiele + errorRate = (double) errors/numberOfExamples; + } + + @Override + public double getScore() { + return score; + } + + @Override + public String toString() { + DecimalFormat df = new DecimalFormat("0.00"); + String str = ""; + str += "score method "; + if(Config.scoreMethod == ScoreMethod.FULL) + str += "full"; + else + str += "positive"; + if(!Config.penalizeNeutralExamples) + str += " (neutral examples not penalized)"; + str += "\n"; + if(Config.showCorrectClassifications) { + str += "Correctly classified:\n"; + str += " positive --> positive: " + posAsPos + "\n"; + str += " neutral --> neutral: " + neutAsNeut + "\n"; + str += " negative --> negative: " + negAsNeg + "\n"; + } + str += "Inaccurately classified (penalty of " + df.format(Config.accuracyPenalty) + " per instance):\n"; + str += " positive --> neutral: " + posAsNeut + "\n"; + if(Config.penalizeNeutralExamples) { + str += " neutral --> positive: " + neutAsPos + "\n"; + str += " neutral --> negative: " + neutAsNeg + "\n"; + } + if(Config.scoreMethod == ScoreMethod.FULL) + str += " negative --> neutral: " + negAsNeut + "\n"; + str += "Classification errors (penalty of " + df.format(Config.errorPenalty) + " per instance):\n"; + str += " positive --> negative: " + posAsNeg + "\n"; + str += " negative --> positive: " + negAsPos + "\n"; + str += "Statistics:\n"; + str += " Score: " + df.format(score) + "\n"; + str += " Accuracy: " + df.format(accuracy*100) + "%\n"; + str += " Accuracy on exa... [truncated message content] |
From: <jen...@us...> - 2007-10-02 15:30:41
|
Revision: 161 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=161&view=rev Author: jenslehmann Date: 2007-10-02 08:30:37 -0700 (Tue, 02 Oct 2007) Log Message: ----------- parser split between Conf file and KB file parser, small improvements (warning: intermediate commit) Added Paths: ----------- 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/ConfParserTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/JJTConfParserState.java trunk/src/dl-learner/org/dllearner/parser/JJTKBParserState.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/KBParserConstants.java trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/KBParserTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/parser/conf.jjt trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/parser/kb.jjt Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerConstants.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java trunk/src/dl-learner/org/dllearner/parser/JJTDLLearnerState.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt Added: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-02 15:30:37 UTC (rev 161) @@ -0,0 +1,1108 @@ +/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParser.java */ +package org.dllearner.parser; + +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.TreeMap; +import java.util.Set; +import java.util.HashSet; +import java.util.SortedSet; +import java.util.TreeSet; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; + +import org.dllearner.Main; +import org.dllearner.Info; + +import org.dllearner.core.dl.*; +import org.dllearner.ConfigurationOption; +import org.dllearner.utilities.*; + +public @SuppressWarnings("all") class ConfParser/*@bgen(jjtree)*/implements ConfParserTreeConstants, ConfParserConstants {/*@bgen(jjtree)*/ + protected JJTConfParserState jjtree = new JJTConfParserState(); + private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); + private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + + // Konfigurationsoptionen + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + + // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen + // Argumenten aufgerufen werden) + // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); + // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe + // werden in einer Liste gespeichert + private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // => irgendwie Funktionsname + Argumente speichern + // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element + // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante + + // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es + // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal + // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit + // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser + // private static boolean constructorCalled = false; + + // Wissensbasis + // private KB kb = new KB(); + // public static final String internalNamespace = "http://localhost/foo#"; + + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } + + public SortedSet<Individual> getNegativeExamples() { + return negativeExamples; + } + + public List<ConfigurationOption> getConfOptions() { + return confOptions; + } + + public List<List<String>> getFunctionCalls() { + return functionCalls; + } + + /* + private static void addFunctionCall(String functionName, String argument) { + if(functionCalls.containsKey(functionName)) { + functionCalls.get(functionName).add(argument); + } else { + Set<String> newFunction = new TreeSet<String>(); + newFunction.add(argument); + functionCalls.put(functionName,newFunction); + } + } + */ + + + + public static SimpleNode parseString(String str) throws ParseException { + StringReader sr = new StringReader(str); + DLLearner learner = new DLLearner(sr); + SimpleNode n = learner.Start(); + return n; + } + + public static DLLearner parseFile(String filename) { + DLLearner learner = null; + try { + learner = new DLLearner(new FileInputStream(filename)); + learner.Start(); + } catch(FileNotFoundException e) { + e.printStackTrace(); + } catch(ParseException e) { + e.printStackTrace(); + } + return learner; + } + + public static void main(String args[]) { + + if(args.length==0) { + System.out.println("Please specify an input file."); + System.exit(0); + } + + System.out.println("Starting DL-Learner (Build " + Info.build + ")"); + // System.out.println(args); + + // System.out.println(args[0]); + // System.out.println(args[1]); + // System.out.println(args.length); + + File f = new File(args[args.length-1]); + String baseDir = ""; + + System.out.print("Parsing " + f.getName() + " ... "); + long parseStartTime = System.currentTimeMillis(); + + SimpleNode n = null; + DLLearner learner = null; + try { + learner = new DLLearner(new FileInputStream(args[args.length-1])); + baseDir = f.getParentFile().getPath(); + } catch(IOException e) { + System.err.println(e); + System.exit(0); + } + try { + n = learner.Start(); + // n.dump(""); + // System.out.println("Thank you."); + } catch (Exception e) { + System.out.println("\nParse exception occurred. Please follow the advise given below."); + System.out.println(e.getMessage()); + e.printStackTrace(); + System.exit(0); + } + + long parseDuration = System.currentTimeMillis() - parseStartTime; + System.out.println("OK (" + parseDuration + " ms)"); + + boolean queryMode = false; + // solution test mode wird nicht unbedingt gebraucht, da man die covers + // gleich standardmäßig beim query mit anzeigen kann + // boolean solutionTestMode = false; + + if(args.length>1 && args[0].equals("-q")) + queryMode = true; + + //if(args.length>1 && args[0].equals("-qt")) { + // queryMode = true; + // solutionTestMode = true; + //} + + // new Main(n, baseDir, queryMode); + // Parser erstmal Standalone testen + // n.dump(""); + + // neuer Aufruf des Hauptprogramms + // TODO: remove (in the future, the parser will be called from whatever method + // needs it, instead of starting the learning process itself) + // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); + } + + final public SimpleNode Start() throws ParseException { + /*@bgen(jjtree) Start */ + SimpleNode jjtn000 = new SimpleNode(JJTSTART); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);ConceptAssertion conceptAssertion; + RoleAssertion roleAssertion; + RBoxAxiom rBoxAxiom; + Equality equality; + Inclusion inclusion; + ConfigurationOption confOption; + try { + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case POS_EX: + case NEG_EX: + case ID: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + if (jj_2_1(2147483647)) { + confOption = ConfOption(); + confOptions.add(confOption); + } else if (jj_2_2(2147483647)) { + FunctionCall(); + } else if (jj_2_3(2147483647)) { + PosExample(); + } else if (jj_2_4(2147483647)) { + NegExample(); + } else { + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(0); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return jjtn000;} + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public ConfigurationOption ConfOption() throws ParseException { + /*@bgen(jjtree) ConfOption */ + SimpleNode jjtn000 = new SimpleNode(JJTCONFOPTION); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; + String option="", subOption="", value="", tmp=""; + int number = 0; + double numberDouble = 0; + ConfigurationOption confOption; + Set<String> values = new HashSet<String>(); + try { + option = Id(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMAND_END: + jj_consume_token(COMMAND_END); + subOption = Id(); + containsSubOption=true; + break; + default: + jj_la1[1] = jj_gen; + ; + } + jj_consume_token(25); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + value = Id(); + break; + case STRING: + value = String(); + break; + case NUMBER: + number = Integer(); + isNumeric=true; + break; + case DOUBLE: + numberDouble = Double(); + isNumeric=true; isDouble=true; + break; + default: + jj_la1[4] = jj_gen; + if (jj_2_6(2147483647)) { + jj_consume_token(26); + jj_consume_token(27); + isSet=true; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 26: + jj_consume_token(26); + label_2: + while (true) { + if (jj_2_5(2)) { + ; + } else { + break label_2; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + values.add(tmp); + jj_consume_token(28); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + values.add(tmp); + jj_consume_token(27); + isSet=true; + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + jj_consume_token(CONF_END); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + if(containsSubOption) { + if(isNumeric) + if(isDouble) + confOption = new ConfigurationOption(option,subOption,numberDouble); + else + confOption = new ConfigurationOption(option,subOption,number); + else + if(isSet) + confOption = new ConfigurationOption(option,subOption,values); + else + confOption = new ConfigurationOption(option,subOption,value); + } else { + if(isNumeric) + if(isDouble) + confOption = new ConfigurationOption(option,numberDouble); + else + confOption = new ConfigurationOption(option,number); + else + if(isSet) + confOption = new ConfigurationOption(option,values); + else + confOption = new ConfigurationOption(option,value); + } + {if (true) return confOption;} + // confOptions.add(confOption); + + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public void FunctionCall() throws ParseException { + /*@bgen(jjtree) FunctionCall */ + SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONCALL); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);String s, s1, s2; + List<String> list = new LinkedList<String>(); + try { + s1 = Id(); + jj_consume_token(29); + s2 = String(); + list.add(s1); list.add(s2); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 28: + ; + break; + default: + jj_la1[6] = jj_gen; + break label_3; + } + jj_consume_token(28); + s = String(); + list.add(s); + } + jj_consume_token(30); + jj_consume_token(CONF_END); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + functionCalls.add(list); + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + } + + final public void PosExample() throws ParseException { + /*@bgen(jjtree) PosExample */ + SimpleNode jjtn000 = new SimpleNode(JJTPOSEXAMPLE); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Individual i; + try { + jj_consume_token(POS_EX); + i = Individual(); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + positiveExamples.add(i); + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + } + + final public void NegExample() throws ParseException { + /*@bgen(jjtree) NegExample */ + SimpleNode jjtn000 = new SimpleNode(JJTNEGEXAMPLE); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Individual i; + try { + jj_consume_token(NEG_EX); + i = Individual(); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + negativeExamples.add(i); + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + } + + final public Individual Individual() throws ParseException { + /*@bgen(jjtree) Individual */ + SimpleNode jjtn000 = new SimpleNode(JJTINDIVIDUAL); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);String name; + try { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + name = Id(); + break; + case STRING: + name = String(); + break; + default: + jj_la1[7] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return new Individual(KBParser.getInternalURI(name));} + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + {if (true) throw (RuntimeException)jjte000;} + } + if (jjte000 instanceof ParseException) { + {if (true) throw (ParseException)jjte000;} + } + {if (true) throw (Error)jjte000;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public String Id() throws ParseException { + /*@bgen(jjtree) Id */ + SimpleNode jjtn000 = new SimpleNode(JJTID); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Token t; + try { + t = jj_consume_token(ID); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return t.image;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public double Double() throws ParseException { + /*@bgen(jjtree) Double */ + SimpleNode jjtn000 = new SimpleNode(JJTDOUBLE); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Token t; + try { + t = jj_consume_token(DOUBLE); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return new Double(t.image);} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public int Integer() throws ParseException { + /*@bgen(jjtree) Integer */ + SimpleNode jjtn000 = new SimpleNode(JJTINTEGER); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Token t; + try { + t = jj_consume_token(NUMBER); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return new Integer(t.image);} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public String String() throws ParseException { + /*@bgen(jjtree) String */ + SimpleNode jjtn000 = new SimpleNode(JJTSTRING); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);Token t; + String s; + try { + t = jj_consume_token(STRING); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + // enclosing "" are removed + s = t.image; + s = s.substring(1, s.length() - 1); + {if (true) return s;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + final private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + final private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + final private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + final private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + final private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + final private boolean jj_3R_7() { + if (jj_3R_16()) return true; + return false; + } + + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; + return false; + } + + final private boolean jj_3R_6() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_22() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_6() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_13() { + if (jj_scan_token(28)) return true; + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_5() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) { + jj_scanpos = xsp; + if (jj_3R_15()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3R_12() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3R_21() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_18() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_21()) { + jj_scanpos = xsp; + if (jj_3R_22()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3R_9() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_5() { + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_4() { + if (jj_scan_token(NEG_EX)) return true; + return false; + } + + final private boolean jj_3_3() { + if (jj_scan_token(POS_EX)) return true; + return false; + } + + final private boolean jj_3R_11() { + if (jj_scan_token(26)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_18()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_19()) { + jj_scanpos = xsp; + if (jj_3R_20()) return true; + } + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_16() { + if (jj_scan_token(NUMBER)) return true; + return false; + } + + final private boolean jj_3R_20() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_2() { + if (jj_3R_4()) return true; + if (jj_scan_token(29)) return true; + if (jj_3R_12()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_13()) { 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_15() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_1() { + if (jj_3R_4()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_5()) jj_scanpos = xsp; + if (jj_scan_token(25)) return true; + xsp = jj_scanpos; + if (jj_3R_6()) { + jj_scanpos = xsp; + if (jj_3R_7()) { + jj_scanpos = xsp; + if (jj_3R_8()) { + jj_scanpos = xsp; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_3R_10()) { + jj_scanpos = xsp; + if (jj_3R_11()) return true; + } + } + } + } + } + if (jj_scan_token(CONF_END)) return true; + return false; + } + + final private boolean jj_3R_8() { + if (jj_3R_17()) return true; + return false; + } + + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_19() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_3R_12()) return true; + return false; + } + + public ConfParserTokenManager token_source; + SimpleCharStream jj_input_stream; + public Token token, jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + public boolean lookingAhead = false; + private boolean jj_semLA; + private int jj_gen; + final private int[] jj_la1 = new int[8]; + static private int[] jj_la1_0; + static { + jj_la1_0(); + } + private static void jj_la1_0() { + jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1007000,0x4000000,0x10000000,0x1001000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[6]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + public ConfParser(java.io.InputStream stream) { + this(stream, null); + } + public ConfParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jjtree.reset(); + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public ConfParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jjtree.reset(); + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public ConfParser(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jjtree.reset(); + jj_gen = 0; + for (int i = 0; i < 8; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + final private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + final private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + final public Token getToken(int index) { + Token t = lookingAhead ? jj_scanpos : token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + final private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.Vector jj_expentries = new java.util.Vector(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + boolean exists = false; + for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { + int[] oldentry = (int[])(e.nextElement()); + if (oldentry.length == jj_expentry.length) { + exists = true; + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + exists = false; + break; + } + } + if (exists) break; + } + } + if (!exists) jj_expentries.addElement(jj_expentry); + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + public ParseException generateParseException() { + jj_expentries.removeAllElements(); + boolean[] la1tokens = new boolean[31]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 8; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<<j)) != 0) { + la1tokens[j] = true; + } + } + } + } + for (int i = 0; i < 31; i++) { + if (la1tokens[i]) { + jj_expentry = new int[1]; + jj_expentry[0] = i; + jj_expentries.addElement(jj_expentry); + } + } + jj_endpos = 0; + jj_rescan_token(); + jj_add_error_token(0, 0); + int[][] exptokseq = new int[jj_expentries.size()][]; + for (int i = 0; i < jj_expentries.size(); i++) { + exptokseq[i] = (int[])jj_expentries.elementAt(i); + } + return new ParseException(token, exptokseq, tokenImage); + } + + final public void enable_tracing() { + } + + final public void disable_tracing() { + } + + final private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 6; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + final private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} Added: trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserConstants.java 2007-10-02 15:30:37 UTC (rev 161) @@ -0,0 +1,64 @@ +/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParserConstants.java */ +package org.dllearner.parser; + +public @SuppressWarnings("all") interface ConfParserConstants { + + int EOF = 0; + int SINGLE_LINE_COMMENT = 5; + int FORMAL_COMMENT = 6; + int MULTI_LINE_COMMENT = 7; + int COMMAND_END = 8; + int CONF_END = 9; + int POS_EX = 10; + int NEG_EX = 11; + int ID = 12; + int NUMBER = 13; + int DOUBLE = 14; + int TOP = 15; + int BOTTOM = 16; + int AND = 17; + int OR = 18; + int EXISTS = 19; + int ALL = 20; + int NOT = 21; + int GE = 22; + int LE = 23; + int STRING = 24; + + int DEFAULT = 0; + + String[] tokenImage = { + "<EOF>", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "<SINGLE_LINE_COMMENT>", + "<FORMAL_COMMENT>", + "<MULTI_LINE_COMMENT>", + "\".\"", + "\";\"", + "\"+\"", + "\"-\"", + "<ID>", + "<NUMBER>", + "<DOUBLE>", + "\"TOP\"", + "\"BOTTOM\"", + "\"AND\"", + "\"OR\"", + "<EXISTS>", + "<ALL>", + "<NOT>", + "\">=\"", + "\"<=\"", + "<STRING>", + "\"=\"", + "\"{\"", + "\"}\"", + "\",\"", + "\"(\"", + "\")\"", + }; + +} Added: trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-02 15:30:37 UTC (rev 161) @@ -0,0 +1,755 @@ +/* Generated By:JJTree&JavaCC: Do not edit this line. ConfParserTokenManager.java */ +package org.dllearner.parser; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.TreeMap; +import java.util.Set; +import java.util.HashSet; +import java.util.SortedSet; +import java.util.TreeSet; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; +import org.dllearner.Main; +import org.dllearner.Info; +import org.dllearner.core.dl.*; +import org.dllearner.ConfigurationOption; +import org.dllearner.utilities.*; + +public @SuppressWarnings("all") class ConfParserTokenManager implements ConfParserConstants +{ + public java.io.PrintStream debugStream = System.out; + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + case 0: + if ((active0 & 0x20000L) != 0L) + return 13; + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private final int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private final int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +private final int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 29); + case 41: + return jjStopAtPos(0, 30); + case 43: + return jjStopAtPos(0, 10); + case 44: + return jjStopAtPos(0, 28); + case 45: + return jjStopAtPos(0, 11); + case 46: + return jjStopAtPos(0, 8); + case 59: + return jjStopAtPos(0, 9); + case 60: + return jjMoveStringLiteralDfa1_0(0x800000L); + case 61: + return jjStopAtPos(0, 25); + case 62: + return jjMoveStringLiteralDfa1_0(0x400000L); + case 65: + return jjMoveStringLiteralDfa1_0(0x20000L); + case 66: + return jjMoveStringLiteralDfa1_0(0x10000L); + case 79: + return jjMoveStringLiteralDfa1_0(0x40000L); + case 84: + return jjMoveStringLiteralDfa1_0(0x8000L); + case 123: + return jjStopAtPos(0, 26); + case 125: + return jjStopAtPos(0, 27); + default : + return jjMoveNfa_0(0, 0); + } +} +private final int jjMoveStringLiteralDfa1_0(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 61: + if ((active0 & 0x400000L) != 0L) + return jjStopAtPos(1, 22); + else if ((active0 & 0x800000L) != 0L) + return jjStopAtPos(1, 23); + break; + case 78: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L); + case 79: + return jjMoveStringLiteralDfa2_0(active0, 0x18000L); + case 82: + if ((active0 & 0x40000L) != 0L) + return jjStopAtPos(1, 18); + break; + default : + break; + } + return jjStartNfa_0(0, active0); +} +private final int jjMoveStringLiteralDfa2_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 68: + if ((active0 & 0x20000L) != 0L) + return jjStopAtPos(2, 17); + break; + case 80: + if ((active0 & 0x8000L) != 0L) + return jjStopAtPos(2, 15); + break; + case 84: + return jjMoveStringLiteralDfa3_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(1, active0); +} +private final int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 84: + return jjMoveStringLiteralDfa4_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(2, active0); +} +private final int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0); + return 4; + } + switch(curChar) + { + case 79: + return jjMoveStringLiteralDfa5_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(3, active0); +} +private final int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0); + return 5; + } + switch(curChar) + { + case 77: + if ((active0 & 0x10000L) != 0L) + return jjStopAtPos(5, 16); + break; + default : + break; + } + return jjStartNfa_0(4, active0); +} +private final void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private final void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private final void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} +private final void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} +private final void jjCheckNAddStates(int start) +{ + jjCheckNAdd(jjnextStates[start]); + jjCheckNAdd(jjnextStates[start + 1]); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private final int jjMoveNfa_0(int startState, int curPos) +{ + int[] nextStates; + int startsAt = 0; + jjnewStateCnt = 53; + int i = 1; + jjstateSet[0] = startState; + int j, kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + } + else if (curChar == 48) + { + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + } + else if (curChar == 47) + jjAddStates(3, 5); + else if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjstateSet[jjnewStateCnt++] = 1; + break; + case 20: + if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 21: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(21, 22); + break; + case 22: + if (curChar == 34 && kind > 24) + kind = 24; + break; + case 28: + if (curChar == 47) + jjAddStates(3, 5); + break; + case 29: + if (curChar == 47) + jjCheckNAddStates(6, 8); + break; + case 30: + if ((0xffffffffffffdbffL & l) != 0L) + jjCheckNAddStates(6, 8); + break; + case 31: + if ((0x2400L & l) != 0L && kind > 5) + kind = 5; + break; + case 32: + if (curChar == 10 && kind > 5) + kind = 5; + break; + case 33: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 34: + if (curChar == 42) + jjCheckNAddTwoStates(35, 36); + break; + case 35: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 36: + if (curChar == 42) + jjCheckNAddStates(9, 11); + break; + case 37: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 38: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 39: + if (curChar == 47 && kind > 6) + kind = 6; + break; + case 40: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 34; + break; + case 41: + if (curChar == 42) + jjCheckNAddTwoStates(42, 43); + break; + case 42: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 43: + if (curChar == 42) + jjCheckNAddStates(12, 14); + break; + case 44: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 45: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 46: + if (curChar == 47 && kind > 7) + kind = 7; + break; + case 47: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + break; + case 48: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(48); + break; + case 49: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(49, 50); + break; + case 50: + if (curChar != 46) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 51: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 52: + if (curChar != 48) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x7fffffe00000000L & l) != 0L) + { + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + } + else if (curChar == 78) + jjAddStates(15, 16); + else if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + else if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + else if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + else if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 1: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + break; + case 2: + if (curChar == 83 && kind > 19) + kind = 19; + break; + case 3: + if (curChar == 84) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 4: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 3; + break; + case 5: + if (curChar == 73) + jjstateSet[jjnewStateCnt++] = 4; + break; + case 6: + if (curChar == 88) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 7: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 8: + if (curChar == 69 && kind > 19) + kind = 19; + break; + case 9: + if (curChar == 77) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: + if (curChar == 76 && kind > 20) + kind = 20; + break; + case 13: + case 15: + if (curChar == 76) + jjCheckNAdd(12); + break; + case 14: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 16: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 15; + break; + case 17: + if (curChar == 82) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 18: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + break; + case 21: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(17, 18); + break; + case 23: + if (curChar == 78) + jjAddStates(15, 16); + break; + case 24: + if (curChar == 71 && kind > 21) + kind = 21; + break; + case 25: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 26: + if (curChar == 84 && kind > 21) + kind = 21; + break; + case 27: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 26; + break; + case 30: + jjAddStates(6, 8); + break; + case 35: + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + jjCheckNAddTwoStates(38, 36); + break; + case 42: + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 21: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(17, 18); + break; + case 30: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(6, 8); + break; + case 35: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 42: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 53 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 48, 49, 50, 29, 40, 41, 30, 31, 33, 36, 37, 39, 43, 44, 46, 25, + 27, 21, 22, +}; +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", }; +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0x7fffff01L, +}; +static final long[] jjtoSkip = { + 0xfeL, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[53]; +private final int[] jjstateSet = new int[106]; +protected char curChar; +public ConfParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} +public ConfParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private final void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 53; i-- > 0;) + jjrounds[i] = 0x80000000; +} +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + Token t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + String im = jjstrLiteralImages[jjmatchedKind]; + t.image = (im == null) ? input_stream.GetImage() : im; + t.beginLine = input_stream.getBeginLine(); + t.beginColumn = input_stream.getBeginColumn(); + t.endLine = input_stream.getEndLine(); + t.endColumn = input_stream.getEndColumn(); + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +public Token getNextToken() +{ + int kind; + Token specialToken = null; + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ?... [truncated message content] |
From: <jen...@us...> - 2007-10-01 17:14:20
|
Revision: 160 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=160&view=rev Author: jenslehmann Date: 2007-10-01 10:14:03 -0700 (Mon, 01 Oct 2007) Log Message: ----------- changed previous static parser to dynamic parser Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jj trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-10-01 17:14:03 UTC (rev 160) @@ -12,6 +12,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; @@ -24,21 +25,21 @@ // @SuppressWarnings({"all"}) public @SuppressWarnings("all") class DLLearner/*@bgen(jjtree)*/implements DLLearnerTreeConstants, DLLearnerConstants {/*@bgen(jjtree)*/ - protected static JJTDLLearnerState jjtree = new JJTDLLearnerState(); + protected JJTDLLearnerState jjtree = new JJTDLLearnerState(); private static ConceptComparator conceptComparator = new ConceptComparator(); // hier wird Parse-Fehler angezeigt, obwohl eigentlich alles stimmt?? - private static Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - private static Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); // Konfigurationsoptionen - private static List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private static List<List<String>> functionCalls = new LinkedList<List<String>>(); + private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante @@ -47,13 +48,13 @@ // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - private static boolean constructorCalled = false; + // private static boolean constructorCalled = false; // Wissensbasis - private static KB kb = new KB(); + private KB kb = new KB(); public static final String internalNamespace = "http://localhost/foo#"; - private static void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { + private void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { if(positiveExamples.containsKey(conceptName)) { positiveExamples.get(conceptName).add(instanceName); } else { @@ -63,7 +64,7 @@ } } - private static void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { + private void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { if(negativeExamples.containsKey(conceptName)) { negativeExamples.get(conceptName).add(instanceName); } else { @@ -73,23 +74,23 @@ } } - public static Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { return positiveExamples; } - public static Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { return negativeExamples; } - public static List<ConfigurationOption> getConfOptions() { + public List<ConfigurationOption> getConfOptions() { return confOptions; } - public static List<List<String>> getFunctionCalls() { + public List<List<String>> getFunctionCalls() { return functionCalls; } - public static KB getKB() { + public KB getKB() { return kb; } @@ -117,19 +118,14 @@ public static SimpleNode parseString(String str) throws ParseException { StringReader sr = new StringReader(str); - // new DLLearner(sr); - DLLearner.ReInit(sr); - SimpleNode n = DLLearner.Start(); + DLLearner learner = new DLLearner(sr); + SimpleNode n = learner.Start(); return n; } public static Concept parseConcept(String str) throws ParseException { StringReader sr = new StringReader(str); - if(constructorCalled) - DLLearner.ReInit(sr); - else - new DLLearner(sr); - constructorCalled = true; + DLLearner learner = new DLLearner(sr); // //SimpleNode n = DLLearner.Start(); //return n; @@ -142,29 +138,22 @@ // TODO Auto-generated catch block e.printStackTrace(); }*/ - Concept c = DLLearner.Concept(); + Concept c = learner.Concept(); return c; } - public static void parseFile(String filename) { - - positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - confOptions = new LinkedList<ConfigurationOption>(); - functionCalls = new LinkedList<List<String>>(); - kb = new KB(); - + public static DLLearner parseFile(String filename) { + DLLearner learner = null; try { - if(constructorCalled) - DLLearner.ReInit(new FileInputStream(filename)); - else - new DLLearner(new FileInputStream(filename)); - constructorCalled = true; - DLLearner.Start(); - } catch(Exception e) { + learner = new DLLearner(new FileInputStream(filename)); + learner.Start(); + } catch(FileNotFoundException e) { e.printStackTrace(); + } catch(ParseException e) { + e.printStackTrace(); } + return learner; } public static void main(String args[]) { @@ -188,16 +177,16 @@ long parseStartTime = System.currentTimeMillis(); SimpleNode n = null; + DLLearner learner = null; try { - new DLLearner(new FileInputStream(args[args.length-1])); - constructorCalled = true; + learner = new DLLearner(new FileInputStream(args[args.length-1])); baseDir = f.getParentFile().getPath(); } catch(IOException e) { System.err.println(e); System.exit(0); } try { - n = DLLearner.Start(); + n = learner.Start(); // n.dump(""); // System.out.println("Thank you."); } catch (Exception e) { @@ -228,7 +217,9 @@ // n.dump(""); // neuer Aufruf des Hauptprogramms - new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); + // TODO: remove (in the future, the parser will be called from whatever method + // needs it, instead of starting the learning process itself) + // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); } /* Grob�berblick: @@ -244,7 +235,7 @@ | Concept() "=" Concept() <COMMAND_END> // TBox - �quivalenz von Konzepten | Concept() "SUBCLASS" Concept() <COMMAND_END> // TBox - Konzept 1 Teilmenge von Konzept 2 */ - static final public SimpleNode Start() throws ParseException { + final public SimpleNode Start() throws ParseException { /*@bgen(jjtree) Start */ SimpleNode jjtn000 = new SimpleNode(JJTSTART); boolean jjtc000 = true; @@ -253,6 +244,7 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; + ConfigurationOption confOption; try { label_1: while (true) { @@ -281,7 +273,8 @@ break label_1; } if (jj_2_1(2147483647)) { - ConfOption(); + confOption = ConfOption(); + confOptions.add(confOption); } else if (jj_2_2(2147483647)) { FunctionCall(); } else if (jj_2_3(2147483647)) { @@ -357,7 +350,25 @@ throw new Error("Missing return statement in function"); } - static final public void ConfOption() throws ParseException { + final public KB parseKB() throws ParseException { + /*@bgen(jjtree) parseKB */ + SimpleNode jjtn000 = new SimpleNode(JJTPARSEKB); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);KB kb = null; + try { + jj_consume_token(0); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return kb;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public ConfigurationOption ConfOption() throws ParseException { /*@bgen(jjtree) ConfOption */ SimpleNode jjtn000 = new SimpleNode(JJTCONFOPTION); boolean jjtc000 = true; @@ -476,7 +487,9 @@ else confOption = new ConfigurationOption(option,value); } - confOptions.add(confOption); + {if (true) return confOption;} + // confOptions.add(confOption); + } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); @@ -496,9 +509,10 @@ jjtree.closeNodeScope(jjtn000, true); } } + throw new Error("Missing return statement in function"); } - static final public void FunctionCall() throws ParseException { + final public void FunctionCall() throws ParseException { /*@bgen(jjtree) FunctionCall */ SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONCALL); boolean jjtc000 = true; @@ -549,7 +563,7 @@ } } - static final public void PosExample() throws ParseException { + final public void PosExample() throws ParseException { /*@bgen(jjtree) PosExample */ SimpleNode jjtn000 = new SimpleNode(JJTPOSEXAMPLE); boolean jjtc000 = true; @@ -585,7 +599,7 @@ } } - static final public void NegExample() throws ParseException { + final public void NegExample() throws ParseException { /*@bgen(jjtree) NegExample */ SimpleNode jjtn000 = new SimpleNode(JJTNEGEXAMPLE); boolean jjtc000 = true; @@ -621,7 +635,7 @@ } } - static final public ConceptAssertion ABoxConcept() throws ParseException { + final public ConceptAssertion ABoxConcept() throws ParseException { /*@bgen(jjtree) ABoxConcept */ SimpleNode jjtn000 = new SimpleNode(JJTABOXCONCEPT); boolean jjtc000 = true; @@ -657,7 +671,7 @@ throw new Error("Missing return statement in function"); } - static final public RoleAssertion ABoxRole() throws ParseException { + final public RoleAssertion ABoxRole() throws ParseException { /*@bgen(jjtree) ABoxRole */ SimpleNode jjtn000 = new SimpleNode(JJTABOXROLE); boolean jjtc000 = true; @@ -709,7 +723,7 @@ throw new Error("Missing return statement in function"); } - static final public TransitiveRoleAxiom Transitive() throws ParseException { + final public TransitiveRoleAxiom Transitive() throws ParseException { /*@bgen(jjtree) Transitive */ SimpleNode jjtn000 = new SimpleNode(JJTTRANSITIVE); boolean jjtc000 = true; @@ -745,7 +759,7 @@ throw new Error("Missing return statement in function"); } - static final public FunctionalRoleAxiom Functional() throws ParseException { + final public FunctionalRoleAxiom Functional() throws ParseException { /*@bgen(jjtree) Functional */ SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONAL); boolean jjtc000 = true; @@ -781,7 +795,7 @@ throw new Error("Missing return statement in function"); } - static final public SymmetricRoleAxiom Symmetric() throws ParseException { + final public SymmetricRoleAxiom Symmetric() throws ParseException { /*@bgen(jjtree) Symmetric */ SimpleNode jjtn000 = new SimpleNode(JJTSYMMETRIC); boolean jjtc000 = true; @@ -817,7 +831,7 @@ throw new Error("Missing return statement in function"); } - static final public InverseRoleAxiom Inverse() throws ParseException { + final public InverseRoleAxiom Inverse() throws ParseException { /*@bgen(jjtree) Inverse */ SimpleNode jjtn000 = new SimpleNode(JJTINVERSE); boolean jjtc000 = true; @@ -855,7 +869,7 @@ throw new Error("Missing return statement in function"); } - static final public SubRoleAxiom Subrole() throws ParseException { + final public SubRoleAxiom Subrole() throws ParseException { /*@bgen(jjtree) Subrole */ SimpleNode jjtn000 = new SimpleNode(JJTSUBROLE); boolean jjtc000 = true; @@ -954,7 +968,7 @@ { return new SubRoleAxiom(new AtomicRole(s1),new AtomicRole(s2));} } ****************************************************************/ - static final public Equality TBoxEquiv() throws ParseException { + final public Equality TBoxEquiv() throws ParseException { /*@bgen(jjtree) TBoxEquiv */ SimpleNode jjtn000 = new SimpleNode(JJTTBOXEQUIV); boolean jjtc000 = true; @@ -989,7 +1003,7 @@ throw new Error("Missing return statement in function"); } - static final public Inclusion TBoxSub() throws ParseException { + final public Inclusion TBoxSub() throws ParseException { /*@bgen(jjtree) TBoxSub */ SimpleNode jjtn000 = new SimpleNode(JJTTBOXSUB); boolean jjtc000 = true; @@ -1039,7 +1053,7 @@ } // TODO: Support f�r inverse Rollen - static final public Concept Concept() throws ParseException { + final public Concept Concept() throws ParseException { /*@bgen(jjtree) Concept */ SimpleNode jjtn000 = new SimpleNode(JJTCONCEPT); boolean jjtc000 = true; @@ -1165,7 +1179,7 @@ throw new Error("Missing return statement in function"); } - static final public void Or() throws ParseException { + final public void Or() throws ParseException { /*@bgen(jjtree) Or */ SimpleNode jjtn000 = new SimpleNode(JJTOR); boolean jjtc000 = true; @@ -1179,7 +1193,7 @@ } } - static final public void And() throws ParseException { + final public void And() throws ParseException { /*@bgen(jjtree) And */ SimpleNode jjtn000 = new SimpleNode(JJTAND); boolean jjtc000 = true; @@ -1193,7 +1207,7 @@ } } - static final public void Top() throws ParseException { + final public void Top() throws ParseException { /*@bgen(jjtree) Top */ SimpleNode jjtn000 = new SimpleNode(JJTTOP); boolean jjtc000 = true; @@ -1207,7 +1221,7 @@ } } - static final public void Bottom() throws ParseException { + final public void Bottom() throws ParseException { /*@bgen(jjtree) Bottom */ SimpleNode jjtn000 = new SimpleNode(JJTBOTTOM); boolean jjtc000 = true; @@ -1221,7 +1235,7 @@ } } - static final public void Exists() throws ParseException { + final public void Exists() throws ParseException { /*@bgen(jjtree) Exists */ SimpleNode jjtn000 = new SimpleNode(JJTEXISTS); boolean jjtc000 = true; @@ -1235,7 +1249,7 @@ } } - static final public void All() throws ParseException { + final public void All() throws ParseException { /*@bgen(jjtree) All */ SimpleNode jjtn000 = new SimpleNode(JJTALL); boolean jjtc000 = true; @@ -1249,7 +1263,7 @@ } } - static final public void Not() throws ParseException { + final public void Not() throws ParseException { /*@bgen(jjtree) Not */ SimpleNode jjtn000 = new SimpleNode(JJTNOT); boolean jjtc000 = true; @@ -1263,7 +1277,7 @@ } } - static final public void GE() throws ParseException { + final public void GE() throws ParseException { /*@bgen(jjtree) GE */ SimpleNode jjtn000 = new SimpleNode(JJTGE); boolean jjtc000 = true; @@ -1277,7 +1291,7 @@ } } - static final public void LE() throws ParseException { + final public void LE() throws ParseException { /*@bgen(jjtree) LE */ SimpleNode jjtn000 = new SimpleNode(JJTLE); boolean jjtc000 = true; @@ -1291,7 +1305,7 @@ } } - static final public AtomicConcept AtomicConcept() throws ParseException { + final public AtomicConcept AtomicConcept() throws ParseException { /*@bgen(jjtree) AtomicConcept */ SimpleNode jjtn000 = new SimpleNode(JJTATOMICCONCEPT); boolean jjtc000 = true; @@ -1334,7 +1348,7 @@ throw new Error("Missing return statement in function"); } - static final public AtomicRole AtomicRole() throws ParseException { + final public AtomicRole AtomicRole() throws ParseException { /*@bgen(jjtree) AtomicRole */ SimpleNode jjtn000 = new SimpleNode(JJTATOMICROLE); boolean jjtc000 = true; @@ -1377,7 +1391,7 @@ throw new Error("Missing return statement in function"); } - static final public Individual Individual() throws ParseException { + final public Individual Individual() throws ParseException { /*@bgen(jjtree) Individual */ SimpleNode jjtn000 = new SimpleNode(JJTINDIVIDUAL); boolean jjtc000 = true; @@ -1420,7 +1434,7 @@ throw new Error("Missing return statement in function"); } - static final public String Id() throws ParseException { + final public String Id() throws ParseException { /*@bgen(jjtree) Id */ SimpleNode jjtn000 = new SimpleNode(JJTID); boolean jjtc000 = true; @@ -1439,7 +1453,7 @@ throw new Error("Missing return statement in function"); } - static final public double Double() throws ParseException { + final public double Double() throws ParseException { /*@bgen(jjtree) Double */ SimpleNode jjtn000 = new SimpleNode(JJTDOUBLE); boolean jjtc000 = true; @@ -1457,7 +1471,7 @@ throw new Error("Missing return statement in function"); } - static final public int Integer() throws ParseException { + final public int Integer() throws ParseException { /*@bgen(jjtree) Integer */ SimpleNode jjtn000 = new SimpleNode(JJTINTEGER); boolean jjtc000 = true; @@ -1477,7 +1491,7 @@ throw new Error("Missing return statement in function"); } - static final public String String() throws ParseException { + final public String String() throws ParseException { /*@bgen(jjtree) String */ SimpleNode jjtn000 = new SimpleNode(JJTSTRING); boolean jjtc000 = true; @@ -1500,148 +1514,110 @@ throw new Error("Missing return statement in function"); } - static final private boolean jj_2_1(int xla) { + final private boolean jj_2_1(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_1(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(0, xla); } } - static final private boolean jj_2_2(int xla) { + final private boolean jj_2_2(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_2(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(1, xla); } } - static final private boolean jj_2_3(int xla) { + final private boolean jj_2_3(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_3(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(2, xla); } } - static final private boolean jj_2_4(int xla) { + final private boolean jj_2_4(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_4(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(3, xla); } } - static final private boolean jj_2_5(int xla) { + final private boolean jj_2_5(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_5(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(4, xla); } } - static final private boolean jj_2_6(int xla) { + final private boolean jj_2_6(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_6(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(5, xla); } } - static final private boolean jj_2_7(int xla) { + final private boolean jj_2_7(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_7(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(6, xla); } } - static final private boolean jj_2_8(int xla) { + final private boolean jj_2_8(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_8(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(7, xla); } } - static final private boolean jj_2_9(int xla) { + final private boolean jj_2_9(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_9(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(8, xla); } } - static final private boolean jj_2_10(int xla) { + final private boolean jj_2_10(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_10(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(9, xla); } } - static final private boolean jj_2_11(int xla) { + final private boolean jj_2_11(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_11(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(10, xla); } } - static final private boolean jj_2_12(int xla) { + final private boolean jj_2_12(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_12(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(11, xla); } } - static final private boolean jj_3R_34() { - if (jj_3R_39()) return true; - if (jj_3R_14()) return true; - return false; - } - - static final private boolean jj_3_12() { - if (jj_scan_token(29)) return true; - if (jj_3R_14()) return true; - if (jj_3R_21()) return true; - return false; - } - - static final private boolean jj_3R_12() { - if (jj_scan_token(STRING)) return true; - return false; - } - - static final private boolean jj_3R_33() { - if (jj_3R_48()) return true; + final private boolean jj_3R_32() { + if (jj_3R_47()) return true; if (jj_3R_17()) return true; if (jj_scan_token(COMMAND_END)) return true; if (jj_3R_14()) return true; return false; } - static final private boolean jj_3R_8() { - if (jj_3R_23()) return true; - return false; - } - - static final private boolean jj_3_11() { - if (jj_scan_token(29)) return true; - if (jj_3R_14()) return true; - if (jj_3R_20()) return true; - return false; - } - - static final private boolean jj_3_10() { + final private boolean jj_3_10() { if (jj_scan_token(26)) return true; if (jj_scan_token(27)) return true; return false; } - static final private boolean jj_3R_32() { - if (jj_3R_47()) return true; - if (jj_3R_17()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_14()) return true; + final private boolean jj_3R_26() { + if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_25() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3_9() { + final private boolean jj_3_9() { Token xsp; xsp = jj_scanpos; if (jj_3R_18()) { @@ -1652,7 +1628,7 @@ return false; } - static final private boolean jj_3R_31() { + final private boolean jj_3R_31() { if (jj_scan_token(29)) return true; if (jj_3R_14()) return true; if (jj_3R_21()) return true; @@ -1661,7 +1637,7 @@ return false; } - static final private boolean jj_3R_30() { + final private boolean jj_3R_30() { if (jj_scan_token(29)) return true; if (jj_3R_14()) return true; if (jj_3R_20()) return true; @@ -1670,32 +1646,37 @@ return false; } - static final private boolean jj_3R_7() { - if (jj_3R_22()) return true; + final private boolean jj_3R_8() { + if (jj_3R_23()) return true; return false; } - static final private boolean jj_3R_22() { + final private boolean jj_3R_22() { if (jj_scan_token(NUMBER)) return true; return false; } - static final private boolean jj_3R_29() { + final private boolean jj_3R_29() { if (jj_3R_46()) return true; return false; } - static final private boolean jj_3R_28() { + final private boolean jj_3R_28() { if (jj_3R_45()) return true; return false; } - static final private boolean jj_3R_27() { + final private boolean jj_3R_25() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_27() { if (jj_3R_44()) return true; return false; } - static final private boolean jj_3R_14() { + final private boolean jj_3R_14() { Token xsp; xsp = jj_scanpos; if (jj_3R_27()) { @@ -1729,17 +1710,27 @@ return false; } - static final private boolean jj_3R_6() { - if (jj_3R_4()) return true; + final private boolean jj_3R_7() { + if (jj_3R_22()) return true; return false; } - static final private boolean jj_3R_43() { + final private boolean jj_3R_23() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_38() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_6() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3_8() { + final private boolean jj_3_8() { if (jj_3R_14()) return true; Token xsp; xsp = jj_scanpos; @@ -1750,52 +1741,72 @@ return false; } - static final private boolean jj_3_7() { + final private boolean jj_3R_43() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_7() { if (jj_3R_14()) return true; if (jj_scan_token(25)) return true; return false; } - static final private boolean jj_3R_13() { + final private boolean jj_3R_13() { if (jj_scan_token(28)) return true; if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_23() { - if (jj_scan_token(DOUBLE)) return true; + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; return false; } - static final private boolean jj_3R_38() { + final private boolean jj_3R_41() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_42() { - if (jj_3R_12()) return true; + final private boolean jj_3R_37() { + if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_24() { + final private boolean jj_3R_15() { Token xsp; xsp = jj_scanpos; - if (jj_3R_42()) { + if (jj_3R_37()) { jj_scanpos = xsp; - if (jj_3R_43()) return true; + if (jj_3R_38()) return true; } - if (jj_scan_token(28)) return true; return false; } - static final private boolean jj_3R_16() { + final private boolean jj_3R_42() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_16() { if (jj_3R_39()) return true; return false; } - static final private boolean jj_3_6() { + final private boolean jj_3R_24() { Token xsp; xsp = jj_scanpos; + if (jj_3R_42()) { + jj_scanpos = xsp; + if (jj_3R_43()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3_6() { + Token xsp; + xsp = jj_scanpos; if (jj_3R_16()) jj_scanpos = xsp; if (jj_3R_17()) return true; if (jj_scan_token(29)) return true; @@ -1804,33 +1815,33 @@ return false; } - static final private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; - return false; - } - - static final private boolean jj_3R_5() { + final private boolean jj_3R_5() { if (jj_scan_token(COMMAND_END)) return true; if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_41() { + final private boolean jj_3R_52() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_37() { + final private boolean jj_3_4() { + if (jj_scan_token(NEG_EX)) return true; + return false; + } + + final private boolean jj_3R_40() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3_4() { - if (jj_scan_token(NEG_EX)) return true; + final private boolean jj_3_3() { + if (jj_scan_token(POS_EX)) return true; return false; } - static final private boolean jj_3R_11() { + final private boolean jj_3R_11() { if (jj_scan_token(26)) return true; Token xsp; while (true) { @@ -1846,22 +1857,17 @@ return false; } - static final private boolean jj_3_3() { - if (jj_scan_token(POS_EX)) return true; - return false; - } - - static final private boolean jj_3R_15() { + final private boolean jj_3R_17() { Token xsp; xsp = jj_scanpos; - if (jj_3R_37()) { + if (jj_3R_40()) { jj_scanpos = xsp; - if (jj_3R_38()) return true; + if (jj_3R_41()) return true; } return false; } - static final private boolean jj_3_2() { + final private boolean jj_3_2() { if (jj_3R_4()) return true; if (jj_scan_token(29)) return true; if (jj_3R_12()) return true; @@ -1875,7 +1881,7 @@ return false; } - static final private boolean jj_3_5() { + final private boolean jj_3_5() { if (jj_3R_14()) return true; if (jj_scan_token(29)) return true; if (jj_3R_15()) return true; @@ -1884,7 +1890,7 @@ return false; } - static final private boolean jj_3_1() { + final private boolean jj_3_1() { if (jj_3R_4()) return true; Token xsp; xsp = jj_scanpos; @@ -1911,68 +1917,48 @@ return false; } - static final private boolean jj_3R_52() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_10() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - static final private boolean jj_3R_40() { - if (jj_3R_4()) return true; - return false; - } - - static final private boolean jj_3R_17() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_40()) { - jj_scanpos = xsp; - if (jj_3R_41()) return true; - } - return false; - } - - static final private boolean jj_3R_50() { + final private boolean jj_3R_50() { if (jj_scan_token(LE)) return true; return false; } - static final private boolean jj_3R_47() { + final private boolean jj_3R_47() { if (jj_scan_token(EXISTS)) return true; return false; } - static final private boolean jj_3R_49() { + final private boolean jj_3R_49() { if (jj_scan_token(GE)) return true; return false; } - static final private boolean jj_3R_45() { + final private boolean jj_3R_45() { if (jj_scan_token(BOTTOM)) return true; return false; } - static final private boolean jj_3R_39() { + final private boolean jj_3R_39() { if (jj_scan_token(NOT)) return true; return false; } - static final private boolean jj_3R_51() { + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_51() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_48() { + final private boolean jj_3R_48() { if (jj_scan_token(ALL)) return true; return false; } - static final private boolean jj_3R_46() { + final private boolean jj_3R_46() { Token xsp; xsp = jj_scanpos; if (jj_3R_51()) { @@ -1982,32 +1968,27 @@ return false; } - static final private boolean jj_3R_44() { + final private boolean jj_3R_44() { if (jj_scan_token(TOP)) return true; return false; } - static final private boolean jj_3R_20() { + final private boolean jj_3R_20() { if (jj_scan_token(AND)) return true; return false; } - static final private boolean jj_3R_21() { + final private boolean jj_3R_21() { if (jj_scan_token(OR)) return true; return false; } - static final private boolean jj_3R_19() { + final private boolean jj_3R_19() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_9() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_36() { + final private boolean jj_3R_36() { if (jj_3R_50()) return true; if (jj_3R_22()) return true; if (jj_3R_17()) return true; @@ -2016,12 +1997,12 @@ return false; } - static final private boolean jj_3R_18() { + final private boolean jj_3R_18() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_35() { + final private boolean jj_3R_35() { if (jj_3R_49()) return true; if (jj_3R_22()) return true; if (jj_3R_17()) return true; @@ -2030,22 +2011,54 @@ return false; } - static final private boolean jj_3R_26() { - if (jj_3R_4()) return true; + final private boolean jj_3R_34() { + if (jj_3R_39()) return true; + if (jj_3R_14()) return true; return false; } - static private boolean jj_initialized_once = false; - static public DLLearnerTokenManager token_source; - static SimpleCharStream jj_input_stream; - static public Token token, jj_nt; - static private int jj_ntk; - static private Token jj_scanpos, jj_lastpos; - static private int jj_la; - static public boolean lookingAhead = false; - static private boolean jj_semLA; - static private int jj_gen; - static final private int[] jj_la1 = new int[15]; + final private boolean jj_3_12() { + if (jj_scan_token(29)) return true; + if (jj_3R_14()) return true; + if (jj_3R_21()) return true; + return false; + } + + final private boolean jj_3R_12() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3R_33() { + if (jj_3R_48()) return true; + if (jj_3R_17()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_14()) return true; + return false; + } + + final private boolean jj_3R_9() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_11() { + if (jj_scan_token(29)) return true; + if (jj_3R_14()) return true; + if (jj_3R_20()) return true; + return false; + } + + public DLLearnerTokenManager token_source; + SimpleCharStream jj_input_stream; + public Token token, jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + public boolean lookingAhead = false; + private boolean jj_semLA; + private int jj_gen; + final private int[] jj_la1 = new int[15]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { @@ -2058,21 +2071,14 @@ private static void jj_la1_1() { jj_la1_1 = new int[] {0x3e,0x3e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x41,0x0,0x0,0x0,0x0,0x0,}; } - static final private JJCalls[] jj_2_rtns = new JJCalls[12]; - static private boolean jj_rescan = false; - static private int jj_gc = 0; + final private JJCalls[] jj_2_rtns = new JJCalls[12]; + private boolean jj_rescan = false; + private int jj_gc = 0; public DLLearner(java.io.InputStream stream) { this(stream, null); } public DLLearner(java.io.InputStream stream, String encoding) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source = new DLLearnerTokenManager(jj_input_stream); token = new Token(); @@ -2082,10 +2088,10 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static public void ReInit(java.io.InputStream stream) { + public void ReInit(java.io.InputStream stream) { ReInit(stream, null); } - static public void ReInit(java.io.InputStream stream, String encoding) { + public void ReInit(java.io.InputStream stream, String encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source.ReInit(jj_input_stream); token = new Token(); @@ -2097,13 +2103,6 @@ } public DLLearner(java.io.Reader stream) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new DLLearnerTokenManager(jj_input_stream); token = new Token(); @@ -2113,7 +2112,7 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static public void ReInit(java.io.Reader stream) { + public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); @@ -2125,13 +2124,6 @@ } public DLLearner(DLLearnerTokenManager tm) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; token_source = tm; token = new Token(); jj_ntk = -1; @@ -2150,7 +2142,7 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static final private Token jj_consume_token(int kind) throws ParseException { + final private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); @@ -2175,8 +2167,8 @@ } static private final class LookaheadSuccess extends java.lang.Error { } - static final private LookaheadSuccess jj_ls = new LookaheadSuccess(); - static final private boolean jj_scan_token(int kind) { + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + final private boolean jj_scan_token(int kind) { if (jj_scanpos == jj_lastpos) { jj_la--; if (jj_scanpos.next == null) { @@ -2197,7 +2189,7 @@ return false; } - static final public Token getNextToken() { + final public Token getNextToken() { if (token.next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; @@ -2205,7 +2197,7 @@ return token; } - static final public Token getToken(int index) { + final public Token getToken(int index) { Token t = lookingAhead ? jj_scanpos : token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; @@ -2214,20 +2206,20 @@ return t; } - static final private int jj_ntk() { + final private int jj_ntk() { if ((jj_nt=token.next) == null) return (jj_ntk = (token.next=token_source.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); } - static private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); - static private int[] jj_expentry; - static private int jj_kind = -1; - static private int[] jj_lasttokens = new int[100]; - static private int jj_endpos; + private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; - static private void jj_add_error_token(int kind, int pos) { + private void jj_add_error_token(int kind, int pos) { if (pos >= 100) return; if (pos == jj_endpos + 1) { jj_lasttokens[jj_endpos++] = kind; @@ -2255,7 +2247,7 @@ } } - static public ParseException generateParseException() { + public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[39]; if (jj_kind >= 0) { @@ -2291,13 +2283,13 @@ return new ParseException(token, exptokseq, tokenImage); } - static final public void enable_tracing() { + final public void enable_tracing() { } - static final public void disable_tracing() { + final public void disable_tracing() { } - static final private void jj_rescan_token() { + final private void jj_rescan_token() { jj_rescan = true; for (int i = 0; i < 12; i++) { try { @@ -2327,7 +2319,7 @@ jj_rescan = false; } - static final private void jj_save(int index, int xla) { + final private void jj_save(int index, int xla) { JJCalls p = jj_2_rtns[index]; while (p.gen > jj_gen) { if (p.next == null) { p = p.next = new JJCalls(); break; } Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-10-01 17:14:03 UTC (rev 160) @@ -10,6 +10,7 @@ import java.util.TreeSet; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; import org.dllearner.Main; @@ -20,9 +21,9 @@ public @SuppressWarnings("all") class DLLearnerTokenManager implements DLLearnerConstants { - public static java.io.PrintStream debugStream = System.out; - public static void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private static final int jjStopStringLiteralDfa_0(int pos, long active0) + public java.io.PrintStream debugStream = System.out; + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) { switch (pos) { @@ -38,17 +39,17 @@ return -1; } } -private static final int jjStartNfa_0(int pos, long active0) +private final int jjStartNfa_0(int pos, long active0) { return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); } -static private final int jjStopAtPos(int pos, int kind) +private final int jjStopAtPos(int pos, int kind) { jjmatchedKind = kind; jjmatchedPos = pos; return pos + 1; } -static private final int jjStartNfaWithStates_0(int pos, int kind, int state) +private final int jjStartNfaWithStates_0(int pos, int kind, int state) { jjmatchedKind = kind; jjmatchedPos = pos; @@ -56,7 +57,7 @@ catch(java.io.IOException e) { return pos + 1; } return jjMoveNfa_0(state, pos + 1); } -static private final int jjMoveStringLiteralDfa0_0() +private final int jjMoveStringLiteralDfa0_0() { switch(curChar) { @@ -102,7 +103,7 @@ return jjMoveNfa_0(0, 0); } } -static private final int jjMoveStringLiteralDfa1_0(long active0) +private final int jjMoveStringLiteralDfa1_0(long active0) { try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { @@ -140,7 +141,7 @@ } return jjStartNfa_0(0, active0); } -static private final int jjMoveStringLiteralDfa2_0(long old0, long active0) +private final int jjMoveStringLiteralDfa2_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(0, old0); @@ -183,7 +184,7 @@ } return jjStartNfa_0(1, active0); } -static private final int jjMoveStringLiteralDfa3_0(long old0, long active0) +private final int jjMoveStringLiteralDfa3_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(1, old0); @@ -213,7 +214,7 @@ } return jjStartNfa_0(2, active0); } -static private final int jjMoveStringLiteralDfa4_0(long old0, long active0) +private final int jjMoveStringLiteralDfa4_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(2, old0); @@ -243,7 +244,7 @@ } return jjStartNfa_0(3, active0); } -static private final int jjMoveStringLiteralDfa5_0(long old0, long active0) +private final int jjMoveStringLiteralDfa5_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(3, old0); @@ -275,7 +276,7 @@ } return jjStartNfa_0(4, active0); } -static private final int jjMoveStringLiteralDfa6_0(long old0, long active0) +private final int jjMoveStringLiteralDfa6_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(4, old0); @@ -307,7 +308,7 @@ } return jjStartNfa_0(5, active0); } -static private final int jjMoveStringLiteralDfa7_0(long old0, long active0) +private final int jjMoveStringLiteralDfa7_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(5, old0); @@ -331,7 +332,7 @@ } return jjStartNfa_0(6, active0); } -static private final int jjMoveStringLiteralDfa8_0(long old0, long active0) +private final int jjMoveStringLiteralDfa8_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(6, old0); @@ -359,7 +360,7 @@ } return jjStartNfa_0(7, active0); } -static private final int jjMoveStringLiteralDfa9_0(long old0, long active0) +private final int jjMoveStringLiteralDfa9_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(7, old0); @@ -389,7 +390,7 @@ } return jjStartNfa_0(8, active0); } -static private final int jjMoveStringLiteralDfa10_0(long old0, long active0) +private final int jjMoveStringLiteralDfa10_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(8, old0); @@ -407,7 +408,7 @@ } return jjStartNfa_0(9, active0); } -static private final int jjMoveStringLiteralDfa11_0(long old0, long active0) +private final int jjMoveStringLiteralDfa11_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(9, old0); @@ -427,7 +428,7 @@ } return jjStartNfa_0(10, active0); } -static private final void jjCheckNAdd(int state) +private final void jjCheckNAdd(int state) { if (jjrounds[state] != jjround) { @@ -435,24 +436,24 @@ jjrounds[state] = jjround; } } -static private final void jjAddStates(int start, int end) +private final void jjAddStates(int start, int end) { do { jjstateSet[jjnewStateCnt++] = jjnextStates[start]; } while (start++ != end); } -static private final void jjCheckNAddTwoStates(int state1, int state2) +private final void jjCheckNAddTwoStates(int state1, int state2) { jjCheckNAdd(state1); jjCheckNAdd(state2); } -static private final void jjCheckNAddStates(int start, int end) +private final void jjCheckNAddStates(int start, int end) { do { jjCheckNAdd(jjnextStates[start]); } while (start++ != end); } -static private final void jjCheckNAddStates(int start) +private final void jjCheckNAddStates(int start) { jjCheckNAdd(jjnextStates[start]); jjCheckNAdd(jjnextStates[start + 1]); @@ -460,7 +461,7 @@ static final long[] jjbitVec0 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; -static private final int jjMoveNfa_0(int startState, int curPos) +private final int jjMoveNfa_0(int startState, int curPos) { int[] nextStates; int startsAt = 0; @@ -853,39 +854,39 @@ static final long[] jjtoSkip = { 0xfeL, }; -static protected SimpleCharStream input_stream; -static private final int[] jjrounds = new int[53]; -static private final int[] jjstateSet = new int[106]; -static protected char curChar; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[53]; +private final int[] jjstateSet = new int[106]; +protected char curChar; public DLLearnerTokenManager(SimpleCharStream stream){ - if (input_stream != null) - throw new TokenMgrError("ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.", TokenMgrError.STATIC_LEXER_ERROR); + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); input_stream = stream; } public DLLearnerTokenManager(SimpleCharStream stream, int lexState){ this(stream); SwitchTo(lexState); } -static public void ReInit(SimpleCharStream stream) +public void ReInit(SimpleCharStream stream) { jjmatchedPos = jjnewStateCnt = 0; curLexState = defaultLexState; input_stream = stream; ReInitRounds(); } -static private final void ReInitRounds() +private final void ReInitRounds() { int i; jjround = 0x80000001; for (i = 53; i-- > 0;) jjrounds[i] = 0x80000000; } -static public void ReInit(SimpleCharStream stream, int lexState) +public void ReInit(SimpleCharStream stream, int lexState) { ReInit(stream); SwitchTo(lexState); } -static public void SwitchTo(int lexState) +public void SwitchTo(int lexState) { if (lexState >= 1 || lexState < 0) throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); @@ -893,7 +894,7 @@ curLexState = lexState; } -static protected Token jjFillToken() +protected Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); t.kind = jjmatchedKind; @@ -906,14 +907,14 @@ return t; } -static int curLexState = 0; -static int defaultLexState = 0; -static int jjnewStateCnt; -static int jjround; -static int jjmatchedPos; -static int jjmatchedKind; +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; -public static Token getNextToken() +public Token getNextToken() { int kind; Token specialToken = null; Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-01 17:14:03 UTC (rev 160) @@ -5,40 +5,42 @@ public @SuppressWarnings("all") interface DLLearnerTreeConstants { public int JJTSTART = 0; - public int JJTCONFOPTION = 1; - public int JJTFUNCTIONCALL = 2; - public int JJTPOSEXAMPLE = 3; - public int JJTNEGEXAMPLE = 4; - public int JJTABOXCONCEPT = 5; - public int JJTABOXROLE = 6; - public int JJTTRANSITIVE = 7; - public int JJTFUNCTIONAL = 8; - public int JJTSYMMETRIC = 9; - public int JJTINVERSE = 10; - public int JJTSUBROLE = 11; - public int JJTTBOXEQUIV = 12; - public int JJTTBOXSUB = 13; - public int JJTCONCEPT = 14; - public int JJTOR = 15; - public int JJTAND = 16; - public int JJTTOP = 17; - public int JJTBOTTOM = 18; - public int JJTEXISTS = 19; - public int JJTALL = 20; - public int JJTNOT = 21; - public int JJTGE = 22; - public int JJTLE = 23; - public int JJTATOMICCONCEPT = 24; - public int JJTATOMICROLE = 25; - public int JJTINDIVIDUAL = 26; - public int JJTID = 27; - public int JJTDOUBLE = 28; - public int JJTINTEGER = 29; - public int JJTSTRING = 30; + public int JJTPARSEKB = 1; + public int JJTCONFOPTION = 2; + public int JJTFUNCTIONCALL = 3; + public int JJTPOSEXAMPLE = 4; + public int JJTNEGEXAMPLE = 5; + public int JJTABOXCONCEPT = 6; + public int JJTABOXROLE = 7; + public int JJTTRANSITIVE = 8; + public int JJTFUNCTIONAL = 9; + public int JJTSYMMETRIC = 10; + public int JJTINVERSE = 11; + public int JJTSUBROLE = 12; + public int JJTTBOXEQUIV = 13; + public int JJTTBOXSUB = 14; + public int JJTCONCEPT = 15; + public int JJTOR = 16; + public int JJTAND = 17; + public int JJTTOP = 18; + public int JJTBOTTOM = 19; + public int JJTEXISTS = 20; + public int JJTALL = 21; + public int JJTNOT = 22; + public int JJTGE = 23; + public int JJTLE = 24; + public int JJTATOMICCONCEPT = 25; + public int JJTATOMICROLE = 26; + public int JJTINDIVIDUAL = 27; + public int JJTID = 28; + public int JJTDOUBLE = 29; + public int JJTINTEGER = 30; + public int JJTSTRING = 31; public String[] jjtNodeName = { "Start", + "parseKB", "ConfOption", "FunctionCall", "PosExample", Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-10-01 17:14:03 UTC (rev 160) @@ -8,6 +8,7 @@ options { // MULTI=true; JDK_VERSION = "1.5"; + STATIC = false; } // wenn der Parser ge\ufffdndert wird, dann muss man in einigen Dateien SuppressWarnings @@ -27,6 +28,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; @@ -39,24 +41,24 @@ // @SuppressWarnings({"all"}) public class DLLearner/*@bgen(jjtree)*/implements DLLearnerTreeConstants/*@egen*/ {/*@bgen(jjtree)*/ - protected static JJTDLLearnerState jjtree = new JJTDLLearnerState(); + protected JJTDLLearnerState jjtree = new JJTDLLearnerState(); /*@egen*/ private static ConceptComparator conceptComparator = new ConceptComparator(); // hier wird Parse-Fehler angezeigt, obwohl eigentlich alles stimmt?? - private static Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - private static Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); // Konfigurationsoptionen - private static List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private static List<List<String>> functionCalls = new LinkedList<List<String>>(); + private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man br\u00e4uchte f\u00fcr jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante @@ -65,13 +67,13 @@ // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal // aufgerufen werden; weitere Parsevorg\u00e4nge erfolgen dann mit ReInit // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - private static boolean constructorCalled = false; + // private static boolean constructorCalled = false; // Wissensbasis - private static KB kb = new KB(); + private KB kb = new KB(); public static final String internalNamespace = "http://localhost/foo#"; - private static void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { + private void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { if(positiveExamples.containsKey(conceptName)) { positiveExamples.get(conceptName).add(instanceName); } else { @@ -81,7 +83,7 @@ } } - private static void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { + private void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { if(negativeExamples.containsKey(conceptName)) { negativeExamples.get(conceptName).add(instanceName); } else { @@ -91,23 +93,23 @@ } } - public static Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { return positiveExamples; } - public static Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { return negativeExamples; } - public static List<ConfigurationOption> getConfOptions() { + public List<ConfigurationOption> getConfOptions() { return confOptions; } - public static List<List<String>> getFunctionCalls() { + public List<List<String>> getFunctionCalls() { return functionCalls; } - public static KB getKB() { + public KB getKB() { return kb; } @@ -135,19 +137,14 @@ public static SimpleNode parseString(String str) throws ParseException { StringReader sr = new StringReader(str); - // new DLLearner(sr); - DLLearner... [truncated message content] |
From: <jen...@us...> - 2007-10-01 14:41:41
|
Revision: 159 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=159&view=rev Author: jenslehmann Date: 2007-10-01 07:41:28 -0700 (Mon, 01 Oct 2007) Log Message: ----------- - added method for automatically documenting all config options - some smaller structural changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.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/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/reasoning/AbstractReasoner.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/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java trunk/src/dl-learner/org/dllearner/utilities/Files.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-01 14:41:28 UTC (rev 159) @@ -22,7 +22,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; @@ -70,6 +69,7 @@ import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; import org.dllearner.utilities.Stat; @@ -954,7 +954,7 @@ // am Ende => man kann den Test also auch zwischendurch abbrechen for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - createFile(fileAr[j][k], exportString[j][k].toString()); + Files.createFile(fileAr[j][k], exportString[j][k].toString()); } } } @@ -964,29 +964,6 @@ + Helper.prettyPrintNanoSeconds(overallTime)); } - // creates a file with the given content - public static void createFile(File file, String content) { - try { - FileOutputStream fos = new FileOutputStream(file); - fos.write(content.getBytes()); - fos.close(); - } catch (Exception e) { - System.out.println(e); - System.exit(0); - } - } - - public static void appendFile(File file, String content) { - try { - FileOutputStream fos = new FileOutputStream(file, true); - fos.write(content.getBytes()); - fos.close(); - } catch (Exception e) { - System.out.println(e); - System.exit(0); - } - } - // TODO: query mode umschreiben private void processQueryMode(Reasoner reasoner) { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -11,7 +11,6 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Main; import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.core.dl.Concept; @@ -20,6 +19,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; public class ROLearner implements LearningAlgorithm { @@ -330,7 +330,7 @@ searchTree += treeString + "\n"; // TODO: ev. immer nur einen search tree speichern und den an die // Datei anhängen => spart Speicher - Main.createFile(Config.Refinement.searchTreeFile, searchTree); + Files.createFile(Config.Refinement.searchTreeFile, searchTree); } // Anzahl Schleifendurchläufe @@ -343,7 +343,7 @@ // Suchbaum in Datei schreiben if(Config.Refinement.writeSearchTree) - Main.createFile(Config.Refinement.searchTreeFile, searchTree); + Files.createFile(Config.Refinement.searchTreeFile, searchTree); // Ergebnisausgabe /* Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-01 14:41:28 UTC (rev 159) @@ -21,6 +21,7 @@ import java.io.BufferedReader; import java.io.DataInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -38,6 +39,8 @@ import java.util.TreeMap; import java.util.TreeSet; +import org.dllearner.utilities.Files; + /** * Central manager class for DL-Learner. There are currently four types of * components in DL-Learner: knowledge sources, reasoners, learning problems, @@ -296,6 +299,51 @@ return invokeConstructor(la, new Class[] { constructorArgument }, new Object[] { lp }); } + public void writeConfigDocumentation(File file) { + String doc = ""; + doc += "This file contains an automatically generated files of all components and their config options.\n\n"; + + // go through all types of components and write down their documentation + doc += "*********************\n"; + doc += "* Knowledge Sources *\n"; + doc += "*********************\n\n"; + for(Class<? extends Component> component : knowledgeSources) + doc += getComponentConfigString(component); + + doc += "*************\n"; + doc += "* Reasoners *\n"; + doc += "*************\n\n"; + for(Class<? extends Component> component : reasonerComponents) + doc += getComponentConfigString(component); + + doc += "*********************\n"; + doc += "* Learning Problems *\n"; + doc += "*********************\n\n"; + for(Class<? extends Component> component : learningProblems) + doc += getComponentConfigString(component); + + doc += "***********************\n"; + doc += "* Learning Algorithms *\n"; + doc += "***********************\n\n"; + for(Class<? extends Component> component : learningAlgorithms) + doc += getComponentConfigString(component); + + Files.createFile(file, doc); + } + + private String getComponentConfigString(Class<? extends Component> component) { + String componentDescription = "component: " + invokeStaticMethod(component,"getName") + " (" + component.getName() + ")"; + String str = componentDescription + "\n"; + for(int i=0; i<componentDescription.length(); i++) + str += "="; + str += "\n\n"; + + for(ConfigOption<?> option : componentOptions.get(component)) { + str += option.toString() + "\n"; + } + return str; + } + 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 Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-01 14:41:28 UTC (rev 159) @@ -44,6 +44,8 @@ // get singleton instance of component manager ComponentManager cm = ComponentManager.getInstance(); + cm.writeConfigDocumentation(new File("doc/configOptionsNew.txt")); + // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); String example = "examples/father.owl"; Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -28,9 +28,9 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-10-01 14:41:28 UTC (rev 159) @@ -29,8 +29,8 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-01 14:41:28 UTC (rev 159) @@ -33,11 +33,11 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Copied: trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java (from rev 152, trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,109 @@ +/** + * 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.dl; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.RoleComparator; + +/** + * Represents a hierarchy of roles. + * + * @todo Currently, the role hierarchy pruning algorithm (analogous to the + * subsumption hierarchy) is not implemented. + * + * @author Jens Lehmann + * + */ +public class RoleHierarchy { + + RoleComparator rc = new RoleComparator(); + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp; + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown; + TreeSet<AtomicRole> mostGeneralRoles = new TreeSet<AtomicRole>(rc); + TreeSet<AtomicRole> mostSpecialRoles = new TreeSet<AtomicRole>(rc); + + public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { + this.roleHierarchyUp = roleHierarchyUp; + this.roleHierarchyDown = roleHierarchyDown; + + // find most general and most special roles + for(AtomicRole role : atomicRoles) { + if(getMoreGeneralRoles(role).size()==0) + mostGeneralRoles.add(role); + if(getMoreSpecialRoles(role).size()==0) + mostSpecialRoles.add(role); + } + } + + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<AtomicRole>) roleHierarchyUp.get(role).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { + return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); + } + + + + @Override + public String toString() { + String str = ""; + for(AtomicRole role : mostGeneralRoles) { + str += toString(roleHierarchyDown, role, 0); + } + return str; + } + + private String toString(TreeMap<AtomicRole,TreeSet<AtomicRole>> hierarchy, AtomicRole role, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += role.toString() + "\n"; + Set<AtomicRole> tmp = hierarchy.get(role); + if(tmp!=null) { + for(AtomicRole c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } + + /** + * @return The most general roles. + */ + public TreeSet<AtomicRole> getMostGeneralRoles() { + return mostGeneralRoles; + } + + /** + * @return The most special roles. + */ + public TreeSet<AtomicRole> getMostSpecialRoles() { + return mostSpecialRoles; + } + +} Copied: trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java (from rev 152, trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,125 @@ +/** + * 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.dl; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.ConceptComparator; + +/** + * Represents a subsumption hierarchy (ignoring equivalent concepts). + * + * @author Jens Lehmann + * + */ +public class SubsumptionHierarchy { + + ConceptComparator conceptComparator = new ConceptComparator(); + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + public SubsumptionHierarchy(Set<AtomicConcept> atomicConcepts, TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp , TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown) { + this.subsumptionHierarchyUp = subsumptionHierarchyUp; + this.subsumptionHierarchyDown = subsumptionHierarchyDown; + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); + allowedConceptsInSubsumptionHierarchy.add(new Top()); + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + } + + @SuppressWarnings("unchecked") + public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { + return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); + } + + public void improveSubsumptionHierarchy() { + TreeMap<Concept,TreeSet<Concept>> hierarchyDownNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); + TreeMap<Concept,TreeSet<Concept>> hierarchyUpNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + + // Einträge für alle Konzepte machen (init) + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + hierarchyDownNew.put(c, new TreeSet<Concept>(conceptComparator)); + hierarchyUpNew.put(c, new TreeSet<Concept>(conceptComparator)); + } + + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + // schauen, ob es mehrere allgemeinere Nachbarn gibt + SortedSet<Concept> moreGeneral = subsumptionHierarchyUp.get(c); + if(moreGeneral != null) { + Concept chosenParent = moreGeneral.first(); + hierarchyDownNew.get(chosenParent).add(c); + } + } + + // for(Concept c : allowedConceptsInSubsumptionHierarchy) { + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + SortedSet<Concept> moreSpecial = subsumptionHierarchyDown.get(c); + if(moreSpecial != null) { + Concept chosenParent = moreSpecial.first(); + hierarchyUpNew.get(chosenParent).add(c); + } + } + + subsumptionHierarchyDown = hierarchyDownNew; + subsumptionHierarchyUp = hierarchyUpNew; + } + + @Override + public String toString() { + return toString(false); + } + + public String toString(boolean showUpwardHierarchy) { + if(showUpwardHierarchy) { + String str = "downward subsumption:\n"; + str += toString(subsumptionHierarchyDown, new Top(), 0); + str += "upward subsumption:\n"; + str += toString(subsumptionHierarchyUp, new Bottom(), 0); + return str; + } else { + return toString(subsumptionHierarchyDown, new Top(), 0); + } + } + + private String toString(TreeMap<Concept,TreeSet<Concept>> hierarchy, Concept concept, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += concept.toString() + "\n"; + Set<Concept> tmp = hierarchy.get(concept); + if(tmp!=null) { + for(Concept c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -12,6 +12,8 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; public abstract class AbstractReasoner implements Reasoner { Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-01 14:41:28 UTC (rev 159) @@ -13,7 +13,7 @@ import org.apache.xmlbeans.XmlException; import org.dllearner.Config; -import org.dllearner.Main; +import org.dllearner.utilities.Files; import org.kr.dl.dig.v1_1.GetIdentifierDocument; import org.kr.dl.dig.v1_1.IdRespType; import org.kr.dl.dig.v1_1.IdentifierDocument; @@ -132,7 +132,7 @@ osw.close(); if(Config.writeDIGProtocol) - Main.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); + Files.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); // Antwort empfangen InputStream is = connection.getInputStream(); @@ -155,7 +155,7 @@ // DIG-Kommunikation protokollieren, falls das eingestellt ist if(Config.writeDIGProtocol) - Main.appendFile(Config.digProtocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); + Files.appendFile(Config.digProtocolFile, "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-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -42,6 +42,8 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-10-01 14:41:28 UTC (rev 159) @@ -49,6 +49,8 @@ import org.dllearner.core.dl.Bottom; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -78,7 +78,7 @@ Set<AtomicRole> atomicRoles; SortedSet<Individual> individuals; SubsumptionHierarchy kaon2SubsumptionHierarchy = null; - org.dllearner.reasoning.SubsumptionHierarchy subsumptionHierarchy; + org.dllearner.core.dl.SubsumptionHierarchy subsumptionHierarchy; private org.semanticweb.kaon2.api.reasoner.Reasoner kaon2Reasoner; private KAON2Connection kaon2Connection; @@ -270,7 +270,7 @@ subsumptionHierarchyUp.put(ac, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Ac).getParentNodes())); } - subsumptionHierarchy = new org.dllearner.reasoning.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); + subsumptionHierarchy = new org.dllearner.core.dl.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); } @Override @@ -399,7 +399,7 @@ */ @Override - public org.dllearner.reasoning.SubsumptionHierarchy getSubsumptionHierarchy() { + public org.dllearner.core.dl.SubsumptionHierarchy getSubsumptionHierarchy() { return subsumptionHierarchy; } Deleted: trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -1,110 +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.reasoning; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.utilities.RoleComparator; - -/** - * Represents a hierarchy of roles. - * - * @todo Currently, the role hierarchy pruning algorithm (analogous to the - * subsumption hierarchy) is not implemented. - * - * @author Jens Lehmann - * - */ -public class RoleHierarchy { - - RoleComparator rc = new RoleComparator(); - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp; - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown; - TreeSet<AtomicRole> mostGeneralRoles = new TreeSet<AtomicRole>(rc); - TreeSet<AtomicRole> mostSpecialRoles = new TreeSet<AtomicRole>(rc); - - public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { - this.roleHierarchyUp = roleHierarchyUp; - this.roleHierarchyDown = roleHierarchyDown; - - // find most general and most special roles - for(AtomicRole role : atomicRoles) { - if(getMoreGeneralRoles(role).size()==0) - mostGeneralRoles.add(role); - if(getMoreSpecialRoles(role).size()==0) - mostSpecialRoles.add(role); - } - } - - @SuppressWarnings("unchecked") - public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { - // we clone all concepts before returning them such that they cannot be - // modified externally - return (TreeSet<AtomicRole>) roleHierarchyUp.get(role).clone(); - } - - @SuppressWarnings("unchecked") - public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { - return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); - } - - - - @Override - public String toString() { - String str = ""; - for(AtomicRole role : mostGeneralRoles) { - str += toString(roleHierarchyDown, role, 0); - } - return str; - } - - private String toString(TreeMap<AtomicRole,TreeSet<AtomicRole>> hierarchy, AtomicRole role, int depth) { - String str = ""; - for(int i=0; i<depth; i++) - str += " "; - str += role.toString() + "\n"; - Set<AtomicRole> tmp = hierarchy.get(role); - if(tmp!=null) { - for(AtomicRole c : tmp) - str += toString(hierarchy, c, depth+1); - } - return str; - } - - /** - * @return The most general roles. - */ - public TreeSet<AtomicRole> getMostGeneralRoles() { - return mostGeneralRoles; - } - - /** - * @return The most special roles. - */ - public TreeSet<AtomicRole> getMostSpecialRoles() { - return mostSpecialRoles; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -1,129 +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.reasoning; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.Bottom; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Top; -import org.dllearner.utilities.ConceptComparator; - -/** - * Represents a subsumption hierarchy (ignoring equivalent concepts). - * - * @author Jens Lehmann - * - */ -public class SubsumptionHierarchy { - - ConceptComparator conceptComparator = new ConceptComparator(); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - Set<Concept> allowedConceptsInSubsumptionHierarchy; - - public SubsumptionHierarchy(Set<AtomicConcept> atomicConcepts, TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp , TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown) { - this.subsumptionHierarchyUp = subsumptionHierarchyUp; - this.subsumptionHierarchyDown = subsumptionHierarchyDown; - allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Top()); - allowedConceptsInSubsumptionHierarchy.add(new Bottom()); - } - - @SuppressWarnings("unchecked") - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - // we clone all concepts before returning them such that they cannot be - // modified externally - return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); - } - - @SuppressWarnings("unchecked") - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); - } - - public void improveSubsumptionHierarchy() { - TreeMap<Concept,TreeSet<Concept>> hierarchyDownNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); - TreeMap<Concept,TreeSet<Concept>> hierarchyUpNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - - // Einträge für alle Konzepte machen (init) - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - hierarchyDownNew.put(c, new TreeSet<Concept>(conceptComparator)); - hierarchyUpNew.put(c, new TreeSet<Concept>(conceptComparator)); - } - - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - // schauen, ob es mehrere allgemeinere Nachbarn gibt - SortedSet<Concept> moreGeneral = subsumptionHierarchyUp.get(c); - if(moreGeneral != null) { - Concept chosenParent = moreGeneral.first(); - hierarchyDownNew.get(chosenParent).add(c); - } - } - - // for(Concept c : allowedConceptsInSubsumptionHierarchy) { - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - SortedSet<Concept> moreSpecial = subsumptionHierarchyDown.get(c); - if(moreSpecial != null) { - Concept chosenParent = moreSpecial.first(); - hierarchyUpNew.get(chosenParent).add(c); - } - } - - subsumptionHierarchyDown = hierarchyDownNew; - subsumptionHierarchyUp = hierarchyUpNew; - } - - @Override - public String toString() { - return toString(false); - } - - public String toString(boolean showUpwardHierarchy) { - if(showUpwardHierarchy) { - String str = "downward subsumption:\n"; - str += toString(subsumptionHierarchyDown, new Top(), 0); - str += "upward subsumption:\n"; - str += toString(subsumptionHierarchyUp, new Bottom(), 0); - return str; - } else { - return toString(subsumptionHierarchyDown, new Top(), 0); - } - } - - private String toString(TreeMap<Concept,TreeSet<Concept>> hierarchy, Concept concept, int depth) { - String str = ""; - for(int i=0; i<depth; i++) - str += " "; - str += concept.toString() + "\n"; - Set<Concept> tmp = hierarchy.get(concept); - if(tmp!=null) { - for(Concept c : tmp) - str += toString(hierarchy, c, depth+1); - } - return str; - } -} Added: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * @author Jens Lehmann + * + */ +public class Files { + + /** + * Creates a new file with the given content or replaces the content of a + * file. + * + * @param file + * The file to use. + * @param content + * Content of the file. + */ + public static void createFile(File file, String content) { + try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(content.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Appends content to a file. + * + * @param file + * The file to create. + * @param content + * Content of the file. + */ + public static void appendFile(File file, String content) { + try { + FileOutputStream fos = new FileOutputStream(file, true); + fos.write(content.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-01 14:41:28 UTC (rev 159) @@ -291,7 +291,7 @@ statDetailsString += "concept length: " + conceptLength + "\n"; statDetailsString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "\n\n"; - Main.createFile(statDetailsFile, statDetailsString); + Files.createFile(statDetailsFile, statDetailsString); } // end run loop @@ -300,7 +300,7 @@ statString += "concept length: " + length.getMean() + " (standard deviation: " + length.getStandardDeviation() + ")\n"; statString += "runtime: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getMean())) + " (standard deviation: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getStandardDeviation())) + ")\n\n"; - Main.createFile(statFile, statString); + Files.createFile(statFile, statString); } // end algorithm loop This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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-09-29 18:30:32
|
Revision: 157 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=157&view=rev Author: jenslehmann Date: 2007-09-29 11:30:29 -0700 (Sat, 29 Sep 2007) Log Message: ----------- config options extended Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.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/reasoning/DIGReasonerNew.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-29 18:30:29 UTC (rev 157) @@ -58,8 +58,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new IntegerConfigOption("numberOfTrees")); - options.add(new IntegerConfigOption("maxDepth")); + options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); + options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); return options; } Modified: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,8 +27,8 @@ */ public class BooleanConfigOption extends ConfigOption<Boolean> { - public BooleanConfigOption(String name) { - super(name); + public BooleanConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,7 +27,7 @@ public static final IntegerConfigOption getVerbosityOption() { // TODO: temporary code - IntegerConfigOption verbosityOption = new IntegerConfigOption("verbosity"); + IntegerConfigOption verbosityOption = new IntegerConfigOption("verbosity", "control verbosity of output"); return verbosityOption; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-29 18:30:29 UTC (rev 157) @@ -42,7 +42,14 @@ /** - * Central manager class for DL-Learner. + * 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 * @@ -375,4 +382,31 @@ return null; } + private <T,U> T invokeConstructor(Class<T> clazz, Class<U> argumentClass, U argumentObject) { + try { + Constructor<T> constructor = clazz.getConstructor(argumentClass); + return constructor.newInstance(argumentObject); + } 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; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -33,17 +33,38 @@ */ public abstract class ConfigOption<T> { - private String name; + protected String name; - public ConfigOption(String name) { + protected String description; + + protected T defaultValue; + + public ConfigOption(String name, String description) { + this(name, description, null); + } + + public ConfigOption(String name, String description, T defaultValue) { this.name = name; + this.description = description; + this.defaultValue = defaultValue; } public String getName() { return name; } + public String getDescription() { + return description; + } + /** + * @return the defaultValue + */ + public T getDefaultValue() { + return defaultValue; + } + + /** * Checks whether the object has the correct type to be used as * a value for this option (this method is necessary, because * generic information is erased at runtime in Java). @@ -55,4 +76,13 @@ public abstract boolean isValidValue(T value); + public static String getRestrictionDescription() { + return "none"; + } + + @Override + public String toString() { + return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getRestrictionDescription() + "\ndefault value: " + defaultValue + "\n"; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -31,8 +31,8 @@ private int lowerLimit = Integer.MIN_VALUE; private int upperLimit = Integer.MAX_VALUE; - public IntegerConfigOption(String name) { - super(name); + public IntegerConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -33,8 +33,8 @@ private Set<String> allowedValues; - public StringConfigOption(String name) { - super(name); + public StringConfigOption(String name, String description) { + super(name, description); allowedValues = new TreeSet<String>(); } Modified: trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,8 +27,8 @@ */ public class StringSetConfigOption extends ConfigOption<Set<String>> { - public StringSetConfigOption(String name) { - super(name); + public StringSetConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-29 18:30:29 UTC (rev 157) @@ -49,7 +49,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url")); + options.add(new StringConfigOption("url", "URL pointing to the OWL file")); return options; } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-29 18:30:29 UTC (rev 157) @@ -63,9 +63,12 @@ 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")); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); return options; } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-29 18:30:29 UTC (rev 157) @@ -144,7 +144,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("reasonerUrl")); + options.add(new StringConfigOption("reasonerUrl", "URL of the DIG reasoner")); return options; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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-26 12:44:16
|
Revision: 155 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=155&view=rev Author: jenslehmann Date: 2007-09-26 05:44:02 -0700 (Wed, 26 Sep 2007) Log Message: ----------- More base structure added and preparations for first simple tests made. Warning: The next commits (within approx. the next two weeks) are likely to involve transforming different parts of DL-Learner to the new structure, so they can render parts of DL-Learner temporarily unusable. Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/core/CommonConfigMappings.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/StringSetConfigOption.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/DIGReasonerNew.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/lib/components.ini 2007-09-26 12:44:02 UTC (rev 155) @@ -6,3 +6,4 @@ # learning problems org.dllearner.learningproblems.DefinitionLPTwoValued # learning algorithms +org.dllearner.algorithms.RandomGuesser Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-09-26 12:44:02 UTC (rev 155) @@ -113,7 +113,7 @@ public static int maxLineLength = 100; public static boolean writeDIGProtocol = false; - public static File digProtocolFile = new File("digProtocol.txt"); + public static File digProtocolFile = new File("log/digProtocol.txt"); // public static String preprocessingModule = ""; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-26 12:44:02 UTC (rev 155) @@ -75,6 +75,7 @@ Program p; for(int i=0; i<numberOfTrees; i++) { + // p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth); p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth); if(p.getFitness()>bestFitness) { bestFitness = p.getFitness(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-26 12:44:02 UTC (rev 155) @@ -123,7 +123,7 @@ public static Program createProgram(LearningProblem learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); - } + } private static Program createProgram(LearningProblem learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); Modified: trunk/src/dl-learner/org/dllearner/core/CommonConfigMappings.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/CommonConfigMappings.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/core/CommonConfigMappings.java 2007-09-26 12:44:02 UTC (rev 155) @@ -19,10 +19,23 @@ */ package org.dllearner.core; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.dl.Individual; + /** * @author Jens Lehmann * */ public class CommonConfigMappings { + public static SortedSet<Individual> getIndividualSet(Set<String> individuals) { + SortedSet<Individual> set = new TreeSet<Individual>(); + for(String individual : individuals) + set.add(new Individual(individual)); + return set; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-26 12:44:02 UTC (rev 155) @@ -137,7 +137,7 @@ String line; while ((line = br.readLine()) != null) { - if(!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%"))) + if(!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%") || line.length()<=1)) componentStrings.add(line); } @@ -166,7 +166,7 @@ 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); + System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component + ". It does not have the correct type."); return; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-26 12:44:02 UTC (rev 155) @@ -21,6 +21,8 @@ import java.io.File; import java.net.MalformedURLException; +import java.util.Set; +import java.util.TreeSet; import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; @@ -59,14 +61,26 @@ ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); rs.init(); + Set<String> positiveExamples = new TreeSet<String>(); + positiveExamples.add("http://example.com/father#stefan"); + positiveExamples.add("http://example.com/father#markus"); + positiveExamples.add("http://example.com/father#martin"); + Set<String> negativeExamples = new TreeSet<String>(); + 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); - // ... add positive and negative examples here ... + cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); + cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); lp.init(); LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp); + cm.applyConfigEntry(la, "numberOfTrees", 100); + cm.applyConfigEntry(la, "maxDepth", 5); la.init(); - // la.start(); + la.start(); System.out.println(la.getBestSolution()); } Modified: trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-26 12:44:02 UTC (rev 155) @@ -36,8 +36,7 @@ */ @Override public boolean isValidValue(Set<String> value) { - // TODO Auto-generated method stub - return false; + return true; } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-26 12:44:02 UTC (rev 155) @@ -27,14 +27,5 @@ * */ public abstract class DefinitionLP extends LearningProblemNew { - - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) { - // TODO Auto-generated method stub - - } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-26 12:44:02 UTC (rev 155) @@ -19,6 +19,9 @@ */ package org.dllearner.learningproblems; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.InvalidConfigOptionValueException; + /** * @author Jens Lehmann * @@ -41,4 +44,13 @@ } + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + // TODO Auto-generated method stub + + } + } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-26 12:44:02 UTC (rev 155) @@ -19,13 +19,56 @@ */ 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.IntegerConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Individual; + /** * @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; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples")); + options.add(new StringSetConfigOption("negativeExamples")); + return options; + } + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @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()); + } + + /* (non-Javadoc) * @see org.dllearner.core.Component#getName() */ public static String getName() { @@ -41,4 +84,17 @@ } + public SortedSet<Individual> getNegativeExamples() { + return negativeExamples; + } + + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public ReasoningService getReasoningService() { + return rs; + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-25 18:23:59 UTC (rev 154) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-26 12:44:02 UTC (rev 155) @@ -113,23 +113,25 @@ "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+"\">"); +// 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()) { + System.err.println("DIG-Reasoner cannot read knowledgebase."); + System.exit(0); + } } - sb.append("</tells>"); +// sb.append("</tells>"); - ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } - // DIG-Abfragen nach Konzepten, Rollen, Individuals atomicConcepts = getAtomicConceptsDIG(); atomicRoles = getAtomicRolesDIG(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-25 18:24:02
|
Revision: 154 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=154&view=rev Author: jenslehmann Date: 2007-09-25 11:23:59 -0700 (Tue, 25 Sep 2007) Log Message: ----------- continued implementing the new base structure Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.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/InvalidConfigOptionValueException.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/lib/components.ini 2007-09-25 18:23:59 UTC (rev 154) @@ -1,3 +1,8 @@ // list of all components DL-Learner should use // (if you implement your own components add them here) +# knowledge sources +org.dllearner.kb.OWLFile +# reasoners +# learning problems org.dllearner.learningproblems.DefinitionLPTwoValued +# learning algorithms Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-25 18:23:59 UTC (rev 154) @@ -1,12 +1,21 @@ package org.dllearner.algorithms; +import java.util.Collection; +import java.util.LinkedList; + import org.dllearner.LearningProblem; import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; +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.LearningProblemNew; import org.dllearner.core.dl.Concept; -public class RandomGuesser implements LearningAlgorithm { +public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; @@ -15,6 +24,37 @@ private int numberOfTrees; private int maxDepth; + public RandomGuesser(LearningProblemNew lp) { + + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new IntegerConfigOption("numberOfTrees")); + options.add(new IntegerConfigOption("maxDepth")); + 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(); + if (name.equals("numberOfTrees")) + numberOfTrees = (Integer) entry.getValue(); + else if(name.equals("maxDepth")) + maxDepth = (Integer) entry.getValue(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } /** * Generiert zufaellig Loesungen. @@ -26,6 +66,7 @@ this.maxDepth = maxDepth; } + @Override public void start() { // this.learningProblem = learningProblem; @@ -50,16 +91,21 @@ // System.out.println(bestScore); } + @Override public Score getSolutionScore() { return bestScore; } + @Override public Concept getBestSolution() { return bestDefinition; } + @Override public void stop() { // TODO Auto-generated method stub } + + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-25 18:23:59 UTC (rev 154) @@ -27,15 +27,16 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; -import org.dllearner.kb.OWLFile; - /** * Central manager class for DL-Learner. * @@ -44,23 +45,30 @@ */ public class ComponentManager { + // these variables are valid for the complete lifetime of DL-Learner private static String componentsFile = "lib/components.ini"; - private static ComponentManager cm = new ComponentManager(); + private static Set<Class<? extends Component>> components; - private List<Class<? extends Component>> components; - // 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 Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { + + public int compare(Class<?> c1, Class<?> c2) { + return c1.getName().compareTo(c2.getName()); + } + + }; + @SuppressWarnings({"unchecked"}) private ComponentManager() { // read in components file List<String> componentsString = readComponentsFile(); // component list - components = new LinkedList<Class<? extends Component>>(); + components = new TreeSet<Class<? extends Component>>(classComparator); // create classes from strings for(String componentString : componentsString) { @@ -151,10 +159,10 @@ */ public <T> void applyConfigEntry(Component component, String optionName, T value) { // first we look whether the component is registered - if(components.contains(component)) { + if(components.contains(component.getClass())) { // look for a config option with the specified name - ConfigOption<?> option = (ConfigOption<?>) componentOptionsByName.get(component).get(optionName); + 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)) { @@ -204,9 +212,15 @@ return null; } + 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) { try { - Constructor<T> constructor = reasoner.getConstructor(ReasonerComponent.class); + Constructor<T> constructor = reasoner.getConstructor(Set.class); T reasonerInstance = constructor.newInstance(sources); return new ReasoningService(reasonerInstance); } catch (IllegalArgumentException e) { @@ -232,9 +246,9 @@ return null; } - public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasonerComponent reasoner) { + public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasoningService reasoner) { try { - Constructor<T> constructor = lp.getConstructor(ReasonerComponent.class); + Constructor<T> constructor = lp.getConstructor(ReasoningService.class); return constructor.newInstance(reasoner); } catch (SecurityException e) { // TODO Auto-generated catch block @@ -259,4 +273,31 @@ return null; } + public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblemNew lp) { + try { + Constructor<T> constructor = la.getConstructor(LearningProblemNew.class); + return constructor.newInstance(lp); + } 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; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-25 18:23:59 UTC (rev 154) @@ -19,7 +19,13 @@ */ package org.dllearner.core; +import java.io.File; +import java.net.MalformedURLException; + +import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.reasoning.DIGReasonerNew; /** * Test for component based design. @@ -34,18 +40,35 @@ */ 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", "father.owl"); + cm.applyConfigEntry(source, "url", example); + source.init(); - // ... to be continued ... + ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + rs.init(); - // ReasonerComponent reasoner = new ReasonerComponent(); - // ComponentManager.getInstance().learningProblem(LearningProblemNew.class, reasoner); - + LearningProblemNew lp = cm.learningProblem(DefinitionLPTwoValued.class, rs); + // ... add positive and negative examples here ... + lp.init(); + + LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp); + la.init(); + + // la.start(); + + System.out.println(la.getBestSolution()); } } Modified: trunk/src/dl-learner/org/dllearner/core/InvalidConfigOptionValueException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/InvalidConfigOptionValueException.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/core/InvalidConfigOptionValueException.java 2007-09-25 18:23:59 UTC (rev 154) @@ -30,5 +30,9 @@ public InvalidConfigOptionValueException(ConfigOption<?> option, Object value) { super("The value " + value + " is not valid for the configuration option " + option + "."); } - + + public InvalidConfigOptionValueException(ConfigOption<?> option, Object value, String reason) { + super("The value " + value + " is not valid for the configuration option " + option + ". Reason: " + reason + "."); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-09-25 18:23:59 UTC (rev 154) @@ -19,12 +19,39 @@ */ package org.dllearner.core; +import org.dllearner.Score; +import org.dllearner.core.dl.Concept; + /** * @author Jens Lehmann * */ public abstract class LearningAlgorithmNew extends Component { + /** + * Starts the algorithm. + * + */ + public abstract void start(); + + /** + * Stops the algorithm gracefully. + * + */ + public abstract void stop(); + /** + * Every algorithm must be able to return the score of the + * best solution found. + * @return Best score. + */ + public abstract Score getSolutionScore(); + + /** + * Returns the best solutions obtained so far. + * @return Best solution. + */ + public abstract Concept getBestSolution(); + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-25 18:23:59 UTC (rev 154) @@ -95,11 +95,20 @@ public ReasoningService(Reasoner reasoner) { this.reasoner = reasoner; + resetStatistics(); + } + + public ReasoningService(ReasonerComponent reasoner) { + this.reasoner = reasoner; + } + + public void init() { + // temporary ugly hack to keep old version working + ((ReasonerComponent)reasoner).init(); + // Listenansicht atomicConceptsList = new LinkedList<AtomicConcept>(getAtomicConcepts()); - atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); - - resetStatistics(); + atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); } // zurücksetzen aller Statistiken (wenn z.B. vorher ein Satisfiability Check gemacht wird, @@ -417,7 +426,7 @@ public List<AtomicRole> getAtomicRolesList() { return atomicRolesList; } - + public long getInstanceCheckReasoningTimeNs() { return instanceCheckReasoningTimeNs; } Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-25 18:23:59 UTC (rev 154) @@ -19,8 +19,10 @@ */ 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; @@ -60,13 +62,27 @@ String s = (String) entry.getValue(); try { url = new URL(s); + // File f = new File(url.toURI()); + //if(!f.canRead()) + // throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); } catch (MalformedURLException e) { - // e.printStackTrace(); - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); - } + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); + } //catch (URISyntaxException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + //} } } + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + /* * (non-Javadoc) * @@ -78,13 +94,6 @@ return OWLAPIDIGConverter.getTellsString(url, OntologyFileFormat.RDF_XML, kbURI); } - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - // TODO Auto-generated method stub - - } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-25 14:38:43 UTC (rev 153) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-25 18:23:59 UTC (rev 154) @@ -43,19 +43,16 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.StringConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Bottom; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; -import org.dllearner.utilities.SortedSetTuple; import org.kr.dl.dig.v1_1.Concepts; import org.kr.dl.dig.v1_1.Csynonyms; import org.kr.dl.dig.v1_1.IdType; @@ -728,23 +725,6 @@ // kaon2Reasoner.saveOntology(file, format); } - /* (non-Javadoc) - * @see org.dllearner.core.Reasoner#doubleRetrieval(org.dllearner.core.dl.Concept) - */ - public SortedSetTuple<Individual> doubleRetrieval(Concept concept) - throws ReasoningMethodUnsupportedException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.dllearner.core.Reasoner#doubleRetrieval(org.dllearner.core.dl.Concept, org.dllearner.core.dl.Concept) - */ - public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) - throws ReasoningMethodUnsupportedException { - // TODO Auto-generated method stub - return null; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-25 14:38:46
|
Revision: 153 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=153&view=rev Author: jenslehmann Date: 2007-09-25 07:38:43 -0700 (Tue, 25 Sep 2007) Log Message: ----------- parser changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jj Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-09-25 14:32:25 UTC (rev 152) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-09-25 14:38:43 UTC (rev 153) @@ -18,7 +18,7 @@ import org.dllearner.Main; import org.dllearner.Info; -import org.dllearner.dl.*; +import org.dllearner.core.dl.*; import org.dllearner.ConfigurationOption; import org.dllearner.utilities.*; Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-09-25 14:32:25 UTC (rev 152) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-09-25 14:38:43 UTC (rev 153) @@ -14,7 +14,7 @@ import java.io.StringReader; import org.dllearner.Main; import org.dllearner.Info; -import org.dllearner.dl.*; +import org.dllearner.core.dl.*; import org.dllearner.ConfigurationOption; import org.dllearner.utilities.*; Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-09-25 14:32:25 UTC (rev 152) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-09-25 14:38:43 UTC (rev 153) @@ -33,7 +33,7 @@ import org.dllearner.Main; import org.dllearner.Info; -import org.dllearner.dl.*; +import org.dllearner.core.dl.*; import org.dllearner.ConfigurationOption; import org.dllearner.utilities.*; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |