|
From: <jen...@us...> - 2009-02-12 08:57:43
|
Revision: 1593
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1593&view=rev
Author: jenslehmann
Date: 2009-02-12 08:57:36 +0000 (Thu, 12 Feb 2009)
Log Message:
-----------
small CLI improvements
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
trunk/src/dl-learner/org/dllearner/cli/Start.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-11 16:58:59 UTC (rev 1592)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-12 08:57:36 UTC (rev 1593)
@@ -423,7 +423,7 @@
}
public static String getName() {
- return "example driven refinement operator based learning algorithm";
+ return "refinement operator based learning algorithm II";
}
public static String getUsage() {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-11 16:58:59 UTC (rev 1592)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-12 08:57:36 UTC (rev 1593)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007-2008, Jens Lehmann
+ * Copyright (C) 2007-2009, Jens Lehmann
*
* This file is part of DL-Learner.
*
@@ -57,17 +57,8 @@
import com.jamonapi.Monitor;
/**
- * Implements the example based refinement operator learning approach.
+ * Implements the 2nd version of the refinement operator based learning approach.
*
- * TODO: Solve subsumption problems. It is easy to implement approximate fast
- * instance checks. However, subsumption is difficult to optimise. It should by
- * analysed whether it is reasonable to perform instance comparisions instead of
- * subsumption checks, e.g. a concept is only included in the search tree when
- * it covers strictly less examples than its parent. Note, that this does not
- * mean that concepts not bearing an advantage in classification are thrown
- * away. They are just handled like improper refinements. [TODO: How does this
- * differ from not checking subsumption at all?]
- *
* @author Jens Lehmann
*
*/
@@ -403,6 +394,8 @@
ExampleBasedNode bestNode = startNode;
ExampleBasedNode bestNodeStable = startNode;
+ logger.info("starting top down refinement with: " + startNode.getConcept().toManchesterSyntaxString(baseURI, prefixes) + " (" + df.format(100*startNode.getAccuracy(nrOfPositiveExamples, nrOfNegativeExamples)) + "% accuracy)");
+
int loop = 0;
algorithmStartTime = System.nanoTime();
@@ -446,7 +439,7 @@
.getCovPosMinusCovNeg()) {
String acc = new DecimalFormat( ".00%" ).format((candidatesStable.last().getAccuracy(nrOfPositiveExamples, nrOfNegativeExamples)));
// no handling needed, it will just look ugly in the output
- logger.info("more accurate ("+acc+") node found: " + candidatesStable.last());
+ logger.info("more accurate ("+acc+") class expression found: " + candidatesStable.last().getConcept().toManchesterSyntaxString(baseURI, prefixes));
bestNodeStable = candidatesStable.last();
}
@@ -524,17 +517,18 @@
if (solutionFound) {
int solutionLimit = 20;
- logger.info("best node "
- + candidatesStable.last().getShortDescription(nrOfPositiveExamples,
- nrOfNegativeExamples, baseURI));
+ // we do not need to print the best node if we display the top 20 solutions below anyway
+// logger.info("best node "
+// + candidatesStable.last().getShortDescription(nrOfPositiveExamples,
+// nrOfNegativeExamples, baseURI));
logger.info("solutions (at most " + solutionLimit + " are shown):");
int show = 1;
String manchester = "MANCHESTER:\n";
String kbSyntax = "KBSyntax:\n";
for (Description c : solutions) {
- logger.info(show + ": " + c.toString(baseURI, null) + " (length " + c.getLength()
+ logger.info(show + ": " + c.toManchesterSyntaxString(baseURI, prefixes) + " (length " + c.getLength()
+ ", depth " + c.getDepth() + ")");
- manchester += show + ": " + c.toManchesterSyntaxString(baseURI, prefixes) + "\n";
+// manchester += show + ": " + c.toManchesterSyntaxString(baseURI, prefixes) + "\n";
kbSyntax += show + ": " + c.toKBSyntaxString() + "\n";
if (show >= solutionLimit) {
break;
@@ -551,10 +545,11 @@
printStatistics(true);
- if (stop)
- logger.info("Algorithm stopped.");
- else
- logger.info("Algorithm terminated succesfully.");
+ if (stop) {
+ logger.info("Algorithm stopped.\n");
+ } else {
+ logger.info("Algorithm terminated succesfully.\n");
+ }
totalLearningTime.stop();
isRunning = false;
Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-11 16:58:59 UTC (rev 1592)
+++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-12 08:57:36 UTC (rev 1593)
@@ -329,6 +329,11 @@
// handle any CLI options
processCLIOptions(cm, parser, rc, lp);
+
+ // newline to separate init phase from learning phase
+ if(logger.isInfoEnabled()) {
+ System.out.println("");
+ }
}
public void start(boolean inQueryMode) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-13 17:10:53
|
Revision: 1604
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1604&view=rev
Author: jenslehmann
Date: 2009-02-13 17:10:49 +0000 (Fri, 13 Feb 2009)
Log Message:
-----------
fast retrieval algorithm started
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java
trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2009-02-13 11:44:38 UTC (rev 1603)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2009-02-13 17:10:49 UTC (rev 1604)
@@ -49,6 +49,8 @@
// example based variables
private Set<Individual> coveredPositives;
private Set<Individual> coveredNegatives;
+// private int coveredPositiveSize;
+// private int coveredNegativeSize;
// the method by which quality was evaluated in this node
public enum QualityEvaluationMethod { START, REASONER, TOO_WEAK_LIST, OVERLY_GENERAL_LIST };
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-02-13 11:44:38 UTC (rev 1603)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-02-13 17:10:49 UTC (rev 1604)
@@ -70,6 +70,15 @@
public boolean getDefaultNegation() {
return (Boolean) ComponentManager.getInstance().getConfigOptionValue(fastInstanceChecker, "defaultNegation") ;
}
+/**
+* forallRetrievalSemantics This option controls how to interpret the all quantifier in orall r.C. The standard option isto return all those which do not have an r-filler not in C. The domain semantics is to use thosewhich are in the domain of r and do not have an r-filler not in C. The forallExists semantics is touse those which have at least one r-filler and do not have an r-filler not in C..
+* mandatory: false| reinit necessary: true
+* default value: forallExists
+* @return String
+**/
+public String getForallRetrievalSemantics() {
+return (String) ComponentManager.getInstance().getConfigOptionValue(fastInstanceChecker, "forallRetrievalSemantics") ;
+}
/**
* @param reasonerType FaCT++ or Pellet to dematerialize.
@@ -89,6 +98,15 @@
ComponentManager.getInstance().applyConfigEntry(fastInstanceChecker, "defaultNegation", defaultNegation);
reinitNecessary = true;
}
+/**
+* @param forallRetrievalSemantics This option controls how to interpret the all quantifier in orall r.C. The standard option isto return all those which do not have an r-filler not in C. The domain semantics is to use thosewhich are in the domain of r and do not have an r-filler not in C. The forallExists semantics is touse those which have at least one r-filler and do not have an r-filler not in C..
+* mandatory: false| reinit necessary: true
+* default value: forallExists
+**/
+public void setForallRetrievalSemantics(String forallRetrievalSemantics) {
+ComponentManager.getInstance().applyConfigEntry(fastInstanceChecker, "forallRetrievalSemantics", forallRetrievalSemantics);
+reinitNecessary = true;
+}
/**
* true, if this component needs reinitializsation.
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-13 11:44:38 UTC (rev 1603)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-13 17:10:49 UTC (rev 1604)
@@ -28,6 +28,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.Map.Entry;
import org.apache.log4j.Logger;
import org.dllearner.core.ComponentInitException;
@@ -82,7 +83,10 @@
* object creation, which makes it extremely fast compared to standard
* reasoners.
*
- * Note: This algorithm works only on concepts in negation normal form!
+ * Meanwhile, the algorithm has been extended to also perform fast retrieval
+ * operations. However, those need write access to memory and potentially have
+ * to deal with all individuals in a knowledge base. For many knowledge bases,
+ * they should still be reasonably fast.
*
* @author Jens Lehmann
*
@@ -149,6 +153,15 @@
// http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup
options.add(type);
options.add(new BooleanConfigOption("defaultNegation", "Whether to use default negation, i.e. an instance not being in a class means that it is in the negation of the class.", true, false, true));
+ StringConfigOption forallSemantics = new StringConfigOption("forallRetrievalSemantics",
+ "This option controls how to interpret the all quantifier in \forall r.C. The standard option is" +
+ "to return all those which do not have an r-filler not in C. The domain semantics is to use those" +
+ "which are in the domain of r and do not have an r-filler not in C. The forallExists semantics is to" +
+ "use those which have at least one r-filler and do not have an r-filler not in C.", "forallExists");
+ forallSemantics.setAllowedValues(new String[] { "standard", "domain", "forallExists" });
+ // closure option? see:
+ // http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup
+ options.add(forallSemantics);
return options;
}
@@ -482,22 +495,111 @@
}
@Override
- public SortedSet<Individual> getIndividualsImpl(Description concept)
+ public SortedSet<Individual> getIndividualsImpl(Description description)
throws ReasoningMethodUnsupportedException {
- if (concept instanceof NamedClass) {
- return classInstancesPos.get((NamedClass) concept);
- } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) {
- return classInstancesNeg.get((NamedClass) concept.getChild(0));
+ // policy: returned sets are clones, i.e. can be modified
+ // (of course we only have to clone the leafs of a class description tree)
+ if (description instanceof NamedClass) {
+ return new TreeSet<Individual>(classInstancesPos.get((NamedClass) description));
+ } else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) {
+ return new TreeSet<Individual>(classInstancesNeg.get((NamedClass) description.getChild(0)));
+ } else if (description instanceof Thing) {
+ return new TreeSet<Individual>(individuals);
+ } else if (description instanceof Nothing) {
+ return new TreeSet<Individual>();
+ } else if (description instanceof Union) {
+ // copy instances of first element and then subtract all others
+ SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0));
+ int childNr = 0;
+ for(Description child : description.getChildren()) {
+ if(childNr != 0) {
+ ret.addAll(getIndividualsImpl(child));
+ }
+ childNr++;
+ }
+ return ret;
+ } else if (description instanceof Intersection) {
+ // copy instances of first element and then subtract all others
+ SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0));
+ int childNr = 0;
+ for(Description child : description.getChildren()) {
+ if(childNr != 0) {
+ ret.retainAll(getIndividualsImpl(child));
+ }
+ childNr++;
+ }
+ return ret;
+ } else if (description instanceof ObjectSomeRestriction) {
+ SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0));
+ SortedSet<Individual> returnSet = new TreeSet<Individual>();
+
+ ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole();
+ if (!(ope instanceof ObjectProperty)) {
+ throw new ReasoningMethodUnsupportedException("Instance check for description "
+ + description + " unsupported. Inverse object properties not supported.");
+ }
+ ObjectProperty op = (ObjectProperty) ope;
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+
+ // each individual is connected to a set of individuals via the property;
+ // we loop through the complete mapping
+ for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) {
+ SortedSet<Individual> inds = entry.getValue();
+ for(Individual ind : inds) {
+ if(targetSet.contains(ind)) {
+ returnSet.add(ind);
+ // once we found an individual, we do not need to check the others
+ continue;
+ }
+ }
+ }
+ } else if (description instanceof ObjectAllRestriction) {
+ // \forall restrictions are difficult to handle; assume we want to check
+ // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons
+ // this is satisfied trivially (all of their non-existing children are male)
+ if(!configurator.getForallRetrievalSemantics().equals("forallExists")) {
+ throw new Error("Only forallExists semantics currently implemented.");
+ }
+
+ // problem: we need to make sure that \neg \exists r.\top \equiv \forall r.\bot
+ // can still be reached in an algorithm (\forall r.\bot \equiv \bot under forallExists
+ // semantics)
+
+ SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0));
+
+ ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole();
+ if (!(ope instanceof ObjectProperty)) {
+ throw new ReasoningMethodUnsupportedException("Instance check for description "
+ + description + " unsupported. Inverse object properties not supported.");
+ }
+ ObjectProperty op = (ObjectProperty) ope;
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+ SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet());
+
+ // each individual is connected to a set of individuals via the property;
+ // we loop through the complete mapping
+ for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) {
+ SortedSet<Individual> inds = entry.getValue();
+ for(Individual ind : inds) {
+ if(!targetSet.contains(ind)) {
+ returnSet.remove(ind);
+ continue;
+ }
+ }
+ }
}
-
+
+ throw new ReasoningMethodUnsupportedException("Retrieval for description "
+ + description + " unsupported.");
+
// return rs.retrieval(concept);
- SortedSet<Individual> inds = new TreeSet<Individual>();
- for (Individual i : individuals) {
- if (hasType(concept, i)) {
- inds.add(i);
- }
- }
- return inds;
+// SortedSet<Individual> inds = new TreeSet<Individual>();
+// for (Individual i : individuals) {
+// if (hasType(concept, i)) {
+// inds.add(i);
+// }
+// }
+// return inds;
}
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-16 13:03:55
|
Revision: 1605
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1605&view=rev
Author: jenslehmann
Date: 2009-02-16 13:03:46 +0000 (Mon, 16 Feb 2009)
Log Message:
-----------
continued ontology engineering algorithm
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java
trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
trunk/src/dl-learner/org/dllearner/core/Score.java
trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java
trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStandard.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStrict.java
trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java
Added: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -0,0 +1,43 @@
+/**
+ * Copyright (C) 2007-2009, 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 org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.owl.Description;
+import org.dllearner.learningproblems.ClassScore;
+
+/**
+ * An evaluated description for learning classes in ontologies.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class EvaluatedDescriptionClass extends EvaluatedDescription {
+
+ /**
+ * Constructs an evaluated description for learning classes in ontologies.
+ * @param description Description.
+ * @param score Score of description.
+ */
+ public EvaluatedDescriptionClass(Description description, ClassScore score) {
+ super(description, score);
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -19,13 +19,33 @@
*/
package org.dllearner.algorithms.celoe;
-import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
import org.dllearner.core.ComponentInitException;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
+import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.configurators.CELOEConfigurator;
import org.dllearner.core.configurators.Configurator;
+import org.dllearner.core.options.CommonConfigOptions;
+import org.dllearner.core.options.ConfigOption;
+import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.ClassLearningProblem;
+import org.dllearner.refinementoperators.RefinementOperator;
+import org.dllearner.refinementoperators.RhoDRDown;
+import org.dllearner.utilities.owl.ConceptComparator;
+import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
/**
* The CELOE (Class Expression Learner for Ontology Engineering) algorithm.
@@ -37,71 +57,195 @@
*/
public class CELOE extends LearningAlgorithm {
+ private static Logger logger = Logger.getLogger(CELOE.class);
+ private CELOEConfigurator configurator;
+
+ private boolean isRunning = false;
+ private boolean stop = false;
+
+// private OEHeuristicStable heuristicStable = new OEHeuristicStable();
+// private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime();
+
+ private RefinementOperator operator;
+
+ // all nodes in the search tree (used for selecting most promising node)
+ private TreeSet<OENode> nodes;
+ // root of search tree
+ private OENode startNode;
+
+ // all descriptions in the search tree plus those which were too weak (for fast redundancy check)
+ private TreeSet<Description> descriptions;
+
+ private EvaluatedDescriptionSet bestEvaluatedDescriptions = new EvaluatedDescriptionSet(LearningAlgorithm.MAX_NR_OF_RESULTS);
+
+ private NamedClass classToDescribe;
+ private boolean isEquivalenceProblem;
+
+ private long nanoStartTime;
+
+ // important parameters
+ private double minAcc;
+
+ @Override
+ public Configurator getConfigurator() {
+ return configurator;
+ }
+
public CELOE(ClassLearningProblem problem, ReasonerComponent reasoner) {
super(problem, reasoner);
+ classToDescribe = problem.getClassToDescribe();
+ isEquivalenceProblem = problem.isEquivalenceProblem();
}
- /* (non-Javadoc)
- * @see org.dllearner.core.LearningAlgorithm#getCurrentlyBestDescription()
- */
+ public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() {
+ Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>();
+ problems.add(ClassLearningProblem.class);
+ return problems;
+ }
+
+ public static Collection<ConfigOption<?>> createConfigOptions() {
+ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>();
+ options.add(CommonConfigOptions.useAllConstructor());
+ options.add(CommonConfigOptions.useExistsConstructor());
+ options.add(CommonConfigOptions.useHasValueConstructor());
+ options.add(CommonConfigOptions.valueFreqencyThreshold());
+ options.add(CommonConfigOptions.useCardinalityRestrictions());
+ options.add(CommonConfigOptions.cardinalityLimit());
+ options.add(CommonConfigOptions.useNegation());
+ options.add(CommonConfigOptions.useBooleanDatatypes());
+ options.add(CommonConfigOptions.useDoubleDatatypes());
+ options.add(CommonConfigOptions.maxExecutionTimeInSeconds());
+ options.add(CommonConfigOptions.getNoisePercentage());
+ return options;
+ }
+
+ public static String getName() {
+ return "CELOE";
+ }
+
@Override
- public Description getCurrentlyBestDescription() {
- // TODO Auto-generated method stub
- return null;
+ public void init() throws ComponentInitException {
+ // copy class hierarchy and modify it such that each class is only
+ // reachable via a single path
+ ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone();
+ classHierarchy.thinOutSubsumptionHierarchy();
+
+ // create refinement operator
+ operator = new RhoDRDown(reasoner, classHierarchy, configurator);
+
+ // we put important parameters in class variables
+ minAcc = configurator.getNoisePercentage()/100d;
}
- /* (non-Javadoc)
- * @see org.dllearner.core.LearningAlgorithm#getCurrentlyBestEvaluatedDescription()
- */
@Override
- public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
- // TODO Auto-generated method stub
- return null;
+ public Description getCurrentlyBestDescription() {
+ return getCurrentlyBestEvaluatedDescription().getDescription();
}
- /* (non-Javadoc)
- * @see org.dllearner.core.LearningAlgorithm#isRunning()
- */
@Override
- public boolean isRunning() {
- // TODO Auto-generated method stub
- return false;
+ public List<Description> getCurrentlyBestDescriptions() {
+ return bestEvaluatedDescriptions.toDescriptionList();
}
-
- /* (non-Javadoc)
- * @see org.dllearner.core.LearningAlgorithm#start()
- */
+
@Override
+ public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
+ return bestEvaluatedDescriptions.getSet().last();
+ }
+
+ @Override
+ public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ return bestEvaluatedDescriptions.getSet();
+ }
+
+ @Override
public void start() {
- // TODO Auto-generated method stub
-
+ stop = false;
+ isRunning = true;
+ reset();
+ nanoStartTime = System.nanoTime();
+
+ // start class: intersection of super classes for definitions (since it needs to
+ // capture all instances), but owl:Thing for learning subclasses (since it is
+ // superfluous to add super classes in this case)
+ Description startClass;
+ if(isEquivalenceProblem) {
+ Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe);
+ startClass = new Intersection(new LinkedList<Description>(superClasses));
+ } else {
+ startClass = Thing.instance;
+ }
+ addNode(startClass, null);
+
+
+ // print solution(s)
+ logger.info("solution : " + bestEvaluatedDescriptions.getBest());
+
+ isRunning = false;
}
- /* (non-Javadoc)
- * @see org.dllearner.core.LearningAlgorithm#stop()
- */
- @Override
- public void stop() {
- // TODO Auto-generated method stub
-
+ // expand node horizontically
+ private void expandNode(OENode node) {
+
}
-
- /* (non-Javadoc)
- * @see org.dllearner.core.Component#getConfigurator()
- */
- @Override
- public Configurator getConfigurator() {
- // TODO Auto-generated method stub
- return null;
+
+ // add node to search tree if it is not too weak
+ // returns true if node was added and false otherwise
+ private boolean addNode(Description description, OENode parentNode) {
+
+ // redundancy check (return if redundant)
+ boolean nonRedundant = descriptions.add(description);
+ if(!nonRedundant) {
+ return false;
+ }
+
+ // quality of description (return if too weak)
+ double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc);
+ if(accuracy == -1) {
+ return false;
+ }
+
+ OENode node = new OENode(parentNode, description, accuracy);
+
+ // link to parent (unless start node)
+ if(parentNode == null) {
+ startNode = node;
+ } else {
+ parentNode.addChild(node);
+ }
+
+ // maybe add to best descriptions (method keeps set size fixed)
+ bestEvaluatedDescriptions.add(description, accuracy, learningProblem);
+
+ return true;
+ }
+
+ // check whether the node is a potential solution candidate
+ // (sufficient accuracy; minimal; rewriting steps?)
+ private boolean checkNode(OENode node) {
+ return true;
}
-
- /* (non-Javadoc)
- * @see org.dllearner.core.Component#init()
- */
+
+ private boolean terminationCriteriaSatisfied() {
+ return !stop && (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()/1000000));
+ }
+
+ private void reset() {
+ // set all values back to their default values (used for running
+ // the algorithm more than once)
+// candidates.clear();
+ nodes = new TreeSet<OENode>(new OEHeuristicRuntime());
+ descriptions = new TreeSet<Description>(new ConceptComparator());
+ bestEvaluatedDescriptions.getSet().clear();
+ }
+
@Override
- public void init() throws ComponentInitException {
- // TODO Auto-generated method stub
-
+ public boolean isRunning() {
+ return isRunning;
+ }
+
+ @Override
+ public void stop() {
+ stop = true;
}
}
Added: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) 2007-2009, 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.celoe;
+
+import java.util.Comparator;
+
+/**
+ * Marker interface for heurist comparators over nodes in the search tree.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public interface OEHeuristic extends Comparator<OENode> {
+
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2007-2009, 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.celoe;
+
+import java.util.Comparator;
+
+/**
+ * @author Jens Lehmann
+ *
+ */
+public class OEHeuristicRuntime implements OEHeuristic {
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(OENode o1, OENode o2) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2007-2009, 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.celoe;
+
+/**
+ * @author Jens Lehmann
+ *
+ */
+public class OEHeuristicStable implements OEHeuristic {
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(OENode o1, OENode o2) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -19,12 +19,70 @@
*/
package org.dllearner.algorithms.celoe;
+import java.util.List;
+
+import org.dllearner.core.owl.Description;
+
/**
* A node in the search tree of the ontology engineering algorithm.
*
+ * Differences to the node structures in other algorithms (this may change):
+ * - covered examples are not stored in node (i.e. coverage needs to be recomputed
+ * for child nodes, which costs time but saves memory)
+ * - only evaluated nodes are stored
+ * - too weak nodes are not stored
+ * - redundant nodes are not stored (?)
+ * - only accuracy is stored to make the node structure reusable for different
+ * learning problems and -algorithms
+ *
* @author Jens Lehmann
*
*/
public class OENode {
+ private Description description;
+
+ private double accuracy;
+
+ private OENode parent;
+ private List<OENode> children;
+
+ public OENode(OENode parentNode, Description description, double accuracy) {
+ this.parent = parentNode;
+ this.description = description;
+ this.accuracy = accuracy;
+ }
+
+ public void addChild(OENode node) {
+ children.add(node);
+ }
+
+ /**
+ * @return the description
+ */
+ public Description getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the accuracy
+ */
+ public double getAccuracy() {
+ return accuracy;
+ }
+
+ /**
+ * @return the parent
+ */
+ public OENode getParent() {
+ return parent;
+ }
+
+ /**
+ * @return the children
+ */
+ public List<OENode> getChildren() {
+ return children;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -168,7 +168,7 @@
// the description has a chance to make it in the set if it has
// at least as high accuracy - if not we can save the reasoner calls
// for fully computing the evaluated description
- if(bestEvaluatedDescriptions.size() == 0 || bestEvaluatedDescriptions.getWorst().getCoveredNegatives().size() >= node.getCoveredNegatives()) {
+ if(bestEvaluatedDescriptions.size() == 0 || ((EvaluatedDescriptionPosNeg)bestEvaluatedDescriptions.getWorst()).getCoveredNegatives().size() >= node.getCoveredNegatives()) {
ScorePosNeg score = (ScorePosNeg) learningProblem.computeScore(description);
EvaluatedDescriptionPosNeg ed = new EvaluatedDescriptionPosNeg(description, score);
bestEvaluatedDescriptions.add(ed);
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ExampleBasedNode.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -42,6 +42,8 @@
*/
public class ExampleBasedNode {
+// public static long exampleMemoryCounter = 0;
+
private ROLComponent2Configurator configurator;
private static DecimalFormat df = new DecimalFormat();
@@ -114,6 +116,8 @@
this.coveredPositives = coveredPositives;
this.coveredNegatives = coveredNegatives;
isQualityEvaluated = true;
+// exampleMemoryCounter += coveredPositives.size() * 4;
+// exampleMemoryCounter += coveredNegatives.size() * 4;
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -418,6 +418,8 @@
printStatistics(false);
lastPrintTime = currentTime;
logger.debug("--- loop " + loop + " started ---");
+// logger.info("used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/1024);
+// logger.info("test: " + ExampleBasedNode.exampleMemoryCounter/1024);
}
// traverse the current search tree to find a solution
Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -77,6 +77,15 @@
public abstract Score computeScore(Description description);
/**
+ * Evaluates the description by computing the score and returning an
+ * evaluated description of the correct type (ClassLearningProblem
+ * returns EvaluatedDescriptionClass instead of generic EvaluatedDescription).
+ * @param description Description to evaluate.
+ * @return
+ */
+ public abstract EvaluatedDescription evaluate(Description description);
+
+ /**
* This method returns a value, which indicates how accurate a
* class description solves a learning problem. There can be different
* ways to compute accuracy depending on the type of learning problem
Modified: trunk/src/dl-learner/org/dllearner/core/Score.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -25,6 +25,8 @@
* different criteria can be used. (Similar learning problems probably
* score class descriptions/hypothesis in a similar way.)
*
+ * TODO: Maybe we don't really need a score, but only EvaluatedDescription.
+ *
* @author Jens Lehmann
*
*/
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -25,12 +25,13 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.configurators.RefinementOperatorConfigurator;
/**
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class CELOEConfigurator implements Configurator {
+public class CELOEConfigurator extends RefinementOperatorConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
@@ -55,7 +56,205 @@
return component;
}
+/**
+* useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseAllConstructor() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useAllConstructor") ;
+}
+/**
+* useExistsConstructor specifies whether the existential concept constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseExistsConstructor() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useExistsConstructor") ;
+}
+/**
+* useHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: false
+* @return boolean
+**/
+public boolean getUseHasValueConstructor() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useHasValueConstructor") ;
+}
+/**
+* valueFrequencyThreshold specifies how often an object must occur as value in order to be considered for hasValue restrictions.
+* mandatory: false| reinit necessary: true
+* default value: 3
+* @return int
+**/
+public int getValueFrequencyThreshold() {
+return (Integer) ComponentManager.getInstance().getConfigOptionValue(cELOE, "valueFrequencyThreshold") ;
+}
+/**
+* useCardinalityRestrictions specifies whether CardinalityRestrictions is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseCardinalityRestrictions() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useCardinalityRestrictions") ;
+}
+/**
+* cardinalityLimit Gives the maximum number used in cardinality restrictions..
+* mandatory: false| reinit necessary: true
+* default value: 5
+* @return int
+**/
+public int getCardinalityLimit() {
+return (Integer) ComponentManager.getInstance().getConfigOptionValue(cELOE, "cardinalityLimit") ;
+}
+/**
+* useNegation specifies whether negation is used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseNegation() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useNegation") ;
+}
+/**
+* useBooleanDatatypes specifies whether boolean datatypes are used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseBooleanDatatypes() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useBooleanDatatypes") ;
+}
+/**
+* useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+* @return boolean
+**/
+public boolean getUseDoubleDatatypes() {
+return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useDoubleDatatypes") ;
+}
+/**
+* maxExecutionTimeInSeconds algorithm will stop after specified seconds.
+* mandatory: false| reinit necessary: true
+* default value: 0
+* @return int
+**/
+public int getMaxExecutionTimeInSeconds() {
+return (Integer) ComponentManager.getInstance().getConfigOptionValue(cELOE, "maxExecutionTimeInSeconds") ;
+}
+/**
+* noisePercentage the (approximated) percentage of noise within the examples.
+* mandatory: false| reinit necessary: true
+* default value: 0.0
+* @return double
+**/
+public double getNoisePercentage() {
+return (Double) ComponentManager.getInstance().getConfigOptionValue(cELOE, "noisePercentage") ;
+}
+/**
+* @param useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseAllConstructor(boolean useAllConstructor) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useAllConstructor", useAllConstructor);
+reinitNecessary = true;
+}
+/**
+* @param useExistsConstructor specifies whether the existential concept constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseExistsConstructor(boolean useExistsConstructor) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useExistsConstructor", useExistsConstructor);
+reinitNecessary = true;
+}
+/**
+* @param useHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: false
+**/
+public void setUseHasValueConstructor(boolean useHasValueConstructor) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useHasValueConstructor", useHasValueConstructor);
+reinitNecessary = true;
+}
+/**
+* @param valueFrequencyThreshold specifies how often an object must occur as value in order to be considered for hasValue restrictions.
+* mandatory: false| reinit necessary: true
+* default value: 3
+**/
+public void setValueFrequencyThreshold(int valueFrequencyThreshold) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "valueFrequencyThreshold", valueFrequencyThreshold);
+reinitNecessary = true;
+}
+/**
+* @param useCardinalityRestrictions specifies whether CardinalityRestrictions is used in the learning algorithm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseCardinalityRestrictions(boolean useCardinalityRestrictions) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useCardinalityRestrictions", useCardinalityRestrictions);
+reinitNecessary = true;
+}
+/**
+* @param cardinalityLimit Gives the maximum number used in cardinality restrictions..
+* mandatory: false| reinit necessary: true
+* default value: 5
+**/
+public void setCardinalityLimit(int cardinalityLimit) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "cardinalityLimit", cardinalityLimit);
+reinitNecessary = true;
+}
+/**
+* @param useNegation specifies whether negation is used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseNegation(boolean useNegation) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useNegation", useNegation);
+reinitNecessary = true;
+}
+/**
+* @param useBooleanDatatypes specifies whether boolean datatypes are used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseBooleanDatatypes(boolean useBooleanDatatypes) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useBooleanDatatypes", useBooleanDatatypes);
+reinitNecessary = true;
+}
+/**
+* @param useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm.
+* mandatory: false| reinit necessary: true
+* default value: true
+**/
+public void setUseDoubleDatatypes(boolean useDoubleDatatypes) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "useDoubleDatatypes", useDoubleDatatypes);
+reinitNecessary = true;
+}
+/**
+* @param maxExecutionTimeInSeconds algorithm will stop after specified seconds.
+* mandatory: false| reinit necessary: true
+* default value: 0
+**/
+public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds);
+reinitNecessary = true;
+}
+/**
+* @param noisePercentage the (approximated) percentage of noise within the examples.
+* mandatory: false| reinit necessary: true
+* default value: 0.0
+**/
+public void setNoisePercentage(double noisePercentage) {
+ComponentManager.getInstance().applyConfigEntry(cELOE, "noisePercentage", noisePercentage);
+reinitNecessary = true;
+}
/**
* true, if this component needs reinitializsation.
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -197,6 +197,11 @@
return str;
}
+ @Override
+ public ClassHierarchy clone() {
+ return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown);
+ }
+
/**
* The method computes a new class hierarchy, which is a copy of this
* one, but only the specified classes are allowed to occur. For instance,
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -23,6 +23,8 @@
import java.util.LinkedList;
import java.util.Set;
+import org.dllearner.algorithms.EvaluatedDescriptionClass;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.ClassLearningProblemConfigurator;
@@ -129,4 +131,20 @@
// TODO Auto-generated method stub
return 0;
}
+
+ /**
+ * @return the classToDescribe
+ */
+ public NamedClass getClassToDescribe() {
+ return classToDescribe;
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningProblem#evaluate(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public EvaluatedDescription evaluate(Description description) {
+ ClassScore score = computeScore(description);
+ return new EvaluatedDescriptionClass(description, score);
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -22,6 +22,7 @@
import java.util.Set;
import java.util.SortedSet;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.ComponentFactory;
import org.dllearner.core.configurators.PosNegInclusionLPConfigurator;
@@ -217,4 +218,13 @@
return 0;
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningProblem#evaluate(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public EvaluatedDescription evaluate(Description description) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStandard.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStandard.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStandard.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -24,6 +24,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.PosNegLPStandardConfigurator;
import org.dllearner.core.options.ConfigOption;
@@ -247,4 +248,13 @@
return 0;
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningProblem#evaluate(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public EvaluatedDescription evaluate(Description description) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStrict.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStrict.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStrict.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -23,6 +23,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.PosNegLPStrictConfigurator;
import org.dllearner.core.options.BooleanConfigOption;
@@ -221,4 +222,13 @@
// TODO Auto-generated method stub
return 0;
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningProblem#evaluate(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public EvaluatedDescription evaluate(Description description) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -39,6 +39,7 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.configurators.CELOEConfigurator;
import org.dllearner.core.configurators.ROLearnerConfigurator;
import org.dllearner.core.configurators.RefinementOperatorConfigurator;
import org.dllearner.core.options.ConfigOption;
@@ -65,7 +66,7 @@
private static final SortedSet<String> EXTENDSREFINEMENTOPERATOR =
new TreeSet<String>(Arrays.asList(new String[]{
ROLearnerConfigurator.class.getSimpleName(),
- CELOE.class.getSimpleName(),
+ CELOEConfigurator.class.getSimpleName(),
}));
@SuppressWarnings("unchecked")
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-13 17:10:49 UTC (rev 1604)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-16 13:03:46 UTC (rev 1605)
@@ -27,6 +27,8 @@
import java.util.TreeSet;
import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.LearningProblem;
import org.dllearner.core.owl.Description;
/**
@@ -39,9 +41,9 @@
*/
public class EvaluatedDescriptionSet {
- private EvaluatedDescriptionPosNegComparator comp = new EvaluatedDescriptionPosNegComparator();
+ private EvaluatedDescriptionComparator comp = new EvaluatedDescriptionComparator();
- private SortedSet<EvaluatedDescriptionPosNeg> set = new TreeSet<EvaluatedDescriptionPosNeg>(comp);
+ private SortedSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp);
private int maxSize;
@@ -49,10 +51,21 @@
this.maxSize = maxSize;
}
- public void add(EvaluatedDescriptionPosNeg ed) {
+ public void add(Description description, double accuracy, LearningProblem problem) {
+ if(set.size()==0 || getWorst().getAccuracy() <= accuracy) {
+ set.add(problem.evaluate(description));
+ }
+ if(set.size()>maxSize) {
+ Iterator<EvaluatedDescription> it = set.iterator();
+ it.next();
+ it.remove();
+ }
+ }
+
+ public void add(EvaluatedDescription ed) {
set.add(ed);
if(set.size()>maxSize) {
- Iterator<EvaluatedDescriptionPosNeg> it = set.iterator();
+ Iterator<EvaluatedDescription> it = set.iterator();
it.next();
it.remove();
}
@@ -68,24 +81,24 @@
return set.size();
}
- public EvaluatedDescriptionPosNeg getBest() {
+ public EvaluatedDescription getBest() {
return set.first();
}
- public EvaluatedDescriptionPosNeg getWorst() {
+ public EvaluatedDescription getWorst() {
return set.last();
}
/**
* @return the set
*/
- public SortedSet<EvaluatedDescriptionPosNeg> getSet() {
+ public SortedSet<EvaluatedDescription> getSet() {
return set;
}
public List<Description> toDescriptionList() {
List<Description> list = new LinkedList<Description>();
- for(EvaluatedDescriptionPosNeg ed : set) {
+ for(EvaluatedDescription ed : set) {
list.add(ed.getDescription());
}
return list;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-17 15:28:47
|
Revision: 1607
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1607&view=rev
Author: jenslehmann
Date: 2009-02-17 15:28:41 +0000 (Tue, 17 Feb 2009)
Log Message:
-----------
OE algorithm ctd.
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-16 17:09:30 UTC (rev 1606)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-17 15:28:41 UTC (rev 1607)
@@ -204,6 +204,7 @@
int horizExp = bestNode.getHorizontalExpansion();
// apply operator
+ System.out.println(bestNode.getDescription());
TreeSet<Description> refinements = refineNode(bestNode);
while(refinements.size() != 0) {
@@ -301,7 +302,8 @@
}
private boolean terminationCriteriaSatisfied() {
- return stop || (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()*1000000));
+// double runtimeSec = (System.nanoTime() - nanoStartTime;
+ return stop || (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()*1000000000));
}
private void reset() {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-02-16 17:09:30 UTC (rev 1606)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-02-17 15:28:41 UTC (rev 1607)
@@ -19,21 +19,47 @@
*/
package org.dllearner.algorithms.celoe;
-import java.util.Comparator;
-
/**
+ * Search algorithm heuristic for the ontology engineering algorithm. The heuristic
+ * has a strong bias towards short descriptions (i.e. the algorithm is likely to be
+ * less suitable for learning complex descriptions).
+ *
* @author Jens Lehmann
*
*/
public class OEHeuristicRuntime implements OEHeuristic {
-
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
+
+ // strong penalty for long descriptions
+ private double expansionPenaltyFactor = 0.1;
+ // bonus for being better than parent node
+ private double gainBonusFactor = 0.3;
+ // penalty if a node has very many children since exploring such a node is
+ // computationally very expensive
+ private double nodeChildPenalty = 0.0005;
+
@Override
- public int compare(OENode o1, OENode o2) {
- // TODO Auto-generated method stub
- return 0;
+ public int compare(OENode node1, OENode node2) {
+ double diff = getNodeScore(node1) - getNodeScore(node2);
+ if(diff>0)
+ return 1;
+ else if(diff<0)
+ return -1;
+ else
+ return 0;
}
+ public double getNodeScore(OENode node) {
+ // accuracy as baseline
+ double score = node.getAccuracy();
+ // being better than the parent gives a bonus;
+ if(!node.isRoot()) {
+ double parentAccuracy = node.getParent().getAccuracy();
+ score += (parentAccuracy - score) * gainBonusFactor;
+ }
+ // penalty for horizontal expansion
+ score -= node.getHorizontalExpansion() * expansionPenaltyFactor;
+ // penalty for having many child nodes (stuck prevention)
+ score -= node.getChildren().size() * nodeChildPenalty;
+ return score;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-16 17:09:30 UTC (rev 1606)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-17 15:28:41 UTC (rev 1607)
@@ -19,6 +19,7 @@
*/
package org.dllearner.algorithms.celoe;
+import java.util.LinkedList;
import java.util.List;
import org.dllearner.core.owl.Description;
@@ -47,7 +48,7 @@
private int horizontalExpansion;
private OENode parent;
- private List<OENode> children;
+ private List<OENode> children = new LinkedList<OENode>();
public OENode(OENode parentNode, Description description, double accuracy) {
this.parent = parentNode;
@@ -64,6 +65,10 @@
horizontalExpansion++;
}
+ public boolean isRoot() {
+ return (parent == null);
+ }
+
/**
* @return the description
*/
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java 2009-02-16 17:09:30 UTC (rev 1606)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java 2009-02-17 15:28:41 UTC (rev 1607)
@@ -20,13 +20,13 @@
package org.dllearner.core.configurators;
/**
- * Common options of refinement operators.
+ * Common options of refinement operators (manually created interface).
*
* @author Jens Lehmann
*
*/
public abstract class RefinementOperatorConfigurator {
+ public abstract boolean getUseCardinalityRestrictions();
-
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-16 17:09:30 UTC (rev 1606)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-17 15:28:41 UTC (rev 1607)
@@ -190,7 +190,9 @@
public RhoDRDown(ReasonerComponent reasoner, ClassHierarchy subHierarchy, RefinementOperatorConfigurator configurator) {
this.rs = reasoner;
this.subHierarchy = subHierarchy;
+ useCardinalityRestrictions = configurator.getUseCardinalityRestrictions();
// TODO add more options from configurator object
+ init();
}
// TODO constructor which takes a RhoDRDownConfigurator object;
@@ -212,9 +214,11 @@
this.useNegation = useNegation;
this.useBooleanDatatypes = useBooleanDatatypes;
this.useDoubleDatatypes = useDoubleDatatypes;
+ init();
+ }
// subHierarchy = rs.getClassHierarchy();
-
+ public void init() {
// query reasoner for domains and ranges
// (because they are used often in the operator)
for(ObjectProperty op : rs.getObjectProperties()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-18 17:13:14
|
Revision: 1613
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1613&view=rev
Author: jenslehmann
Date: 2009-02-18 17:13:11 +0000 (Wed, 18 Feb 2009)
Log Message:
-----------
continued ontology engineering algorithm
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -39,5 +39,5 @@
public EvaluatedDescriptionClass(Description description, ClassScore score) {
super(description, score);
}
-
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -142,6 +142,8 @@
// create refinement operator
operator = new RhoDRDown(reasoner, classHierarchy, configurator);
+ baseURI = reasoner.getBaseURI();
+ prefixes = reasoner.getPrefixes();
// we put important parameters in class variables
minAcc = configurator.getNoisePercentage()/100d;
@@ -194,9 +196,11 @@
int loop = 0;
while (!terminationCriteriaSatisfied()) {
+// System.out.println(startNode.toTreeString(baseURI));
+
if(bestEvaluatedDescriptions.getBest().getAccuracy() > highestAccuracy) {
highestAccuracy = bestEvaluatedDescriptions.getBest().getAccuracy();
- logger.info("more accurate (" + dfPercent.format(100*highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription()));
+ logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription()));
}
// chose best node according to heuristics
@@ -204,7 +208,6 @@
int horizExp = bestNode.getHorizontalExpansion();
// apply operator
- System.out.println(bestNode.getDescription());
TreeSet<Description> refinements = refineNode(bestNode);
while(refinements.size() != 0) {
@@ -213,7 +216,8 @@
int length = refinement.getLength();
// we ignore all refinements with lower length and too high depth
- if(length >= horizExp && refinement.getDepth() <= maxDepth) {
+ // (this also avoids duplicate node children)
+ if(length > horizExp && refinement.getDepth() <= maxDepth) {
boolean added = addNode(refinement, bestNode);
@@ -239,7 +243,8 @@
}
// print solution(s)
- logger.info("solution : " + bestDescriptionToString());
+// logger.info("solution : " + bestDescriptionToString());
+ logger.info(getSolutionString());
isRunning = false;
}
@@ -285,6 +290,7 @@
// maybe add to best descriptions (method keeps set size fixed)
if(checkNode(node)) {
bestEvaluatedDescriptions.add(description, accuracy, learningProblem);
+// System.out.println(bestEvaluatedDescriptions.toString());
}
return true;
@@ -302,8 +308,7 @@
}
private boolean terminationCriteriaSatisfied() {
-// double runtimeSec = (System.nanoTime() - nanoStartTime;
- return stop || (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()*1000000000));
+ return stop || ((System.nanoTime() - nanoStartTime) >= (configurator.getMaxExecutionTimeInSeconds()*1000000000l));
}
private void reset() {
@@ -334,8 +339,23 @@
return description.toManchesterSyntaxString(baseURI, prefixes);
}
+ @SuppressWarnings("unused")
private String bestDescriptionToString() {
EvaluatedDescription best = bestEvaluatedDescriptions.getBest();
- return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()*100) + ")";
+ return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")";
}
+
+ private String getSolutionString() {
+ int max = 10;
+ int current = 1;
+ String str = "";
+ for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) {
+ str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n";
+ current++;
+ if(current == max) {
+ break;
+ }
+ }
+ return str;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -19,9 +19,12 @@
*/
package org.dllearner.algorithms.celoe;
+import java.text.DecimalFormat;
import java.util.LinkedList;
import java.util.List;
+import org.dllearner.algorithms.refinement2.ExampleBasedNode;
+import org.dllearner.algorithms.refinement2.MultiHeuristic;
import org.dllearner.core.owl.Description;
/**
@@ -50,11 +53,13 @@
private OENode parent;
private List<OENode> children = new LinkedList<OENode>();
+ DecimalFormat dfPercent = new DecimalFormat("0.00%");
+
public OENode(OENode parentNode, Description description, double accuracy) {
this.parent = parentNode;
this.description = description;
this.accuracy = accuracy;
- horizontalExpansion = 0;
+ horizontalExpansion = description.getLength()-1;
}
public void addChild(OENode node) {
@@ -104,4 +109,32 @@
return horizontalExpansion;
}
+ public String getShortDescription(String baseURI) {
+ String ret = description.toString(baseURI,null) + " [";
+ ret += "acc:" + dfPercent.format(accuracy) + ", ";
+ ret += "he:" + horizontalExpansion + ", ";
+ ret += "c:" + children.size() + "]";
+ return ret;
+ }
+
+ public String toTreeString() {
+ return toTreeString(0, null).toString();
+ }
+
+ public String toTreeString(String baseURI) {
+ return toTreeString(0, baseURI).toString();
+ }
+
+ private StringBuilder toTreeString(int depth, String baseURI) {
+ StringBuilder treeString = new StringBuilder();
+ for(int i=0; i<depth-1; i++)
+ treeString.append(" ");
+ if(depth!=0)
+ treeString.append("|--> ");
+ treeString.append(getShortDescription(baseURI)+"\n");
+ for(OENode child : children) {
+ treeString.append(child.toTreeString(depth+1,baseURI));
+ }
+ return treeString;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -19,6 +19,8 @@
*/
package org.dllearner.core;
+import java.text.DecimalFormat;
+
import org.dllearner.core.owl.Description;
import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor;
import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
@@ -39,6 +41,8 @@
protected Description description;
protected Score score;
+ protected static DecimalFormat dfPercent = new DecimalFormat("0.00%");
+
/**
* Constructs an evaluated description using its score.
* @param description The description, which was evaluated.
@@ -124,5 +128,10 @@
return null;
}
}
+
+ @Override
+ public String toString() {
+ return description.toString() + " " + dfPercent.format(getAccuracy());
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -95,19 +95,26 @@
public ClassScore computeScore(Description description) {
Set<Individual> retrieval = reasoner.getIndividuals(description);
+// int instancesProtused = 0;
+//
+// for(Individual ind : retrieval) {
+// if(classInstances.contains(ind)) {
+// instancesCovered++;
+// } else {
+// instancesProtused++;
+// }
+// }
+
int instancesCovered = 0;
- int instancesProtused = 0;
- for(Individual ind : retrieval) {
- if(classInstances.contains(ind)) {
+ for(Individual ind : classInstances) {
+ if(retrieval.contains(ind)) {
instancesCovered++;
- } else {
- instancesProtused++;
}
}
double coverage = instancesCovered/(double)classInstances.size();
- double protusion = instancesCovered/(double)(instancesCovered + instancesProtused);
+ double protusion = instancesCovered/(double)retrieval.size();
return new ClassScore(coverage, protusion);
}
@@ -121,8 +128,19 @@
*/
@Override
public double getAccuracy(Description description) {
- // TODO Auto-generated method stub
- return 0;
+ Set<Individual> retrieval = reasoner.getIndividuals(description);
+ int instancesCovered = 0;
+
+ for(Individual ind : classInstances) {
+ if(retrieval.contains(ind)) {
+ instancesCovered++;
+ }
+ }
+
+ double coverage = instancesCovered/(double)classInstances.size();
+ double protusion = instancesCovered/(double)retrieval.size();
+
+ return 0.5d * (coverage + protusion);
}
/* (non-Javadoc)
@@ -130,8 +148,14 @@
*/
@Override
public double getAccuracyOrTooWeak(Description description, double minAccuracy) {
- // TODO Auto-generated method stub
- return 0;
+ // since we have to perform a retrieval operation anyway, we cannot easily
+ // get a benefit from the accuracy limit
+ double accuracy = getAccuracy(description);
+ if(accuracy >= minAccuracy) {
+ return accuracy;
+ } else {
+ return -1;
+ }
}
/**
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -19,10 +19,7 @@
*/
package org.dllearner.learningproblems;
-import java.util.Set;
-
import org.dllearner.core.Score;
-import org.dllearner.core.owl.Individual;
/**
* The score of a class in ontology engineering.
@@ -59,8 +56,7 @@
*/
@Override
public double getAccuracy() {
- // TODO Auto-generated method stub
- return 0;
+ return 0.5 * (coverage + protusion);
}
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -110,7 +110,7 @@
private SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>();
private SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>();
private SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>();
- private SortedSet<Individual> individuals;
+ private TreeSet<Individual> individuals;
// private ReasonerComponent rs;
private OWLAPIReasoner rc;
@@ -118,14 +118,14 @@
// we use sorted sets (map indices) here, because they have only log(n)
// complexity for checking whether an element is contained in them
// instances of classes
- private Map<NamedClass, SortedSet<Individual>> classInstancesPos = new TreeMap<NamedClass, SortedSet<Individual>>();
- private Map<NamedClass, SortedSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, SortedSet<Individual>>();
+ private Map<NamedClass, TreeSet<Individual>> classInstancesPos = new TreeMap<NamedClass, TreeSet<Individual>>();
+ private Map<NamedClass, TreeSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, TreeSet<Individual>>();
// object property mappings
private Map<ObjectProperty, Map<Individual, SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty, Map<Individual, SortedSet<Individual>>>();
// datatype property mappings
// we have one mapping for true and false for efficiency reasons
- private Map<DatatypeProperty, SortedSet<Individual>> bdPos = new TreeMap<DatatypeProperty, SortedSet<Individual>>();
- private Map<DatatypeProperty, SortedSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, SortedSet<Individual>>();
+ private Map<DatatypeProperty, TreeSet<Individual>> bdPos = new TreeMap<DatatypeProperty, TreeSet<Individual>>();
+ private Map<DatatypeProperty, TreeSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, TreeSet<Individual>>();
// for int and double we assume that a property can have several values,
// althoug this should be rare,
// e.g. hasValue(object,2) and hasValue(object,3)
@@ -200,7 +200,7 @@
doubleDatatypeProperties = rc.getDoubleDatatypeProperties();
intDatatypeProperties = rc.getIntDatatypeProperties();
atomicRoles = rc.getObjectProperties();
- individuals = rc.getIndividuals();
+ individuals = (TreeSet<Individual>) rc.getIndividuals();
// rs = new ReasonerComponent(rc);
@@ -215,10 +215,10 @@
for (NamedClass atomicConcept : rc.getNamedClasses()) {
SortedSet<Individual> pos = rc.getIndividuals(atomicConcept);
- classInstancesPos.put(atomicConcept, pos);
+ classInstancesPos.put(atomicConcept, (TreeSet<Individual>) pos);
if (configurator.getDefaultNegation()) {
- classInstancesNeg.put(atomicConcept, Helper.difference(individuals, pos));
+ classInstancesNeg.put(atomicConcept, (TreeSet<Individual>) Helper.difference(individuals, pos));
} else {
// Pellet needs approximately infinite time to answer
// negated queries
@@ -226,7 +226,7 @@
// we have to
// be careful here
Negation negatedAtomicConcept = new Negation(atomicConcept);
- classInstancesNeg.put(atomicConcept, rc.getIndividuals(negatedAtomicConcept));
+ classInstancesNeg.put(atomicConcept, (TreeSet<Individual>) rc.getIndividuals(negatedAtomicConcept));
}
}
@@ -240,8 +240,8 @@
logger.debug("dematerialising datatype properties");
for (DatatypeProperty dp : booleanDatatypeProperties) {
- bdPos.put(dp, rc.getTrueDatatypeMembers(dp));
- bdNeg.put(dp, rc.getFalseDatatypeMembers(dp));
+ bdPos.put(dp, (TreeSet<Individual>) rc.getTrueDatatypeMembers(dp));
+ bdNeg.put(dp, (TreeSet<Individual>) rc.getFalseDatatypeMembers(dp));
}
for (DatatypeProperty dp : intDatatypeProperties) {
@@ -495,16 +495,17 @@
}
@Override
+ @SuppressWarnings("unchecked")
public SortedSet<Individual> getIndividualsImpl(Description description)
throws ReasoningMethodUnsupportedException {
// policy: returned sets are clones, i.e. can be modified
// (of course we only have to clone the leafs of a class description tree)
if (description instanceof NamedClass) {
- return new TreeSet<Individual>(classInstancesPos.get((NamedClass) description));
+ return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone();
} else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) {
- return new TreeSet<Individual>(classInstancesNeg.get((NamedClass) description.getChild(0)));
+ return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone();
} else if (description instanceof Thing) {
- return new TreeSet<Individual>(individuals);
+ return (TreeSet<Individual>) individuals.clone();
} else if (description instanceof Nothing) {
return new TreeSet<Individual>();
} else if (description instanceof Union) {
@@ -535,7 +536,7 @@
ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole();
if (!(ope instanceof ObjectProperty)) {
- throw new ReasoningMethodUnsupportedException("Instance check for description "
+ throw new ReasoningMethodUnsupportedException("Retrieval for description "
+ description + " unsupported. Inverse object properties not supported.");
}
ObjectProperty op = (ObjectProperty) ope;
@@ -553,6 +554,7 @@
}
}
}
+ return returnSet;
} else if (description instanceof ObjectAllRestriction) {
// \forall restrictions are difficult to handle; assume we want to check
// \forall hasChild.male with domain(hasChild)=Person; then for all non-persons
@@ -587,6 +589,138 @@
}
}
}
+ return returnSet;
+ } else if (description instanceof ObjectMinCardinalityRestriction) {
+ ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole();
+ if (!(ope instanceof ObjectProperty)) {
+ throw new ReasoningMethodUnsupportedException("Instance check for description "
+ + description + " unsupported. Inverse object properties not supported.");
+ }
+ ObjectProperty op = (ObjectProperty) ope;
+ Description child = description.getChild(0);
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+ SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0));
+ SortedSet<Individual> returnSet = new TreeSet<Individual>();
+
+ int number = ((ObjectCardinalityRestriction) description).getNumber();
+
+ for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) {
+ int nrOfFillers = 0;
+ int index = 0;
+ SortedSet<Individual> inds = entry.getValue();
+
+ // we do not need to run tests if there are not sufficiently many fillers
+ if(inds.size() < number) {
+ continue;
+ }
+
+ for(Individual ind : inds) {
+ // stop inner loop when nr of fillers is reached
+ if(nrOfFillers >= number) {
+ returnSet.add(entry.getKey());
+ break;
+ }
+ // early abort when too many instance checks failed
+ if (inds.size() - index < number) {
+ break;
+ }
+ if(targetSet.contains(ind)) {
+ nrOfFillers++;
+ }
+ index++;
+ }
+ }
+
+ return returnSet;
+ } else if (description instanceof ObjectMaxCardinalityRestriction) {
+ ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole();
+ if (!(ope instanceof ObjectProperty)) {
+ throw new ReasoningMethodUnsupportedException("Instance check for description "
+ + description + " unsupported. Inverse object properties not supported.");
+ }
+ ObjectProperty op = (ObjectProperty) ope;
+ Description child = description.getChild(0);
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+ SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0));
+ // initially all individuals are in the return set and we then remove those
+ // with too many fillers
+ SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone();
+
+ int number = ((ObjectCardinalityRestriction) description).getNumber();
+
+ for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) {
+ int nrOfFillers = 0;
+ int index = 0;
+ SortedSet<Individual> inds = entry.getValue();
+
+ // we do not need to run tests if there are not sufficiently many fillers
+ if(number < inds.size()) {
+ returnSet.add(entry.getKey());
+ continue;
+ }
+
+ for(Individual ind : inds) {
+ // stop inner loop when nr of fillers is reached
+ if(nrOfFillers >= number) {
+ break;
+ }
+ // early abort when too many instance are true already
+ if (inds.size() - index < number) {
+ returnSet.add(entry.getKey());
+ break;
+ }
+ if(targetSet.contains(ind)) {
+ nrOfFillers++;
+ }
+ index++;
+ }
+ }
+
+ return returnSet;
+ } else if (description instanceof ObjectValueRestriction) {
+ Individual i = ((ObjectValueRestriction)description).getIndividual();
+ ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression();
+
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+ SortedSet<Individual> returnSet = new TreeSet<Individual>();
+
+ for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) {
+ if(entry.getValue().contains(i)) {
+ returnSet.add(entry.getKey());
+ }
+ }
+ return returnSet;
+ } else if (description instanceof BooleanValueRestriction) {
+ DatatypeProperty dp = ((BooleanValueRestriction) description)
+ .getRestrictedPropertyExpresssion();
+ boolean value = ((BooleanValueRestriction) description).getBooleanValue();
+
+ if (value) {
+ return (TreeSet<Individual>) bdPos.get(dp).clone();
+ } else {
+ return (TreeSet<Individual>) bdNeg.get(dp).clone();
+ }
+ } else if (description instanceof DatatypeSomeRestriction) {
+ DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description;
+ DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression();
+ DataRange dr = dsr.getDataRange();
+
+ Map<Individual, SortedSet<Double>> mapping = dd.get(dp);
+ SortedSet<Individual> returnSet = new TreeSet<Individual>();
+
+ if (dr instanceof DoubleMaxValue) {
+ for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) {
+ if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) {
+ returnSet.add(entry.getKey());
+ }
+ }
+ } else if (dr instanceof DoubleMinValue) {
+ for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) {
+ if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) {
+ returnSet.add(entry.getKey());
+ }
+ }
+ }
}
throw new ReasoningMethodUnsupportedException("Retrieval for description "
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -341,6 +341,10 @@
@Override
public Set<Description> refine(Description description, int maxLength) {
+ // check that maxLength is valid
+ if(maxLength < description.getLength()) {
+ throw new Error("length has to be at least description length (description: " + description + ", max length: " + maxLength + ")");
+ }
return refine(description, maxLength, null, startClass);
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -43,16 +43,16 @@
double acc1 = ed1.getAccuracy();
double acc2 = ed2.getAccuracy();
if(acc1 > acc2)
+ return 1;
+ else if(acc1 < acc2)
return -1;
- else if(acc1 < acc2)
- return 1;
else {
int length1 = ed1.getDescriptionLength();
int length2 = ed2.getDescriptionLength();
if(length1 < length2)
+ return 1;
+ else if(length1 > length2)
return -1;
- else if(length1 > length2)
- return 1;
else
return cc.compare(ed1.getDescription(), ed2.getDescription());
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-18 13:09:16 UTC (rev 1612)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-18 17:13:11 UTC (rev 1613)
@@ -43,7 +43,7 @@
private EvaluatedDescriptionComparator comp = new EvaluatedDescriptionComparator();
- private SortedSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp);
+ private TreeSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp);
private int maxSize;
@@ -56,6 +56,7 @@
set.add(problem.evaluate(description));
}
if(set.size()>maxSize) {
+ // delete the worst element
Iterator<EvaluatedDescription> it = set.iterator();
it.next();
it.remove();
@@ -82,17 +83,17 @@
}
public EvaluatedDescription getBest() {
- return set.first();
+ return set.last();
}
public EvaluatedDescription getWorst() {
- return set.last();
+ return set.first();
}
/**
* @return the set
*/
- public SortedSet<EvaluatedDescription> getSet() {
+ public TreeSet<EvaluatedDescription> getSet() {
return set;
}
@@ -103,4 +104,9 @@
}
return list;
}
+
+ @Override
+ public String toString() {
+ return set.toString();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-19 13:21:16
|
Revision: 1615
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1615&view=rev
Author: jenslehmann
Date: 2009-02-19 12:08:55 +0000 (Thu, 19 Feb 2009)
Log Message:
-----------
fast retrieval ctd.
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-19 10:07:39 UTC (rev 1614)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-19 12:08:55 UTC (rev 1615)
@@ -123,7 +123,7 @@
options.add(CommonConfigOptions.useNegation());
options.add(CommonConfigOptions.useBooleanDatatypes());
options.add(CommonConfigOptions.useDoubleDatatypes());
- options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10));
+ options.add(CommonConfigOptions.maxExecutionTimeInSeconds(1));
options.add(CommonConfigOptions.getNoisePercentage());
options.add(CommonConfigOptions.getMaxDepth(4));
return options;
@@ -187,7 +187,12 @@
Description startClass;
if(isEquivalenceProblem) {
Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe);
- startClass = new Intersection(new LinkedList<Description>(superClasses));
+ if(superClasses.size() > 1) {
+ startClass = new Intersection(new LinkedList<Description>(superClasses));
+ } else {
+ startClass = (Description) superClasses.toArray()[0];
+ }
+
} else {
startClass = Thing.instance;
}
@@ -246,6 +251,8 @@
// logger.info("solution : " + bestDescriptionToString());
logger.info(getSolutionString());
+// System.out.println(startNode.toTreeString(baseURI));
+
isRunning = false;
}
@@ -270,6 +277,11 @@
return false;
}
+ // check whether the description is allowed
+ if(!isDescriptionAllowed(description)) {
+ return false;
+ }
+
// quality of description (return if too weak)
double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc);
if(accuracy == -1) {
@@ -296,6 +308,29 @@
return true;
}
+ // checks whether the description is allowed
+ private boolean isDescriptionAllowed(Description description) {
+ if(isEquivalenceProblem) {
+ // for equivalence problems, we need to check that the class we are learning does
+ // not itself occur on the outermost level (property depth 0)
+ if(description instanceof NamedClass) {
+ if(description.equals(classToDescribe)) {
+ return false;
+ }
+ } else if(description.getChildren().size() > 1) {
+ for(Description child : description.getChildren()) {
+ if(child.equals(classToDescribe)) {
+ return false;
+ }
+ }
+ }
+ } else {
+
+ }
+
+ return true;
+ }
+
// check whether the node is a potential solution candidate
// (sufficient accuracy; minimal; rewriting steps?)
private boolean checkNode(OENode node) {
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-19 10:07:39 UTC (rev 1614)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-19 12:08:55 UTC (rev 1615)
@@ -157,7 +157,7 @@
"This option controls how to interpret the all quantifier in \forall r.C. The standard option is" +
"to return all those which do not have an r-filler not in C. The domain semantics is to use those" +
"which are in the domain of r and do not have an r-filler not in C. The forallExists semantics is to" +
- "use those which have at least one r-filler and do not have an r-filler not in C.", "forallExists");
+ "use those which have at least one r-filler and do not have an r-filler not in C.", "standard");
forallSemantics.setAllowedValues(new String[] { "standard", "domain", "forallExists" });
// closure option? see:
// http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup
@@ -548,7 +548,7 @@
SortedSet<Individual> inds = entry.getValue();
for(Individual ind : inds) {
if(targetSet.contains(ind)) {
- returnSet.add(ind);
+ returnSet.add(entry.getKey());
// once we found an individual, we do not need to check the others
continue;
}
@@ -559,7 +559,7 @@
// \forall restrictions are difficult to handle; assume we want to check
// \forall hasChild.male with domain(hasChild)=Person; then for all non-persons
// this is satisfied trivially (all of their non-existing children are male)
- if(!configurator.getForallRetrievalSemantics().equals("forallExists")) {
+ if(!configurator.getForallRetrievalSemantics().equals("standard")) {
throw new Error("Only forallExists semantics currently implemented.");
}
@@ -576,7 +576,8 @@
}
ObjectProperty op = (ObjectProperty) ope;
Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
- SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet());
+// SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet());
+ SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone();
// each individual is connected to a set of individuals via the property;
// we loop through the complete mapping
@@ -584,7 +585,7 @@
SortedSet<Individual> inds = entry.getValue();
for(Individual ind : inds) {
if(!targetSet.contains(ind)) {
- returnSet.remove(ind);
+ returnSet.remove(entry.getKey());
continue;
}
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-19 10:07:39 UTC (rev 1614)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-19 12:08:55 UTC (rev 1615)
@@ -327,8 +327,8 @@
System.exit(0);
*/
- if(startClass != null)
- this.startClass = startClass;
+// if(startClass != null)
+// this.startClass = startClass;
}
/* (non-Javadoc)
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-02-19 10:07:39 UTC (rev 1614)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-02-19 12:08:55 UTC (rev 1615)
@@ -25,6 +25,7 @@
import java.net.MalformedURLException;
import java.util.LinkedList;
import java.util.List;
+import java.util.SortedSet;
import org.apache.log4j.Logger;
import org.dllearner.core.ComponentInitException;
@@ -158,9 +159,9 @@
}
}
- @Test
+// @Test
public void fastInstanceCheck2() throws ComponentInitException, ParseException {
- String file = "examples/epc/conf/sap_modell_komplett_2.owl";
+ String file = "examples/epc/sap_epc.owl";
ComponentManager cm = ComponentManager.getInstance();
KnowledgeSource ks = cm.knowledgeSource(OWLFile.class);
try {
@@ -180,6 +181,33 @@
System.out.println(result);
}
+ // simple unit test for new retrieval algorithm
+ @Test
+ public void fastInstanceCheck3() throws MalformedURLException, ComponentInitException, ParseException {
+ String file = "examples/family/father_oe.owl";
+ ComponentManager cm = ComponentManager.getInstance();
+ KnowledgeSource ks = cm.knowledgeSource(OWLFile.class);
+ cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL());
+ ks.init();
+ ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks);
+ reasoner.init();
+ baseURI = reasoner.getBaseURI();
+ Description description = KBParser.parseConcept("(\"http://example.com/father#male\" AND EXISTS \"http://example.com/father#hasChild\".TOP)");
+// Description description = KBParser.parseConcept("EXISTS \"http://example.com/father#hasChild\".TOP");
+ SortedSet<Individual> result = reasoner.getIndividuals(description);
+ assertTrue(result.size()==3);
+ assertTrue(result.contains(new Individual("http://example.com/father#markus")));
+ assertTrue(result.contains(new Individual("http://example.com/father#martin")));
+ assertTrue(result.contains(new Individual("http://example.com/father#stefan")));
+// System.out.println(result);
+
+ Description description2 = KBParser.parseConcept("(\"http://example.com/father#male\" AND ALL \"http://example.com/father#hasChild\".\"http://example.com/father#father\")");
+ SortedSet<Individual> result2 = reasoner.getIndividuals(description2);
+ assertTrue(result2.size()==2);
+ assertTrue(result2.contains(new Individual("http://example.com/father#heinz")));
+ assertTrue(result2.contains(new Individual("http://example.com/father#stefan")));
+ }
+
private List<Individual> getIndSet(String... inds) {
List<Individual> individuals = new LinkedList<Individual>();
for(String ind : inds) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-20 10:56:08
|
Revision: 1619
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1619&view=rev
Author: jenslehmann
Date: 2009-02-20 10:56:04 +0000 (Fri, 20 Feb 2009)
Log Message:
-----------
- wrote a class which uses reasoning to minimize a given class description
- reasoning results are cached to improve performance over time for many minimize operations
- implementation passes simple unit test
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/owl/Description.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/junit/MinimizeTests.java
trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
Modified: trunk/src/dl-learner/org/dllearner/core/owl/Description.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2009-02-19 15:25:44 UTC (rev 1618)
+++ trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2009-02-20 10:56:04 UTC (rev 1619)
@@ -160,6 +160,11 @@
children.remove(child);
}
+ public void replaceChild(int index, Description newChild) {
+ children.remove(index);
+ children.add(index, newChild);
+ }
+
/**
* Tests whether this description is at the root, i.e.
* does not have a parent.
Added: trunk/src/dl-learner/org/dllearner/test/junit/MinimizeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/MinimizeTests.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/junit/MinimizeTests.java 2009-02-20 10:56:04 UTC (rev 1619)
@@ -0,0 +1,46 @@
+/**
+ * Copyright (C) 2007-2009, 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.test.junit;
+
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.owl.Description;
+import org.dllearner.parser.KBParser;
+import org.dllearner.parser.ParseException;
+import org.dllearner.test.junit.TestOntologies.TestOntology;
+import org.dllearner.utilities.owl.DescriptionMinimizer;
+import org.junit.Test;
+
+/**
+ * Tests for minimizing class descriptions.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class MinimizeTests {
+
+ @Test
+ public void minimizeTest1() throws ParseException {
+ ReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.FATHER_OE);
+ DescriptionMinimizer minimizer = new DescriptionMinimizer(reasoner);
+ Description d = KBParser.parseConcept("(\"http://example.com/father#male\" AND (\"http://example.com/father#male\" OR EXISTS \"http://example.com/father#hasChild\".TOP))");
+ Description minD = minimizer.minimize(d);
+ assert(minD.toString().equals("http://example.com/father#male"));
+ }
+}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-02-19 15:25:44 UTC (rev 1618)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-02-20 10:56:04 UTC (rev 1619)
@@ -19,11 +19,16 @@
*/
package org.dllearner.test.junit;
+import java.io.File;
+import java.net.MalformedURLException;
+
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.ComponentManager;
+import org.dllearner.core.KnowledgeSource;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.KB;
import org.dllearner.kb.KBFile;
+import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
import org.dllearner.reasoning.FastInstanceChecker;
@@ -36,10 +41,11 @@
*/
public final class TestOntologies {
- public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES };
+ public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES, FATHER_OE };
public static ReasonerComponent getTestOntology(TestOntology ont) {
String kbString = "";
+ String owlFile = "";
if(ont.equals(TestOntology.EMPTY)) {
// no background knowledge
@@ -103,22 +109,31 @@
kbString += "r3(a,b).\n";
kbString += "r4(a,b).\n";
kbString += "r5(a,b).\n";
+ } else if(ont.equals(TestOntology.FATHER_OE)) {
+ owlFile = "examples/family/father_oe.owl";
}
try {
- KB kb = KBParser.parseKBFile(kbString);
+ ComponentManager cm = ComponentManager.getInstance();
+ KnowledgeSource source;
- // create reasoner
- ComponentManager cm = ComponentManager.getInstance();
- KBFile source = new KBFile(kb);
+ // parse KB string if one has been specified
+ if(!kbString.isEmpty()) {
+ KB kb = KBParser.parseKBFile(kbString);
+ source = new KBFile(kb);
+ // parse OWL file otherwise
+ } else {
+ source = cm.knowledgeSource(OWLFile.class);
+ try {
+ cm.applyConfigEntry(source, "url", new File(owlFile).toURI().toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source);
-// ReasonerComponent rs = cm.reasoningService(rc);
source.init();
rc.init();
- // TODO there shouldn't be a need to call this explicitly!
- // (otherwise we get a NullPointerException, because the hierarchy is not created)
-// rs.prepareSubsumptionHierarchy();
-// rs.prepareRoleHierarchy();
return rc;
} catch(ParseException e) {
e.printStackTrace();
Added: trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java 2009-02-20 10:56:04 UTC (rev 1619)
@@ -0,0 +1,207 @@
+/**
+ * Copyright (C) 2007-2009, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.utilities.owl;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.Negation;
+import org.dllearner.core.owl.Nothing;
+import org.dllearner.core.owl.ObjectAllRestriction;
+import org.dllearner.core.owl.ObjectMaxCardinalityRestriction;
+import org.dllearner.core.owl.ObjectMinCardinalityRestriction;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.core.owl.Thing;
+import org.dllearner.core.owl.Union;
+
+/**
+ * Rewrites a description to an equivalent shorter description. Note that
+ * minimizing is not a trivial operation and requires reasoning. The class
+ * keeps an internal cache on reasoning results, i.e. if similar descriptions
+ * are passed to the minimizer, then its performance will improve over time.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class DescriptionMinimizer {
+
+ private ReasonerComponent reasoner;
+ private ConceptComparator conceptComparator = new ConceptComparator();
+ private Map<Description,Map<Description,Boolean>> cachedSubclassOf = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator);
+
+ public DescriptionMinimizer(ReasonerComponent reasoner) {
+ this.reasoner = reasoner;
+ }
+
+ /**
+ * Method which minimzes the input description. The algorithm does not
+ * replace subdescriptions with named classes, e.g.
+ * if the description "male \sqcap \exists hasChild.\top" is passed to the
+ * algorithm and a class "father" is defined in the obvious way
+ * in the background knowledge, then
+ * it will intentionally not return father. Instead, it preserves the
+ * existing structure of the description, but tries to detect and delete
+ * redundant parts within it. For instance, the description "male \sqcap
+ * father" is minimized to "father".
+ *
+ * @param description The description to minimize.
+ * @return Minimized description.
+ */
+ public Description minimizeClone(Description description) {
+ Description descriptionToMinimize = description.clone();
+ return minimize(descriptionToMinimize);
+ }
+
+ /**
+ * Same as {@link #minimizeClone(Description)}, but with no guarantee that
+ * the input description remains unmodified.
+ * @see #minimizeClone(Description)
+ * @param description The description to minimize.
+ * @return Minimized description.
+ */
+ public Description minimize(Description description) {
+ // minimize all children of the description
+ List<Description> children = description.getChildren();
+ for(int i=0; i<children.size(); i++) {
+ description.replaceChild(i, minimize(children.get(i)));
+ }
+ // make a case distinction based on the structure of the description
+ // (note that we do not have to do anything for a number of cases:
+ // a named class, Thing, Nothing, hasValue restrictions, boolean
+ // value restrictions, double value restrictions)
+ if(children.size()==0) {
+ return description;
+ } else if(description instanceof ObjectSomeRestriction) {
+ // \exists r.\bot \equiv \bot
+ if(description.getChild(0) instanceof Nothing) {
+ return Nothing.instance;
+ }
+ return description;
+ } else if(description instanceof ObjectAllRestriction) {
+ // \forall r.\top \equiv \top
+ if(description.getChild(0) instanceof Thing) {
+ return Thing.instance;
+ }
+ return description;
+ } else if(description instanceof Negation) {
+ // \neg \bot \equiv \top
+ if(description.getChild(0) instanceof Nothing) {
+ return Thing.instance;
+ // \neg \top \equiv \bot
+ } else if(description.getChild(0) instanceof Thing) {
+ return Nothing.instance;
+ }
+ return description;
+ } else if(description instanceof ObjectMaxCardinalityRestriction) {
+ // <= n r.\bot \equiv \top
+ if(description.getChild(0) instanceof Nothing) {
+ return Thing.instance;
+ }
+ return description;
+ } else if(description instanceof ObjectMinCardinalityRestriction) {
+ // >= 0 r.C \equiv \top
+ int number = ((ObjectMinCardinalityRestriction)description).getNumber();
+ if(number == 0) {
+ return Thing.instance;
+ }
+ // >= n r.\bot \equiv \bot if n != 0
+ if(description.getChild(0) instanceof Nothing) {
+ return Nothing.instance;
+ }
+ return description;
+ } else if(description instanceof Intersection || description instanceof Union) {
+ List<Integer> toRemove = new LinkedList<Integer>();
+ // intersection
+ if(description instanceof Intersection) {
+ // in an intersection, we have that D1 \sqcap D2 \equiv D1 if
+ // D1 \sqsubseteq D2; this means we first check whether the
+ // first element in a union is superclass of any other element in the
+ // union; if yes, then we delete it and proceed to the next element
+ for(int i=0; i<children.size(); i++) {
+ for(int j=0; j<children.size(); j++) {
+ if(i != j && isSubclassOf(children.get(j), children.get(i))) {
+ toRemove.add(i-toRemove.size());
+ break;
+ }
+ }
+ }
+ // union
+ } else {
+ // in a union, we have that D1 \sqcup D2 \equiv D2 if
+ // D1 \sqsubseteq D2; this means we first check whether the
+ // first element in a union is subclass of any other element in the
+ // union; if yes, then we delete it and proceed to the next element
+ // (note the difference to intersection)
+ for(int i=0; i<children.size(); i++) {
+ for(int j=0; j<children.size(); j++) {
+ if(i != j && isSubclassOf(children.get(i), children.get(j))) {
+ toRemove.add(i-toRemove.size());
+ break;
+ }
+ }
+ }
+ }
+ // if all elements are superfluous wrt. another element, then we need
+ // to keep at least one
+ if(toRemove.size() == children.size()) {
+ return children.get(0);
+ } else {
+ // remove all elements according to remove list
+ for(int pos : toRemove) {
+ children.remove(pos);
+ }
+ // dissolve intersection with only one element
+ if(children.size()==1) {
+ return children.get(0);
+ }
+ return description;
+ }
+ } else {
+ throw new Error("Cannot minimize description " + description + ".");
+ }
+ }
+
+ private boolean isSubclassOf(Description d1, Description d2) {
+ // check whether we have cached this query
+ Map<Description,Boolean> tmp = cachedSubclassOf.get(d1);
+ Boolean tmp2 = null;
+ if(tmp != null)
+ tmp2 = tmp.get(d2);
+
+ if(tmp2==null) {
+ Boolean result = reasoner.isSuperClassOf(d2, d1);
+
+ // create new entry if necessary
+ Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator);
+ if(tmp == null)
+ cachedSubclassOf.put(d1, map1);
+
+ cachedSubclassOf.get(d1).put(d2, result);
+ return result;
+ } else {
+ return tmp2;
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-25 16:26:19
|
Revision: 1631
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1631&view=rev
Author: jenslehmann
Date: 2009-02-25 16:26:08 +0000 (Wed, 25 Feb 2009)
Log Message:
-----------
- wrote a method which detects whether a description can be transformed to another one by removing parts of it
- CELOE is guaranteed not to return descriptions with the same accuracy where one can be transformed to the other
- CELOE does not extend correct nodes further than description length
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java
trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java
trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -21,6 +21,7 @@
import java.text.DecimalFormat;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -133,7 +134,8 @@
options.add(CommonConfigOptions.valueFreqencyThreshold());
options.add(CommonConfigOptions.useCardinalityRestrictions());
options.add(CommonConfigOptions.cardinalityLimit());
- options.add(CommonConfigOptions.useNegation());
+ // by default, we do not use negation (should be configurable in GUI)
+ options.add(CommonConfigOptions.useNegation(false));
options.add(CommonConfigOptions.useBooleanDatatypes());
options.add(CommonConfigOptions.useDoubleDatatypes());
options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10));
@@ -227,7 +229,7 @@
// highest accuracy so far
double highestAccuracy = 0.0;
- OENode bestNode;
+ OENode nextNode;
addNode(startClass, null);
@@ -242,12 +244,12 @@
}
// chose best node according to heuristics
- bestNode = nodes.last();
- int horizExp = bestNode.getHorizontalExpansion();
+ nextNode = getNextNodeToExpand();
+ int horizExp = nextNode.getHorizontalExpansion();
// apply operator
Monitor mon = MonitorFactory.start("refineNode");
- TreeSet<Description> refinements = refineNode(bestNode);
+ TreeSet<Description> refinements = refineNode(nextNode);
mon.stop();
while(refinements.size() != 0) {
@@ -260,7 +262,7 @@
if(length > horizExp && refinement.getDepth() <= maxDepth) {
Monitor mon2 = MonitorFactory.start("addNode");
- boolean added = addNode(refinement, bestNode);
+ boolean added = addNode(refinement, nextNode);
mon2.stop();
// if refinements have the same length, we apply the operator again
@@ -293,6 +295,23 @@
isRunning = false;
}
+ private OENode getNextNodeToExpand() {
+ // we expand the best node of those, which have not achieved 100% accuracy
+ // already and have a horizontal expansion equalling their length
+ // (rationale: further extension is likely to add irrelevant syntactical constructs)
+ Iterator<OENode> it = nodes.descendingIterator();
+ while(it.hasNext()) {
+ OENode node = it.next();
+ if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) {
+ return node;
+ }
+ }
+
+ // this should practically never be called, since for any reasonable learning
+ // task, we will always have at least one node with less than 100% accuracy
+ return nodes.last();
+ }
+
// expand node horizontically
private TreeSet<Description> refineNode(OENode node) {
// we have to remove and add the node since its heuristic evaluation changes through the expansion
@@ -356,7 +375,21 @@
if(isCandidate) {
Description niceDescription = rewriteNode(node);
- bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem);
+
+ // another test: none of the other suggested descriptions should be
+ // a subdescription of this one unless accuracy is different
+ boolean shorterDescriptionExists = false;
+ for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet()) {
+ if(ed.getAccuracy()==accuracy && ConceptTransformation.isSubdescription(niceDescription, ed.getDescription())) {
+ shorterDescriptionExists = true;
+ break;
+ }
+ }
+
+ if(!shorterDescriptionExists) {
+ bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem);
+ }
+
}
return true;
@@ -379,8 +412,14 @@
}
toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d));
}
- return true;
}
+
+ // we do not want to have negations of sibling classes on the outermost level
+ // (they are expressed more naturally by saying that the siblings are disjoint,
+ // so it is reasonable not to include them in solutions)
+ Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe);
+
+ return true;
}
// determine whether a named class occurs on the outermost level, i.e. property depth 0
@@ -405,10 +444,29 @@
return false;
}
+ private boolean occursNegatedOnFirstLevel(Description description, Description clazz) {
+ if(description instanceof NamedClass) {
+ if(description.equals(clazz)) {
+ return true;
+ }
+ }
+
+ if(description instanceof Restriction) {
+ return false;
+ }
+
+ for(Description child : description.getChildren()) {
+ if(occursOnFirstLevel(child, clazz)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
// check whether the node is a potential solution candidate
private Description rewriteNode(OENode node) {
Description description = node.getDescription();
-// Description niceDescription = description;
// minimize description (expensive!)
Description niceDescription = minimizer.minimizeClone(description);
// replace \exists r.\top with \exists r.range(r) which is easier to read for humans
@@ -423,7 +481,6 @@
private void reset() {
// set all values back to their default values (used for running
// the algorithm more than once)
-// candidates.clear();
nodes = new TreeSet<OENode>(new OEHeuristicRuntime());
descriptions = new TreeSet<Description>(new ConceptComparator());
bestEvaluatedDescriptions.getSet().clear();
@@ -456,15 +513,11 @@
}
private String getSolutionString() {
-// int max = 10;
int current = 1;
String str = "";
for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) {
str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n";
current++;
-// if(current == max) {
-// break;
-// }
}
return str;
}
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/RefinementOperatorConfigurator.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -23,10 +23,35 @@
* Common options of refinement operators (manually created interface).
*
* @author Jens Lehmann
- *
+ *
*/
public abstract class RefinementOperatorConfigurator {
public abstract boolean getUseCardinalityRestrictions();
+
+ public abstract boolean getUseNegation();
+
+ public abstract boolean getUseAllConstructor();
+
+ public abstract boolean getUseExistsConstructor();
+
+ public abstract boolean getUseBooleanDatatypes();
+ // below are optional parameters (neutral return values choosen)
+
+ public boolean getUseHasValueConstructor() {
+ return false;
+ }
+
+ public int getValueFrequencyThreshold() {
+ return 3;
+ }
+
+ public int getCardinalityLimit() {
+ return 5;
+ }
+
+ public boolean getUseDoubleDatatypes() {
+ return false;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -147,6 +147,10 @@
return new BooleanConfigOption("useNegation", "specifies whether negation is used in the learning algorothm",useNegationDefault);
}
+ public static BooleanConfigOption useNegation(boolean defaultValue) {
+ return new BooleanConfigOption("useNegation", "specifies whether negation is used in the learning algorothm",defaultValue);
+ }
+
public static BooleanConfigOption useBooleanDatatypes() {
return new BooleanConfigOption("useBooleanDatatypes", "specifies whether boolean datatypes are used in the learning algorothm",useBooleanDatatypesDefault);
}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -89,6 +89,25 @@
}
/**
+ * Computes the siblings of the specified descriptions. Siblings are all those
+ * classes, which are subclasses of a parent of a class and not equal to the
+ * class itself. Note that retrieving siblings is computationally more
+ * expensive than descending/ascending the hierarchy as siblings are computed
+ * when required and not cached.
+ * @param description A named class.
+ * @return A set of named classes, which are siblings of the given class.
+ */
+ public SortedSet<Description> getSiblingClasses(Description description) {
+ Set<Description> superClasses = subsumptionHierarchyUp.get(description);
+ TreeSet<Description> siblingClasses = new TreeSet<Description>(conceptComparator);
+ for(Description superClass : superClasses) {
+ siblingClasses.addAll(subsumptionHierarchyDown.get(superClass));
+ }
+ siblingClasses.remove(description);
+ return siblingClasses;
+ }
+
+ /**
* This method modifies the subsumption hierarchy such that for each class,
* there is only a single path to reach it via upward and downward
* refinement respectively.
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -857,7 +857,7 @@
// Negation neg = new Negation(subConcept);
// Intersection c = new Intersection(neg,superConcept);
// return fastRetrieval.calculateSets(c).getPosSet().isEmpty();
- return rc.isSuperClassOf(superConcept, subConcept);
+ return rc.isSuperClassOfImpl(superConcept, subConcept);
}
/**
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -191,8 +191,15 @@
this.rs = reasoner;
this.subHierarchy = subHierarchy;
this.startClass = startClass;
+ useAllConstructor = configurator.getUseAllConstructor();
+ useExistsConstructor = configurator.getUseExistsConstructor();
+ useHasValueConstructor = configurator.getUseHasValueConstructor();
+ frequencyThreshold = configurator.getValueFrequencyThreshold();
useCardinalityRestrictions = configurator.getUseCardinalityRestrictions();
- // TODO add more options from configurator object
+ cardinalityLimit = configurator.getCardinalityLimit();
+ useNegation = configurator.getUseNegation();
+ useBooleanDatatypes = configurator.getUseBooleanDatatypes();
+ useDoubleDatatypes = configurator.getUseDoubleDatatypes();
init();
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -59,6 +59,8 @@
public static long shorteningTimeNs = 0;
private static long shorteningTimeNsStart = 0;
+ private static ConceptComparator descComp = new ConceptComparator();
+
public static void cleanConceptNonRecursive(Description concept) {
// cleaningTimeNsStart = System.nanoTime();
@@ -487,4 +489,85 @@
}
}
+ /**
+ * Tests whether a description is a subdescription in the sense that when
+ * parts of <code>description</code> can be removed to yield <code>subdescription</code>.
+ *
+ * @param description A description.
+ * @param subDescription A potential subdescription.
+ * @return True if <code>subdescription</code> is indeed a sub description and false
+ * otherwise.
+ */
+ public static boolean isSubdescription(Description description, Description subDescription) {
+// if(description instanceof Thing) {
+// return (subDescription instanceof Thing);
+// } else if(description instanceof Nothing) {
+// return (subDescription instanceof Thing);
+// } else if(description instanceof NamedClass) {
+// return ((subDescription instanceof NamedClass) && (((NamedClass)description).getName().equals(((NamedClass)subDescription).getName())));
+// }
+
+ List<Description> children = description.getChildren();
+ List<Description> subChildren = subDescription.getChildren();
+
+ // no children: both have to be equal
+ if(children.size()==0) {
+ return (descComp.compare(description, subDescription)==0);
+ // one child: both have to be of the same class, type, and the first
+ // child has to be sub description of the other child
+ } else if(children.size()==1) {
+ return (subChildren.size() == 1) && description.getClass().equals(subDescription.getClass()) && isSubdescription(children.get(0), subChildren.get(0));
+ // intersection or union
+ } else {
+ // test whether subdescription corresponds to an element of the
+ // intersection/union
+ if(subChildren.size()<2) {
+ for(Description child : children) {
+ if(isSubdescription(child, subDescription)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // make sure that both are of the same type and subdescription actually has fewer children
+ if(!description.getClass().equals(subDescription.getClass()) || subChildren.size() > children.size()) {
+ return false;
+ }
+
+ // comparing everything is quadratic; the faster linear variant (below)
+ // using
+
+ for(Description subChild : subChildren) {
+ boolean foundMatch = false;
+ for(Description child : children) {
+ if(isSubdescription(child, subChild)) {
+ foundMatch = true;
+ break;
+ }
+ }
+ if(!foundMatch) {
+ return false;
+ }
+ }
+
+ return true;
+
+// // method core; traverse the descriptions in linear time using ordered
+// // normal form (TODO: does not always work e.g. A2 \sqcap (A1 \sqcup A3)
+ // and A1 \sqcap A2 -> it won't find the A2 match because it has advanced
+ // beyond it already)
+// int j = 0;
+// for(Description child : children) {
+// if(isSubdescription(child, subChildren.get(j))) {
+// j++;
+// }
+// if(j == subChildren.size()) {
+// return true;
+// }
+// }
+// // there is at least one child we could not match
+// return false;
+ }
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java 2009-02-25 13:17:50 UTC (rev 1630)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java 2009-02-25 16:26:08 UTC (rev 1631)
@@ -32,6 +32,7 @@
import org.dllearner.core.owl.ObjectAllRestriction;
import org.dllearner.core.owl.ObjectMaxCardinalityRestriction;
import org.dllearner.core.owl.ObjectMinCardinalityRestriction;
+import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.Union;
@@ -51,6 +52,8 @@
private ConceptComparator conceptComparator = new ConceptComparator();
private Map<Description,Map<Description,Boolean>> cachedSubclassOf = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator);
+ private boolean beautify = false;
+
public DescriptionMinimizer(ReasonerComponent reasoner) {
this.reasoner = reasoner;
}
@@ -104,6 +107,12 @@
if(description.getChild(0) instanceof Thing) {
return Thing.instance;
}
+ // we rewrite \forall r.\bot to \neg \exists r.\top
+ // which is longer but easier to understand for humans
+ if(beautify && description.getChild(0) instanceof Nothing) {
+ ObjectProperty p = (ObjectProperty)((ObjectAllRestriction)description).getRole();
+ return new Negation(new ObjectSomeRestriction(p, Thing.instance));
+ }
return description;
} else if(description instanceof Negation) {
// \neg \bot \equiv \top
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-25 16:52:51
|
Revision: 1633
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1633&view=rev
Author: jenslehmann
Date: 2009-02-25 16:52:45 +0000 (Wed, 25 Feb 2009)
Log Message:
-----------
small changes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-25 16:32:26 UTC (rev 1632)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-25 16:52:45 UTC (rev 1633)
@@ -197,7 +197,7 @@
@Override
public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return bestEvaluatedDescriptions.getSet().last();
+ return bestEvaluatedDescriptions.getBest();
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-25 16:32:26 UTC (rev 1632)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2009-02-25 16:52:45 UTC (rev 1633)
@@ -102,7 +102,7 @@
public List<Description> toDescriptionList() {
List<Description> list = new LinkedList<Description>();
- for(EvaluatedDescription ed : set) {
+ for(EvaluatedDescription ed : set.descendingSet()) {
list.add(ed.getDescription());
}
return list;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-26 16:24:28
|
Revision: 1635
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1635&view=rev
Author: jenslehmann
Date: 2009-02-26 16:24:18 +0000 (Thu, 26 Feb 2009)
Log Message:
-----------
- started \forall checks
- some beautification of output descriptions
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-26 15:29:25 UTC (rev 1634)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-26 16:24:18 UTC (rev 1635)
@@ -43,6 +43,7 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.Restriction;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.ClassLearningProblem;
@@ -341,6 +342,15 @@
return false;
}
+ // perform forall sanity tests (TODO: move to separate method)
+ if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) {
+ // we have an additional \forall construct, so we now fetch the contexts
+ // in which it occurs
+ List<List<ObjectProperty>> contexts = ConceptTransformation.getForallContexts(description);
+ List<List<ObjectProperty>> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription());
+
+ }
+
// quality of description (return if too weak)
double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc);
descriptionTests++;
@@ -559,4 +569,5 @@
public int getMinimumHorizontalExpansion() {
return minHorizExp;
}
+
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-26 15:29:25 UTC (rev 1634)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-02-26 16:24:18 UTC (rev 1635)
@@ -502,8 +502,12 @@
// (of course we only have to clone the leafs of a class description tree)
if (description instanceof NamedClass) {
return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone();
- } else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) {
- return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone();
+ } else if (description instanceof Negation) {
+ if(description.getChild(0) instanceof NamedClass) {
+ return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone();
+ }
+ // implement retrieval as default negation
+ return Helper.difference((TreeSet<Individual>) individuals.clone(), getIndividualsImpl(description.getChild(0)));
} else if (description instanceof Thing) {
return (TreeSet<Individual>) individuals.clone();
} else if (description instanceof Nothing) {
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-26 15:29:25 UTC (rev 1634)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-26 16:24:18 UTC (rev 1635)
@@ -39,6 +39,7 @@
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.Restriction;
import org.dllearner.core.owl.Union;
import org.dllearner.core.owl.Negation;
import org.dllearner.core.owl.ObjectPropertyExpression;
@@ -570,4 +571,44 @@
// return false;
}
}
+
+ public static int getForallOccurences(Description description) {
+ int count = 0;
+ if(description instanceof ObjectAllRestriction) {
+ count++;
+ }
+ for(Description child : description.getChildren()) {
+ count += getForallOccurences(child);
+ }
+ return count;
+ }
+
+ public static List<List<ObjectProperty>> getForallContexts(Description description) {
+ return getForallContexts(description, new LinkedList<ObjectProperty>());
+ }
+
+ private static List<List<ObjectProperty>> getForallContexts(Description description, List<ObjectProperty> currentContext) {
+ // the context changes if we have a restriction
+ if(description instanceof Restriction) {
+ ObjectProperty op = (ObjectProperty) ((Restriction)description).getRestrictedPropertyExpression();
+ currentContext.add(op);
+ // if we have an all-restriction, we return it; otherwise we only change the context
+ // and call the method on the child
+ if(description instanceof ObjectAllRestriction) {
+ List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>();
+ contexts.add(currentContext);
+ contexts.addAll(getForallContexts(description.getChild(0), currentContext));
+ return contexts;
+ } else {
+ return getForallContexts(description.getChild(0), currentContext);
+ }
+ // for non-restrictions, we collect contexts over all children
+ } else {
+ List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>();
+ for(Description child : description.getChildren()) {
+ contexts.addAll(getForallContexts(child, currentContext));
+ }
+ return contexts;
+ }
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java 2009-02-26 15:29:25 UTC (rev 1634)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionMinimizer.java 2009-02-26 16:24:18 UTC (rev 1635)
@@ -52,7 +52,7 @@
private ConceptComparator conceptComparator = new ConceptComparator();
private Map<Description,Map<Description,Boolean>> cachedSubclassOf = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator);
- private boolean beautify = false;
+ private boolean beautify = true;
public DescriptionMinimizer(ReasonerComponent reasoner) {
this.reasoner = reasoner;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-27 11:39:38
|
Revision: 1637
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1637&view=rev
Author: jenslehmann
Date: 2009-02-27 11:39:32 +0000 (Fri, 27 Feb 2009)
Log Message:
-----------
extended CELOE such that the all quantifier is not suggested in some unreasonable cases, e.g. \exists r.\forall s.\top cannot (from a human point of view) be a preferred solution if none of the instances of the considered class has an r-filler which has an s-filler
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-26 19:03:36 UTC (rev 1636)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-27 11:39:32 UTC (rev 1637)
@@ -41,6 +41,7 @@
import org.dllearner.core.options.ConfigOption;
import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Individual;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
@@ -53,6 +54,7 @@
import org.dllearner.utilities.owl.ConceptTransformation;
import org.dllearner.utilities.owl.DescriptionMinimizer;
import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
+import org.dllearner.utilities.owl.PropertyContext;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
@@ -93,6 +95,7 @@
private EvaluatedDescriptionSet bestEvaluatedDescriptions;
private NamedClass classToDescribe;
+ private Set<Individual> classInstances;
private boolean isEquivalenceProblem;
private long nanoStartTime;
@@ -160,6 +163,8 @@
ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone();
classHierarchy.thinOutSubsumptionHierarchy();
+ classInstances = reasoner.getIndividuals(classToDescribe);
+
minimizer = new DescriptionMinimizer(reasoner);
// start class: intersection of super classes for definitions (since it needs to
@@ -338,19 +343,10 @@
}
// check whether the description is allowed
- if(!isDescriptionAllowed(description)) {
+ if(!isDescriptionAllowed(description, parentNode)) {
return false;
}
- // perform forall sanity tests (TODO: move to separate method)
- if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) {
- // we have an additional \forall construct, so we now fetch the contexts
- // in which it occurs
- List<List<ObjectProperty>> contexts = ConceptTransformation.getForallContexts(description);
- List<List<ObjectProperty>> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription());
-
- }
-
// quality of description (return if too weak)
double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc);
descriptionTests++;
@@ -405,10 +401,12 @@
}
// checks whether the description is allowed
- private boolean isDescriptionAllowed(Description description) {
+ private boolean isDescriptionAllowed(Description description, OENode parentNode) {
if(isEquivalenceProblem) {
// the class to learn must not appear on the outermost property level
- return !occursOnFirstLevel(description, classToDescribe);
+ if(occursOnFirstLevel(description, classToDescribe)) {
+ return false;
+ }
} else {
// none of the superclasses of the class to learn must appear on the
// outermost property level
@@ -423,10 +421,42 @@
}
}
+ // perform forall sanity tests
+ if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) {
+ // we have an additional \forall construct, so we now fetch the contexts
+ // in which it occurs
+ SortedSet<PropertyContext> contexts = ConceptTransformation.getForallContexts(description);
+ SortedSet<PropertyContext> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription());
+ contexts.removeAll(parentContexts);
+// System.out.println("parent description: " + parentNode.getDescription());
+// System.out.println("description: " + description);
+// System.out.println("contexts: " + contexts);
+ // we now have to perform sanity checks: if \forall is used, then there
+ // should be at least on class instance which has a filler at the given context
+ for(PropertyContext context : contexts) {
+ // transform [r,s] to \exists r.\exists s.\top
+ Description existentialContext = context.toExistentialContext();
+ boolean fillerFound = false;
+ for(Individual instance : classInstances) {
+ if(reasoner.hasType(existentialContext, instance)) {
+// System.out.println(instance + " " + existentialContext);
+ fillerFound = true;
+ break;
+ }
+ }
+ // if we do not find a filler, this means that putting \forall at
+ // that position is not meaningful
+ if(!fillerFound) {
+ return false;
+ }
+ }
+ }
+
// we do not want to have negations of sibling classes on the outermost level
// (they are expressed more naturally by saying that the siblings are disjoint,
// so it is reasonable not to include them in solutions)
- Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe);
+// Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe);
+// for now, we just disable negation
return true;
}
@@ -453,26 +483,6 @@
return false;
}
- private boolean occursNegatedOnFirstLevel(Description description, Description clazz) {
- if(description instanceof NamedClass) {
- if(description.equals(clazz)) {
- return true;
- }
- }
-
- if(description instanceof Restriction) {
- return false;
- }
-
- for(Description child : description.getChildren()) {
- if(occursOnFirstLevel(child, clazz)) {
- return true;
- }
- }
-
- return false;
- }
-
// check whether the node is a potential solution candidate
private Description rewriteNode(OENode node) {
Description description = node.getDescription();
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-26 19:03:36 UTC (rev 1636)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-02-27 11:39:32 UTC (rev 1637)
@@ -583,11 +583,11 @@
return count;
}
- public static List<List<ObjectProperty>> getForallContexts(Description description) {
- return getForallContexts(description, new LinkedList<ObjectProperty>());
+ public static SortedSet<PropertyContext> getForallContexts(Description description) {
+ return getForallContexts(description, new PropertyContext());
}
- private static List<List<ObjectProperty>> getForallContexts(Description description, List<ObjectProperty> currentContext) {
+ private static SortedSet<PropertyContext> getForallContexts(Description description, PropertyContext currentContext) {
// the context changes if we have a restriction
if(description instanceof Restriction) {
ObjectProperty op = (ObjectProperty) ((Restriction)description).getRestrictedPropertyExpression();
@@ -595,7 +595,7 @@
// if we have an all-restriction, we return it; otherwise we only change the context
// and call the method on the child
if(description instanceof ObjectAllRestriction) {
- List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>();
+ TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>();
contexts.add(currentContext);
contexts.addAll(getForallContexts(description.getChild(0), currentContext));
return contexts;
@@ -604,7 +604,7 @@
}
// for non-restrictions, we collect contexts over all children
} else {
- List<List<ObjectProperty>> contexts = new LinkedList<List<ObjectProperty>>();
+ TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>();
for(Description child : description.getChildren()) {
contexts.addAll(getForallContexts(child, currentContext));
}
Added: trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/PropertyContext.java 2009-02-27 11:39:32 UTC (rev 1637)
@@ -0,0 +1,76 @@
+/**
+ * Copyright (C) 2007-2009, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.utilities.owl;
+
+import java.util.LinkedList;
+
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.core.owl.Thing;
+
+/**
+ * A property context is a utility class which specifies the
+ * position of constructs with respect to properties of a
+ * construct in a class description. For instance, the A
+ * in \exists r.\exists s.A occurs in property context [r,s].
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class PropertyContext extends LinkedList<ObjectProperty> implements Comparable<PropertyContext> {
+
+ private static final long serialVersionUID = -4403308689522524077L;
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(PropertyContext context) {
+ // we first distinguish on size - simpler contexts come first
+ int diff = context.size() - size();
+ if(diff != 0) {
+ return diff;
+ }
+
+ for(int i=0; i<size(); i++) {
+ int cmp = get(i).getName().compareTo(context.get(i).getName());
+ if(cmp != 0) {
+ return cmp;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * Transforms context [r,s] to \exists r.\exists s.\top.
+ * @return A description with existential quantifiers and \top corresponding
+ * to the context.
+ */
+ public Description toExistentialContext() {
+ Description d = Thing.instance;
+ for(int i = size()-1; i>=0; i--) {
+ d = new ObjectSomeRestriction(get(i), d);
+ }
+ return d;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2009-03-07 16:25:37
|
Revision: 1646
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1646&view=rev
Author: kurzum
Date: 2009-03-07 16:25:26 +0000 (Sat, 07 Mar 2009)
Log Message:
-----------
fixed warnings,
couldn't find a good solution for RDFBlankNode
set SuppressWarnings("all")
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyLPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java
trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java
trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java
trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -33,7 +33,7 @@
public class BruteForceLearnerConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private BruteForceLearner bruteForceLearner;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -31,10 +31,11 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
+@SuppressWarnings("all")
public class CELOEConfigurator extends RefinementOperatorConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private CELOE cELOE;
@@ -113,7 +114,7 @@
/**
* useNegation specifies whether negation is used in the learning algorothm.
* mandatory: false| reinit necessary: true
-* default value: true
+* default value: false
* @return boolean
**/
public boolean getUseNegation() {
@@ -231,7 +232,7 @@
/**
* @param useNegation specifies whether negation is used in the learning algorothm.
* mandatory: false| reinit necessary: true
-* default value: true
+* default value: false
**/
public void setUseNegation(boolean useNegation) {
ComponentManager.getInstance().applyConfigEntry(cELOE, "useNegation", useNegation);
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -31,7 +31,7 @@
public class ClassLearningProblemConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private ClassLearningProblem classLearningProblem;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class DIGReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private DIGReasoner dIGReasoner;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -33,7 +33,7 @@
public class ELLearningAlgorithmConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private ELLearningAlgorithm eLLearningAlgorithm;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class FastInstanceCheckerConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private FastInstanceChecker fastInstanceChecker;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class FastRetrievalReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private FastRetrievalReasoner fastRetrievalReasoner;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -33,7 +33,7 @@
public class GPConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private GP gP;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -31,7 +31,7 @@
public class KBFileConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private KBFile kBFile;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -30,7 +30,7 @@
public class OWLAPIOntologyConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private OWLAPIOntology oWLAPIOntology;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class OWLAPIReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private OWLAPIReasoner oWLAPIReasoner;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -31,7 +31,7 @@
public class OWLFileConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private OWLFile oWLFile;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class PosNegLPStandardConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private PosNegLPStandard posNegLPStandard;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class PosNegLPStrictConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private PosNegLPStrict posNegLPStrict;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyLPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyLPConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyLPConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,7 +32,7 @@
public class PosOnlyLPConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private PosOnlyLP posOnlyLP;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -34,7 +34,7 @@
public class ROLComponent2Configurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private ROLComponent2 rOLComponent2;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -32,10 +32,11 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
+@SuppressWarnings("all")
public class ROLearnerConfigurator extends RefinementOperatorConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private ROLearner rOLearner;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -33,7 +33,7 @@
public class RandomGuesserConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private RandomGuesser randomGuesser;
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -34,7 +34,7 @@
public class SparqlKnowledgeSourceConfigurator implements Configurator {
private boolean reinitNecessary = false;
-@SuppressWarnings("all")
+@SuppressWarnings("unused")
private SparqlKnowledgeSource sparqlKnowledgeSource;
Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -55,12 +55,13 @@
}
// overidden Functions
-
+ @SuppressWarnings("all")
public RDFNode as(Class view) {
return blankNode.as(view);
}
+ @SuppressWarnings("all")
public boolean canAs(Class view) {
return blankNode.canAs(view);
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -258,14 +258,22 @@
}
private void addFiltersForDBpediaUMBEL() {
- addObjectFilter("http://umbel.org/umbel/sc/");
+ addObjectFilter("http://umbel.org/umbel/");
}
+ @SuppressWarnings("unused")
+ private void addFiltersForDBpediaOntology() {
+ addObjectFilter("http://dbpedia.org/ontology/");
+ }
+ @SuppressWarnings("unused")
+ private void addFiltersForDBpediaCyc() {
+ addObjectFilter("http://sw.opencyc.org/2008/06/10/concept/");
+ }
-
private void addFiltersForYago() {
addObjectFilter("http://dbpedia.org/class/yago");
}
+
private void addFiltersForOWLSameAs() {
addPredicateFilter("http://www.w3.org/2002/07/owl#sameAs");
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -74,6 +74,7 @@
private static final boolean INCLUDE_UNUSED = false;
private static final String UNUSED = "@SuppressWarnings(\"unused\")\n";
+ private static final String OVERRIDE = "@SuppressWarnings(\"all\")\n";
private static final String TARGET_DIR = "src/dl-learner/org/dllearner/core/configurators";
@@ -538,6 +539,7 @@
ret += imports + "\n";
ret += fillJavaDocComment(CLASS_COMMENT);
ret += (INCLUDE_UNUSED) ? UNUSED : "";
+ ret += (!extendS.isEmpty()) ? OVERRIDE : "";
ret += "public "+classModifier+" class " + className + " "
+ ((extendS.length() > 0) ? " extends " + extendS : "")
+ ((implementS.length() > 0) ? " implements " + implementS : "")
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -24,7 +24,6 @@
import java.util.List;
import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.utilities.Files;
import org.dllearner.utilities.datastructures.SetManipulation;
Modified: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -39,7 +39,6 @@
import org.dllearner.kb.sparql.SPARQLTasks;
import org.dllearner.kb.sparql.SparqlQuery;
import org.dllearner.kb.sparql.SparqlQueryMaker;
-import org.dllearner.utilities.JamonMonitorLogger;
/**
* Test class, uses the whole thing
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java 2009-03-06 10:35:34 UTC (rev 1645)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java 2009-03-07 16:25:26 UTC (rev 1646)
@@ -60,7 +60,7 @@
LearningAlgorithm la = null;
// try {
-//// la = learn.learn(posExamples, negExamples, OWLAPIReasoner.class);
+ //la = learn.learn(posExamples, negExamples, OWLAPIReasoner.class);
// } catch (ComponentInitException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-03-09 09:58:20
|
Revision: 1647
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1647&view=rev
Author: jenslehmann
Date: 2009-03-09 09:58:09 +0000 (Mon, 09 Mar 2009)
Log Message:
-----------
implemented coverage weight in class learning to enable reasonable super class learning
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-03-07 16:25:26 UTC (rev 1646)
+++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-03-09 09:58:09 UTC (rev 1647)
@@ -77,6 +77,7 @@
* @see org.dllearner.learningproblems.ScorePosNeg#getAccuracy()
* @return Accuracy of the description.
*/
+ @Override
public double getAccuracy() {
return score2.getAccuracy();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-07 16:25:26 UTC (rev 1646)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-09 09:58:09 UTC (rev 1647)
@@ -44,7 +44,6 @@
import org.dllearner.core.owl.Individual;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
-import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.Restriction;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.ClassLearningProblem;
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-07 16:25:26 UTC (rev 1646)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-09 09:58:09 UTC (rev 1647)
@@ -54,6 +54,9 @@
private boolean equivalence = true;
private ClassLearningProblemConfigurator configurator;
+ // factor for higher weight on coverage (needed for subclass learning)
+ private double coverageFactor;
+
// instances of super classes excluding instances of the class itself
private List<Individual> superClassInstances;
@@ -90,6 +93,12 @@
classInstances = reasoner.getIndividuals(classToDescribe);
equivalence = (configurator.getType().equals("equivalence"));
+ if(equivalence) {
+ coverageFactor = 1;
+ } else {
+ coverageFactor = 3;
+ }
+
// we compute the instances of the super class to perform
// optimisations later on
Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe);
@@ -165,7 +174,7 @@
double coverage = instancesCovered/(double)classInstances.size();
double protusion = instancesCovered/(double)retrieval.size();
- return 0.5d * (coverage + protusion);
+ return (coverageFactor * coverage + protusion) / (coverageFactor + 1);
}
@Override
@@ -239,7 +248,7 @@
// System.out.println(instancesDescription);
// System.out.println("prot: " + protusion);
- double acc = 0.5d * (coverage + protusion);
+ double acc = (coverageFactor * coverage + protusion) / (coverageFactor + 1);
// System.out.println("acc: " + acc);
Modified: trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java 2009-03-07 16:25:26 UTC (rev 1646)
+++ trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java 2009-03-09 09:58:09 UTC (rev 1647)
@@ -43,7 +43,6 @@
import org.dllearner.kb.sparql.Cache;
import org.dllearner.kb.sparql.SparqlKnowledgeSource;
import org.dllearner.kb.sparql.SparqlQuery;
-import org.dllearner.reasoning.FastInstanceChecker;
import org.dllearner.reasoning.ReasonerType;
import org.dllearner.utilities.Files;
import org.dllearner.utilities.components.ReasonerComponentFactory;
@@ -75,7 +74,7 @@
public static String ontologyPath = "examples/semantic_bible/NTNcombined.owl";
- private static Class<? extends ReasonerComponent> usedReasoner = FastInstanceChecker.class;
+// private static Class<? extends ReasonerComponent> usedReasoner = FastInstanceChecker.class;
/**
* @param args
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-03-19 17:31:42
|
Revision: 1654
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1654&view=rev
Author: jenslehmann
Date: 2009-03-19 17:31:22 +0000 (Thu, 19 Mar 2009)
Log Message:
-----------
fix for possible division by zero
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-17 14:56:12 UTC (rev 1653)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-19 17:31:22 UTC (rev 1654)
@@ -122,8 +122,6 @@
public CELOE(ClassLearningProblem problem, ReasonerComponent reasoner) {
super(problem, reasoner);
configurator = new CELOEConfigurator(this);
- classToDescribe = problem.getClassToDescribe();
- isEquivalenceProblem = problem.isEquivalenceProblem();
}
public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() {
@@ -157,6 +155,10 @@
@Override
public void init() throws ComponentInitException {
+ ClassLearningProblem problem = (ClassLearningProblem) learningProblem;
+ classToDescribe = problem.getClassToDescribe();
+ isEquivalenceProblem = problem.isEquivalenceProblem();
+
// copy class hierarchy and modify it such that each class is only
// reachable via a single path
ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone();
@@ -175,8 +177,7 @@
startClass = new Intersection(new LinkedList<Description>(superClasses));
} else {
startClass = (Description) superClasses.toArray()[0];
- }
-
+ }
} else {
startClass = Thing.instance;
}
@@ -186,7 +187,7 @@
baseURI = reasoner.getBaseURI();
prefixes = reasoner.getPrefixes();
- bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults());
+ bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults());
// we put important parameters in class variables
minAcc = configurator.getNoisePercentage()/100d;
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-17 14:56:12 UTC (rev 1653)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-19 17:31:22 UTC (rev 1654)
@@ -73,8 +73,8 @@
public static Collection<ConfigOption<?>> createConfigOptions() {
Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>();
options.add(new StringConfigOption("classToDescribe", "class of which a description should be learned", null, true, false));
- StringConfigOption type = new StringConfigOption("type", "Whether to learn an equivalence class or super class axiom.","equivalence");
- type.setAllowedValues(new String[] {"equivalence", "superClass"});
+ StringConfigOption type = new StringConfigOption("type", "Whether to learn an equivalence class or super class axiom or domain/range of a property.","equivalence");
+ type.setAllowedValues(new String[] {"equivalence", "superClass", "domain", "range"});
options.add(type);
return options;
}
@@ -148,9 +148,10 @@
Set<Individual> additionalInstances = Helper.difference(retrieval, coveredInstances);
double coverage = instancesCovered/(double)classInstances.size();
- double protusion = instancesCovered/(double)retrieval.size();
+ double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size();
+// double accuracy = coverage + Math.sqrt(protusion);
- return new ClassScore(coveredInstances, coverage, additionalInstances, protusion);
+ return new ClassScore(coveredInstances, coverage, additionalInstances, protusion, getAccuracy(coverage, protusion));
}
public boolean isEquivalenceProblem() {
@@ -172,9 +173,12 @@
}
double coverage = instancesCovered/(double)classInstances.size();
- double protusion = instancesCovered/(double)retrieval.size();
+// double protusion = instancesCovered/(double)retrieval.size();
+ double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size();
+//
- return (coverageFactor * coverage + protusion) / (coverageFactor + 1);
+// return (coverageFactor * coverage + protusion) / (coverageFactor + 1);
+ return getAccuracy(coverage, protusion);
}
@Override
@@ -243,16 +247,19 @@
// since we measured/estimated accuracy only on instances outside A (superClassInstances
// does not include instances of A), we need to add it in the denominator
double protusion = instancesCovered/(double)(instancesDescription+instancesCovered);
+ if(instancesCovered + instancesDescription == 0) {
+ protusion = 0;
+ }
// System.out.println(description);
// System.out.println(instancesDescription);
// System.out.println("prot: " + protusion);
- double acc = (coverageFactor * coverage + protusion) / (coverageFactor + 1);
+// double acc = (coverageFactor * coverage + protusion) / (coverageFactor + 1);
// System.out.println("acc: " + acc);
- return acc;
+ return getAccuracy(coverage, protusion);
}
/* (non-Javadoc)
@@ -269,6 +276,10 @@
}
}
+ private double getAccuracy(double coverage, double protusion) {
+ return (coverageFactor * coverage + Math.sqrt(protusion)) / (coverageFactor + 1);
+ }
+
/**
* @return the classToDescribe
*/
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-17 14:56:12 UTC (rev 1653)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-19 17:31:22 UTC (rev 1654)
@@ -37,12 +37,14 @@
private double coverage;
private double addition;
+ private double accuracy;
- public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion) {
+ public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion, double accuracy) {
this.coveredInstances = coveredInstances;
this.additionalInstances = additionalInstances;
this.coverage = coverage;
this.addition = protusion;
+ this.accuracy = accuracy;
}
/**
@@ -67,7 +69,8 @@
*/
@Override
public double getAccuracy() {
- return 0.5 * (coverage + addition);
+// return 0.5 * (coverage + addition);
+ return accuracy;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-03-27 11:16:23
|
Revision: 1669
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1669&view=rev
Author: jenslehmann
Date: 2009-03-27 11:16:11 +0000 (Fri, 27 Mar 2009)
Log Message:
-----------
started implementing consistency check for added axiom
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java
trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
Modified: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -23,6 +23,7 @@
import java.util.Set;
import java.util.SortedSet;
+import org.dllearner.core.owl.Axiom;
import org.dllearner.core.owl.Constant;
import org.dllearner.core.owl.DatatypeProperty;
import org.dllearner.core.owl.Entity;
@@ -51,6 +52,13 @@
public boolean isSatisfiable();
/**
+ * Checks whether adding the specified axiom leads to an inconsistency.
+ * @param axiom The axiom to be added to the knowledge base.
+ * @return True of the knowledge base including the axiom is satisfiable. False otherwise.
+ */
+ public boolean remainsSatisfiable(Axiom axiom);
+
+ /**
* Gets all named classes in the knowledge base, e.g. Person, City, Car.
* @return All named classes in KB.
*/
Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -30,6 +30,7 @@
import java.util.Map.Entry;
import org.apache.log4j.Logger;
+import org.dllearner.core.owl.Axiom;
import org.dllearner.core.owl.Constant;
import org.dllearner.core.owl.DataRange;
import org.dllearner.core.owl.DatatypeProperty;
@@ -398,6 +399,26 @@
}
@Override
+ public final boolean remainsSatisfiable(Axiom axiom) {
+ reasoningStartTimeTmp = System.nanoTime();
+ boolean result;
+ try {
+ result = remainsSatisfiableImpl(axiom);
+ } catch (ReasoningMethodUnsupportedException e) {
+ handleExceptions(e);
+ return false;
+ }
+ reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp;
+ otherReasoningTimeNs += reasoningDurationTmp;
+ overallReasoningTimeNs += reasoningDurationTmp;
+ return result;
+ }
+
+ protected boolean remainsSatisfiableImpl(Axiom axiom) throws ReasoningMethodUnsupportedException {
+ throw new ReasoningMethodUnsupportedException();
+ }
+
+ @Override
public final Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationships(Individual individual) {
try {
return getObjectPropertyRelationshipsImpl(individual);
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -33,9 +33,12 @@
import org.dllearner.core.configurators.ClassLearningProblemConfigurator;
import org.dllearner.core.options.ConfigOption;
import org.dllearner.core.options.StringConfigOption;
+import org.dllearner.core.owl.Axiom;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.EquivalentClassesAxiom;
import org.dllearner.core.owl.Individual;
import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.SubClassAxiom;
/**
* The problem of learning the description of an existing class
@@ -150,8 +153,9 @@
double coverage = coveredInstances.size()/(double)classInstances.size();
double protusion = (additionalInstances.size() + coveredInstances.size() == 0) ? 0 : coveredInstances.size()/(double)(coveredInstances.size()+additionalInstances.size());
+ boolean isConsistent = isConsistent(description);
- return new ClassScore(coveredInstances, coverage, additionalInstances, protusion, getAccuracy(coverage, protusion));
+ return new ClassScore(coveredInstances, coverage, additionalInstances, protusion, getAccuracy(coverage, protusion), isConsistent);
}
public boolean isEquivalenceProblem() {
@@ -367,4 +371,17 @@
ClassScore score = computeScore(description);
return new EvaluatedDescriptionClass(description, score);
}
+
+ /**
+ * @return the isConsistent
+ */
+ public boolean isConsistent(Description description) {
+ Axiom axiom;
+ if(equivalence) {
+ axiom = new EquivalentClassesAxiom(classToDescribe, description);
+ } else {
+ axiom = new SubClassAxiom(classToDescribe, description);
+ }
+ return reasoner.remainsSatisfiable(axiom);
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -39,12 +39,15 @@
private double addition;
private double accuracy;
- public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion, double accuracy) {
+ private boolean isConsistent;
+
+ public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion, double accuracy, boolean isConsistent) {
this.coveredInstances = coveredInstances;
this.additionalInstances = additionalInstances;
this.coverage = coverage;
this.addition = protusion;
this.accuracy = accuracy;
+ this.isConsistent = isConsistent;
}
/**
@@ -85,6 +88,13 @@
*/
public Set<Individual> getAdditionalInstances() {
return additionalInstances;
+ }
+
+ /**
+ * @return the isConsistent
+ */
+ public boolean isConsistent() {
+ return isConsistent;
}
}
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -78,5 +78,13 @@
public Set<Individual> getCoveredInstances() {
return classScore.getCoveredInstances();
}
+
+ /**
+ *
+ * @return True if adding the axiom to the knowledge base leads to an inconsistent knowledge base. False otherwise.
+ */
+ public boolean isConsistent() {
+ return classScore.isConsistent();
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -43,6 +43,7 @@
import org.dllearner.core.options.ConfigOption;
import org.dllearner.core.options.InvalidConfigOptionValueException;
import org.dllearner.core.options.StringConfigOption;
+import org.dllearner.core.owl.Axiom;
import org.dllearner.core.owl.BooleanValueRestriction;
import org.dllearner.core.owl.Constant;
import org.dllearner.core.owl.DataRange;
@@ -1002,4 +1003,12 @@
return rc.getTypesImpl(individual);
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.BaseReasoner#remainsSatisfiable(org.dllearner.core.owl.Axiom)
+ */
+ @Override
+ public boolean remainsSatisfiableImpl(Axiom axiom) {
+ return rc.remainsSatisfiableImpl(axiom);
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -208,6 +208,7 @@
rc.releaseKB();
}
+
// @Override
// public boolean hasDatatypeSupport() {
// return true;
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-03-27 10:53:47 UTC (rev 1668)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-03-27 11:16:11 UTC (rev 1669)
@@ -47,6 +47,7 @@
import org.dllearner.core.options.ConfigOption;
import org.dllearner.core.options.InvalidConfigOptionValueException;
import org.dllearner.core.options.StringConfigOption;
+import org.dllearner.core.owl.Axiom;
import org.dllearner.core.owl.Constant;
import org.dllearner.core.owl.Datatype;
import org.dllearner.core.owl.DatatypeProperty;
@@ -72,6 +73,7 @@
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.model.OWLAnnotation;
+import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLConstant;
import org.semanticweb.owl.model.OWLDataFactory;
@@ -1011,6 +1013,17 @@
}
return annotations;
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.BaseReasoner#remainsSatisfiable(org.dllearner.core.owl.Axiom)
+ */
+ @Override
+ public boolean remainsSatisfiableImpl(Axiom axiom) {
+ OWLAxiom axiomOWLAPI = OWLAPIAxiomConvertVisitor.convertAxiom(axiom);
+
+ // TODO Auto-generated method stub
+ return false;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-01 11:18:07
|
Revision: 1677
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1677&view=rev
Author: jenslehmann
Date: 2009-04-01 11:17:54 +0000 (Wed, 01 Apr 2009)
Log Message:
-----------
cleaned up SparqlQuery class (might break existing code)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -278,13 +278,13 @@
readTime.stop();
if (result != null) {
- query.setJson(result);
+// query.setJson(result);
+//
+// query.setRunning(false);
+// SparqlQuery.writeToSparqlLog("***********\nJSON retrieved from cache");
+// SparqlQuery.writeToSparqlLog("wget -S -O - '\n"+query.getSparqlEndpoint().getHTTPRequest());
+// SparqlQuery.writeToSparqlLog(query.getSparqlQueryString());
- query.setRunning(false);
- SparqlQuery.writeToSparqlLog("***********\nJSON retrieved from cache");
- SparqlQuery.writeToSparqlLog("wget -S -O - '\n"+query.getSparqlEndpoint().getHTTPRequest());
- SparqlQuery.writeToSparqlLog(query.getSparqlQueryString());
-
//SparqlQuery.writeToSparqlLog("JSON: "+result);
JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits");
@@ -295,7 +295,8 @@
String json = query.getJson();
if (json!=null){
addToCache(query.getSparqlQueryString(), json);
- SparqlQuery.writeToSparqlLog("result added to cache: "+json);
+// SparqlQuery.writeToSparqlLog("result added to cache: "+json);
+ logger.debug("result added to SPARQL cache: "+json);
result=json;
//query.setJson(result);
} else {
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -479,14 +479,8 @@
* @return jena ResultSet
*/
public ResultSetRewindable queryAsResultSet(String sparqlQueryString) {
- return SparqlQuery.convertJSONtoResultSet(query(sparqlQueryString));
-
- }
-
- public ResultSet queryAsResultSet2(String sparqlQueryString) {
SparqlQuery sq = new SparqlQuery(sparqlQueryString, sparqlEndpoint);
- sq.send();
- return sq.getResultSet();
+ return sq.send();
}
/**
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -35,13 +35,13 @@
import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.query.ResultSetRewindable;
-import com.hp.hpl.jena.sparql.engine.http.HttpQuery;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
import com.jamonapi.Monitor;
/**
* Represents one SPARQL query. It includes support for stopping the SPARQL
- * query (which may be necessary if a timeout is reached).
+ * query (which may be necessary if a timeout is reached) and is designed to be
+ * able to run a query in a separate thread.
*
* @author Jens Lehmann
* @author Sebastian Hellmann
@@ -50,11 +50,16 @@
public class SparqlQuery {
private static boolean logDeletedOnStart = false;
-
+
private static Logger logger = Logger.getLogger(SparqlQuery.class);
+
+ // additional file for logging SPARQL queries etc.
+ private static String sparqlLog = "log/sparql.txt";
+ // whether the query is currently running
private boolean isRunning = false;
+ // whether the query has been executed
private boolean wasExecuted = false;
private String sparqlQueryString;
@@ -63,13 +68,15 @@
private SparqlEndpoint sparqlEndpoint;
- private String json = null;
+ private ResultSetRewindable rs;
/**
* Standard constructor.
*
- * @param sparqlQueryString A SPARQL query string
- * @param sparqlEndpoint An Endpoint object
+ * @param sparqlQueryString
+ * A SPARQL query string
+ * @param sparqlEndpoint
+ * An Endpoint object
*/
public SparqlQuery(String sparqlQueryString, SparqlEndpoint sparqlEndpoint) {
// QUALITY there seems to be a bug in ontowiki
@@ -78,81 +85,63 @@
}
/**
- * Sends a SPARQL query using the Jena library. main format is JSON, use
- * method getasjson
+ * Sends a SPARQL query using the Jena library.
*
*/
- public void send(){
- wasExecuted = true;
- // isRunning = true;
-
- ResultSet rs;
+ public ResultSetRewindable send() {
+ isRunning = true;
+
String service = sparqlEndpoint.getURL().toString();
-
+
writeToSparqlLog("***********\nNew Query:");
- SparqlQuery.writeToSparqlLog("wget -S -O - '\n"+sparqlEndpoint.getHTTPRequest());
+ SparqlQuery.writeToSparqlLog("wget -S -O - '\n" + sparqlEndpoint.getHTTPRequest());
writeToSparqlLog(sparqlQueryString);
-
- logger.trace("making queryExecution Object");
- // Jena access to SPARQL endpoint
+
queryExecution = new QueryEngineHTTP(service, sparqlQueryString);
- //System.out.println(sparqlEndpoint.getDefaultGraphURIs());
-
-
+
+ // add default and named graphs
for (String dgu : sparqlEndpoint.getDefaultGraphURIs()) {
queryExecution.addDefaultGraph(dgu);
}
for (String ngu : sparqlEndpoint.getNamedGraphURIs()) {
queryExecution.addNamedGraph(ngu);
}
- // TODO remove after overnext Jena release
- HttpQuery.urlLimit = 3 * 1024;
- Monitor httpTime = JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").start();
-
- //TODO correct Bug: when there is a & in the result like in the
- //URL: http://www.discusmedia.com/catalog.php?catID=5.2.2&profile=map
- //the XML Parser throws an error, because he thinks &profile is an html entitie
- //but it doesn't end with an ;
- //the & must be masked to an & but I am not sure at the moment how to do that
- try{
-
+
+ Monitor httpTime = JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "sparql query time").start();
+
+ try {
logger.debug("sending query: length: " + sparqlQueryString.length() + " | ENDPOINT: "
+ sparqlEndpoint.getURL().toString());
- rs = queryExecution.execSelect();
-
- logger.trace("query executed, converting to json");
- json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs));
- logger.trace(json);
- //writeToSparqlLog("JSON: " + json);
- //}catch (ResultSetException e) {
+ // we execute the query and store the result in a rewindable result set
+ ResultSet tmp = queryExecution.execSelect();
+ rs = ResultSetFactory.makeRewindable(tmp);
} catch (HTTPException e) {
- logger.debug("HTTPException in SparqlQuery\n"+ e.toString());
- logger.debug("query was "+ sparqlQueryString);
- writeToSparqlLog("ERROR: HTTPException occured"+ e.toString());
+ logger.debug("HTTPException in SparqlQuery\n" + e.toString());
+ logger.debug("query was " + sparqlQueryString);
+ writeToSparqlLog("ERROR: HTTPException occured" + e.toString());
isRunning = false;
throw e;
-
- }catch (RuntimeException e) {
-
- if(logger.isDebugEnabled()) {
- logger.debug("RuntimeException in SparqlQuery (see /log/sparql.txt): "+ e.toString());
- int length = Math.min(sparqlQueryString.length(), 300);
- logger.debug("query was (max. 300 chars displayed) "+ sparqlQueryString.substring(0,length-1).replaceAll("\n", " "));
+ // TODO: RuntimeException is very general; is it possible to catch more specific exceptions?
+ } catch (RuntimeException e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("RuntimeException in SparqlQuery (see /log/sparql.txt): "
+ + e.toString());
+ int length = Math.min(sparqlQueryString.length(), 300);
+ logger.debug("query was (max. 300 chars displayed) "
+ + sparqlQueryString.substring(0, length - 1).replaceAll("\n", " "));
}
- writeToSparqlLog("ERROR: HTTPException occured: "+ e.toString());
+ writeToSparqlLog("ERROR: HTTPException occured: " + e.toString());
isRunning = false;
throw e;
}
-
- // there is a minor issue here: Jamon now also measures ResultsetConversion
- // the code would need a second try catch block to handle it correctly
+
httpTime.stop();
- isRunning = false;
+ isRunning = false;
+ wasExecuted = true;
+ return rs;
}
-
-
/**
* Stops the execution of the query.
*/
@@ -163,6 +152,7 @@
/**
* Gets the String representation of the SPARQL query.
+ *
* @return sparqlQueryString
*/
public String getSparqlQueryString() {
@@ -185,111 +175,59 @@
}
/**
- * @return the Jena QueryEngineHTTP
- */
- // ANY NEED TO GET THIS FROM OUTSIDE?
- @Deprecated
- public QueryEngineHTTP getExecution() {
- return queryExecution;
- }
-
- /**
- * insert a result, e.g. from the cache
- * @param json a jsonString
- */
- // LOOKS LIKE A HACK
- @Deprecated
- public void setJson(String json) {
- this.wasExecuted = true;
- this.json = json;
- }
-
- /**
- * @param running s.e.
- */
- // SHOULD NOT BE SET FROM OUTSIDE
- @Deprecated
- public void setRunning(boolean running) {
- this.isRunning = running;
- }
-
- /**
- * returns the Result of the query as JSON string executes the query if it
- * wasn't executed before.
+ * Return the result in JSON format.
*
- * @return a JSON string
+ * @return A JSON string converted from the result set or null
+ * if the query has not been executed.
*/
- // WHY NOT EXECUTE SEND() AND THEN CALL THIS METHOD?
- // returning null seems safer instead of executing the query (again)
- @Deprecated
public String getJson() {
- if (!wasExecuted) {
- this.send();
+ if(wasExecuted) {
+ return convertResultSetToJSON(rs);
+ } else {
+ return null;
}
- return json;
}
/**
- * makes a ResultSet from the Json String, depends on getJSON.
+ * Converts the result set to an XML string.
*
- * @return a Jena ResultSet
- */
- // SHOULD BE A SIMPLE GETTER SINCE RESULTSET IS MAIN JENA STRUCTURE
- public ResultSet getResultSet() {
- return (getJson() == null) ? null : convertJSONtoResultSet(json);
- }
-
- /**
- * makes an XML String from the Json String, depends on getJSON.
- *
* @return An XML String
*/
- // SHOULD CONVERT FROM RESULTSET
public String getXMLString() {
- return (getJson() == null) ? null : convertJSONtoXML(json);
+ if(wasExecuted) {
+ return convertResultSetToXMLString(rs);
+ } else {
+ return null;
+ }
}
/**
- * Special log for debugging SPARQL query execution.
- * It lives here: "log/sparql.txt"
- * if the directory doesn't exist, there could be an error.
- * @param s the String to log
+ * Special log for debugging SPARQL query execution. It lives here:
+ * "log/sparql.txt" if the directory doesn't exist, there could be an error.
+ *
+ * @param s
+ * the String to log
*/
- public static void writeToSparqlLog(String s) {
-
- if(!logDeletedOnStart){
- Files.createFile(new File("log/sparql.txt"),s+"\n");
+ private static void writeToSparqlLog(String s) {
+ if (!logDeletedOnStart) {
+ Files.createFile(new File(sparqlLog), s + "\n");
logDeletedOnStart = true;
- }else{
- Files.appendFile(new File("log/sparql.txt"), s+"\n");
+ } else {
+ Files.appendFile(new File(sparqlLog), s + "\n");
}
-
- /*try {
-
- FileWriter fw = new FileWriter("log/sparql.txt", logDeletedOnStart);
- logDeletedOnStart = true;
- fw.write(s + "\n");
- fw.flush();
- fw.close();
- } catch (Exception e) {
- e.printStackTrace();
- // make the e object more special FileNotFound??
- //new File("log").mkdir();
- //writeToSparqlLog(s);
- }*/
}
-
/**
- * Converts Jena result set to XML.
- * To make a ResultSet rewindable use:
- * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
- * @param resultSet The result set to transform, must be rewindable to prevent errors.
+ * Converts Jena result set to XML. To make a ResultSet rewindable use:
+ * ResultSetRewindable rsRewind =
+ * ResultSetFactory.makeRewindable(resultSet);
+ *
+ * @param resultSet
+ * The result set to transform, must be rewindable to prevent
+ * errors.
* @return String xml
*/
public static String convertResultSetToXMLString(ResultSetRewindable resultSet) {
- // if (rs == null)
- // this.send();
String retVal = ResultSetFormatter.asXMLString(resultSet);
resultSet.reset();
return retVal;
@@ -297,11 +235,10 @@
/**
* Converts Jena result set to JSON.
- * To make a ResultSet rewindable use:
- * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
*
* @param resultSet
- * The result set to transform, must be rewindable to prevent errors.
+ * The result set to transform, must be rewindable to prevent
+ * errors.
* @return JSON representation of the result set.
*/
public static String convertResultSetToJSON(ResultSetRewindable resultSet) {
@@ -340,5 +277,5 @@
public static String convertJSONtoXML(String json) {
return convertResultSetToXMLString(convertJSONtoResultSet(json));
}
-
+
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -23,7 +23,6 @@
import org.dllearner.kb.sparql.SPARQLTasks;
import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlQuery;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
@@ -54,7 +53,7 @@
query += "<" + dbpediaURI + "> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long . } LIMIT 1";
// perform query and read lat and long from results
- ResultSet results = st.queryAsResultSet2(query);
+ ResultSet results = st.queryAsResultSet(query);
QuerySolution qs = results.nextSolution();
String geoLat = qs.getLiteral("lat").getString();
String geoLong = qs.getLiteral("long").getString();
Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -828,15 +828,11 @@
@Override
public void run() {
if (ks.isUseCache()){
- state.getQuery(id).setRunning(true);
Cache cache=new Cache(ks.getCacheDir());
cache.executeSparqlQuery(state.getQuery(id));
- state.getQuery(id).setRunning(false);
}
else{
- state.getQuery(id).setRunning(true);
state.getQuery(id).send();
- state.getQuery(id).setRunning(false);
}
}
};
Modified: trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2009-04-01 11:01:11 UTC (rev 1676)
+++ trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2009-04-01 11:17:54 UTC (rev 1677)
@@ -22,6 +22,7 @@
import org.dllearner.kb.sparql.SparqlEndpoint;
import org.dllearner.kb.sparql.SparqlQuery;
+import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
@@ -82,8 +83,8 @@
for (int i = 0; i < howOften; i++) {
// sqJena.getAsList();
- sqJena.send();
- ResultSetFormatter.toList(sqJena.getResultSet());
+ ResultSet rs = sqJena.send();
+ ResultSetFormatter.toList(rs);
p("Jena as List needed: "
+ (System.currentTimeMillis() - tmp));
tmp = System.currentTimeMillis();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-06 10:58:50
|
Revision: 1682
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1682&view=rev
Author: jenslehmann
Date: 2009-04-06 10:58:30 +0000 (Mon, 06 Apr 2009)
Log Message:
-----------
fixed some problems detected by unit tests
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
trunk/src/dl-learner/org/dllearner/utilities/Helper.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -266,7 +266,7 @@
public boolean hasTypeImpl(Description description, Individual individual)
throws ReasoningMethodUnsupportedException {
-// System.out.println(description + " " + individual);
+// System.out.println("FIC: " + description + " " + individual);
if (description instanceof NamedClass) {
return classInstancesPos.get((NamedClass) description).contains(individual);
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -1,3 +1,22 @@
+/**
+ * Copyright (C) 2007-2009, 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.HashSet;
@@ -22,6 +41,13 @@
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.datastructures.SortedSetTuple;
+/**
+ *
+ * Reasoner for fast retrieval inference (other tasks redirected to OWL API reasoner). Not actively used anymore.
+ *
+ * @author Jens Lehmann
+ *
+ */
public class FastRetrievalReasoner extends ReasonerComponent {
private FastRetrievalReasonerConfigurator configurator;
@@ -36,16 +62,13 @@
Set<ObjectProperty> atomicRoles;
SortedSet<Individual> individuals;
- ReasonerComponent rs;
ReasonerComponent rc;
-
-
public FastRetrievalReasoner(Set<KnowledgeSource> sources) {
super(sources);
this.configurator = new FastRetrievalReasonerConfigurator(this);
- rc = ComponentFactory.getDIGReasoner(sources);
+ rc = ComponentFactory.getOWLAPIReasoner(sources);
try {
rc.init();
} catch (ComponentInitException e1) {
@@ -57,7 +80,7 @@
individuals = rc.getIndividuals();
// rs = new ReasonerComponent(rc);
try {
- abox = Helper.createFlatABox(rs);
+ abox = Helper.createFlatABox(rc);
} catch (ReasoningMethodUnsupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -130,7 +153,7 @@
// Negation neg = new Negation(subConcept);
// Intersection c = new Intersection(neg,superConcept);
// return fastRetrieval.calculateSets(c).getPosSet().isEmpty();
- return rs.isSuperClassOf(superConcept, subConcept);
+ return rc.isSuperClassOf(superConcept, subConcept);
}
// @Override
@@ -154,7 +177,7 @@
@Override
public boolean isSatisfiableImpl() {
- return rs.isSatisfiable();
+ return rc.isSatisfiable();
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -185,6 +185,8 @@
public RhoDRDown(ReasonerComponent reasoningService) {
// this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null);
this.rs = reasoningService;
+ this.subHierarchy = rs.getClassHierarchy();
+ init();
}
public RhoDRDown(ReasonerComponent reasoner, ClassHierarchy subHierarchy, Description startClass, RefinementOperatorConfigurator configurator) {
Modified: trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -48,7 +48,12 @@
JUnitCore.main("org.dllearner.test.junit.ComponentTests",
"org.dllearner.test.junit.ReasonerTests",
- "org.dllearner.test.junit.RefinementOperatorTests");
+ "org.dllearner.test.junit.RefinementOperatorTests",
+ "org.dllearner.test.junit.ELDescriptionTreeTests",
+ "org.dllearner.test.junit.ELDownTests",
+ "org.dllearner.test.junit.MinimizeTests",
+ "org.dllearner.test.junit.SimulationTests",
+ "org.dllearner.test.junit.UtilitiesTests");
}
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -85,7 +85,7 @@
ConceptTransformation.cleanConcept(d);
ELDescriptionTree tree = new ELDescriptionTree(rs, d);
// clone performance (false for simple unit test, true for clone performance test)
- boolean testPerformance = true;
+ boolean testPerformance = false;
ELDescriptionTree treeCloned = null;
if(testPerformance) {
int runs = 1000000;
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -284,6 +284,7 @@
}
}
+ // not part of the regular test suite, since Galen 2 is required
// @Test
public void test4() throws ComponentInitException, ParseException, IOException {
@@ -312,6 +313,7 @@
}
+ // not part of the regular test suite, since Galen 2 is required
// @Test
public void asTest() throws ComponentInitException, MalformedURLException {
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -39,8 +39,8 @@
import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
+import org.dllearner.reasoning.DIGReasoner;
import org.dllearner.reasoning.FastInstanceChecker;
-import org.dllearner.reasoning.OWLAPIReasoner;
import org.junit.Test;
/**
@@ -78,8 +78,13 @@
* Performs an instance checks on all reasoner components to verify that
* they all return the correct result.
*/
-// @Test
+ @Test
public void instanceCheckTest() {
+
+ // DIG can be excluded from test since it requires a separate DIG reasoner and is no
+ // longer the default reasoning mechanism
+ boolean excludeDIG = true;
+
try {
ComponentManager cm = ComponentManager.getInstance();
KB kb = getSimpleKnowledgeBase();
@@ -91,6 +96,9 @@
Individual i = new Individual(KBParser.getInternalURI("stephen"));
List<Class<? extends ReasonerComponent>> reasonerClasses = cm.getReasonerComponents();
for (Class<? extends ReasonerComponent> reasonerClass : reasonerClasses) {
+ if(excludeDIG && reasonerClass.equals(DIGReasoner.class)) {
+ continue;
+ }
ReasonerComponent reasoner = cm.reasoner(reasonerClass, ks);
reasoner.init();
// long startTime = System.nanoTime();
@@ -116,7 +124,7 @@
* @throws ComponentInitException
* @throws ParseException
*/
-// @Test
+ @Test
public void fastInstanceCheckTest() throws ComponentInitException, ParseException {
String file = "examples/carcinogenesis/carcinogenesis.owl";
ComponentManager cm = ComponentManager.getInstance();
@@ -128,7 +136,7 @@
e.printStackTrace();
}
ks.init();
- ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, ks);
+ ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks);
reasoner.init();
baseURI = reasoner.getBaseURI();
@@ -137,7 +145,7 @@
List<List<Individual>> negIndividuals = new LinkedList<List<Individual>>();
// TODO manually verify that the results are indeed correct
- testDescriptions.add(KBParser.parseConcept("\"http://dl-learner.org/carcinogenesis#Compound\" AND (\"http://dl-learner.org/carcinogenesis#amesTestPositive\" = true OR >= 2 \"http://dl-learner.org/carcinogenesis#hasStructure\" \"http://dl-learner.org/carcinogenesis#Ar_halide\"))"));
+ testDescriptions.add(KBParser.parseConcept("(\"http://dl-learner.org/carcinogenesis#Compound\" AND ((\"http://dl-learner.org/carcinogenesis#amesTestPositive\" IS TRUE) OR >= 2 \"http://dl-learner.org/carcinogenesis#hasStructure\".\"http://dl-learner.org/carcinogenesis#Ar_halide\"))"));
posIndividuals.add(getIndSet("d113","d133","d171","d262","d265","d294","d68","d77","d79"));
negIndividuals.add(getIndSet("d139","d199","d202","d203","d283","d42"));
@@ -150,16 +158,18 @@
List<Individual> neg = negIndividuals.get(i);
for(Individual ind : pos) {
+ System.out.println("description: " + description.toString(baseURI, null) + " individual: " + ind.toString(baseURI, null));
assertTrue(reasoner.hasType(description, ind));
}
for(Individual ind : neg) {
+ System.out.println("description: " + description.toString(baseURI, null) + " individual: " + ind.toString(baseURI, null));
assertTrue(!reasoner.hasType(description, ind));
}
}
}
-// @Test
+ @Test
public void fastInstanceCheck2() throws ComponentInitException, ParseException {
String file = "examples/epc/sap_epc.owl";
ComponentManager cm = ComponentManager.getInstance();
@@ -217,7 +227,8 @@
}
private String uri(String name) {
- return "\""+baseURI+name+"\"";
+// return "\""+baseURI+name+"\"";
+ return baseURI+name;
}
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -102,13 +102,13 @@
RhoDRDown op = new RhoDRDown(reasoner);
Description concept = KBParser.parseConcept("(\"http://localhost/aris/sap_model.owl#EPC\" AND EXISTS \"http://localhost/aris/sap_model.owl#hasModelElements\".\"http://localhost/aris/sap_model.owl#Object\")");
- Set<Description> results = op.refine(concept, 6);
+ Set<Description> results = op.refine(concept,10);
for(Description result : results) {
- System.out.println(result);
+ System.out.println(result.toString("http://localhost/aris/sap_model.owl#",null));
}
- int desiredResultSize = 141;
+ int desiredResultSize = 116;
if(results.size() != desiredResultSize) {
System.out.println(results.size() + " results found, but should be " + desiredResultSize + ".");
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -122,10 +122,10 @@
KnowledgeSource source;
// parse KB string if one has been specified
- if(!kbString.isEmpty()) {
+ if(!kbString.isEmpty() || ont.equals(TestOntology.EMPTY)) {
KB kb = KBParser.parseKBFile(kbString);
source = new KBFile(kb);
- // parse OWL file otherwise
+ // do nothing for empty ontology
} else {
source = cm.knowledgeSource(OWLFile.class);
try {
Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2009-04-03 07:48:52 UTC (rev 1681)
+++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2009-04-06 10:58:30 UTC (rev 1682)
@@ -556,18 +556,22 @@
long dematStartTime = System.currentTimeMillis();
FlatABox aBox = new FlatABox(); // FlatABox.getInstance();
- for (NamedClass atomicConcept : rs.getNamedClasses()) {
- aBox.atomicConceptsPos.put(atomicConcept.getName(), getStringSet(rs
- .getIndividuals(atomicConcept)));
- Negation negatedAtomicConcept = new Negation(atomicConcept);
- aBox.atomicConceptsNeg.put(atomicConcept.getName(), getStringSet(rs
- .getIndividuals(negatedAtomicConcept)));
- aBox.concepts.add(atomicConcept.getName());
+ if(!rs.getNamedClasses().isEmpty()) {
+ for (NamedClass atomicConcept : rs.getNamedClasses()) {
+ aBox.atomicConceptsPos.put(atomicConcept.getName(), getStringSet(rs
+ .getIndividuals(atomicConcept)));
+ Negation negatedAtomicConcept = new Negation(atomicConcept);
+ aBox.atomicConceptsNeg.put(atomicConcept.getName(), getStringSet(rs
+ .getIndividuals(negatedAtomicConcept)));
+ aBox.concepts.add(atomicConcept.getName());
+ }
}
- for (ObjectProperty atomicRole : rs.getObjectProperties()) {
- aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getPropertyMembers(atomicRole)));
- aBox.roles.add(atomicRole.getName());
+ if(!rs.getObjectProperties().isEmpty()) {
+ for (ObjectProperty atomicRole : rs.getObjectProperties()) {
+ aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getPropertyMembers(atomicRole)));
+ aBox.roles.add(atomicRole.getName());
+ }
}
aBox.domain = getStringSet(rs.getIndividuals());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-06 12:23:46
|
Revision: 1683
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1683&view=rev
Author: jenslehmann
Date: 2009-04-06 12:23:42 +0000 (Mon, 06 Apr 2009)
Log Message:
-----------
reasoning problem fixed (unit tests continued)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-06 10:58:30 UTC (rev 1682)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-06 12:23:42 UTC (rev 1683)
@@ -638,7 +638,12 @@
if(set.size()==0)
return new Thing();
OWLClass oc = (OWLClass) set.iterator().next().iterator().next();
- return new NamedClass(oc.getURI().toString());
+ String str = oc.getURI().toString();
+ if(str.equals("http://www.w3.org/2002/07/owl#Thing")) {
+ return new Thing();
+ } else {
+ return new NamedClass(str);
+ }
} catch (OWLReasonerException e) {
throw new Error(e);
}
@@ -657,7 +662,12 @@
if(set.size()==0)
return new Thing();
OWLClass oc = (OWLClass) set.iterator().next().iterator().next();
- return new NamedClass(oc.getURI().toString());
+ String str = oc.getURI().toString();
+ if(str.equals("http://www.w3.org/2002/07/owl#Thing")) {
+ return new Thing();
+ } else {
+ return new NamedClass(str);
+ }
} catch (OWLReasonerException e) {
throw new Error(e);
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-06 10:58:30 UTC (rev 1682)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-04-06 12:23:42 UTC (rev 1683)
@@ -393,8 +393,9 @@
computeTopRefinements(maxLength);
refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone();
} else {
- if(maxLength>topARefinementsLength.get(currDomain))
+ if(maxLength>topARefinementsLength.get(currDomain)) {
computeTopRefinements(maxLength, (NamedClass) currDomain);
+ }
refinements = (TreeSet<Description>) topARefinementsCumulative.get(currDomain).get(maxLength).clone();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-08 14:18:11
|
Revision: 1689
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1689&view=rev
Author: jenslehmann
Date: 2009-04-08 14:18:01 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved domain to description conversion to separate method
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-08 14:00:46 UTC (rev 1688)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-08 14:18:01 UTC (rev 1689)
@@ -48,7 +48,6 @@
import org.dllearner.core.options.InvalidConfigOptionValueException;
import org.dllearner.core.options.StringConfigOption;
import org.dllearner.core.owl.Axiom;
-import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Constant;
import org.dllearner.core.owl.Datatype;
import org.dllearner.core.owl.DatatypeProperty;
@@ -102,8 +101,6 @@
import org.semanticweb.owl.util.SimpleURIMapper;
import org.semanticweb.owl.vocab.NamespaceOWLOntologyFormat;
-import uk.ac.manchester.cs.owl.OWLPropertyAxiomImpl;
-
/**
* Mapping to OWL API reasoner interface. The OWL API currently
* supports two reasoners: FaCT++ and Pellet. FaCT++ is connected
@@ -632,45 +629,10 @@
public Description getDomainImpl(ObjectProperty objectProperty) {
OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty);
try {
- // TODO: look up why OWL API return a two dimensional set here
- // instead of only one description (probably there can be several
- // domain axiom for one property and the inner set is a conjunction
- // of descriptions (?))
- // Answer: this function is just horribly broken in OWL API
+ // Pellet returns a set of sets of named class, which are more
+ // general than the actual domain/range
Set<Set<OWLDescription>> set = reasoner.getDomains(prop);
-
-
- if(set.size()==0)
- return new Thing();
-
- Set<OWLDescription> union = new HashSet<OWLDescription>();
- Set<OWLDescription> domains = new HashSet<OWLDescription>();
-
- for(Set<OWLDescription> descs : set){
- for(OWLDescription desc : descs){
- union.add(desc);
- }
- }
- for(OWLDescription desc : union){
- boolean isSuperClass = false;
- for(Description d : getClassHierarchy().getSubClasses(OWLAPIConverter.convertClass(desc.asOWLClass()))){
- if(union.contains(OWLAPIConverter.getOWLAPIDescription(d))){
- isSuperClass = true;
- break;
- }
- }
- if(!isSuperClass){
- domains.add(desc);
- }
- }
-
- OWLClass oc = (OWLClass) domains.iterator().next();
- String str = oc.getURI().toString();
- if(str.equals("http://www.w3.org/2002/07/owl#Thing")) {
- return new Thing();
- } else {
- return new NamedClass(str);
- }
+ return getDescriptionFromReturnedDomain(set);
} catch (OWLReasonerException e) {
throw new Error(e);
}
@@ -680,43 +642,9 @@
public Description getDomainImpl(DatatypeProperty datatypeProperty) {
OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty);
try {
- // TODO: look up why OWL API return a two dimensional set here
- // instead of only one description (probably there can be several
- // domain axiom for one property and the inner set is a conjunction
- // of descriptions (?))
- // Answer: this function is just horribly broken in OWL API
Set<Set<OWLDescription>> set = reasoner.getDomains(prop);
- if(set.size()==0)
- return new Thing();
-
- Set<OWLDescription> union = new HashSet<OWLDescription>();
- Set<OWLDescription> domains = new HashSet<OWLDescription>();
-
- for(Set<OWLDescription> descs : set){
- for(OWLDescription desc : descs){
- union.add(desc);
- }
- }
- for(OWLDescription desc : union){
- boolean isSuperClass = false;
- for(Description d : getClassHierarchy().getSubClasses(OWLAPIConverter.convertClass(desc.asOWLClass()))){
- if(union.contains(OWLAPIConverter.getOWLAPIDescription(d))){
- isSuperClass = true;
- break;
- }
- }
- if(!isSuperClass){
- domains.add(desc);
- }
- }
-
- OWLClass oc = (OWLClass) domains.iterator().next();
- String str = oc.getURI().toString();
- if(str.equals("http://www.w3.org/2002/07/owl#Thing")) {
- return new Thing();
- } else {
- return new NamedClass(str);
- }
+ return getDescriptionFromReturnedDomain(set);
+
} catch (OWLReasonerException e) {
throw new Error(e);
}
@@ -736,6 +664,40 @@
}
}
+ private Description getDescriptionFromReturnedDomain(Set<Set<OWLDescription>> set) {
+ if(set.size()==0)
+ return new Thing();
+
+ Set<OWLDescription> union = new HashSet<OWLDescription>();
+ Set<OWLDescription> domains = new HashSet<OWLDescription>();
+
+ for(Set<OWLDescription> descs : set){
+ for(OWLDescription desc : descs){
+ union.add(desc);
+ }
+ }
+ for(OWLDescription desc : union){
+ boolean isSuperClass = false;
+ for(Description d : getClassHierarchy().getSubClasses(OWLAPIConverter.convertClass(desc.asOWLClass()))){
+ if(union.contains(OWLAPIConverter.getOWLAPIDescription(d))){
+ isSuperClass = true;
+ break;
+ }
+ }
+ if(!isSuperClass){
+ domains.add(desc);
+ }
+ }
+
+ OWLClass oc = (OWLClass) domains.iterator().next();
+ String str = oc.getURI().toString();
+ if(str.equals("http://www.w3.org/2002/07/owl#Thing")) {
+ return new Thing();
+ } else {
+ return new NamedClass(str);
+ }
+ }
+
@Override
public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) {
OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole);
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-04-08 14:00:46 UTC (rev 1688)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-04-08 14:18:01 UTC (rev 1689)
@@ -22,7 +22,6 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.util.LinkedList;
import java.util.List;
@@ -39,7 +38,6 @@
import org.dllearner.core.owl.KB;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
-import org.dllearner.core.owl.Thing;
import org.dllearner.kb.KBFile;
import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-09 12:53:12
|
Revision: 1693
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1693&view=rev
Author: jenslehmann
Date: 2009-04-09 12:53:04 +0000 (Thu, 09 Apr 2009)
Log Message:
-----------
test case
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/PelletBug.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-09 11:47:12 UTC (rev 1692)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-09 12:53:04 UTC (rev 1693)
@@ -495,6 +495,7 @@
@Override
public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) {
try {
+// System.out.println("super: " + superConcept + "; sub: " + subConcept);
return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept));
} catch (OWLReasonerException e) {
e.printStackTrace();
Added: trunk/src/dl-learner/org/dllearner/test/PelletBug.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/PelletBug.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/PelletBug.java 2009-04-09 12:53:04 UTC (rev 1693)
@@ -0,0 +1,50 @@
+package org.dllearner.test;
+
+import java.io.File;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.semanticweb.owl.apibinding.OWLManager;
+import org.semanticweb.owl.inference.OWLReasoner;
+import org.semanticweb.owl.inference.OWLReasonerException;
+import org.semanticweb.owl.model.OWLClass;
+import org.semanticweb.owl.model.OWLDataFactory;
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLOntology;
+import org.semanticweb.owl.model.OWLOntologyCreationException;
+import org.semanticweb.owl.model.OWLOntologyManager;
+
+public class PelletBug {
+
+ public static void main(String[] args) throws OWLOntologyCreationException, OWLReasonerException {
+
+ OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+ File f = new File("examples/family/father_oe.owl");
+ URI physicalURI = f.toURI();
+ OWLOntology ontology = manager.loadOntologyFromPhysicalURI(physicalURI);
+ OWLDataFactory factory = manager.getOWLDataFactory();
+
+ String ontologyURI = "http://example.com/father#";
+
+ // super: (http://example.com/father#female AND http://example.com/father#male); sub: http://example.com/father#female
+
+ OWLClass male = factory.getOWLClass(URI.create(ontologyURI + "male"));
+ OWLClass female = factory.getOWLClass(URI.create(ontologyURI + "female"));
+// OWLDescription negA = factory.getOWLObjectComplementOf(a);
+ OWLDescription insat = factory.getOWLObjectIntersectionOf(male, female);
+// OWLClass d = factory.getOWLClass(URI.create(ontologyURI + "#b"));
+
+ Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
+ ontologies.add(ontology);
+
+ OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager);
+ reasoner.loadOntologies(ontologies);
+
+ boolean result = reasoner.isSubClassOf(female, insat);
+ System.out.println(result);
+
+// System.out.println(reasoner.getIndividuals(female, true));
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-14 07:01:54
|
Revision: 1695
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1695&view=rev
Author: jenslehmann
Date: 2009-04-14 07:01:50 +0000 (Tue, 14 Apr 2009)
Log Message:
-----------
test case showing a bug in Pellet
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
trunk/src/dl-learner/org/dllearner/test/PelletBug.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-09 16:36:41 UTC (rev 1694)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2009-04-14 07:01:50 UTC (rev 1695)
@@ -1051,17 +1051,23 @@
public boolean remainsSatisfiableImpl(Axiom axiom) {
boolean consistent = true;
OWLAxiom axiomOWLAPI = OWLAPIAxiomConvertVisitor.convertAxiom(axiom);
+
try {
manager.applyChange(new AddAxiom(ontology, axiomOWLAPI));
+ } catch (OWLOntologyChangeException e1) {
+ e1.printStackTrace();
+ }
+
+ try {
consistent = reasoner.isConsistent(ontology);
+ } catch (OWLReasonerException e) {
+ e.printStackTrace();
+ }
+
+ try {
manager.applyChange(new RemoveAxiom(ontology, axiomOWLAPI));
-
} catch (OWLOntologyChangeException e) {
-
e.printStackTrace();
- } catch (OWLReasonerException e) {
-
- e.printStackTrace();
}
return consistent;
Modified: trunk/src/dl-learner/org/dllearner/test/PelletBug.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/PelletBug.java 2009-04-09 16:36:41 UTC (rev 1694)
+++ trunk/src/dl-learner/org/dllearner/test/PelletBug.java 2009-04-14 07:01:50 UTC (rev 1695)
@@ -8,16 +8,22 @@
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.inference.OWLReasonerException;
+import org.semanticweb.owl.model.AddAxiom;
+import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLDataFactory;
import org.semanticweb.owl.model.OWLDescription;
import org.semanticweb.owl.model.OWLOntology;
+import org.semanticweb.owl.model.OWLOntologyChangeException;
import org.semanticweb.owl.model.OWLOntologyCreationException;
import org.semanticweb.owl.model.OWLOntologyManager;
+import org.semanticweb.owl.model.OWLOntologyStorageException;
+import org.semanticweb.owl.model.RemoveAxiom;
+import org.semanticweb.owl.model.UnknownOWLOntologyException;
public class PelletBug {
- public static void main(String[] args) throws OWLOntologyCreationException, OWLReasonerException {
+ public static void main(String[] args) throws OWLOntologyCreationException, OWLReasonerException, UnknownOWLOntologyException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File f = new File("examples/family/father_oe.owl");
@@ -25,26 +31,54 @@
OWLOntology ontology = manager.loadOntologyFromPhysicalURI(physicalURI);
OWLDataFactory factory = manager.getOWLDataFactory();
+ // create a view class expressions and an axiom
String ontologyURI = "http://example.com/father#";
-
- // super: (http://example.com/father#female AND http://example.com/father#male); sub: http://example.com/father#female
-
OWLClass male = factory.getOWLClass(URI.create(ontologyURI + "male"));
OWLClass female = factory.getOWLClass(URI.create(ontologyURI + "female"));
-// OWLDescription negA = factory.getOWLObjectComplementOf(a);
+ OWLClass father = factory.getOWLClass(URI.create(ontologyURI + "father"));
OWLDescription insat = factory.getOWLObjectIntersectionOf(male, female);
-// OWLClass d = factory.getOWLClass(URI.create(ontologyURI + "#b"));
+ OWLDescription test = factory.getOWLObjectComplementOf(male);
+ OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(father, test);
+ // load ontology
Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
ontologies.add(ontology);
-
OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager);
reasoner.loadOntologies(ontologies);
+ // first subsumption check => everything runs smoothly
boolean result = reasoner.isSubClassOf(female, insat);
- System.out.println(result);
+ System.out.println("subsumption before: " + result);
+
+ // add axiom causing the ontology to be inconsistent
+ try {
+ manager.applyChange(new AddAxiom(ontology, axiom));
+ } catch (OWLOntologyChangeException e1) {
+ e1.printStackTrace();
+ }
-// System.out.println(reasoner.getIndividuals(female, true));
+ // Pellet correctly detects the inconsistency
+ try {
+ System.out.println("consistent: " + reasoner.isConsistent(ontology));
+ } catch (OWLReasonerException e) {
+ e.printStackTrace();
+ }
+
+ // remove axiom
+ try {
+ manager.applyChange(new RemoveAxiom(ontology, axiom));
+ } catch (OWLOntologyChangeException e) {
+ e.printStackTrace();
+ }
+
+ // save file to verify that it remained unchanged (it is unchanged)
+ manager.saveOntology(ontology, new File("test.owl").toURI());
+
+ // perform subsumption check => Pellet now fails due to an inconsistency,
+ // although the ontology is unchanged from the point of view of the OWL API
+ result = reasoner.isSubClassOf(female, insat);
+ System.out.println("subsumption after: " + result);
+
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-17 09:34:46
|
Revision: 1710
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1710&view=rev
Author: jenslehmann
Date: 2009-04-17 09:34:44 +0000 (Fri, 17 Apr 2009)
Log Message:
-----------
CELOE bug fixes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-04-17 06:36:08 UTC (rev 1709)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-04-17 09:34:44 UTC (rev 1710)
@@ -410,7 +410,7 @@
} else {
// none of the superclasses of the class to learn must appear on the
// outermost property level
- TreeSet<Description> toTest = new TreeSet<Description>();
+ TreeSet<Description> toTest = new TreeSet<Description>(descriptionComparator);
toTest.add(classToDescribe);
while(!toTest.isEmpty()) {
Description d = toTest.pollFirst();
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-04-17 06:36:08 UTC (rev 1709)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2009-04-17 09:34:44 UTC (rev 1710)
@@ -39,6 +39,7 @@
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.Property;
import org.dllearner.core.owl.Restriction;
import org.dllearner.core.owl.Union;
import org.dllearner.core.owl.Negation;
@@ -572,6 +573,11 @@
}
}
+ /**
+ * Counts occurrences of \forall in description.
+ * @param description A description.
+ * @return Number of \forall occurrences.
+ */
public static int getForallOccurences(Description description) {
int count = 0;
if(description instanceof ObjectAllRestriction) {
@@ -583,6 +589,13 @@
return count;
}
+ /**
+ * Gets the "contexts" of all \forall occurrences in a description. A context
+ * is a set of properties, i.e. in \exists hasChild.\exists hasBrother.\forall hasChild.male,
+ * the context of the only \forall occurrence is [hasChild, hasBrother, hasChild].
+ * @param description A description.
+ * @return Set of property contexts.
+ */
public static SortedSet<PropertyContext> getForallContexts(Description description) {
return getForallContexts(description, new PropertyContext());
}
@@ -590,17 +603,23 @@
private static SortedSet<PropertyContext> getForallContexts(Description description, PropertyContext currentContext) {
// the context changes if we have a restriction
if(description instanceof Restriction) {
- ObjectProperty op = (ObjectProperty) ((Restriction)description).getRestrictedPropertyExpression();
- currentContext.add(op);
- // if we have an all-restriction, we return it; otherwise we only change the context
- // and call the method on the child
- if(description instanceof ObjectAllRestriction) {
- TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>();
- contexts.add(currentContext);
- contexts.addAll(getForallContexts(description.getChild(0), currentContext));
- return contexts;
+ Property op = (Property) ((Restriction)description).getRestrictedPropertyExpression();
+ // object restrictions
+ if(op instanceof ObjectProperty) {
+ currentContext.add((ObjectProperty)op);
+ // if we have an all-restriction, we return it; otherwise we only change the context
+ // and call the method on the child
+ if(description instanceof ObjectAllRestriction) {
+ TreeSet<PropertyContext> contexts = new TreeSet<PropertyContext>();
+ contexts.add(currentContext);
+ contexts.addAll(getForallContexts(description.getChild(0), currentContext));
+ return contexts;
+ } else {
+ return getForallContexts(description.getChild(0), currentContext);
+ }
+ // we have a data restriction => no \forall can occur in those
} else {
- return getForallContexts(description.getChild(0), currentContext);
+ return new TreeSet<PropertyContext>();
}
// for non-restrictions, we collect contexts over all children
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-19 16:38:25
|
Revision: 1715
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1715&view=rev
Author: jenslehmann
Date: 2009-04-19 16:38:14 +0000 (Sun, 19 Apr 2009)
Log Message:
-----------
- fixed sorting issues in learning algorithm results (now SortedSet is in ascending order as required in Java)
- fixed remaining warnings
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java
trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java
trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java
trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java
trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java
trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -227,7 +227,7 @@
}
@Override
- public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
return bestEvaluatedDescriptions.getSet();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.log4j.Logger;
@@ -217,7 +216,7 @@
}
@Override
- public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
return bestEvaluatedDescriptions.getSet();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -1037,10 +1037,10 @@
}
@Override
- public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
+ public TreeSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
int count = 0;
SortedSet<Node> rev = candidatesStable.descendingSet();
- SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
+ TreeSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
for(Node eb : rev) {
cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getSolutionScore(eb.getConcept())));
// return a maximum of 200 elements (we need a maximum, because the
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -25,7 +25,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -456,7 +456,7 @@
}
@Override
- public synchronized SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
+ public synchronized TreeSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
return algorithm.getCurrentlyBestEvaluatedDescriptions();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -1198,10 +1198,10 @@
return best;
}
- public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
+ public TreeSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
Iterator<ExampleBasedNode> it = candidatesStable.descendingIterator();
int count = 0;
- SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
+ TreeSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
while(it.hasNext()) {
ExampleBasedNode eb = it.next();
cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getScore(eb.getConcept())));
@@ -1280,7 +1280,7 @@
if(this.stop){
return true;
}
- System.out.println("ssssss");
+// System.out.println("ssssss");
long totalTimeNeeded = System.currentTimeMillis() - this.runtime;
long maxMilliSeconds = maxExecutionTimeInSeconds * 1000;
long minMilliSeconds = minExecutionTimeInSeconds * 1000;
Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import java.util.SortedSet;
import java.util.TreeSet;
import org.dllearner.core.owl.Description;
@@ -204,10 +203,10 @@
/**
* Returns a sorted set of the best descriptions found so far. We
* assume that they are ordered such that the best ones come in
- * first.
+ * last. (In Java, iterators traverse a SortedSet in ascending order.)
* @return Best class descriptions found so far.
*/
- public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
TreeSet<EvaluatedDescription> ds = new TreeSet<EvaluatedDescription>();
ds.add(getCurrentlyBestEvaluatedDescription());
return ds;
@@ -232,9 +231,9 @@
* @return A list of currently best class descriptions.
*/
public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) {
- SortedSet<? extends EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions();
+ TreeSet<? extends EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions();
List<EvaluatedDescription> returnList = new LinkedList<EvaluatedDescription>();
- for(EvaluatedDescription ed : currentlyBest) {
+ for(EvaluatedDescription ed : currentlyBest.descendingSet()) {
// once we hit a description with a below threshold accuracy, we simply return
// because learning algorithms are advised to order descriptions by accuracy,
// so we won't find any concept with higher accuracy in the remaining list
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ClassLearningProblemConfigurator.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -63,7 +63,7 @@
return (String) ComponentManager.getInstance().getConfigOptionValue(classLearningProblem, "classToDescribe") ;
}
/**
-* type Whether to learn an equivalence class or super class axiom..
+* type Whether to learn an equivalence class or super class axiom or domain/range of a property..
* mandatory: false| reinit necessary: true
* default value: equivalence
* @return String
@@ -81,7 +81,7 @@
ComponentManager.getInstance().applyConfigEntry(classLearningProblem, "classToDescribe", classToDescribe);
}
/**
-* @param type Whether to learn an equivalence class or super class axiom..
+* @param type Whether to learn an equivalence class or super class axiom or domain/range of a property..
* mandatory: false| reinit necessary: true
* default value: equivalence
**/
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLComponent2Configurator.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -26,12 +26,14 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.configurators.RefinementOperatorConfigurator;
/**
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class ROLComponent2Configurator extends RefinementOperatorConfigurator implements Configurator {
+@SuppressWarnings("all")
+public class ROLComponent2Configurator extends RefinementOperatorConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
@@ -331,15 +333,6 @@
return (Boolean) ComponentManager.getInstance().getConfigOptionValue(rOLComponent2, "usePropernessChecks") ;
}
/**
-* maxPosOnlyExpansion specifies how often a node in the search tree of a posonly learning problem needs to be expanded before it is considered as solution candidate.
-* mandatory: false| reinit necessary: true
-* default value: 4
-* @return int
-**/
-public int getMaxPosOnlyExpansion() {
-return (Integer) ComponentManager.getInstance().getConfigOptionValue(rOLComponent2, "maxPosOnlyExpansion") ;
-}
-/**
* noisePercentage the (approximated) percentage of noise within the examples.
* mandatory: false| reinit necessary: true
* default value: 0.0
@@ -683,15 +676,6 @@
reinitNecessary = true;
}
/**
-* @param maxPosOnlyExpansion specifies how often a node in the search tree of a posonly learning problem needs to be expanded before it is considered as solution candidate.
-* mandatory: false| reinit necessary: true
-* default value: 4
-**/
-public void setMaxPosOnlyExpansion(int maxPosOnlyExpansion) {
-ComponentManager.getInstance().applyConfigEntry(rOLComponent2, "maxPosOnlyExpansion", maxPosOnlyExpansion);
-reinitNecessary = true;
-}
-/**
* @param noisePercentage the (approximated) percentage of noise within the examples.
* mandatory: false| reinit necessary: true
* default value: 0.0
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -67,6 +67,7 @@
return result;
}
+ @Override
public Set<OWLDescription> visit(OWLObjectExactCardinalityRestriction desc)
{
Set<OWLDescription> fillers = computeBeta((OWLDescription)desc.getFiller());
@@ -79,6 +80,7 @@
return result;
}
+ @Override
public Set<OWLDescription> visit(OWLObjectUnionOf desc)
{
return super.visit(desc);
@@ -96,16 +98,19 @@
return result;
}
+ @Override
protected OWLClass getLimit()
{
return getDataFactory().getOWLNothing();
}
+ @Override
protected OWLDataRange getDataLimit()
{
return getDataFactory().getOWLDataComplementOf(getDataFactory().getTopDataType());
}
+ @Override
public Set<OWLDescription> visit(OWLDataValueRestriction desc)
{
return Collections.singleton((OWLDescription)desc);
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -67,6 +67,7 @@
return result;
}
+ @Override
public Set<OWLDescription> visit(OWLObjectExactCardinalityRestriction desc)
{
Set<OWLDescription> fillers = computeBeta((OWLDescription)desc.getFiller());
@@ -79,6 +80,7 @@
return result;
}
+ @Override
public Set<OWLDescription> visit(OWLObjectUnionOf desc)
{
return super.visit(desc);
@@ -96,16 +98,19 @@
return result;
}
+ @Override
protected OWLClass getLimit()
{
return getDataFactory().getOWLNothing();
}
+ @Override
protected OWLDataRange getDataLimit()
{
return getDataFactory().getOWLDataComplementOf(getDataFactory().getTopDataType());
}
+ @Override
public Set<OWLDescription> visit(OWLDataValueRestriction desc)
{
return Collections.singleton((OWLDescription)desc);
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -68,11 +68,13 @@
return result;
}
+ @Override
protected OWLClass getLimit()
{
return getDataFactory().getOWLThing();
}
+ @Override
protected OWLDataRange getDataLimit()
{
return getDataFactory().getTopDataType();
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -68,11 +68,13 @@
return result;
}
+ @Override
protected OWLClass getLimit()
{
return getDataFactory().getOWLThing();
}
+ @Override
protected OWLDataRange getDataLimit()
{
return getDataFactory().getTopDataType();
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java 2009-04-19 09:27:10 UTC (rev 1714)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java 2009-04-19 16:38:14 UTC (rev 1715)
@@ -43,16 +43,16 @@
double acc1 = ed1.getAccuracy();
double acc2 = ed2.getAccuracy();
if(acc1 > acc2)
+ return 1;
+ else if(acc1 < acc2)
return -1;
- else if(acc1 < acc2)
- return 1;
else {
int length1 = ed1.getDescriptionLength();
int length2 = ed2.getDescriptionLength();
if(length1 < length2)
+ return 1;
+ else if(length1 > length2)
return -1;
- else if(length1 > length2)
- return 1;
else
return cc.compare(ed1.getDescription(), ed2.getDescription());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-21 13:06:42
|
Revision: 1721
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1721&view=rev
Author: jenslehmann
Date: 2009-04-21 13:06:39 +0000 (Tue, 21 Apr 2009)
Log Message:
-----------
running matching script (needs a lot more tuning)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/Info.java
trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java
trunk/src/dl-learner/org/dllearner/scripts/matching/Point.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Modified: trunk/src/dl-learner/org/dllearner/Info.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/Info.java 2009-04-20 17:32:06 UTC (rev 1720)
+++ trunk/src/dl-learner/org/dllearner/Info.java 2009-04-21 13:06:39 UTC (rev 1721)
@@ -3,6 +3,6 @@
package org.dllearner;
public class Info {
- public static final String build = "2009-04-17";
+ public static final String build = "2009-04-20";
}
\ No newline at end of file
Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-20 17:32:06 UTC (rev 1720)
+++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-21 13:06:39 UTC (rev 1721)
@@ -24,13 +24,21 @@
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Collection;
+import java.util.LinkedList;
import org.dllearner.kb.sparql.SparqlEndpoint;
import org.dllearner.kb.sparql.SparqlQuery;
+import org.dllearner.utilities.Files;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
+import com.wcohen.ss.Jaro;
+import com.wcohen.ss.api.StringDistance;
/**
* Computes owl:sameAs links between DBpedia and LinkedGeoData
@@ -41,16 +49,27 @@
*/
public class DBpediaLinkedGeoData {
- // chose between nt and csv
- private static String dbpediaFileFormat = "csv";
+ // chose between nt and dat
+ private static String dbpediaFileFormat = "dat";
private static File dbpediaFile = new File("log/DBpedia_POIs." + dbpediaFileFormat);
private static boolean regenerateFile = false;
private static File matchingFile = new File("log/DBpedia_GeoData_Links.nt");
+ private static File missesFile = new File("log/DBpedia_GeoData_Misses.dat");
+ private static double scoreThreshold = 0.8;
+ private static StringDistance distance = new Jaro();
private static SparqlEndpoint dbpediaEndpoint = SparqlEndpoint.getEndpointLOCALDBpedia();
private static SparqlEndpoint geoDataEndpoint = SparqlEndpoint.getEndpointLOCALGeoData();
+ // read in DBpedia ontology such that we perform taxonomy reasoning
+// private static ReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.DBPEDIA_OWL);
+// private static ClassHierarchy hierarchy = reasoner.getClassHierarchy();
+
+ // true = SPARQL is used for retrieving close points;
+ // false = Triplify spatial extension is used
+ private static boolean useSparqlForGettingNearbyPoints = false;
+
public static void main(String[] args) throws IOException {
// download all objects having geo-coordinates from DBpedia if necessary
@@ -58,34 +77,66 @@
createDBpediaFile();
}
+ Files.clearFile(matchingFile);
+ Files.clearFile(missesFile);
FileOutputStream fos = new FileOutputStream(matchingFile, true);
+ FileOutputStream fosMiss = new FileOutputStream(missesFile, true);
// read file point by point
BufferedReader br = new BufferedReader(new FileReader(dbpediaFile));
String line;
int counter = 0;
int matches = 0;
+
+ // temporary variables needed while reading in file
+ int itemCount = 0;
+ URI uri = null;
+ String label = null;
+ String[] classes = null;
+ int decimalCount = 0;
+ double geoLat = 0;
+ double geoLong = 0;
+
while ((line = br.readLine()) != null) {
- // read line and convert it into an object
- String[] parts = line.split(",");
- URI uri = URI.create(parts[0]);
- String label = parts[1];
- double geoLat = new Double(parts[2]);
- double geoLong = new Double(parts[3]);
- DBpediaPoint dp = new DBpediaPoint(uri, label, geoLat, geoLong);
-
- // find match (we assume there is exactly one match)
- URI matchURI = findGeoDataMatch(dp);
- if(matchURI != null) {
- String matchStr = "<" + uri + "> <http://www.w3.org/2002/07/owl#sameAs> <" + matchURI + "> .\n";
- fos.write(matchStr.getBytes());
- matches++;
+ if(line.isEmpty()) {
+ DBpediaPoint dp = new DBpediaPoint(uri, label, classes, geoLat, geoLong, decimalCount);
+
+ // find match (we assume there is exactly one match)
+ URI matchURI = findGeoDataMatch(dp);
+ if(matchURI == null) {
+ String missStr = dp.toString() + "\n";
+ fosMiss.write(missStr.getBytes());
+ } else {
+ String matchStr = "<" + dp.getUri() + "> <http://www.w3.org/2002/07/owl#sameAs> <" + matchURI + "> .\n";
+ fos.write(matchStr.getBytes());
+ matches++;
+ }
+ counter++;
+
+ if(counter % 1000 == 0) {
+ System.out.println(counter + " points processed. " + matches + " matches found.");
+ }
+
+ itemCount = 0;
+ } else {
+ switch(itemCount) {
+ case 0 : uri = URI.create(line); break;
+ case 1 : label = line; break;
+ case 2 : classes = line.substring(1, line.length()).split(","); break;
+ case 3 :
+ geoLat = new Double(line);
+ decimalCount = 0;
+ String[] tmp = line.split(".");
+ if(tmp.length == 2) {
+ decimalCount = tmp[1].length();
+ }
+ break;
+ case 4: geoLong = new Double(line);
+ }
+
+ itemCount++;
}
- counter++;
- if(counter % 1000 == 0) {
- System.out.println(counter + " points processed. " + matches + " matches found.");
- }
}
br.close();
fos.close();
@@ -99,98 +150,194 @@
int offset = 0;
int counter = 0;
+ int points = 0;
FileOutputStream fos = new FileOutputStream(dbpediaFile, true);
do {
counter = 0;
// query DBpedia for all objects having geo-coordinates
- String queryStr = "SELECT ?object, ?lat, ?long, ?label WHERE {";
+ String queryStr = "SELECT ?object, ?lat, ?long, ?label, ?type WHERE {";
queryStr += "?object <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .";
queryStr += "?object <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long .";
- queryStr += "?object rdfs:label ?label . }";
+ queryStr += "?object rdfs:label ?label . ";
+ queryStr += "OPTIONAL { ?object rdf:type ?type . ";
+ queryStr += "FILTER (!(?type LIKE <http://dbpedia.org/ontology/Resource>)) .";
+ queryStr += "FILTER (?type LIKE <http://dbpedia.org/ontology/%>) .";
+ queryStr += "} }";
queryStr += "LIMIT " + limit + " OFFSET " + offset;
SparqlQuery query = new SparqlQuery(queryStr, dbpediaEndpoint);
ResultSet rs = query.send();
+ String previousObject = null;
+ String geoLat = "";
+ String geoLong = "";
+ String label = "";
+ Collection<String> types = new LinkedList<String>();
while(rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
String object = qs.get("object").toString();
- String geoLat = qs.getLiteral("lat").getString();
- String geoLong = qs.getLiteral("long").getString();
- String label = qs.getLiteral("label").getString();
- String content = "";
- if(dbpediaFileFormat.equals("nt")) {
- content += "<" + object + ">" + " <http://www.w3.org/2000/01/rdf-schema#label> \"" + label + "\" .\n";
- content += "<" + object + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#lat> \"" + geoLat + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n";
- content += "<" + object + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#long> \"" + geoLong + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n";
+ if(object.equals(previousObject)) {
+ // only type has changed compared to previous row
+ types.add(qs.get("type").toString());
+
+ // we are only interested in the most special DBpedia class
+// NamedClass nc = new NamedClass(typeTmp);
+// if(hierarchy.getSubClasses(nc).size()==1) {
+ // usually there is just one type assigned in the DBpedia ontology
+// if(!type.equals("unknown")) {
+// throw new Error("two different types for " + object + ": " + type + " and " + typeTmp);
+// }
+// type = typeTmp;
+// }
} else {
- content += object + ",\"" + label + "\"," + geoLat + "," + geoLong + "\n";
+ if(previousObject != null) {
+ // we have new a new point => write previous point to file
+ String content = "";
+ if(dbpediaFileFormat.equals("nt")) {
+ content += "<" + previousObject + ">" + " <http://www.w3.org/2000/01/rdf-schema#label> \"" + label + "\" .\n";
+ for(String type : types) {
+ content += "<" + previousObject + ">" + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> \"" + type + "\" .\n";
+ }
+ content += "<" + previousObject + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#lat> \"" + geoLat + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n";
+ content += "<" + previousObject + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#long> \"" + geoLong + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n";
+ } else {
+ content += previousObject + "\n" + label + "\n" + types.toString().replace(" ", "") + "\n" + geoLat + "\n" + geoLong + "\n\n";
+ }
+
+ fos.write(content.getBytes());
+
+ }
+
+ // reset default values
+ types.clear();
+
+ // get new data
+ geoLat = qs.getLiteral("lat").getString();
+ geoLong = qs.getLiteral("long").getString();
+ label = qs.getLiteral("label").getString();
+ if(qs.contains("type")) {
+ types.add(qs.get("type").toString());
+
+ // we are only interested in the most special DBpedia class
+// NamedClass nc = new NamedClass(typeTmp);
+// if(hierarchy.getSubClasses(nc).size()==1) {
+ // usually there is just one type assigned in the DBpedia ontology
+// if(!type.equals("unknown")) {
+// throw new Error("two different types for " + object + ": " + type + " and " + typeTmp);
+// }
+// type = typeTmp;
+// }
+ }
+
+ previousObject = object;
+ points++;
}
-
- fos.write(content.getBytes());
-
+
counter++;
}
offset += limit;
- System.out.println(offset + " points queried.");
+ System.out.println(points + " points queried.");
} while(counter == limit);
fos.close();
}
- private static URI findGeoDataMatch(DBpediaPoint dbpediaPoint) {
+ private static URI findGeoDataMatch(DBpediaPoint dbpediaPoint) throws IOException {
- // get all GeoData points close to the given point
-// SparqlQuery query = new SparqlQuery("", geoDataEndpoint);
+ // 1 degree is about 111 km (depending on the specific point)
+ int distanceThresholdMeters = 1000;
+ boolean quiet = true;
- /*
- int distanceThresholdMeters = 100;
-
- // use official DBpedia endpoint (switch to db0 later)
- SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia();
- SPARQLTasks st = new SPARQLTasks(endpoint);
-
- // query latitude and longitude
- String query = "SELECT ?lat ?long WHERE { ";
- query += "<" + dbpediaURI + "> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .";
- query += "<" + dbpediaURI + "> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long . } LIMIT 1";
-
- // perform query and read lat and long from results
- ResultSet results = st.queryAsResultSet(query);
- QuerySolution qs = results.nextSolution();
- String geoLat = qs.getLiteral("lat").getString();
- String geoLong = qs.getLiteral("long").getString();
-
- System.out.println("lat: " + geoLat + ", long: " + geoLong);
-
- URL linkedGeoDataURL = new URL("http://linkedgeodata.org/triplify/near/"+geoLat+","+geoLong+"/"+distanceThresholdMeters);
-
- // TODO: replace by SPARQL query
-
- URLConnection conn = linkedGeoDataURL.openConnection();
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- StringBuffer sb = new StringBuffer();
- String line="";
-// int pointID = 0;
- while ((line = rd.readLine()) != null)
- {
- if(line.contains("Auerbach")) {
- System.out.println(line);
+ if(useSparqlForGettingNearbyPoints) {
+ // TODO: convert from meters to lat/long
+ double distanceThresholdLat = 0.3;
+ double distanceThresholdLong = 0.3;
+
+ // create a box around the point
+ double minLat = dbpediaPoint.getGeoLat() - distanceThresholdLat;
+ double maxLat = dbpediaPoint.getGeoLat() + distanceThresholdLat;
+ double minLong = dbpediaPoint.getGeoLong() - distanceThresholdLong;
+ double maxLong = dbpediaPoint.getGeoLong() + distanceThresholdLong;
+
+ // query all points in the box
+ String queryStr = "select ?point ?lat ?long ?name where { ";
+ queryStr += "?point <http://linkedgeodata.org/vocabulary/latitude> ?lat .";
+ queryStr += "FILTER (xsd:float(?lat) > " + minLat + ") .";
+ queryStr += "FILTER (xsd:float(?lat) < " + maxLat + ") .";
+ queryStr += "?point <http://linkedgeodata.org/vocabulary/longitude> ?long .";
+ queryStr += "FILTER (xsd:float(?long) > " + minLong + ") .";
+ queryStr += "FILTER (xsd:float(?long) < " + maxLong + ") .";
+ queryStr += "?point <http://linkedgeodata.org/vocabulary/name> ?name .";
+ queryStr += "}";
+
+ SparqlQuery query = new SparqlQuery(queryStr, geoDataEndpoint);
+ ResultSet rs = query.send();
+
+ while(rs.hasNext()) {
+// QuerySolution qs = rs.nextSolution();
+
+ // measure string similarity and proximity
+ // TODO: incomplete
+ }
+ return null;
+ // use Tripliy spatial extension
+ } else {
+ if(dbpediaPoint.getGeoLat() < 0 || dbpediaPoint.getGeoLong() < 0) {
+ return null;
}
- sb.append(line);
+ if(!quiet)
+ System.out.println(dbpediaPoint.getLabel());
+
+ URL linkedGeoDataURL = new URL("http://linkedgeodata.org/triplify/near/"+dbpediaPoint.getGeoLat()+","+dbpediaPoint.getGeoLong()+"/"+distanceThresholdMeters);
+
+ double highestScore = 0;
+ String bestURI = null;
+ String bestLabel = null;
+ URLConnection conn = linkedGeoDataURL.openConnection();
+ BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+// StringBuffer sb = new StringBuffer();
+ String line="";
+ while ((line = rd.readLine()) != null)
+ {
+ if(line.contains("<http://linkedgeodata.org/vocabulary#name>") || line.contains("<http://linkedgeodata.org/vocabulary/#name%25en>")) {
+ int first = line.indexOf("\"") + 1;
+ int last = line.lastIndexOf("\"");
+ String label = line.substring(first, last);
+
+ // perform string similarity
+ // (we can use a variety of string matching heuristics)
+ double score = distance.score(label, dbpediaPoint.getLabel());
+ if(score > highestScore) {
+ highestScore = score;
+ bestURI = line.substring(1, line.indexOf(" ")-1);
+ bestLabel = label;
+ }
+ }
+// sb.append(line);
+ }
+ rd.close();
+
+ if(!quiet) {
+ System.out.println(" " + linkedGeoDataURL);
+ System.out.println(" " + highestScore);
+ System.out.println(" " + bestURI);
+ System.out.println(" " + bestLabel);
+ }
+
+ if(highestScore > scoreThreshold) {
+// System.out.println(" match");
+ return URI.create(bestURI);
+ } else {
+// System.out.println(" no match");
+ return null;
+ }
}
- rd.close();
-
-// System.out.println(sb.toString());
-
- */
- return null;
}
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java 2009-04-20 17:32:06 UTC (rev 1720)
+++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java 2009-04-21 13:06:39 UTC (rev 1721)
@@ -32,11 +32,19 @@
private URI uri;
private String label;
+
+ private String[] classes;
- public DBpediaPoint(URI uri, String label, double geoLat, double geoLong) {
+ // decimal count in latitude value => indicator for size of object (no or low
+ // number of decimals indicates a large object)
+ private int decimalCount;
+
+ public DBpediaPoint(URI uri, String label, String[] classes, double geoLat, double geoLong, int decimalCount) {
super(geoLat,geoLong);
this.uri = uri;
this.label = label;
+ this.classes = classes;
+ this.decimalCount = decimalCount;
}
/**
@@ -53,4 +61,23 @@
return label;
}
+ public String[] getClasses() {
+ return classes;
+ }
+
+ /**
+ * @return the decimalCount
+ */
+ public int getDecimalCount() {
+ return decimalCount;
+ }
+
+ @Override
+ public String toString() {
+ String str = uri + ", \"" + label + "\", " + geoLat + ", " + geoLong + " (classes: ";
+ for(String clazz : classes) {
+ str += clazz + " ";
+ }
+ return str + ")";
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/Point.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/matching/Point.java 2009-04-20 17:32:06 UTC (rev 1720)
+++ trunk/src/dl-learner/org/dllearner/scripts/matching/Point.java 2009-04-21 13:06:39 UTC (rev 1721)
@@ -27,9 +27,9 @@
*/
public class Point {
- private double geoLat;
+ protected double geoLat;
- private double geoLong;
+ protected double geoLong;
public Point(double geoLat, double geoLong) {
this.geoLat = geoLat;
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-20 17:32:06 UTC (rev 1720)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-04-21 13:06:39 UTC (rev 1721)
@@ -41,7 +41,7 @@
*/
public final class TestOntologies {
- public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES, FATHER_OE, CARCINOGENESIS, EPC_OE, KRK_ZERO_ONE };
+ public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES, FATHER_OE, CARCINOGENESIS, EPC_OE, KRK_ZERO_ONE, DBPEDIA_OWL };
public static ReasonerComponent getTestOntology(TestOntology ont) {
String kbString = "";
@@ -117,7 +117,9 @@
owlFile = "examples/epc/sap_epc_oe.owl";
} else if(ont.equals(TestOntology.KRK_ZERO_ONE)) {
owlFile = "examples/krk/KRK_ZERO_ONE.owl";
- }
+ } else if(ont.equals(TestOntology.DBPEDIA_OWL)) {
+ owlFile = "/home/jl/promotion/ontologien/dbpedia.owl";
+ }
try {
ComponentManager cm = ComponentManager.getInstance();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-04-25 13:29:45
|
Revision: 1727
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1727&view=rev
Author: jenslehmann
Date: 2009-04-25 13:29:42 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Protege plugin release preparations
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
trunk/src/dl-learner/org/dllearner/tools/protege/INSTALL
Removed Paths:
-------------
trunk/src/dl-learner/org/dllearner/tools/protege/protege-4.0.110.zip
Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-25 09:49:53 UTC (rev 1726)
+++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-25 13:29:42 UTC (rev 1727)
@@ -29,6 +29,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
+import java.util.Date;
import java.util.LinkedList;
import org.dllearner.kb.sparql.SparqlEndpoint;
@@ -114,7 +115,7 @@
counter++;
if(counter % 1000 == 0) {
- System.out.println(counter + " points processed. " + matches + " matches found.");
+ System.out.println(new Date().toString() + ": " + counter + " points processed. " + matches + " matches found.");
}
itemCount = 0;
Modified: trunk/src/dl-learner/org/dllearner/tools/protege/INSTALL
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/protege/INSTALL 2009-04-25 09:49:53 UTC (rev 1726)
+++ trunk/src/dl-learner/org/dllearner/tools/protege/INSTALL 2009-04-25 13:29:42 UTC (rev 1727)
@@ -1,16 +1,15 @@
Requirements
============
-Java 6 and the Protégé 4.0 Beta are required. (All other libraries are included in the release.)
+Java 6 and the Protégé 4.0 Beta are required. (All other libraries are
+included in the release.)
Installation
============
-Put the DL-Learner-protege-plugin.jar in your plugin folder of Protégé.
+Put the DL-Learner-protege-plugin.jar in your plugin folder of Protégé.
+(The plugin is also included in the Protégé plugin repository, so you
+can install it within Protégé.)
Running Instructions
====================
-To use the plugin go to view --> class views and click on class descriptions (including DL-Learner plugin).
-Put the new frame somewhere in the classes tab in Protégé and close the old class description view. All features are included in the plugin.
-
-If you have problems look at the screen cast: http://dl-learner.org/wiki/ProtegePlugin.
-
-
+Please have a look at the wiki page and screen cast:
+http://dl-learner.org/wiki/ProtegePlugin.
Deleted: trunk/src/dl-learner/org/dllearner/tools/protege/protege-4.0.110.zip
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|