From: <jen...@us...> - 2011-04-01 09:38:17
|
Revision: 2743 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2743&view=rev Author: jenslehmann Date: 2011-04-01 09:38:11 +0000 (Fri, 01 Apr 2011) Log Message: ----------- continued design of learning algorithm interfaces, including better support for active learning Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/BruteForceLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/ClassExpressionLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/FuzzyClassExpressionLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/SparqlQueryLearningAlgorithm.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/ActiveLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/Oracle.java trunk/components-core/src/main/java/org/dllearner/core/ResumableLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/StoppableLearningAlgorithm.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/BruteForceLearner.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/BruteForceLearner.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -308,24 +308,6 @@ } /* (non-Javadoc) - * @see org.dllearner.core.LearningAlgorithm#pause() - */ - @Override - public void pause() { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.dllearner.core.LearningAlgorithm#resume() - */ - @Override - public void resume() { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) * @see org.dllearner.core.LearningAlgorithm#isRunning() */ @Override Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -487,18 +487,6 @@ return algorithm.getStartNode(); } - /** {@inheritDoc} */ - @Override - public void pause() { - // TODO: not implemented - } - - /** {@inheritDoc} */ - @Override - public void resume() { - // TODO: not implemented - } - /* (non-Javadoc) * @see org.dllearner.core.LearningAlgorithm#isRunning() */ Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -39,10 +39,14 @@ * may require addition reasoner queries, because the learning * algorithms usually use but do not necessarily store this information. * + * Changes (March/April 2011): Learning algorithms no longer have to use + * this class, but it still serves as a prototypical template for class + * expression learning algorithms. + * * @author Jens Lehmann * */ -public abstract class AbstractCELA extends Component { +public abstract class AbstractCELA extends Component implements ClassExpressionLearningAlgorithm, StoppableLearningAlgorithm { /** * The learning problem variable, which must be used by @@ -102,43 +106,8 @@ * choose to store results.) */ public static final int MAX_NR_OF_RESULTS = 100; - + /** - * Starts the algorithm. It runs until paused, stopped, or - * a termination criterion has been reached. - */ - public abstract void start(); - - /** - * Pauses the algorithm (not all algorithms need to implement - * this operation). - */ - public void pause() { }; - - /** - * Resumes the algorithm (not all algorithms need to implement - * this operation). You can use this method to continue - * an algorithm run even after a termination criterion has been - * reached. It will run until paused, stopped, or terminated - * again. - */ - public void resume() { }; - - /** - * Stops the algorithm gracefully. A stopped algorithm cannot be resumed anymore. - * Use this method for cleanup and freeing memory. - */ - public abstract void stop(); - - /** - * Returns whether the learning algorithm is running. Implementation - * should use a boolean status variable in their implementations of - * the start and resume methods. - * @return True if the algorithm is running, false otherwise. - */ - public abstract boolean isRunning(); - - /** * Every algorithm must be able to return the score of the * best solution found. * Added: trunk/components-core/src/main/java/org/dllearner/core/ActiveLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ActiveLearningAlgorithm.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/ActiveLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + + +/** + * Active Learning algorithms are those, which can use feedback from an oracle. + * + * @author Jens Lehmann + * + */ +public interface ActiveLearningAlgorithm { + + /** + * In order to separate/hide the implementation of an oracle from the active learning algorithm itself, + * an oracle object is passed to the algorithm. + * @param oracle The oracle to be used by the learning algorithm. + */ + public void setOracle(Oracle oracle); + +} Modified: trunk/components-core/src/main/java/org/dllearner/core/ClassExpressionLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ClassExpressionLearningAlgorithm.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/core/ClassExpressionLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -19,6 +19,10 @@ */ package org.dllearner.core; +import java.util.List; + +import org.dllearner.core.owl.Description; + /** * Basic interface for algorithms learning OWL/DL class expressions. * @@ -27,4 +31,19 @@ */ public interface ClassExpressionLearningAlgorithm extends LearningAlgorithm { + /** + * @see #getCurrentlyBestEvaluatedDescriptions(int) + * @param nrOfDescriptions Limit for the number or returned descriptions. + * @return The best class descriptions found by the learning algorithm so far. + */ + public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions); + + /** + * Return the best currently found concepts up to some maximum + * count (no minimality filter used). + * @param nrOfDescriptions Maximum number of descriptions returned. + * @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false). + */ + public List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions); + } Modified: trunk/components-core/src/main/java/org/dllearner/core/FuzzyClassExpressionLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/FuzzyClassExpressionLearningAlgorithm.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/core/FuzzyClassExpressionLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -19,12 +19,33 @@ */ package org.dllearner.core; +import java.util.List; + +import org.dllearner.core.owl.Description; + /** * Basic interface for algorithms learning fuzzy OWL/DL class expressions. * + * TODO: Probably needs to be adapted. + * * @author Jens Lehmann * */ public interface FuzzyClassExpressionLearningAlgorithm extends LearningAlgorithm { + /** + * @see #getCurrentlyBestEvaluatedDescriptions(int) + * @param nrOfDescriptions Limit for the number or returned descriptions. + * @return The best class descriptions found by the learning algorithm so far. + */ + public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions); + + /** + * Return the best currently found concepts up to some maximum + * count (no minimality filter used). + * @param nrOfDescriptions Maximum number of descriptions returned. + * @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false). + */ + public List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions); + } Modified: trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/core/LearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -19,6 +19,7 @@ */ package org.dllearner.core; + /** * Basic interface for all DL-Learner learning algorithms. * @@ -27,4 +28,10 @@ */ public interface LearningAlgorithm { + /** + * Starts the algorithm. It runs until paused, stopped, or + * a termination criterion has been reached. + */ + public abstract void start(); + } Added: trunk/components-core/src/main/java/org/dllearner/core/Oracle.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/Oracle.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/Oracle.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.List; + +import org.dllearner.core.owl.Individual; + +/** + * + * An oracle can be used by a learning algorithm to interactively ask for the + * classification of an individual. Note that an oracle can either be a user or + * an automatic method, which means that the implementation of an oracle can + * reach from simple checks to more complex user interaction processes. + * + * @author Jens Lehmann + * + */ +public interface Oracle { + + /** + * This method should be called by a learning algorithm if it wants a list of individuals + * (including the special case of a single individual) to be classified by the oracle. + * + * For each of the individuals, which are specified in the parameter, the oracle must + * return a value in the obvious order. (The first element in the returned list classifies the first element + * of the list of individuals, the second element in the returned list classifies the + * second element of the individual list etc.) The following values should be used: + * + * <ul> + * <li>-1.0: Indicates that the individual does not belong to the learned class.</li> + * <li>Values between -1.0 and 1.0 indicate the degree to which an individual belongs to the class.</li> + * <li>1.0: The individual does belong to the learned class.</li> + * <li>-2.0: The oracle does not know how to classify the individual (e.g. no feedback given by a user).</li> + * </ul> + * + * Note that the most common case is that the individuals list contains a single element, which + * is answered by 1.0 or -1.0 by the oracle. However, the oracle interface is designed with a + * higher degree of flexibility in mind, which is required for some use cases. + * + * @param individuals A list of individuals, which should be classified by the oracle. + * @return For each element of the list, a classification value as explained above is + * returned. + * + */ + public List<Double> classifyIndividuals(List<Individual> individuals); + +} \ No newline at end of file Added: trunk/components-core/src/main/java/org/dllearner/core/ResumableLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ResumableLearningAlgorithm.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/ResumableLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * Interface for learning algorithms, which can be paused and later continued. + * + * @author Jens Lehmann + * + */ +public interface ResumableLearningAlgorithm { + + /** + * Pauses the algorithm (not all algorithms need to implement + * this operation). + */ + public void pause(); + + /** + * Resumes the algorithm (not all algorithms need to implement + * this operation). You can use this method to continue + * an algorithm run even after a termination criterion has been + * reached. It will run until paused, stopped, or terminated + * again. + */ + public void resume(); + +} Modified: trunk/components-core/src/main/java/org/dllearner/core/SparqlQueryLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/SparqlQueryLearningAlgorithm.java 2011-03-31 06:40:53 UTC (rev 2742) +++ trunk/components-core/src/main/java/org/dllearner/core/SparqlQueryLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -19,12 +19,24 @@ */ package org.dllearner.core; +import java.util.List; + /** * Basic interface for algorithms learning SPARQL queries. * + * TODO: Check whether it is necessary to have a "real" SPARQL query class instead of + * only a string. + * * @author Jens Lehmann * */ public interface SparqlQueryLearningAlgorithm extends LearningAlgorithm { + /** + * @see #getCurrentlyBestEvaluatedDescriptions(int) + * @param nrOfDescriptions Limit for the number or returned descriptions. + * @return The best SPARQL queries found by the learning algorithm so far. + */ + public List<String> getCurrentlyBestDescriptions(int nrOfDescriptions); + } Added: trunk/components-core/src/main/java/org/dllearner/core/StoppableLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/StoppableLearningAlgorithm.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/StoppableLearningAlgorithm.java 2011-04-01 09:38:11 UTC (rev 2743) @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * + * Interface for algorithms, which can be stopped and checked whether they are + * running. This allows learning algorithms to be run in separate threads or + * be terminated by the user. + * + * @author Jens Lehmann + * + */ +public interface StoppableLearningAlgorithm extends LearningAlgorithm { + + /** + * Stops the algorithm gracefully. A stopped algorithm cannot be resumed anymore. + * Use this method for cleanup and freeing memory. + */ + public abstract void stop(); + + /** + * Returns whether the learning algorithm is running. Implementation + * should use a boolean status variable in their implementations of + * the start and resume methods. + * @return True if the algorithm is running, false otherwise. + */ + public abstract boolean isRunning(); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-04-06 07:07:27
|
Revision: 2758 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2758&view=rev Author: jenslehmann Date: 2011-04-06 07:07:20 +0000 (Wed, 06 Apr 2011) Log Message: ----------- added option to allow/ignore classes in CELOE Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/configurators/CELOEConfigurator.java trunk/components-core/src/main/java/org/dllearner/core/configurators/ISLEConfigurator.java trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -38,6 +38,7 @@ import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.CELOEConfigurator; import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigMappings; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.DoubleConfigOption; @@ -183,7 +184,9 @@ options.add(new BooleanConfigOption("writeSearchTree", "specifies whether to write a search tree", false)); options.add(new StringConfigOption("searchTreeFile","file to use for the search tree", "log/searchTree.txt")); options.add(new BooleanConfigOption("replaceSearchTree","specifies whether to replace the search tree in the log file after each run or append the new search tree", false)); - options.add(new DoubleConfigOption("expansionPenaltyFactor","heuristic penalty per syntactic construct used (lower = finds more complex expression, but might miss simple ones)", 0.1)); + options.add(new DoubleConfigOption("expansionPenaltyFactor","heuristic penalty per syntactic construct used (lower = finds more complex expression, but might miss simple ones)", 0.1)); + options.add(CommonConfigOptions.allowedConcepts()); + options.add(CommonConfigOptions.ignoredConcepts()); return options; } @@ -193,9 +196,26 @@ @Override public void init() throws ComponentInitException { + + // compute used concepts/roles from allowed/ignored + // concepts/roles + Set<NamedClass> usedConcepts; + Set<NamedClass> allowedConcepts = CommonConfigMappings.getAtomicConceptSet(configurator.getAllowedConcepts()); + Set<NamedClass> ignoredConcepts = CommonConfigMappings.getAtomicConceptSet(configurator.getIgnoredConcepts()); + if(allowedConcepts != null) { + // sanity check to control if no non-existing concepts are in the list + Helper.checkConcepts(reasoner, allowedConcepts); + usedConcepts = allowedConcepts; + } else if(ignoredConcepts != null) { + usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoner, ignoredConcepts); + } else { + usedConcepts = Helper.computeConcepts(reasoner); + } + // copy class hierarchy and modify it such that each class is only // reachable via a single path - ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); +// ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().cloneAndRestrict(usedConcepts); classHierarchy.thinOutSubsumptionHierarchy(); heuristic = new OEHeuristicRuntime(configurator); Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/CELOEConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/CELOEConfigurator.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/CELOEConfigurator.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -20,6 +20,7 @@ package org.dllearner.core.configurators; +import java.util.Set; import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningProblem; @@ -137,7 +138,7 @@ return (Boolean) ComponentManager.getInstance().getConfigOptionValue(cELOE, "useBooleanDatatypes") ; } /** -* useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true * @return boolean @@ -271,6 +272,26 @@ public double getExpansionPenaltyFactor() { return (Double) ComponentManager.getInstance().getConfigOptionValue(cELOE, "expansionPenaltyFactor") ; } +/** +* allowedConcepts concepts the algorithm is allowed to use. +* mandatory: false| reinit necessary: true +* default value: null +* @return Set(String) +**/ +@SuppressWarnings("unchecked") +public Set<String> getAllowedConcepts() { +return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(cELOE, "allowedConcepts") ; +} +/** +* ignoredConcepts concepts the algorithm must ignore. +* mandatory: false| reinit necessary: true +* default value: null +* @return Set(String) +**/ +@SuppressWarnings("unchecked") +public Set<String> getIgnoredConcepts() { +return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(cELOE, "ignoredConcepts") ; +} /** * @param useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. @@ -354,7 +375,7 @@ reinitNecessary = true; } /** -* @param useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* @param useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true **/ @@ -488,6 +509,24 @@ ComponentManager.getInstance().applyConfigEntry(cELOE, "expansionPenaltyFactor", expansionPenaltyFactor); reinitNecessary = true; } +/** +* @param allowedConcepts concepts the algorithm is allowed to use. +* mandatory: false| reinit necessary: true +* default value: null +**/ +public void setAllowedConcepts(Set<String> allowedConcepts) { +ComponentManager.getInstance().applyConfigEntry(cELOE, "allowedConcepts", allowedConcepts); +reinitNecessary = true; +} +/** +* @param ignoredConcepts concepts the algorithm must ignore. +* mandatory: false| reinit necessary: true +* default value: null +**/ +public void setIgnoredConcepts(Set<String> ignoredConcepts) { +ComponentManager.getInstance().applyConfigEntry(cELOE, "ignoredConcepts", ignoredConcepts); +reinitNecessary = true; +} /** * true, if this component needs reinitializsation. Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/ISLEConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/ISLEConfigurator.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/ISLEConfigurator.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -137,7 +137,7 @@ return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useBooleanDatatypes") ; } /** -* useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true * @return boolean @@ -300,7 +300,7 @@ reinitNecessary = true; } /** -* @param useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* @param useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true **/ Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -277,7 +277,7 @@ return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useBooleanDatatypes") ; } /** -* useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true * @return boolean @@ -647,7 +647,7 @@ reinitNecessary = true; } /** -* @param useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* @param useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true **/ Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStandardConfigurator.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -75,7 +75,7 @@ return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(posNegLPStandard, "negativeExamples") ; } /** -* useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept.. +* useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: false * @return boolean @@ -93,7 +93,7 @@ return (Double) ComponentManager.getInstance().getConfigOptionValue(posNegLPStandard, "percentPerLenghtUnit") ; } /** -* useMultiInstanceChecks See UseMultiInstanceChecks enum.. +* useMultiInstanceChecks See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: twoChecks * @return String @@ -146,7 +146,7 @@ ComponentManager.getInstance().applyConfigEntry(posNegLPStandard, "negativeExamples", negativeExamples); } /** -* @param useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept.. +* @param useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: false **/ @@ -164,7 +164,7 @@ reinitNecessary = true; } /** -* @param useMultiInstanceChecks See UseMultiInstanceChecks enum.. +* @param useMultiInstanceChecks See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: twoChecks **/ Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java 2011-04-05 17:03:24 UTC (rev 2757) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/PosNegLPStrictConfigurator.java 2011-04-06 07:07:20 UTC (rev 2758) @@ -75,7 +75,7 @@ return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(posNegLPStrict, "negativeExamples") ; } /** -* useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept.. +* useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: false * @return boolean @@ -93,7 +93,7 @@ return (Double) ComponentManager.getInstance().getConfigOptionValue(posNegLPStrict, "percentPerLenghtUnit") ; } /** -* useMultiInstanceChecks See UseMultiInstanceChecks enum.. +* useMultiInstanceChecks See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: twoChecks * @return String @@ -146,7 +146,7 @@ ComponentManager.getInstance().applyConfigEntry(posNegLPStrict, "negativeExamples", negativeExamples); } /** -* @param useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept.. +* @param useRetrievalForClassficiation Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: false **/ @@ -164,7 +164,7 @@ reinitNecessary = true; } /** -* @param useMultiInstanceChecks See UseMultiInstanceChecks enum.. +* @param useMultiInstanceChecks See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.. * mandatory: false| reinit necessary: true * default value: twoChecks **/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-07-26 11:37:47
|
Revision: 2966 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2966&view=rev Author: lorenz_b Date: 2011-07-26 11:37:41 +0000 (Tue, 26 Jul 2011) Log Message: ----------- Some changes for better integration of QTL algorithm into DL-Learner. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/core/LearningProblemUnsupportedException.java trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-07-26 11:37:28 UTC (rev 2965) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-07-26 11:37:41 UTC (rev 2966) @@ -106,8 +106,8 @@ "org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive", "org.dllearner.algorithms.celoe.CELOE", "org.dllearner.algorithms.fuzzydll.FuzzyCELOE", //added by Josue - "org.dllearner.algorithms.isle.ISLE" - + "org.dllearner.algorithms.isle.ISLE", + "org.dllearner.algorithm.qtl.QTL" } )); private static ComponentManager cm = null; @@ -308,6 +308,10 @@ logger.warn("Warning: unregistered component " + component); } } + + public ComponentPool getPool() { + return pool; + } /** * Applies a config entry to a component. If the entry is not valid, the method Modified: trunk/components-core/src/main/java/org/dllearner/core/LearningProblemUnsupportedException.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/LearningProblemUnsupportedException.java 2011-07-26 11:37:28 UTC (rev 2965) +++ trunk/components-core/src/main/java/org/dllearner/core/LearningProblemUnsupportedException.java 2011-07-26 11:37:41 UTC (rev 2966) @@ -33,12 +33,12 @@ private static final long serialVersionUID = 177919265073997460L; - public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends AbstractCELA> algorithmClass) { + public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends LearningAlgorithm> algorithmClass) { super("Warning: No suitable constructor registered for algorithm " + algorithmClass.getName() + " and problem " + problemClass.getClass().getName() + "."); } - public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends AbstractCELA> algorithmClass, Collection<Class<? extends LearningProblem>> supportedProblems) { + public LearningProblemUnsupportedException(Class<? extends LearningProblem> problemClass, Class<? extends LearningAlgorithm> algorithmClass, Collection<Class<? extends LearningProblem>> supportedProblems) { super("Warning: No suitable constructor registered for algorithm " + algorithmClass.getName() + " and problem " + problemClass.getClass().getName() + ". Registered constructors for " + algorithmClass.getName() + ": " Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-07-26 11:37:28 UTC (rev 2965) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-07-26 11:37:41 UTC (rev 2966) @@ -71,5 +71,9 @@ @Override public void init() throws ComponentInitException { } + + public SparqlEndpoint getEndpoint() { + return endpoint; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-07-26 11:37:28 UTC (rev 2965) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-07-26 11:37:41 UTC (rev 2966) @@ -65,6 +65,7 @@ public PosOnlyLP() { super(null); + configurator = new PosOnlyLPConfigurator(this); } public PosOnlyLP(ReasonerComponent reasoningService) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-07-27 09:22:11
|
Revision: 2969 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2969&view=rev Author: lorenz_b Date: 2011-07-27 09:22:02 +0000 (Wed, 27 Jul 2011) Log Message: ----------- Started new learning algorithms for property axioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class DisjointPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public DisjointPropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class EquivalentPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public EquivalentPropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class FunctionalPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public FunctionalPropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class PropertyDomainAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public PropertyDomainAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class PropertyRangeAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public PropertyRangeAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class ReflexivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public ReflexivePropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class SubPropertyOfAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public SubPropertyOfAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class SymmetricPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public SymmetricPropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,53 @@ +package org.dllearner.algorithms.properties; + +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.kb.SparqlEndpointKS; + +public class TransitivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { + + @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") + private String propertyToDescribe; + + public String getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(String propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public TransitivePropertyAxiomLearner(SparqlEndpointKS ks){ + + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -0,0 +1,15 @@ +package org.dllearner.core; + +import java.util.List; + +import org.dllearner.core.owl.Axiom; + +public interface AxiomLearningAlgorithm extends LearningAlgorithm { + + /** + * @param nrOfAxioms Limit for the number or returned axioms. + * @return The best axiom found by the learning algorithm so far. + */ + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms); + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-07-27 04:46:43 UTC (rev 2968) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-07-27 09:22:02 UTC (rev 2969) @@ -107,7 +107,8 @@ "org.dllearner.algorithms.celoe.CELOE", "org.dllearner.algorithms.fuzzydll.FuzzyCELOE", //added by Josue "org.dllearner.algorithms.isle.ISLE", - "org.dllearner.algorithm.qtl.QTL" + "org.dllearner.algorithm.qtl.QTL", + "org.dllearner.algorithms.properties.SubPropertyOfAxiomLearner" } )); private static ComponentManager cm = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-07-28 08:30:47
|
Revision: 2971 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2971&view=rev Author: lorenz_b Date: 2011-07-28 08:30:40 +0000 (Thu, 28 Jul 2011) Log Message: ----------- Continued reasoner for SPARQL endpoints. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class DisjointPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class EquivalentPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class FunctionalPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class PropertyDomainAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class PropertyRangeAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class ReflexivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -1,29 +1,36 @@ package org.dllearner.algorithms.properties; +import java.beans.PropertyEditor; +import java.lang.reflect.Field; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.springframework.beans.propertyeditors.CustomNumberEditor; public class SubPropertyOfAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") - private String propertyToDescribe; + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds; - public String getPropertyToDescribe() { - return propertyToDescribe; - } - - public void setPropertyToDescribe(String propertyToDescribe) { - this.propertyToDescribe = propertyToDescribe; - } - + + private SparqlEndpointKS ks; + public SubPropertyOfAxiomLearner(SparqlEndpointKS ks){ - + this.ks = ks; } @Override @@ -50,4 +57,42 @@ } + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public static void main(String[] args) throws Exception{ + Map<String, String> propertiesMap = new HashMap<String, String>(); + propertiesMap.put("propertyToDescribe", "http://dbpedia.org/ontology/locatedIn"); + propertiesMap.put("maxExecutionTimeInSeconds", "20"); + + SubPropertyOfAxiomLearner l = new SubPropertyOfAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + + Field[] fields = l.getClass().getDeclaredFields(); + for(Field f : fields){ + ConfigOption option = f.getAnnotation(ConfigOption.class); + if(option != null){ + String configValue = propertiesMap.get(option.name()); + PropertyEditor editor = (PropertyEditor) option.propertyEditorClass().newInstance(); + editor.setAsText(configValue); + f.set(l, editor.getValue()); + } + } + + System.out.println(l.getPropertyToDescribe()); + System.out.println(l.getMaxExecutionTimeInSeconds()); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class SymmetricPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -11,7 +11,6 @@ public class TransitivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - @org.dllearner.ConfigOption(name="propertyToDescribe", description="property of which a axiom should be learned") private String propertyToDescribe; public String getPropertyToDescribe() { Added: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -0,0 +1,36 @@ +package org.dllearner.core.config; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 7/26/11 + * Time: 8:55 PM + * + * This is an example annotation class allowing one to configure a field with a name, description, and corresponding property editor. + * + * Note: Only put this on Setters that take the actual object you want to end up with as the example expects it to be on the setter + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface ConfigOption { + + /** + * The name of this config option. + * @return The name of this config option. + */ + String name(); + + /** + * The description of this config option + * @return + */ + String description(); + + /** + * An implementation of the Property Editor to use + * @return + */ + Class propertyEditorClass(); +} Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -0,0 +1,82 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +public class IntegerEditor implements PropertyEditor { + + private Integer value; + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public String getAsText() { + return value.toString(); + } + + @Override + public Component getCustomEditor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getJavaInitializationString() { + return value.toString(); + } + + @Override + public String[] getTags() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean isPaintable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = Integer.valueOf(text); + + } + + @Override + public void setValue(Object value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean supportsCustomEditor() { + // TODO Auto-generated method stub + return false; + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/IntegerEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -0,0 +1,88 @@ +package org.dllearner.core.config; + +import org.dllearner.core.owl.ObjectProperty; + +import java.awt.*; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 7/26/11 + * Time: 9:42 PM + * <p/> + * Basic Property Editor for the Object Property DL-Learner class. Doesn't have GUI support yet but we could add that later if we wanted. + */ +public class ObjectPropertyEditor implements PropertyEditor { + + + private ObjectProperty value; + + @Override + public void setValue(Object value) { + this.value = (ObjectProperty) value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean isPaintable() { + /** Not right now, we're doing non gui work */ + return false; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + + } + + @Override + public String getJavaInitializationString() { + /** This returns the value needed to reconstitute the object from a string */ + return value.getName(); + } + + @Override + public String getAsText() { + /** Get the text value of this object - for displaying in GUIS, etc */ + return value.getName(); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = new ObjectProperty(text); + } + + @Override + public String[] getTags() { + /** If there was a known set of values it had to have, we could add that list here */ + return new String[0]; + } + + @Override + public Component getCustomEditor() { + /** GUI stuff, if you wanted to edit it a custom way */ + return null; + } + + @Override + public boolean supportsCustomEditor() { + /** We don't support this right now, but maybe later */ + return false; + + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } +} Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/ObjectPropertyEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -0,0 +1,22 @@ +package org.dllearner.core.config; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 7/26/11 + * Time: 10:17 PM + * <p/> + * Making a basic extension so I can get a default constructor so that using reflection is simpler. + * + * I'm extending a Spring provided class for this. + */ +public class OurStringTrimmerEditor extends org.springframework.beans.propertyeditors.StringTrimmerEditor { + + + /** + * Default Constructor + */ + public OurStringTrimmerEditor() { + super(true); + } +} Property changes on: trunk/components-core/src/main/java/org/dllearner/core/config/OurStringTrimmerEditor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-07-27 14:33:14 UTC (rev 2970) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-07-28 08:30:40 UTC (rev 2971) @@ -1,8 +1,11 @@ package org.dllearner.reasoning; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -16,17 +19,21 @@ import org.dllearner.core.owl.DatatypePropertyHierarchy; 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; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.datastructures.SortedSetTuple; +import com.clarkparsia.owlapiv3.XSD; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; public class SPARQLReasoner implements SchemaReasoner, IndividualReasoner{ @@ -138,8 +145,30 @@ @Override public Map<Individual, SortedSet<Individual>> getPropertyMembers(ObjectProperty objectProperty) { - // TODO Auto-generated method stub - return null; + Map<Individual, SortedSet<Individual>> subject2objects = new HashMap<Individual, SortedSet<Individual>>(); + String query = String.format("select ?s ?o WHERE {" + + "?s %s ?o." + + " FILTER(isIRI(?o))}", + inAngleBrackets(objectProperty.getName())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual sub; + Individual obj; + SortedSet<Individual> objects; + while(rs.hasNext()){ + qs = rs.next(); + sub = new Individual(qs.getResource("s").getURI()); + obj = new Individual(qs.getResource("o").getURI()); + objects = subject2objects.get(sub); + if(objects == null){ + objects = new TreeSet<Individual>(); + subject2objects.put(sub, objects); + } + objects.add(obj); + + } + return subject2objects; } @Override @@ -150,32 +179,124 @@ @Override public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + Map<Individual, SortedSet<Double>> subject2objects = new HashMap<Individual, SortedSet<Double>>(); + String query = String.format("select ?s ?o WHERE {" + + "?s %s ?o." + + " FILTER(DATATYPE(?o) = %s)}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.DOUBLE.toStringID())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual sub; + Double obj; + SortedSet<Double> objects; + while(rs.hasNext()){ + qs = rs.next(); + sub = new Individual(qs.getResource("s").getURI()); + obj = qs.getLiteral("o").getDouble(); + objects = subject2objects.get(sub); + if(objects == null){ + objects = new TreeSet<Double>(); + subject2objects.put(sub, objects); + } + objects.add(obj); + + } + return subject2objects; } @Override public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + Map<Individual, SortedSet<Integer>> subject2objects = new HashMap<Individual, SortedSet<Integer>>(); + String query = String.format("select ?s ?o WHERE {" + + "?s %s ?o." + + " FILTER(DATATYPE(?o) = %s)}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.INT.toStringID())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual sub; + Integer obj; + SortedSet<Integer> objects; + while(rs.hasNext()){ + qs = rs.next(); + sub = new Individual(qs.getResource("s").getURI()); + obj = qs.getLiteral("o").getInt(); + objects = subject2objects.get(sub); + if(objects == null){ + objects = new TreeSet<Integer>(); + subject2objects.put(sub, objects); + } + objects.add(obj); + + } + return subject2objects; } @Override public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + Map<Individual, SortedSet<Boolean>> subject2objects = new HashMap<Individual, SortedSet<Boolean>>(); + String query = String.format("select ?s ?o WHERE {" + + "?s %s ?o." + + " FILTER(DATATYPE(?o) = %s)}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual sub; + Boolean obj; + SortedSet<Boolean> objects; + while(rs.hasNext()){ + qs = rs.next(); + sub = new Individual(qs.getResource("s").getURI()); + obj = qs.getLiteral("o").getBoolean(); + objects = subject2objects.get(sub); + if(objects == null){ + objects = new TreeSet<Boolean>(); + subject2objects.put(sub, objects); + } + objects.add(obj); + + } + return subject2objects; } @Override public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + SortedSet<Individual> members = new TreeSet<Individual>(); + String query = String.format("select ?ind WHERE {" + + "?ind %s ?o." + + " FILTER(isLiteral(?o) && DATATYPE(?o) = %s && ?o=%s)}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID()), + "\"true\"^^"+inAngleBrackets(XSD.BOOLEAN.toStringID())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + members.add(new Individual(qs.getResource("ind").getURI())); + + } + return members; } @Override public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub - return null; + SortedSet<Individual> members = new TreeSet<Individual>(); + String query = String.format("select ?ind WHERE {" + + "?ind %s ?o." + + " FILTER(isLiteral(?o) && DATATYPE(?o) = %s && ?o=%s)}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(XSD.BOOLEAN.toStringID()), + "\"false\"^^"+inAngleBrackets(XSD.BOOLEAN.toStringID())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + members.add(new Individual(qs.getResource("ind").getURI())); + + } + return members; } @Override @@ -186,25 +307,75 @@ @Override public Set<NamedClass> getInconsistentClasses() { - // TODO Auto-generated method stub - return null; + throw new UnsupportedOperationException(); } @Override public Description getDomain(ObjectProperty objectProperty) { - // TODO Auto-generated method stub + String query = String.format("select ?domain WHERE {" + + "%s %s ?domain. FILTER(isIRI(?domain))" + + "}", + inAngleBrackets(objectProperty.getName()), inAngleBrackets(RDFS.domain.getURI())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + List<Description> domains = new ArrayList<Description>(); + while(rs.hasNext()){ + qs = rs.next(); + domains.add(new NamedClass(qs.getResource("domain").getURI())); + + } + if(domains.size() == 1){ + return domains.get(0); + } else if(domains.size() > 1){ + return new Intersection(domains); + } return null; } @Override public Description getDomain(DatatypeProperty datatypeProperty) { - // TODO Auto-generated method stub + String query = String.format("select ?domain WHERE {" + + "%s %s ?domain. FILTER(isIRI(?domain))" + + "}", + inAngleBrackets(datatypeProperty.getName()), inAngleBrackets(RDFS.domain.getURI())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + List<Description> domains = new ArrayList<Description>(); + while(rs.hasNext()){ + qs = rs.next(); + domains.add(new NamedClass(qs.getResource("domain").getURI())); + + } + if(domains.size() == 1){ + return domains.get(0); + } else if(domains.size() > 1){ + return new Intersection(domains); + } return null; } @Override public Description getRange(ObjectProperty objectProperty) { - // TODO Auto-generated method stub + String query = String.format("select ?range WHERE {" + + "%s %s ?range. FILTER(isIRI(?range))" + + "}", + inAngleBrackets(objectProperty.getName()), inAngleBrackets(RDFS.range.getURI())); + + ResultSet rs = executeQuery(query); + QuerySolution qs; + List<Description> ranges = new ArrayList<Description>(); + while(rs.hasNext()){ + qs = rs.next(); + ranges.add(new NamedClass(qs.getResource("range").getURI())); + + } + if(ranges.size() == 1){ + return ranges.get(0); + } else if(ranges.size() > 1){ + return new Intersection(ranges); + } return null; } @@ -312,6 +483,7 @@ } private ResultSet executeQuery(String query){ + System.out.println(query); QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); @@ -338,5 +510,29 @@ private String inAngleBrackets(String s){ return "<" + s + ">"; } + + public static void main(String[] args) { + String NS = "http://dbpedia.org/ontology/"; + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + SPARQLReasoner r = new SPARQLReasoner(ks); + +// ObjectProperty oP = new ObjectProperty(NS + "league"); +// for(Entry<Individual, SortedSet<Individual>> entry : r.getPropertyMembers(oP).entrySet()){ +// System.out.println(entry.getKey()); +// System.out.println(entry.getValue()); +// } +// +// DatatypeProperty dP = new DatatypeProperty(NS+ "areaLand"); +// for(Entry<Individual, SortedSet<Double>> entry : r.getDoubleDatatypeMembers(dP).entrySet()){ +// System.out.println(entry.getKey()); +// System.out.println(entry.getValue()); +// } + + DatatypeProperty dP = new DatatypeProperty(NS+ "internationally"); + for(Individual ind : r.getTrueDatatypeMembers(dP)){ + System.out.println(ind); + } + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-03 05:58:55
|
Revision: 2977 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2977&view=rev Author: lorenz_b Date: 2011-08-03 05:58:49 +0000 (Wed, 03 Aug 2011) Log Message: ----------- Continued new learning algorithm for PropertyDomainAxioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-02 12:45:11 UTC (rev 2976) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-03 05:58:49 UTC (rev 2977) @@ -2,12 +2,17 @@ import java.beans.PropertyEditor; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; @@ -21,6 +26,7 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; @@ -38,11 +44,17 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds; + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; private SPARQLReasoner reasoner; private SparqlEndpointKS ks; + private List<Axiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + public PropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -63,25 +75,44 @@ this.propertyToDescribe = propertyToDescribe; } + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + @Override public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<Axiom>(); //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); logger.debug("Existing domain: " + existingDomain); //get subjects with types - Map<Individual, Set<NamedClass>> individual2Types = getSubjectsWithTypes(); - - //get subjects of property - Map<Individual, SortedSet<Individual>> members = reasoner.getPropertyMembers(propertyToDescribe); - - + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + while(!terminationCriteriaSatisfied()){ + individual2Types.putAll(getSubjectsWithTypes(fetchedRows)); + currentlyBestAxioms = buildBestAxioms(individual2Types); + fetchedRows += 1000; + } + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<Axiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next()); + } + + return bestAxioms; } @Override @@ -96,31 +127,68 @@ } - private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(){ - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - int limit = 1000; - int offset = 135000; - boolean executeAgain = true; + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<Axiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + List<Axiom> axioms = new ArrayList<Axiom>(); + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(NamedClass nc : entry.getValue()){ + Integer cnt = result.get(nc); + if(cnt == null){ + cnt = Integer.valueOf(1); + } + result.put(nc, Integer.valueOf(cnt + 1)); + } + } - while(executeAgain){ - String query = String.format("SELECT ?ind ?type WHERE {?ind %s ?o. ?ind a ?type.} LIMIT %d OFFSET %d", inAngleBrackets(propertyToDescribe.getURI().toString()), limit, offset); - ResultSet rs = executeQuery(query); - QuerySolution qs; - Individual ind; - Set<NamedClass> types; - executeAgain = rs.hasNext(); - while(executeAgain && rs.hasNext()){ - qs = rs.next(); - ind = new Individual(qs.getResource("ind").getURI()); - types = individual2Types.get(ind); - if(types == null){ - types = new HashSet<NamedClass>(); + for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + axioms.add(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey())); + } + + return axioms; + } + + private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ + SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { + + @Override + public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); } - types.add(new NamedClass(qs.getResource("type").getURI())); } - offset += 1000; + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + int limit = 1000; + String query = String.format("SELECT ?ind ?type WHERE {?ind %s ?o. ?ind a ?type.} LIMIT %d OFFSET %d", inAngleBrackets(propertyToDescribe.getURI().toString()), limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual ind; + Set<NamedClass> types; + while(rs.hasNext()){ + qs = rs.next(); + ind = new Individual(qs.getResource("ind").getURI()); + types = individual2Types.get(ind); + if(types == null){ + types = new HashSet<NamedClass>(); + individual2Types.put(ind, types); + } + types.add(new NamedClass(qs.getResource("type").getURI())); } - return individual2Types; } @@ -146,6 +214,7 @@ Map<String, String> propertiesMap = new HashMap<String, String>(); propertiesMap.put("propertyToDescribe", "http://dbpedia.org/ontology/league"); propertiesMap.put("maxExecutionTimeInSeconds", "20"); + propertiesMap.put("maxFetchedRows", "5000"); PropertyDomainAxiomLearner l = new PropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); @@ -162,6 +231,7 @@ l.init(); l.start(); + System.out.println(l.getCurrentlyBestAxioms(3)); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-02 12:45:11 UTC (rev 2976) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-03 05:58:49 UTC (rev 2977) @@ -27,7 +27,7 @@ @Override public void start() { - // TODO Auto-generated method stub + //select COUNT(?o),COUNT(?o2) WHERE {?s dbpedia-owl:influencedBy ?o. ?o dbpedia-owl:influencedBy ?o1. OPTIONAL{?s dbpedia-owl:influencedBy ?o1. ?s dbpedia-owl:influencedBy ?o2}} } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java 2011-08-02 12:45:11 UTC (rev 2976) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java 2011-08-03 05:58:49 UTC (rev 2977) @@ -54,8 +54,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return "Domain(" + getProperty() + ", " + getDomain() + ")"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-03 13:54:34
|
Revision: 2979 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2979&view=rev Author: lorenz_b Date: 2011-08-03 13:54:26 +0000 (Wed, 03 Aug 2011) Log Message: ----------- Added additional axioms type. Continued property learning algorithms. Added convenience class to configure components by analysing the annotations. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -5,6 +5,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.kb.SparqlEndpointKS; @@ -49,4 +50,10 @@ } + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -5,6 +5,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.kb.SparqlEndpointKS; @@ -49,4 +50,10 @@ } + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -1,41 +1,117 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; + public class FunctionalPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - private String propertyToDescribe; +private static final Logger logger = LoggerFactory.getLogger(TransitivePropertyAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public FunctionalPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public FunctionalPropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } @Override public void start() { - // TODO Auto-generated method stub - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as symmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); + boolean declaredAsFunctional = executeAskQuery(query); + if(declaredAsFunctional) { + logger.info("Property is already declared as functional in knowledge base."); + } + + //get fraction of instances s with <s p o> also exists <o p s> + query = "SELECT (COUNT(?s)) AS ?all ,(COUNT(?o1)) AS ?functional WHERE {?s <%s> ?o. OPTIONAL{?o <%s> ?s. ?o <%s> ?o1}}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + int all = qs.getLiteral("all").getInt(); + int symmetric = qs.getLiteral("functional").getInt(); + double frac = symmetric / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + return Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return Collections.singletonList(currentlyBestAxioms.get(0)); + } @Override public Configurator getConfigurator() { @@ -45,8 +121,34 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; } - + + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -17,6 +17,8 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; @@ -29,6 +31,7 @@ import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +54,7 @@ private SPARQLReasoner reasoner; private SparqlEndpointKS ks; - private List<Axiom> currentlyBestAxioms; + private List<EvaluatedAxiom> currentlyBestAxioms; private long startTime; private int fetchedRows; @@ -88,7 +91,7 @@ logger.info("Start learning..."); startTime = System.currentTimeMillis(); fetchedRows = 0; - currentlyBestAxioms = new ArrayList<Axiom>(); + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); logger.debug("Existing domain: " + existingDomain); @@ -107,13 +110,22 @@ public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { List<Axiom> bestAxioms = new ArrayList<Axiom>(); - Iterator<Axiom> it = currentlyBestAxioms.iterator(); + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next()); + bestAxioms.add(it.next().getAxiom()); } return bestAxioms; } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max-1); + + return bestAxioms; + } @Override public Configurator getConfigurator() { @@ -133,8 +145,8 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<Axiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ - List<Axiom> axioms = new ArrayList<Axiom>(); + private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ for(NamedClass nc : entry.getValue()){ @@ -146,13 +158,19 @@ } } + EvaluatedAxiom evalAxiom; for(Entry<NamedClass, Integer> entry : sortByValues(result)){ - axioms.add(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey())); + evalAxiom = new EvaluatedAxiom(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + axioms.add(evalAxiom); } return axioms; } + /* + * Returns the entries of the map sorted by value. + */ private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { @@ -174,7 +192,7 @@ private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); int limit = 1000; - String query = String.format("SELECT ?ind ?type WHERE {?ind %s ?o. ?ind a ?type.} LIMIT %d OFFSET %d", inAngleBrackets(propertyToDescribe.getURI().toString()), limit, offset); + String query = String.format("SELECT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, offset); ResultSet rs = executeQuery(query); QuerySolution qs; Individual ind; @@ -192,10 +210,9 @@ return individual2Types; } - private String inAngleBrackets(String s){ - return "<" + s + ">"; - } - + /* + * Executes a SELECT query and returns the result. + */ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); @@ -218,6 +235,7 @@ PropertyDomainAxiomLearner l = new PropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); + Field[] fields = l.getClass().getDeclaredFields(); for(Field f : fields){ ConfigOption option = f.getAnnotation(ConfigOption.class); @@ -228,10 +246,10 @@ f.set(l, editor.getValue()); } } - + ConfigHelper.configurate(l, "propertyToDescribe", "test"); l.init(); l.start(); - System.out.println(l.getCurrentlyBestAxioms(3)); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(3)); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -5,6 +5,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.kb.SparqlEndpointKS; @@ -49,4 +50,10 @@ } + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -1,41 +1,117 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL2; + public class ReflexivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - private String propertyToDescribe; + private static final Logger logger = LoggerFactory.getLogger(TransitivePropertyAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public ReflexivePropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public ReflexivePropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } @Override public void start() { - // TODO Auto-generated method stub - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as reflexive in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.ReflexiveProperty.getURI()); + boolean declaredAsReflexive = executeAskQuery(query); + if(declaredAsReflexive) { + logger.info("Property is already declared as reflexive in knowledge base."); + } + + //get fraction of instances s with <s p o> also exists <o p s> + query = "SELECT (COUNT(?s)) AS ?all ,(COUNT(?o1)) AS ?reflexiv WHERE {?s <%s> ?o. OPTIONAL{?o <%s> ?s. ?o <%s> ?o1}}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + int all = qs.getLiteral("all").getInt(); + int reflexive = qs.getLiteral("reflexiv").getInt(); + double frac = reflexive / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new ReflexiveObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + return Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return Collections.singletonList(currentlyBestAxioms.get(0)); + } @Override public Configurator getConfigurator() { @@ -45,8 +121,35 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; } + + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -11,6 +11,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; @@ -126,5 +127,11 @@ l.start(); } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + // TODO Auto-generated method stub + return null; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -1,41 +1,118 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL2; + public class SymmetricPropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - private String propertyToDescribe; + private static final Logger logger = LoggerFactory.getLogger(TransitivePropertyAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public SymmetricPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public SymmetricPropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } @Override public void start() { - // TODO Auto-generated method stub - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as symmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.SymmetricProperty.getURI()); + boolean declaredAsSymmetric = executeAskQuery(query); + if(declaredAsSymmetric) { + logger.info("Property is already declared as symmetric in knowledge base."); + } + + //get fraction of instances s with <s p o> also exists <o p s> + query = "SELECT (COUNT(?s)) AS ?all ,(COUNT(?o1)) AS ?symmetric WHERE {?s <%s> ?o. OPTIONAL{?o <%s> ?s. ?o <%s> ?o1}}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + int all = qs.getLiteral("all").getInt(); + int symmetric = qs.getLiteral("symmetric").getInt(); + double frac = symmetric / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new SymmetricObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + return Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return Collections.singletonList(currentlyBestAxioms.get(0)); + } @Override public Configurator getConfigurator() { @@ -45,8 +122,35 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; } + + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -1,41 +1,118 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; + public class TransitivePropertyAxiomLearner extends Component implements AxiomLearningAlgorithm { - private String propertyToDescribe; + private static final Logger logger = LoggerFactory.getLogger(TransitivePropertyAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public TransitivePropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public TransitivePropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } @Override public void start() { - //select COUNT(?o),COUNT(?o2) WHERE {?s dbpedia-owl:influencedBy ?o. ?o dbpedia-owl:influencedBy ?o1. OPTIONAL{?s dbpedia-owl:influencedBy ?o1. ?s dbpedia-owl:influencedBy ?o2}} - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as transitive in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.TransitiveProperty.getURI()); + boolean declaredAsTransitive = executeAskQuery(query); + if(declaredAsTransitive) { + logger.info("Property is already declared as transitive in knowledge base."); + } + + //get fraction of instances s where for a chain <s p o> <o p o1> exists also <s p o1> + query = "SELECT (COUNT(?o)) AS ?all ,(COUNT(?o2)) AS ?transitive WHERE {?s <%s> ?o. ?o <%s> ?o1. OPTIONAL{?s <%s> ?o1. ?s <%s> ?o2}}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + int all = qs.getLiteral("all").getInt(); + int transitive = qs.getLiteral("trans").getInt(); + double frac = transitive / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + return Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return Collections.singletonList(currentlyBestAxioms.get(0)); + } @Override public Configurator getConfigurator() { @@ -45,8 +122,45 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; } + + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + + public static void main(String[] args) throws Exception{ + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); + TransitivePropertyAxiomLearner l = new TransitivePropertyAxiomLearner(ks); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/influencedBy")); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(1)); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -8,8 +8,14 @@ /** * @param nrOfAxioms Limit for the number or returned axioms. - * @return The best axiom found by the learning algorithm so far. + * @return The best axioms found by the learning algorithm so far. */ public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms); + + /** + * @param nrOfAxioms Limit for the number or returned evaluated axioms. + * @return The best evaluated axioms found by the learning algorithm so far. + */ + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms); } Added: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -0,0 +1,30 @@ +package org.dllearner.core; + +import org.dllearner.core.owl.Axiom; + +public class EvaluatedAxiom { + + private Axiom axiom; + private Score score; + + public EvaluatedAxiom(Axiom axiom, Score score) { + this.axiom = axiom; + this.score = score; + } + + public Axiom getAxiom() { + return axiom; + } + + public Score getScore() { + return score; + } + + @Override + public String toString() { + return axiom + "(" + score.getAccuracy()+ ")"; + } + + + +} Added: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -0,0 +1,60 @@ +package org.dllearner.core.config; + +import java.beans.PropertyEditor; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.dllearner.core.Component; + +public class ConfigHelper { + + /** + * Configures the given component by setting the value for the appropriate config option. + * @param component the component to be configured + * @param configName the name of the config option + * @param configValue the value of the config option + */ + public static void configurate(Component component, String configName, String configValue){ + Field[] fields = component.getClass().getDeclaredFields(); + for(Field f : fields){ + ConfigOption option = f.getAnnotation(ConfigOption.class); + if(option != null){ + if(option.name().equals(configName)){ + try { + PropertyEditor editor = (PropertyEditor) option.propertyEditorClass().newInstance(); + editor.setAsText(configValue); + f.set(component, editor.getValue()); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + } + } + } + + /** + * Returns all config options for the given component. + * @param component + * @return + */ + public static List<ConfigOption> getConfigOptions(Component component){ + List<ConfigOption> options = new ArrayList<ConfigOption>(); + + Field[] fields = component.getClass().getDeclaredFields(); + for(Field f : fields){ + ConfigOption option = f.getAnnotation(ConfigOption.class); + if(option != null){ + options.add(option); + } + } + + return options; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -35,6 +35,8 @@ public void visit(TransitiveObjectPropertyAxiom axiom); + public void visit(ReflexiveObjectPropertyAxiom axiom); + public void visit(SubObjectPropertyAxiom axiom); void visit(DatatypePropertyDomainAxiom axiom); Added: trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -0,0 +1,49 @@ +package org.dllearner.core.owl; + +import java.util.Map; + +public class ReflexiveObjectPropertyAxiom extends PropertyAxiom { + + /** + * + */ + private static final long serialVersionUID = -3877477886974844568L; + private ObjectPropertyExpression role; + + public ReflexiveObjectPropertyAxiom(ObjectPropertyExpression role) { + this.role = role; + } + + public int getLength() { + return 1 + role.getLength(); + } + + public ObjectPropertyExpression getRole() { + return role; + } + + public String toString(String baseURI, Map<String,String> prefixes) { + return "Reflexive(" + role.toString(baseURI, prefixes) + ")"; + } + + public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { + return "Reflexive(" + role.toKBSyntaxString(baseURI, prefixes) + ")"; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { + return "Transitive(" + role.toString(baseURI, prefixes) + ")"; + } +} Added: trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/AxiomScore.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -0,0 +1,19 @@ +package org.dllearner.learningproblems; + +import org.dllearner.core.Score; + +public class AxiomScore extends Score{ + + private static final long serialVersionUID = 555252118489924570L; + private double accuracy; + + public AxiomScore(double accuracy) { + this.accuracy = accuracy; + } + + @Override + public double getAccuracy() { + return accuracy; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-03 13:00:19 UTC (rev 2978) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-03 13:54:26 UTC (rev 2979) @@ -44,6 +44,7 @@ import org.dllearner.core.owl.ObjectPropertyAssertion; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.core.owl.ObjectPropertyRangeAxiom; +import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.core.owl.StringDatatypePropertyAssertion; import org.dllearner.core.owl.SubClassAxiom; import org.dllearner.core.owl.SubObjectPropertyAxiom; @@ -235,6 +236,14 @@ OWLAxiom axiomOWLAPI = factory.getOWLTransitiveObjectPropertyAxiom(role); addAxiom(axiomOWLAPI); } + + @Override + public void visit(ReflexiveObjectPropertyAxiom axiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + IRI.create(axiom.getRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLFunctionalObjectPropertyAxiom(role); + addAxiom(axiomOWLAPI); + } /* (non-Javadoc) * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.SubObjectPropertyAxiom) @@ -358,4 +367,6 @@ addAxiom(axiomOWLAPI); } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-05 09:05:32
|
Revision: 3003 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3003&view=rev Author: lorenz_b Date: 2011-08-05 09:05:26 +0000 (Fri, 05 Aug 2011) Log Message: ----------- Continued algorithms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-04 17:51:53 UTC (rev 3002) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -1,44 +1,150 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + @ComponentAnn(name="equivalent property axiom learner") public class EquivalentPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - private String propertyToDescribe; + private static final Logger logger = LoggerFactory.getLogger(EquivalentPropertyAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public EquivalentPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public EquivalentPropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } - + @Override public void start() { - // TODO Auto-generated method stub - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing super properties + SortedSet<ObjectProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); + logger.debug("Existing super properties: " + existingSuperProperties); + + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p (COUNT(?s)) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + ObjectProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } @Override public Configurator getConfigurator() { @@ -48,14 +154,65 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + + EvaluatedAxiom evalAxiom; + for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ + evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(0)); + axioms.add(evalAxiom); + } + + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<ObjectProperty, Integer>> sortByValues(Map<ObjectProperty, Integer> map){ + SortedSet<Entry<ObjectProperty, Integer>> sortedSet = new TreeSet<Map.Entry<ObjectProperty,Integer>>(new Comparator<Entry<ObjectProperty, Integer>>() { - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + @Override + public int compare(Entry<ObjectProperty, Integer> value1, Entry<ObjectProperty, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-04 17:51:53 UTC (rev 3002) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -41,7 +41,7 @@ @ComponentAnn(name="subPropertyOf learner") public class SubPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { -private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); + private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; Added: trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentDatatypePropertiesAxiom.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -0,0 +1,55 @@ +package org.dllearner.core.owl; + +import java.util.Map; + +public class EquivalentDatatypePropertiesAxiom extends PropertyAxiom { + + /** + * + */ + private static final long serialVersionUID = -1085651734702155330L; + private DatatypeProperty role; + private DatatypeProperty equivRole; + + public EquivalentDatatypePropertiesAxiom(DatatypeProperty equivRole, DatatypeProperty role) { + this.role = role; + this.equivRole = equivRole; + } + + public DatatypeProperty getRole() { + return role; + } + + public DatatypeProperty getEquivalentRole() { + return equivRole; + } + + public int getLength() { + return 1 + role.getLength() + equivRole.getLength(); + } + + public String toString(String baseURI, Map<String,String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + } + + public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toKBSyntaxString(baseURI, prefixes) + "," + role.toKBSyntaxString(baseURI, prefixes) + ")"; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + } +} Added: trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -0,0 +1,55 @@ +package org.dllearner.core.owl; + +import java.util.Map; + +public class EquivalentObjectPropertiesAxiom extends PropertyAxiom { + + /** + * + */ + private static final long serialVersionUID = -1085651734702155330L; + private ObjectProperty role; + private ObjectProperty equivRole; + + public EquivalentObjectPropertiesAxiom(ObjectProperty equivRole, ObjectProperty role) { + this.role = role; + this.equivRole = equivRole; + } + + public ObjectProperty getRole() { + return role; + } + + public ObjectProperty getEquivalentRole() { + return equivRole; + } + + public int getLength() { + return 1 + role.getLength() + equivRole.getLength(); + } + + public String toString(String baseURI, Map<String,String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + } + + public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toKBSyntaxString(baseURI, prefixes) + "," + role.toKBSyntaxString(baseURI, prefixes) + ")"; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { + return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + } +} Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java 2011-08-04 17:51:53 UTC (rev 3002) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -39,6 +39,10 @@ public void visit(SubObjectPropertyAxiom axiom); + public void visit(EquivalentObjectPropertiesAxiom axiom); + + public void visit(EquivalentDatatypePropertiesAxiom axiom); + void visit(DatatypePropertyDomainAxiom axiom); void visit(ObjectPropertyDomainAxiom axiom); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-04 17:51:53 UTC (rev 3002) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-05 09:05:26 UTC (rev 3003) @@ -37,6 +37,8 @@ import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.DoubleDatatypePropertyAssertion; import org.dllearner.core.owl.EquivalentClassesAxiom; +import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; +import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.InverseObjectPropertyAxiom; @@ -257,6 +259,28 @@ addAxiom(axiomOWLAPI); } + @Override + public void visit(EquivalentObjectPropertiesAxiom axiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + IRI.create(axiom.getRole().getName())); + OWLObjectProperty equivRole = factory.getOWLObjectProperty( + IRI.create(axiom.getEquivalentRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLEquivalentObjectPropertiesAxiom(equivRole, role); + addAxiom(axiomOWLAPI); + + } + + @Override + public void visit(EquivalentDatatypePropertiesAxiom axiom) { + OWLDataProperty role = factory.getOWLDataProperty( + IRI.create(axiom.getRole().getName())); + OWLDataProperty equivRole = factory.getOWLDataProperty( + IRI.create(axiom.getEquivalentRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLEquivalentDataPropertiesAxiom(equivRole, role); + addAxiom(axiomOWLAPI); + + } + /* * (non-Javadoc) * @@ -369,4 +393,6 @@ + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-08 06:00:23
|
Revision: 3010 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3010&view=rev Author: lorenz_b Date: 2011-08-08 06:00:16 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Continued algorithms. Implemented missing toString() methods in some axioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/FunctionalObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyRangeAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/SubObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java Property Changed: ---------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -23,6 +23,7 @@ import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; @@ -211,7 +212,8 @@ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -17,6 +17,7 @@ import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -150,10 +151,14 @@ return result; } + /* + * Executes a SELECT query and returns the result. + */ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -30,6 +30,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; @@ -221,7 +222,8 @@ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } @@ -232,28 +234,5 @@ return resultSet; } - public static void main(String[] args) throws Exception{ - Map<String, String> propertiesMap = new HashMap<String, String>(); - propertiesMap.put("propertyToDescribe", "http://dbpedia.org/ontology/writer"); - propertiesMap.put("maxExecutionTimeInSeconds", "10"); - propertiesMap.put("maxFetchedRows", "15000"); - - PropertyDomainAxiomLearner l = new PropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - - - Field[] fields = l.getClass().getDeclaredFields(); - for(Field f : fields){ - ConfigOption option = f.getAnnotation(ConfigOption.class); - if(option != null){ - String configValue = propertiesMap.get(option.name()); - PropertyEditor editor = (PropertyEditor) option.propertyEditorClass().newInstance(); - editor.setAsText(configValue); - f.set(l, editor.getValue()); - } - } - l.init(); - l.start(); - System.out.println(l.getCurrentlyBestEvaluatedAxioms(3)); - } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -28,6 +28,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyRangeAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -218,7 +219,8 @@ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -17,6 +17,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -143,10 +144,14 @@ return result; } + /* + * Executes a SELECT query and returns the result. + */ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -10,9 +10,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.aksw.commons.sparql.api.core.QueryExecutionFactory; -import org.aksw.commons.sparql.api.http.QueryExecutionFactoryHttp; -import org.aksw.commons.sparql.api.pagination.core.QueryExecutionFactoryPaginated; import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -26,6 +23,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -215,7 +213,8 @@ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -17,6 +17,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -143,10 +144,14 @@ return result; } + /* + * Executes a SELECT query and returns the result. + */ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -17,6 +17,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; @@ -144,10 +145,14 @@ return result; } + /* + * Executes a SELECT query and returns the result. + */ private ResultSet executeQuery(String query){ logger.info("Sending query \n {}", query); - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -50,6 +50,6 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + return equivRole.toString(baseURI, prefixes) + " EquivalentTo: " + role.toString(baseURI, prefixes); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/FunctionalObjectPropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/FunctionalObjectPropertyAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/FunctionalObjectPropertyAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -50,6 +50,6 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "FUNCTIONALOBJECTPROPERTYAXIOM NOT IMPLEMENTED"; + return "Functional(" + role.toManchesterSyntaxString(baseURI, prefixes) + ")"; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyDomainAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -76,7 +76,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "OBJECTPROPERTYDOMAIN NOT IMPLEMENTED"; + return "Domain(" + getProperty().toManchesterSyntaxString(baseURI, prefixes) + ", " + getDomain().toManchesterSyntaxString(baseURI, prefixes) + ")"; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyRangeAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyRangeAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyRangeAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -48,7 +48,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return "Domain(" + getProperty() + ", " + getRange() + ")"; + return "Range(" + getProperty() + ", " + getRange() + ")"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { @@ -80,7 +80,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "OBJECTPROPERTYRANGE NOT IMPLEMENTED"; + return "Range(" + getProperty().toManchesterSyntaxString(baseURI, prefixes) + ", " + getRange().toManchesterSyntaxString(baseURI, prefixes) + ")"; } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ReflexiveObjectPropertyAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -44,6 +44,6 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "Transitive(" + role.toString(baseURI, prefixes) + ")"; + return "Reflexive(" + role.toManchesterSyntaxString(baseURI, prefixes) + ")"; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/SubObjectPropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/SubObjectPropertyAxiom.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/SubObjectPropertyAxiom.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -50,6 +50,6 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "Subrole(" + subRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + return subRole.toString(baseURI, prefixes) + " SubPropertyOf: " + role.toString(baseURI, prefixes); } } Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql ___________________________________________________________________ Modified: svn:ignore - SparqlQueryDescriptionConvertRDFS.java + SparqlQueryDescriptionConvertRDFS.java Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -0,0 +1,376 @@ +package org.dllearner.kb.sparql; + +import com.hp.hpl.jena.query.*; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.sparql.engine.http.HttpParams; +import com.hp.hpl.jena.sparql.engine.http.Params; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.sparql.resultset.XMLInput; +import com.hp.hpl.jena.sparql.util.Context; +import com.hp.hpl.jena.sparql.util.graph.GraphFactory; +import com.hp.hpl.jena.util.FileManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * Created by Claus Stadler + * Date: Oct 25, 2010 + * Time: 10:15:31 PM + */ +class DisconnectorThread + extends Thread { + private static final Logger logger = LoggerFactory.getLogger(DisconnectorThread.class); + + private HttpQuery connection; + + private long timeOut; + + private boolean canceled = false; + + public DisconnectorThread(HttpQuery connection, long timeOut) { + this.connection = connection; + this.timeOut = timeOut; + } + + public void run() { + synchronized (this) { + + while(!canceled && connection.getConnection() == null) { + //logger.trace("Waiting for connection..."); + + try { + this.wait(500l); + } catch (InterruptedException e) { + } + } + + long startTime = System.currentTimeMillis(); + + long remaining; + while (!canceled && (remaining = (timeOut - (System.currentTimeMillis() - startTime))) > 0) { + logger.trace("Forced disconnect in " + remaining + "ms"); + try { + this.wait(remaining); + } catch (InterruptedException e) { + } + } + + if (!canceled && connection.getConnection() != null) { + logger.warn("Disconnecting Http connection since a sparql query is taking too long"); + connection.getConnection().disconnect(); + canceled = true; + } + } + } + + public void cancel() { + synchronized (this) { + if(!this.canceled) { + logger.trace("Disconnect cancelled"); + } + + this.canceled = true; + this.notify(); + } + } +} + +/** + * A QueryEngineHTTP that is capable of closing connections after a given timeout. + * + * Jena now provides one on its own + */ +public class ExtendedQueryEngineHTTP + implements QueryExecution { + private static Logger log = LoggerFactory.getLogger(QueryEngineHTTP.class); + + public static final String QUERY_MIME_TYPE = "application/sparql-query"; + String queryString; + String service; + Context context = null; + + + long timeOut = 0l; + + public void setTimeOut(long timeOut) { + this.timeOut = timeOut; + } + + public long getTimeOut() { + return timeOut; + } + + + //Params + Params params = null; + + // Protocol + List<String> defaultGraphURIs = new ArrayList<String>(); + List<String> namedGraphURIs = new ArrayList<String>(); + private String user = null; + private char[] password = null; + + // Releasing HTTP input streams is important. We remember this for SELECT, + // and will close when the engine is closed + private InputStream retainedConnection = null; + + public ExtendedQueryEngineHTTP(String serviceURI, Query query) { + this(serviceURI, query.toString()); + } + + public ExtendedQueryEngineHTTP(String serviceURI, String queryString) { + this.queryString = queryString; + service = serviceURI; + // Copy the global context to freeze it. + context = new Context(ARQ.getContext()); + } + +// public void setParams(Params params) +// { this.params = params ; } + + // Meaning-less + + public void setFileManager(FileManager fm) { + throw new UnsupportedOperationException("FileManagers do not apply to remote query execution"); + } + + public void setInitialBinding(QuerySolution binding) { + throw new UnsupportedOperationException("Initial bindings not supported for remote queries"); + } + + public void setInitialBindings(ResultSet table) { + throw new UnsupportedOperationException("Initial bindings not supported for remote queries"); + } + + /** + * @param defaultGraphURIs The defaultGraphURIs to set. + */ + public void setDefaultGraphURIs(List<String> defaultGraphURIs) { + this.defaultGraphURIs = defaultGraphURIs; + } + + /** + * @param namedGraphURIs The namedGraphURIs to set. + */ + public void setNamedGraphURIs(List<String> namedGraphURIs) { + this.namedGraphURIs = namedGraphURIs; + } + + public void addParam(String field, String value) { + if (params == null) + params = new Params(); + params.addParam(field, value); + } + + /** + * @param defaultGraph The defaultGraph to add. + */ + public void addDefaultGraph(String defaultGraph) { + if (defaultGraphURIs == null) + defaultGraphURIs = new ArrayList<String>(); + defaultGraphURIs.add(defaultGraph); + } + + /** + * @param name The URI to add. + */ + public void addNamedGraph(String name) { + if (namedGraphURIs == null) + namedGraphURIs = new ArrayList<String>(); + namedGraphURIs.add(name); + } + + /** + * Set user and password for basic authentication. + * After the request is made (one of the exec calls), the application + * can overwrite the password array to remove details of the secret. + * + * @param user + * @param password + */ + public void setBasicAuthentication(String user, char[] password) { + this.user = user; + this.password = password; + } + + private InputStream doTimedExec(HttpQuery httpQuery) { + DisconnectorThread stopTask = null; + if (timeOut > 0) { + stopTask = new DisconnectorThread(httpQuery, timeOut); +// stopTask.start(); + } + + InputStream in; + try { + in = httpQuery.exec(); + } + finally { + if (stopTask != null) { + stopTask.cancel(); + } + } + + return in; + } + + + public ResultSet execSelect() { + HttpQuery httpQuery = makeHttpQuery(); + // TODO Allow other content types. + httpQuery.setAccept(HttpParams.contentTypeResultsXML); + + InputStream in = doTimedExec(httpQuery); + + + ResultSet rs = ResultSetFactory.fromXML(in); + retainedConnection = in; // This will be closed on close() + return rs; + } + + public Model execConstruct() { + return execConstruct(GraphFactory.makeJenaDefaultModel()); + } + + public Model execConstruct(Model model) { + return execModel(model); + } + + public Model execDescribe() { + return execDescribe(GraphFactory.makeJenaDefaultModel()); + } + + public Model execDescribe(Model model) { + return execModel(model); + } + + private Model execModel(Model model) { + HttpQuery httpQuery = makeHttpQuery(); + httpQuery.setAccept(HttpParams.contentTypeRDFXML); + InputStream in = doTimedExec(httpQuery); + model.read(in, null); + return model; + } + + public boolean execAsk() { + HttpQuery httpQuery = makeHttpQuery(); + httpQuery.setAccept(HttpParams.contentTypeResultsXML); + InputStream in = doTimedExec(httpQuery); + boolean result = XMLInput.booleanFromXML(in); + // Ensure connection is released + try { + in.close(); + } + catch (java.io.IOException e) { + log.warn("Failed to close connection", e); + } + return result; + } + + public Context getContext() { + return context; + } + + private HttpQuery makeHttpQuery() { + HttpQuery httpQuery = new HttpQuery(service); + httpQuery.setTimeOut((int)timeOut); + httpQuery.addParam(HttpParams.pQuery, queryString); + + for (Iterator<String> iter = defaultGraphURIs.iterator(); iter.hasNext();) { + String dft = iter.next(); + httpQuery.addParam(HttpParams.pDefaultGraph, dft); + } + for (Iterator<String> iter = namedGraphURIs.iterator(); iter.hasNext();) { + String name = iter.next(); + httpQuery.addParam(HttpParams.pNamedGraph, name); + } + + if (params != null) + httpQuery.merge(params); + + httpQuery.setBasicAuthentication(user, password); + return httpQuery; + } + + public void abort() { + } + + public void close() { + if (retainedConnection != null) { + try { + retainedConnection.close(); + } + catch (java.io.IOException e) { + log.warn("Failed to close connection", e); + } + finally { + retainedConnection = null; + } + } + } + + @Override + public void setTimeout(long timeout, TimeUnit timeoutUnits) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setTimeout(long timeout) { + this.timeOut = timeout; + } + + @Override + public void setTimeout(long timeout1, TimeUnit timeUnit1, long timeout2, TimeUnit timeUnit2) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setTimeout(long timeout1, long timeout2) { + //To change body of implemented methods use File | Settings | File Templates. + } + +// public boolean isActive() { return false ; } + + @Override + public String toString() { + HttpQuery httpQuery = makeHttpQuery(); + return "GET " + httpQuery.toString(); + } + + public Dataset getDataset() { + return null; + } +} + +/* + * (c) Copyright 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -0,0 +1,401 @@ +package org.dllearner.kb.sparql; + +/* + * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP + * [See end of file] + */ + + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.openjena.atlas.lib.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.ARQ; +import com.hp.hpl.jena.sdb.util.Pair; +import com.hp.hpl.jena.shared.JenaException; +import com.hp.hpl.jena.sparql.ARQInternalErrorException; +import com.hp.hpl.jena.sparql.engine.http.HttpParams; +import com.hp.hpl.jena.sparql.engine.http.Params; +import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; +import com.hp.hpl.jena.sparql.util.Convert; +import com.hp.hpl.jena.util.FileUtils; + +/** Create an execution object for performing a query on a model + * over HTTP. This is the main protocol engine for HTTP query. + * There are higher level classes for doing a query and presenting + * the results in an API fashion. + * + * If the query string is large, then HTTP POST is used. */ +public class HttpQuery extends Params +{ + static final Logger log = LoggerFactory.getLogger(HttpQuery.class.getName()) ; + + /** The definition of "large" queries */ + // Not final so that other code can change it. + static public /*final*/ int urlLimit = 2*1024 ; + + String serviceURL ; + + String contentTypeResult = HttpParams.contentTypeResultsXML ; + HttpURLConnection httpConnection = null ; + + // An object indicate no value associated with parameter name + final static Object noValue = new Object() ; + String user = null ; + char[] password = null ; + + int responseCode = 0; + String responseMessage = null ; + boolean forcePOST = false ; + String queryString = null ; + + private int timeOut = 0; + + public void setTimeOut(int timeOut){ + this.timeOut = timeOut; + } + + //static final String ENC_UTF8 = "UTF-8" ; + + /** Create a execution object for a whole model GET + * @param serviceURL The model + */ + + public HttpQuery(String serviceURL) + { + init(serviceURL) ; + } + + + /** Create a execution object for a whole model GET + * @param url The model + */ + + public HttpQuery(URL url) + { + init(url.toString()) ; + } + + + private void init(String serviceURL) + { + if ( log.isTraceEnabled()) + log.trace("URL: "+serviceURL) ; + + if ( serviceURL.indexOf('?') >= 0 ) + throw new QueryExceptionHTTP(-1, "URL already has a query string ("+serviceURL+")") ; + + this.serviceURL = serviceURL ; + } + + private String getQueryString() + { + if ( queryString == null ) + queryString = super.httpString() ; + return queryString ; + } + + public HttpURLConnection getConnection() { return httpConnection ; } + + /** Set the content type (Accept header) for the results + */ + + public void setAccept(String contentType) + { + contentTypeResult = contentType ; + } + + public void setBasicAuthentication(String user, char[] password) + { + this.user = user ; + this.password = password ; + } + + /** Return whether this request will go by GET or POST + * @return boolean + */ + public boolean usesPOST() + { + if ( forcePOST ) + return true ; + String s = getQueryString() ; + + return serviceURL.length()+s.length() >= urlLimit ; + } + + /** Force the use of HTTP POST for the query operation + */ + + public void setForcePOST() + { + forcePOST = true ; + } + + /** Execute the operation + * @return Model The resulting model + * @throws QueryExceptionHTTP + */ + public InputStream exec() throws QueryExceptionHTTP + { + try { + if (usesPOST()) + return execPost(); + return execGet(); + } catch (QueryExceptionHTTP httpEx) + { + log.trace("Exception in exec", httpEx); + throw httpEx; + } + catch (JenaException jEx) + { + log.trace("JenaException in exec", jEx); + throw jEx ; + } + } + + private InputStream execGet() throws QueryExceptionHTTP + { + URL target = null ; + String qs = getQueryString() ; + + ARQ.getHttpRequestLogger().trace(qs) ; + + try { + if ( count() == 0 ) + target = new URL(serviceURL) ; + else + target = new URL(serviceURL+"?"+qs) ; + } + catch (MalformedURLException malEx) + { throw new QueryExceptionHTTP(0, "Malformed URL: "+malEx) ; } + log.trace("GET "+target.toExternalForm()) ; + + try + { + httpConnection = (HttpURLConnection) target.openConnection(); + httpConnection.setRequestProperty("Accept", contentTypeResult) ; + httpConnection.setReadTimeout(timeOut); + int x = httpConnection.getReadTimeout() ; + + // By default, following 3xx redirects is true + //conn.setFollowRedirects(true) ; + basicAuthentication(httpConnection) ; + + httpConnection.setDoInput(true); + httpConnection.connect(); + try + { + return execCommon(); + } + catch (QueryExceptionHTTP qEx) + { + // Back-off and try POST if something complain about long URIs + // Broken + if (qEx.getResponseCode() == 414 /*HttpServletResponse.SC_REQUEST_URI_TOO_LONG*/ ) + return execPost(); + throw qEx; + } + } + catch (java.net.ConnectException connEx) + { throw new QueryExceptionHTTP(QueryExceptionHTTP.NoServer, "Failed to connect to remote server"); } + catch (IOException ioEx) + { throw new QueryExceptionHTTP(ioEx); } + } + + private InputStream execPost() throws QueryExceptionHTTP + { + URL target = null; + try { target = new URL(serviceURL); } + catch (MalformedURLException malEx) + { throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx); } + log.trace("POST "+target.toExternalForm()) ; + + ARQ.getHttpRequestLogger().trace(target.toExternalForm()) ; + + try + { + httpConnection = (HttpURLConnection) target.openConnection(); + httpConnection.setRequestMethod("POST") ; + httpConnection.setRequestProperty("Accept", contentTypeResult) ; + httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded") ; + basicAuthentication(httpConnection) ; + httpConnection.setDoOutput(true) ; + + boolean first = true ; + OutputStream out = httpConnection.getOutputStream() ; + for ( Iterator<Pair> iter = pairs().listIterator() ; iter.hasNext() ; ) + { + if ( ! first ) + out.write('&') ; + first = false ; + Pair p = iter.next() ; + out.write(p.getName().getBytes()) ; + out.write('=') ; + String x = p.getValue() ; + x = Convert.encWWWForm(x) ; + out.write(x.getBytes()) ; + ARQ.getHttpRequestLogger().trace("Param: "+x) ; + } + out.flush() ; + httpConnection.connect() ; + return execCommon() ; + } + catch (java.net.ConnectException connEx) + { throw new QueryExceptionHTTP(-1, "Failed to connect to remote server"); } + catch (IOException ioEx) + { throw new QueryExceptionHTTP(ioEx); } + } + + private void basicAuthentication(HttpURLConnection httpConnection2) + { + // Do basic authentication : do directly, not via an Authenticator, because it + // avoids an extra round trip (Java normally does the request without authetication, + // then reties with) + + if ( user != null || password != null) + { + try + { + if ( user == null || password == null ) + log.warn("Only one of user/password is set") ; + // We want: "Basic user:password" except user:password is base 64 encoded. + // Build string, get as UTF-8, bytes, translate to base 64. + StringBuffer x = new StringBuffer() ; + byte b[] = x.append(user).append(":").append(password).toString().getBytes("UTF-8") ; + String y = Base64.encodeBytes(b) ; + httpConnection.setRequestProperty("Authorization", "Basic "+y) ; + // Overwrite any password details we copied. + // Still leaves the copy in the HTTP connection. But this only basic auth. + for ( int i = 0 ; i < x.length() ; i++ ) x.setCharAt(i, '*') ; + for ( int i = 0 ; i < b.length ; i++ ) b[i] = (byte)0 ; + } catch (UnsupportedEncodingException ex) + { + // Can't happen - UTF-8 is required of all Java platforms. + throw new ARQInternalErrorException("UTF-8 is broken on this platform", ex) ; + } + } + } + + + private InputStream execCommon() throws QueryExceptionHTTP + { + try { + responseCode = httpConnection.getResponseCode() ; + responseMessage = Convert.decWWWForm(httpConnection.getResponseMessage()) ; + + // 1xx: Informational + // 2xx: Success + // 3xx: Redirection + // 4xx: Client Error + // 5xx: Server Error + + if ( 300 <= responseCode && responseCode < 400 ) + throw new QueryExceptionHTTP(responseCode, responseMessage) ; + + // Other 400 and 500 - errors + + if ( responseCode >= 400 ) + throw new QueryExceptionHTTP(responseCode, responseMessage) ; + + // Request suceeded + //httpConnection.setReadTimeout(10) ; + InputStream in = httpConnection.getInputStream() ; + + if ( false ) + { + // Dump the header + Map<String,List<String>> map = httpConnection.getHeaderFields() ; + for ( Iterator<String> iter = map.keySet().iterator() ; iter.hasNext() ; ) + { + String k = iter.next(); + List<String> v = map.get(k) ; + System.out.println(k+" = "+v) ; + } + } + + // Dump response body + if ( false ) + { + StringBuffer b = new StringBuffer(1000) ; + byte[] chars = new byte[1000] ; + while(true) + { + int x = in.read(chars) ; + if ( x < 0 ) break ; + b.append(new String(chars, 0, x, FileUtils.encodingUTF8)) ; + } + System.out.println(b.toString()) ; + System.out.flush() ; + // Reset + in = new ByteArrayInputStream(b.toString().getBytes(FileUtils.encodingUTF8)) ; + } + + + // +++ WORKAROUND for badly behaved apps. + // Apps sometimes call QueryExecution.close straight after .execSelect. + // that results in some resuls being seen, not all of them => XMl parse errors. +// byte[] bytes = IO.readWholeFile(in) ; +// in = new ByteArrayInputStream(bytes) ; + // +++ + + return in ; + } + catch (IOException ioEx) + { + throw new QueryExceptionHTTP(ioEx) ; + } + catch (JenaException rdfEx) + { + throw new QueryExceptionHTTP(rdfEx) ; + } + } + + @Override + public String toString() + { + String s = httpString() ; + if ( s != null && s.length() > 0 ) + return serviceURL+"?"+s ; + return serviceURL ; + } +} + +/* + * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java 2011-08-05 13:47:08 UTC (rev 3009) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java 2011-08-08 06:00:16 UTC (rev 3010) @@ -219,6 +219,7 @@ */ private static void writeToSparqlLog(String s) { File f = new File(sparqlLog); + f.mkdirs(); if(!f.canWrite() ){ logger.info("could not write SPARQL log to : " + f.getAbsolutePath()); return ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-08 13:35:22
|
Revision: 3013 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3013&view=rev Author: lorenz_b Date: 2011-08-08 13:35:14 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Continued algorithms. Added more OWL axioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/config/DataPropertyEditor.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointDatatypePropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/FunctionalDatatypePropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/core/owl/SubDatatypePropertyAxiom.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,233 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyDomainAxiom; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="property domain axiom learner") +public class DataPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(DataPropertyDomainAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DatatypeProperty.class) + private DatatypeProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public DataPropertyDomainAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public DatatypeProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing domains + Description existingDomain = reasoner.getDomain(propertyToDescribe); + logger.info("Existing domain: " + existingDomain); + + //get subjects with types + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + Map<Individual, Set<NamedClass>> newIndividual2Types; + boolean repeat = true; + while(!terminationCriteriaSatisfied() && repeat){ + newIndividual2Types = getSubjectsWithTypes(fetchedRows); + individual2Types.putAll(newIndividual2Types); + currentlyBestAxioms = buildBestAxioms(individual2Types); + fetchedRows += 1000; + repeat = !newIndividual2Types.isEmpty(); + } + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(NamedClass nc : entry.getValue()){ + Integer cnt = result.get(nc); + if(cnt == null){ + cnt = Integer.valueOf(1); + } + result.put(nc, Integer.valueOf(cnt + 1)); + } + } + + EvaluatedAxiom evalAxiom; + for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + evalAxiom = new EvaluatedAxiom(new DatatypePropertyDomainAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + axioms.add(evalAxiom); + } + + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ + SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { + + @Override + public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + int limit = 1000; + String query = String.format("SELECT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual ind; + Set<NamedClass> types; + while(rs.hasNext()){ + qs = rs.next(); + ind = new Individual(qs.getResource("ind").getURI()); + types = individual2Types.get(ind); + if(types == null){ + types = new HashSet<NamedClass>(); + individual2Types.put(ind, types); + } + types.add(new NamedClass(qs.getResource("type").getURI())); + } + return individual2Types; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,234 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyRangeAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +@ComponentAnn(name="property range learner") +public class DataPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(DataPropertyRangeAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public DataPropertyRangeAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing range + Description existingRange = reasoner.getRange(propertyToDescribe); + logger.debug("Existing range: " + existingRange); + + //get objects with types + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + Map<Individual, Set<NamedClass>> newIndividual2Types; + boolean repeat = true; + while(!terminationCriteriaSatisfied() && repeat){ + newIndividual2Types = getObjectsWithTypes(fetchedRows); + individual2Types.putAll(newIndividual2Types); + currentlyBestAxioms = buildBestAxioms(individual2Types); + fetchedRows += 1000; + repeat = !newIndividual2Types.isEmpty(); + } + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(NamedClass nc : entry.getValue()){ + Integer cnt = result.get(nc); + if(cnt == null){ + cnt = Integer.valueOf(1); + } + result.put(nc, Integer.valueOf(cnt + 1)); + } + } + + EvaluatedAxiom evalAxiom; + for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + evalAxiom = new EvaluatedAxiom(new ObjectPropertyRangeAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + axioms.add(evalAxiom); + } + + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ + SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { + + @Override + public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + private Map<Individual, Set<NamedClass>> getObjectsWithTypes(int offset){ + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + int limit = 1000; + String query = String.format("SELECT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual ind; + Set<NamedClass> types; + while(rs.hasNext()){ + qs = rs.next(); + ind = new Individual(qs.getResource("ind").getURI()); + types = individual2Types.get(ind); + if(types == null){ + types = new HashSet<NamedClass>(); + individual2Types.put(ind, types); + } + types.add(new NamedClass(qs.getResource("type").getURI())); + } + return individual2Types; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,143 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="disjoint property axiom learner") +public class DisjointDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + private DatatypeProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public DisjointDataPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public DatatypeProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //TODO + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-08 06:59:56 UTC (rev 3012) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -1,44 +1,107 @@ package org.dllearner.algorithms.properties; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ResultSet; + @ComponentAnn(name="disjoint property axiom learner") public class DisjointPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - private String propertyToDescribe; + private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); - public String getPropertyToDescribe() { + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public DisjointPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { return propertyToDescribe; } - public void setPropertyToDescribe(String propertyToDescribe) { + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { this.propertyToDescribe = propertyToDescribe; } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } - public DisjointPropertyAxiomLearner(SparqlEndpointKS ks){ - + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; } - + @Override public void start() { - // TODO Auto-generated method stub - + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //TODO + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } @Override public Configurator getConfigurator() { @@ -48,14 +111,33 @@ @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - // TODO Auto-generated method stub - return null; + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; } + + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } } Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,225 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="equivalent property axiom learner") +public class EquivalentDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(EquivalentDataPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + private DatatypeProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public EquivalentDataPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public DatatypeProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing super properties + SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); + logger.debug("Existing super properties: " + existingSuperProperties); + + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + DatatypeProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Integer all = property2Count.get(propertyToDescribe); + property2Count.remove(propertyToDescribe); + + EvaluatedAxiom evalAxiom; + for(Entry<DatatypeProperty, Integer> entry : sortByValues(property2Count)){ + evalAxiom = new EvaluatedAxiom(new EquivalentDatatypePropertiesAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)all)); + axioms.add(evalAxiom); + } + + property2Count.put(propertyToDescribe, all); + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<DatatypeProperty, Integer>> sortByValues(Map<DatatypeProperty, Integer> map){ + SortedSet<Entry<DatatypeProperty, Integer>> sortedSet = new TreeSet<Map.Entry<DatatypeProperty,Integer>>(new Comparator<Entry<DatatypeProperty, Integer>>() { + + @Override + public int compare(Entry<DatatypeProperty, Integer> value1, Entry<DatatypeProperty, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,171 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; + +@ComponentAnn(name="functional property axiom learner") +public class FunctionalDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(FunctionalDataPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + private DatatypeProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public FunctionalDataPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public DatatypeProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as symmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); + boolean declaredAsFunctional = executeAskQuery(query); + if(declaredAsFunctional) { + logger.info("Property is already declared as functional in knowledge base."); + } + + //get number of instances of s with <s p o> + query = String.format("SELECT (COUNT(DISTINCT ?s)) AS ?all WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + int all = 1; + while(rs.hasNext()){ + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + //get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeQuery(query); + int notFunctional = 1; + while(rs.hasNext()){ + qs = rs.next(); + notFunctional = qs.getLiteral("notfunctional").getInt(); + } + if(all > 0){ + double frac = (all - notFunctional) / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalDatatypePropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return currentlyBestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-08 06:59:56 UTC (rev 3012) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -96,7 +96,7 @@ currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); - logger.debug("Existing domain: " + existingDomain); + logger.info("Existing domain: " + existingDomain); //get subjects with types Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,229 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.SubDatatypePropertyAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="subPropertyOf learner") +public class SubDataPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + private DatatypeProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public SubDataPropertyOfAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public DatatypeProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(DatatypeProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing super properties + SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); + logger.debug("Existing super properties: " + existingSuperProperties); + + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); + DatatypeProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildAxioms(Map<DatatypeProperty, Integer> property2Count){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Integer all = property2Count.get(propertyToDescribe); + property2Count.remove(propertyToDescribe); + + EvaluatedAxiom evalAxiom; + for(Entry<DatatypeProperty, Integer> entry : sortByValues(property2Count)){ + evalAxiom = new EvaluatedAxiom(new SubDatatypePropertyAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)all)); + axioms.add(evalAxiom); + } + + property2Count.put(propertyToDescribe, all); + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<DatatypeProperty, Integer>> sortByValues(Map<DatatypeProperty, Integer> map){ + SortedSet<Entry<DatatypeProperty, Integer>> sortedSet = new TreeSet<Map.Entry<DatatypeProperty,Integer>>(new Comparator<Entry<DatatypeProperty, Integer>>() { + + @Override + public int compare(Entry<DatatypeProperty, Integer> value1, Entry<DatatypeProperty, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + private long getRemainingMaxExecutionTime(){ + return (maxExecutionTimeInSeconds == 0) ? 0 : Math.max(1, (maxExecutionTimeInSeconds * 1000)-(System.currentTimeMillis()-startTime)); + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(getRemainingMaxExecutionTime()); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-08 06:59:56 UTC (rev 3012) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -55,6 +55,7 @@ private long startTime; private int fetchedRows; + public SubPropertyOfAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; } @@ -207,6 +208,10 @@ return sortedSet; } + private long getRemainingMaxExecutionTime(){ + return (maxExecutionTimeInSeconds == 0) ? 0 : Math.max(1, (maxExecutionTimeInSeconds * 1000)-(System.currentTimeMillis()-startTime)); + } + /* * Executes a SELECT query and returns the result. */ @@ -214,7 +219,7 @@ logger.info("Sending query \n {}", query); ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + queryExecution.setTimeout(getRemainingMaxExecutionTime()); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Added: trunk/components-core/src/main/java/org/dllearner/core/config/DataPropertyEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/DataPropertyEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/DataPropertyEditor.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,90 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +import org.dllearner.core.owl.DatatypeProperty; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 7/26/11 + * Time: 9:42 PM + * <p/> + * Basic Property Editor for the Object Property DL-Learner class. Doesn't have GUI support yet but we could add that later if we wanted. + */ +public class DataPropertyEditor implements PropertyEditor { + + + private DatatypeProperty value; + + @Override + public void setValue(Object value) { + this.value = (DatatypeProperty) value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean isPaintable() { + /** Not right now, we're doing non gui work */ + return false; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + + } + + @Override + public String getJavaInitializationString() { + /** This returns the value needed to reconstitute the object from a string */ + return value.getName(); + } + + @Override + public String getAsText() { + /** Get the text value of this object - for displaying in GUIS, etc */ + return value.getName(); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = new DatatypeProperty(text); + } + + @Override + public String[] getTags() { + /** If there was a known set of values it had to have, we could add that list here */ + return new String[0]; + } + + @Override + public Component getCustomEditor() { + /** GUI stuff, if you wanted to edit it a custom way */ + return null; + } + + @Override + public boolean supportsCustomEditor() { + /** We don't support this right now, but maybe later */ + return false; + + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } +} Added: trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointDatatypePropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointDatatypePropertyAxiom.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointDatatypePropertyAxiom.java 2011-08-08 13:35:14 UTC (rev 3013) @@ -0,0 +1,55 @@ +package org.dllearner.core.owl; + +import java.util.Map; + +public class DisjointDatatypePropertyAxiom extends PropertyAxiom { + + /** + * + */ + private static final long serialVersionUID = -1085651734702155330L; + private DatatypeProperty role; + private DatatypeProperty disjointRole; + + public DisjointDatatypePropertyAxiom(DatatypeProperty role, DatatypeProperty disjointRole) { + this.role = role; + this.disjointRole = disjointRole; + } + + public DatatypeProperty getRole() { + return role; + } + + public DatatypeProperty getDisjointRole() { + return disjointRole; + } + + public int getLength() { + return 1 + role.getLength() + disjointRole.getLength(); + } + + public String toString(String baseURI, Map<String,String> prefixes) { + return "DisjointObjectProperties(" + role.toString(baseURI, prefixes) + "," + disjointRole.toString(baseURI, prefixes) + ")"; + } + + public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { + return "DisjointObjectProperties(" + role.toKBSyntaxString(baseURI, prefixes) + "," + disjointRole.toKBSyntaxString(baseURI, prefixes) + ")"; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { + return role.toString(baseURI, prefixes) + " DisjointWith: " + disjointRole.toString(baseURI, prefixes); + } +} Added: tr... [truncated message content] |
From: <lor...@us...> - 2011-08-09 09:42:47
|
Revision: 3016 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3016&view=rev Author: lorenz_b Date: 2011-08-09 09:42:41 +0000 (Tue, 09 Aug 2011) Log Message: ----------- Small changes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypePropertyDomainAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-09 08:37:17 UTC (rev 3015) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-09 09:42:41 UTC (rev 3016) @@ -18,6 +18,7 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; @@ -41,7 +42,7 @@ private static final Logger logger = LoggerFactory.getLogger(DataPropertyDomainAxiomLearner.class); - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DatatypeProperty.class) + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) private int maxExecutionTimeInSeconds = 10; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypePropertyDomainAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypePropertyDomainAxiom.java 2011-08-09 08:37:17 UTC (rev 3015) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypePropertyDomainAxiom.java 2011-08-09 09:42:41 UTC (rev 3016) @@ -52,30 +52,19 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return "Domain(" + getProperty() + ", " + getDomain() + ")"; } - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#toKBSyntaxString(java.lang.String, java.util.Map) - */ + public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return "OPDOMAIN(" + property.toKBSyntaxString(baseURI, prefixes) + ") = " + domain.toKBSyntaxString(baseURI, prefixes); } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.Axiom#accept(org.dllearner.core.owl.AxiomVisitor) - */ @Override public void accept(AxiomVisitor visitor) { visitor.visit(this); } - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) - */ public void accept(KBElementVisitor visitor) { visitor.visit(this); } @@ -85,8 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; - } + return "Domain(" + getProperty().toManchesterSyntaxString(baseURI, prefixes) + ", " + getDomain().toManchesterSyntaxString(baseURI, prefixes) + ")"; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-09 12:42:04
|
Revision: 3019 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3019&view=rev Author: lorenz_b Date: 2011-08-09 12:41:57 +0000 (Tue, 09 Aug 2011) Log Message: ----------- Fixed some bugs. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -29,6 +29,7 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -155,8 +156,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } @@ -230,5 +233,14 @@ return resultSet; } + public static void main(String[] args) throws Exception{ + DataPropertyDomainAxiomLearner l = new DataPropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/AutomobileEngine/height")); + l.setMaxExecutionTimeInSeconds(0); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -156,8 +156,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } @@ -208,30 +210,11 @@ types = new HashSet<Datatype>(); individual2Datatypes.put(ind, types); } - types.add(getDatatypeForURI(qs.getResource("datatype").getURI())); + types.add(new Datatype(qs.getResource("datatype").getURI())); } return individual2Datatypes; } - private Datatype getDatatypeForURI(String uri){ - return new Datatype(uri); -// if(uri.equals(OWL2Datatype.BOOLEAN.getURI())) -// return OWL2Datatype.BOOLEAN.getDatatype(); -// else if(uri.equals(OWL2Datatype.DOUBLE.getURI())) -// return OWL2Datatype.DOUBLE.getDatatype(); -// else if(uri.equals(OWL2Datatype.INT.getURI())) -// return OWL2Datatype.INT.getDatatype(); -// else if(uri.equals(OWL2Datatype.INTEGER.getURI())) -// return OWL2Datatype.INTEGER.getDatatype(); -// else if(uri.equals(OWL2Datatype.STRING.getURI())) -// return OWL2Datatype.STRING.getDatatype(); -// else if(uri.equals(OWL2Datatype.DATE.getURI())) -// return OWL2Datatype.DATE.getDatatype(); -// else if(uri.equals(OWL2Datatype.DATETIME.getURI())) -// return OWL2Datatype.DATETIME.getDatatype(); -// throw new Error("Unsupported datatype " + uri + ". Please inform a DL-Learner developer to add it."); - } - /* * Executes a SELECT query and returns the result. */ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -19,6 +19,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; @@ -39,7 +40,7 @@ private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) private int maxExecutionTimeInSeconds = 10; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -1,7 +1,5 @@ package org.dllearner.algorithms.properties; -import java.beans.PropertyEditor; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -14,8 +12,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -24,6 +22,7 @@ import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -39,7 +38,6 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="property domain axiom learner") public class PropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { @@ -159,8 +157,10 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -12,8 +12,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractComponent; import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -22,6 +22,7 @@ import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -29,6 +30,7 @@ import org.dllearner.core.owl.ObjectPropertyRangeAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -36,7 +38,6 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="property range learner") public class PropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { @@ -156,13 +157,15 @@ Integer cnt = result.get(nc); if(cnt == null){ cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); } - result.put(nc, Integer.valueOf(cnt + 1)); + result.put(nc, cnt); } } EvaluatedAxiom evalAxiom; - for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + for(Entry<NamedClass, Integer> entry : sortByValues(result)){System.out.println(entry.getKey());System.out.println(entry.getValue()); evalAxiom = new EvaluatedAxiom(new ObjectPropertyRangeAxiom(propertyToDescribe, entry.getKey()), new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); axioms.add(evalAxiom); @@ -195,7 +198,7 @@ private Map<Individual, Set<NamedClass>> getObjectsWithTypes(int offset){ Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); int limit = 1000; - String query = String.format("SELECT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); ResultSet rs = executeQuery(query); QuerySolution qs; Individual ind; @@ -230,5 +233,14 @@ ResultSet resultSet = queryExecution.execSelect(); return resultSet; } + + public static void main(String[] args) throws Exception{ + PropertyRangeAxiomLearner l = new PropertyRangeAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/aircraftElectronic")); + l.setMaxExecutionTimeInSeconds(0); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2011-08-09 11:55:06 UTC (rev 3018) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2011-08-09 12:41:57 UTC (rev 3019) @@ -65,5 +65,30 @@ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { return uri.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Datatype other = (Datatype) obj; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-10 13:47:48
|
Revision: 3023 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3023&view=rev Author: lorenz_b Date: 2011-08-10 13:47:39 +0000 (Wed, 10 Aug 2011) Log Message: ----------- Renamed algorithms. Added algorithm for inversefunctional object property axioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyAxiomVisitor.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/InverseFunctionalObjectPropertyAxiom.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -38,7 +38,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="property domain axiom learner") +@ComponentAnn(name="dataproperty domain axiom learner") public class DataPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -38,7 +38,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="property range learner") +@ComponentAnn(name="dataproperty range learner") public class DataPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyRangeAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -35,10 +35,10 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="disjoint property axiom learner") +@ComponentAnn(name="disjoint dataproperty axiom learner") public class DisjointDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); + private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -35,10 +35,10 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="disjoint property axiom learner") +@ComponentAnn(name="disjoint objectproperty axiom learner") public class DisjointPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { -private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); +private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -32,7 +32,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="equivalent property axiom learner") +@ComponentAnn(name="equivalent dataproperty axiom learner") public class EquivalentDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(EquivalentDataPropertyAxiomLearner.class); Copied: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java (from rev 3022, trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java) =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -0,0 +1,227 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +@ComponentAnn(name="equivalent objectproperty axiom learner") +public class EquivalentObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(EquivalentObjectPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public EquivalentObjectPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing super properties + SortedSet<ObjectProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); + logger.debug("Existing super properties: " + existingSuperProperties); + + //get subjects with types + int limit = 1000; + int offset = 0; + String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + + "}"; + String query; + Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); + ObjectProperty prop; + Integer oldCnt; + boolean repeat = true; + + while(!terminationCriteriaSatisfied() && repeat){ + query = String.format(queryTemplate, propertyToDescribe, limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + repeat = false; + while(rs.hasNext()){ + qs = rs.next(); + prop = new ObjectProperty(qs.getResource("p").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(prop); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } + result.put(prop, oldCnt); + qs.getLiteral("count").getInt(); + repeat = true; + } + if(!result.isEmpty()){ + currentlyBestAxioms = buildAxioms(result); + offset += 1000; + } + + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Integer all = property2Count.get(propertyToDescribe); + property2Count.remove(propertyToDescribe); + + EvaluatedAxiom evalAxiom; + for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ + evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)all)); + axioms.add(evalAxiom); + } + + property2Count.put(propertyToDescribe, all); + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<ObjectProperty, Integer>> sortByValues(Map<ObjectProperty, Integer> map){ + SortedSet<Entry<ObjectProperty, Integer>> sortedSet = new TreeSet<Map.Entry<ObjectProperty,Integer>>(new Comparator<Entry<ObjectProperty, Integer>>() { + + @Override + public int compare(Entry<ObjectProperty, Integer> value1, Entry<ObjectProperty, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + +} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -1,227 +0,0 @@ -package org.dllearner.algorithms.properties; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; - -@ComponentAnn(name="equivalent property axiom learner") -public class EquivalentPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - - private static final Logger logger = LoggerFactory.getLogger(EquivalentPropertyAxiomLearner.class); - - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) - private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; - @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) - private int maxFetchedRows = 0; - - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - - private List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - - public EquivalentPropertyAxiomLearner(SparqlEndpointKS ks){ - this.ks = ks; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - - public ObjectProperty getPropertyToDescribe() { - return propertyToDescribe; - } - - public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { - this.propertyToDescribe = propertyToDescribe; - } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - - @Override - public void start() { - logger.info("Start learning..."); - startTime = System.currentTimeMillis(); - fetchedRows = 0; - currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //get existing super properties - SortedSet<ObjectProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); - logger.debug("Existing super properties: " + existingSuperProperties); - - //get subjects with types - int limit = 1000; - int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + - "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + - "}"; - String query; - Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); - ObjectProperty prop; - Integer oldCnt; - boolean repeat = true; - - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, propertyToDescribe, limit, offset); - ResultSet rs = executeQuery(query); - QuerySolution qs; - repeat = false; - while(rs.hasNext()){ - qs = rs.next(); - prop = new ObjectProperty(qs.getResource("p").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(prop); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } - result.put(prop, oldCnt); - qs.getLiteral("count").getInt(); - repeat = true; - } - if(!result.isEmpty()){ - currentlyBestAxioms = buildAxioms(result); - offset += 1000; - } - - } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); - } - - @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } - - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - - } - - private boolean terminationCriteriaSatisfied(){ - boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; - boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; - return timeLimitExceeded || resultLimitExceeded; - } - - private List<EvaluatedAxiom> buildAxioms(Map<ObjectProperty, Integer> property2Count){ - List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Integer all = property2Count.get(propertyToDescribe); - property2Count.remove(propertyToDescribe); - - EvaluatedAxiom evalAxiom; - for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ - evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(propertyToDescribe, entry.getKey()), - new AxiomScore(entry.getValue() / (double)all)); - axioms.add(evalAxiom); - } - - property2Count.put(propertyToDescribe, all); - return axioms; - } - - /* - * Returns the entries of the map sorted by value. - */ - private SortedSet<Entry<ObjectProperty, Integer>> sortByValues(Map<ObjectProperty, Integer> map){ - SortedSet<Entry<ObjectProperty, Integer>> sortedSet = new TreeSet<Map.Entry<ObjectProperty,Integer>>(new Comparator<Entry<ObjectProperty, Integer>>() { - - @Override - public int compare(Entry<ObjectProperty, Integer> value1, Entry<ObjectProperty, Integer> value2) { - if(value1.getValue() < value2.getValue()){ - return 1; - } else if(value2.getValue() < value1.getValue()){ - return -1; - } else { - return value1.getKey().compareTo(value2.getKey()); - } - } - }); - sortedSet.addAll(map.entrySet()); - return sortedSet; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } - -} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; -@ComponentAnn(name="functional property axiom learner") +@ComponentAnn(name="functional dataproperty axiom learner") public class FunctionalDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalDataPropertyAxiomLearner.class); Copied: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java (from rev 3022, trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java) =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -0,0 +1,171 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; + +@ComponentAnn(name="functional objectproperty axiom learner") +public class FunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(FunctionalObjectPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public FunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as symmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); + boolean declaredAsFunctional = executeAskQuery(query); + if(declaredAsFunctional) { + logger.info("Property is already declared as functional in knowledge base."); + } + + //get number of instances of s with <s p o> + query = String.format("SELECT (COUNT(DISTINCT ?s)) AS ?all WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + int all = 1; + while(rs.hasNext()){ + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + //get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeQuery(query); + int notFunctional = 1; + while(rs.hasNext()){ + qs = rs.next(); + notFunctional = qs.getLiteral("notfunctional").getInt(); + } + if(all > 0){ + double frac = (all - notFunctional) / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return currentlyBestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } +} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -1,171 +0,0 @@ -package org.dllearner.algorithms.properties; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; -import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.vocabulary.OWL; - -@ComponentAnn(name="functional property axiom learner") -public class FunctionalPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - - private static final Logger logger = LoggerFactory.getLogger(FunctionalPropertyAxiomLearner.class); - - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) - private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; - @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) - private int maxFetchedRows = 0; - - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - - private List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - - - public FunctionalPropertyAxiomLearner(SparqlEndpointKS ks){ - this.ks = ks; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - - public ObjectProperty getPropertyToDescribe() { - return propertyToDescribe; - } - - public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { - this.propertyToDescribe = propertyToDescribe; - } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - - @Override - public void start() { - logger.info("Start learning..."); - startTime = System.currentTimeMillis(); - fetchedRows = 0; - currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - - //check if property is already declared as symmetric in knowledge base - String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); - boolean declaredAsFunctional = executeAskQuery(query); - if(declaredAsFunctional) { - logger.info("Property is already declared as functional in knowledge base."); - } - - //get number of instances of s with <s p o> - query = String.format("SELECT (COUNT(DISTINCT ?s)) AS ?all WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); - ResultSet rs = executeQuery(query); - QuerySolution qs; - int all = 1; - while(rs.hasNext()){ - qs = rs.next(); - all = qs.getLiteral("all").getInt(); - } - //get number of instances of s with <s p o> <s p o1> where o != o1 - query = "SELECT (COUNT(DISTINCT ?s)) AS ?notfunctional WHERE {?s <%s> ?o. ?s <%s> ?o1. FILTER(?o != ?o1) }"; - query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeQuery(query); - int notFunctional = 1; - while(rs.hasNext()){ - qs = rs.next(); - notFunctional = qs.getLiteral("notfunctional").getInt(); - } - if(all > 0){ - double frac = (all - notFunctional) / (double)all; - currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); - } - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); - } - - @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - return currentlyBestAxioms; - } - - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - reasoner = new SPARQLReasoner(ks); - } - - private boolean executeAskQuery(String query){ - logger.info("Sending query \n {}", query); - - QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - boolean result = queryExecution.execAsk(); - return result; - } - - /* - * Executes a SELECT query and returns the result. - */ - private ResultSet executeQuery(String query){ - logger.info("Sending query \n {}", query); - - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); - queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); - for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultSet = queryExecution.execSelect(); - return resultSet; - } -} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -0,0 +1,171 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; + +@ComponentAnn(name="inversefunctional objectproperty axiom learner") +public class InverseFunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(InverseFunctionalObjectPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + + public InverseFunctionalObjectPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as symmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL.FunctionalProperty.getURI()); + boolean declaredAsFunctional = executeAskQuery(query); + if(declaredAsFunctional) { + logger.info("Property is already declared as functional in knowledge base."); + } + + //get number of instances of s with <s p o> + query = String.format("SELECT (COUNT(DISTINCT ?o) AS ?all) WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); + ResultSet rs = executeQuery(query); + QuerySolution qs; + int all = 1; + while(rs.hasNext()){ + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + //get number of instances of s with <s p o> <s p o1> where o != o1 + query = "SELECT (COUNT(DISTINCT ?s) AS ?noninversefunctional) WHERE {?s1 <%s> ?o. ?s2 <%s> ?o. FILTER(?s1 != ?s2) }"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeQuery(query); + int notFunctional = 1; + while(rs.hasNext()){ + qs = rs.next(); + notFunctional = qs.getLiteral("noninversefunctional").getInt(); + } + if(all > 0){ + double frac = (all - notFunctional) / (double)all; + currentlyBestAxioms.add(new EvaluatedAxiom(new FunctionalObjectPropertyAxiom(propertyToDescribe), new AxiomScore(frac))); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return currentlyBestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + } + + private boolean executeAskQuery(String query){ + logger.info("Sending query \n {}", query); + + QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + boolean result = queryExecution.execAsk(); + return result; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } +} Copied: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java (from rev 3022, trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java) =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -0,0 +1,238 @@ +package org.dllearner.algorithms.properties; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="objectproperty domain axiom learner") +public class ObjectPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedAxiom> currentlyBestAxioms; + private long startTime; + private int fetchedRows; + + public ObjectPropertyDomainAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + //get existing domains + Description existingDomain = reasoner.getDomain(propertyToDescribe); + logger.info("Existing domain: " + existingDomain); + + //get subjects with types + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + Map<Individual, Set<NamedClass>> newIndividual2Types; + boolean repeat = true; + while(!terminationCriteriaSatisfied() && repeat){ + newIndividual2Types = getSubjectsWithTypes(fetchedRows); + individual2Types.putAll(newIndividual2Types); + currentlyBestAxioms = buildBestAxioms(individual2Types); + fetchedRows += 1000; + repeat = !newIndividual2Types.isEmpty(); + } + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); + while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ + bestAxioms.add(it.next().getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); + + List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); + + return bestAxioms; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init() throws ComponentInitException { + reasoner = new SPARQLReasoner(ks); + + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); + for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(NamedClass nc : entry.getValue()){ + Integer cnt = result.get(nc); + if(cnt == null){ + cnt = Integer.valueOf(1); + } else { + cnt = Integer.valueOf(cnt + 1); + } + result.put(nc, cnt); + } + } + + EvaluatedAxiom evalAxiom; + for(Entry<NamedClass, Integer> entry : sortByValues(result)){ + evalAxiom = new EvaluatedAxiom(new ObjectPropertyDomainAxiom(propertyToDescribe, entry.getKey()), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + axioms.add(evalAxiom); + } + + return axioms; + } + + /* + * Returns the entries of the map sorted by value. + */ + private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ + SortedSet<Entry<NamedClass, Integer>> sortedSet = new TreeSet<Map.Entry<NamedClass,Integer>>(new Comparator<Entry<NamedClass, Integer>>() { + + @Override + public int compare(Entry<NamedClass, Integer> value1, Entry<NamedClass, Integer> value2) { + if(value1.getValue() < value2.getValue()){ + return 1; + } else if(value2.getValue() < value1.getValue()){ + return -1; + } else { + return value1.getKey().compareTo(value2.getKey()); + } + } + }); + sortedSet.addAll(map.entrySet()); + return sortedSet; + } + + private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ + Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); + int limit = 1000; + String query = String.format("SELECT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, offset); + ResultSet rs = executeQuery(query); + QuerySolution qs; + Individual ind; + Set<NamedClass> types; + while(rs.hasNext()){ + qs = rs.next(); + ind = new Individual(qs.getResource("ind").getURI()); + types = individual2Types.get(ind); + if(types == null){ + types = new HashSet<NamedClass>(); + individual2Types.put(ind, types); + } + types.add(new NamedClass(qs.getResource("type").getURI())); + } + return individual2Types; + } + + /* + * Executes a SELECT query and returns the result. + */ + private ResultSet executeQuery(String query){ + logger.info("Sending query \n {}", query); + + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); + for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : ks.getEndpoint().getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + ResultSet resultSet = queryExecution.execSelect(); + return resultSet; + } + + +} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-10 09:04:00 UTC (rev 3022) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-10 13:47:39 UTC (rev 3023) @@ -1,238 +0,0 @@ -package org.dllearner.algorithms.properties; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerEditor; -import org.dllearner.core.config.ObjectPropertyEditor; -import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyDomainAxiom; -import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.reasoning.SPARQLReasoner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; - -@ComponentAnn(name="property domain axiom learner") -public class PropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { - - private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); - - @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) - private ObjectProperty propertyToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) - private int maxExecutionTimeInSeconds = 10; - @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) - private int maxFetchedRows = 0; - - private SPARQLReasoner reasoner; - private SparqlEndpointKS ks; - - private List<EvaluatedAxiom> currentlyBestAxioms; - private long startTime; - private int fetchedRows; - - public PropertyDomainAxiomLearner(SparqlEndpointKS ks){ - this.ks = ks; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - - public ObjectProperty getPropertyToDescribe() { - return propertyToDescribe; - } - - public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { - this.propertyToDescribe = propertyToDescribe; - } - - public int getMaxFetchedRows() { - return maxFetchedRows; - } - - public void setMaxFetchedRows(int maxFetchedRows) { - this.maxFetchedRows = maxFetchedRows; - } - - @Override - public void start() { - logger.info("Start learning..."); - startTime = System.currentTimeMillis(); - fetchedRows = 0; - currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //get existing domains - Description existingDomain = reasoner.getDomain(propertyToDescribe); - logger.info("Existing domain: " + existingDomain); - - //get subjects with types - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - Map<Individual, Set<NamedClass>> newIndividual2Types; - boolean repeat = true; - while(!terminationCriteriaSatisfied() && repeat){ - newIndividual2Types = getSubjectsWithTypes(fetchedRows); - individual2Types.putAll(newIndividual2Types); - currentlyBestAxioms = buildBestAxioms(individual2Types); - fetchedRows += 1000; - repeat = !newIndividual2Types.isEmpty(); - } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); - } - - @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } - - @Override - public Configurator getConfigurator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init() throws ComponentInitException { - ... [truncated message content] |
From: <lor...@us...> - 2011-08-15 07:30:24
|
Revision: 3038 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3038&view=rev Author: lorenz_b Date: 2011-08-15 07:30:18 +0000 (Mon, 15 Aug 2011) Log Message: ----------- Continued output. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-11 16:01:34 UTC (rev 3037) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-15 07:30:18 UTC (rev 3038) @@ -1,14 +1,26 @@ package org.dllearner.core; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + import org.apache.commons.codec.digest.DigestUtils; import org.dllearner.core.owl.Axiom; import org.dllearner.utilities.EnrichmentVocabulary; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAnnotationAxiom; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.util.DefaultPrefixManager; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; +import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; +import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxPrefixNameShortFormProvider; public class EvaluatedAxiom { @@ -33,17 +45,29 @@ return axiom + "(" + score.getAccuracy()+ ")"; } - public void toRDF(){ + public List<OWLAxiom> toRDF(){ OWLDataFactory f = new OWLDataFactoryImpl(); String id = DigestUtils.md5Hex(axiom.toString()) + score.getAccuracy(); OWLNamedIndividual ind = f.getOWLNamedIndividual(IRI.create(EnrichmentVocabulary.NS + id)); + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer(pw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); + OWLAxiom ax = OWLAPIConverter.getOWLAPIAxiom(axiom); + ax.accept(r); + OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); - OWLAxiom ax2 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, null); + OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); OWLAxiom ax3 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.confidence, ind, score.getAccuracy()); - System.out.println(ax1); + List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); + axioms.add(ax1); + axioms.add(ax2); + axioms.add(ax3); + + return axioms; } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-11 16:01:34 UTC (rev 3037) +++ trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-15 07:30:18 UTC (rev 3038) @@ -25,7 +25,7 @@ //the object properties public static final OWLObjectProperty creation = factory.getOWLObjectProperty(IRI.create(NS + "creation")); - public static final OWLObjectProperty hasAxiom = factory.getOWLObjectProperty(IRI.create(NS + "hasAxiom")); +// public static final OWLObjectProperty hasAxiom = factory.getOWLObjectProperty(IRI.create(NS + "hasAxiom")); public static final OWLObjectProperty hasChange = factory.getOWLObjectProperty(IRI.create(NS + "hasChange")); @@ -49,4 +49,6 @@ public static final OWLDataProperty version = factory.getOWLDataProperty(IRI.create(NS + "version")); + public static final OWLDataProperty hasAxiom = factory.getOWLDataProperty(IRI.create(NS + "hasAxiom")); + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-15 14:49:00
|
Revision: 3046 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3046&view=rev Author: lorenz_b Date: 2011-08-15 14:48:54 +0000 (Mon, 15 Aug 2011) Log Message: ----------- Started simple subclass axioms learner for SPARQL endpoints. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/NamedClassEditor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-15 14:22:11 UTC (rev 3045) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-15 14:48:54 UTC (rev 3046) @@ -19,13 +19,37 @@ */ package org.dllearner.algorithms; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.Score; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerEditor; +import org.dllearner.core.config.NamedClassEditor; +import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.learningproblems.ClassScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + /** * Learns sub classes using SPARQL queries. * @@ -34,6 +58,26 @@ * */ public class SimpleSubclassLearner implements ClassExpressionLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(SimpleSubclassLearner.class); + + @ConfigOption(name="classToDescribe", description="", propertyEditorClass=NamedClassEditor.class) + private NamedClass classToDescribe; + @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) + private int maxFetchedRows = 0; + + private SPARQLReasoner reasoner; + private SparqlEndpointKS ks; + + private List<EvaluatedDescription> currentlyBestEvaluatedDescriptions; + private long startTime; + private int fetchedRows; + + public SimpleSubclassLearner(SparqlEndpointKS ks) { + this.ks = ks; + } @Override public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { @@ -50,14 +94,97 @@ @Override public void start() { - // TODO Auto-generated method stub + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestEvaluatedDescriptions = new ArrayList<EvaluatedDescription>(); + + Map<Individual, SortedSet<NamedClass>> ind2Types = new HashMap<Individual, SortedSet<NamedClass>>(); + int limit = 1000; + int offset = 0; + while(!terminationCriteriaSatisfied()){ + addIndividualsWithTypes(ind2Types, limit, offset); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @Override public void init() throws ComponentInitException { - // TODO Auto-generated method stub + reasoner = new SPARQLReasoner(ks); + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; } + public NamedClass getPropertyToDescribe() { + return classToDescribe; + } + + public void setPropertyToDescribe(NamedClass classToDescribe) { + this.classToDescribe = classToDescribe; + } + + public int getMaxFetchedRows() { + return maxFetchedRows; + } + + public void setMaxFetchedRows(int maxFetchedRows) { + this.maxFetchedRows = maxFetchedRows; + } + + private void addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ + String query = String.format("SELECT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); + + ResultSet rs = new SparqlQuery(query, ks.getEndpoint()).send(); + Individual ind; + NamedClass newType; + QuerySolution qs; + SortedSet<NamedClass> types; + while(rs.hasNext()){ + qs = rs.next(); + ind = new Individual(qs.getResource("ind").getURI()); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); + if(types == null){ + types = new TreeSet<NamedClass>(); + ind2Types.put(ind, types); + } + types.add(newType); + } + } + + private void createEvaluatedDescriptions(Map<Individual, SortedSet<NamedClass>> ind2Types){ + + } + + private double computeScore(){ + return 0; + } + + private boolean terminationCriteriaSatisfied(){ + boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : (System.currentTimeMillis() - startTime) >= maxExecutionTimeInSeconds * 1000; + boolean resultLimitExceeded = maxFetchedRows == 0 ? false : fetchedRows >= maxFetchedRows; + return timeLimitExceeded || resultLimitExceeded; + } + + public static void main(String[] args) { + Map<String, SortedSet<String>> map = new HashMap<String, SortedSet<String>>(); + SortedSet<String> set = new TreeSet<String>(); + set.add("2");set.add("3"); + map.put("1", set); + + set = new TreeSet<String>(); + set.add("2");set.add("4"); + map.put("1", set); + + System.out.println(map); + } + } Added: trunk/components-core/src/main/java/org/dllearner/core/config/NamedClassEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/NamedClassEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/NamedClassEditor.java 2011-08-15 14:48:54 UTC (rev 3046) @@ -0,0 +1,90 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +import org.dllearner.core.owl.NamedClass; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 7/26/11 + * Time: 9:42 PM + * <p/> + * Basic Property Editor for the Object Property DL-Learner class. Doesn't have GUI support yet but we could add that later if we wanted. + */ +public class NamedClassEditor implements PropertyEditor { + + + private NamedClass value; + + @Override + public void setValue(Object value) { + this.value = (NamedClass) value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean isPaintable() { + /** Not right now, we're doing non gui work */ + return false; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + + } + + @Override + public String getJavaInitializationString() { + /** This returns the value needed to reconstitute the object from a string */ + return value.getName(); + } + + @Override + public String getAsText() { + /** Get the text value of this object - for displaying in GUIS, etc */ + return value.getName(); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = new NamedClass(text); + } + + @Override + public String[] getTags() { + /** If there was a known set of values it had to have, we could add that list here */ + return new String[0]; + } + + @Override + public Component getCustomEditor() { + /** GUI stuff, if you wanted to edit it a custom way */ + return null; + } + + @Override + public boolean supportsCustomEditor() { + /** We don't support this right now, but maybe later */ + return false; + + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + /** More gui stuff, we don't need this for our basic example */ + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-16 08:08:10
|
Revision: 3049 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3049&view=rev Author: lorenz_b Date: 2011-08-16 08:08:04 +0000 (Tue, 16 Aug 2011) Log Message: ----------- Continued subclass learner. Added URI to Thing class. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-15 22:15:14 UTC (rev 3048) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-16 08:08:04 UTC (rev 3049) @@ -44,6 +44,7 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; @@ -87,8 +88,11 @@ @Override public List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { - // TODO Auto-generated method stub - return null; + List<Description> bestDescriptions = new ArrayList<Description>(); + for(EvaluatedDescription evDesc : getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions)){ + bestDescriptions.add(evDesc.getDescription()); + } + return bestDescriptions; } @Override @@ -105,6 +109,13 @@ fetchedRows = 0; currentlyBestEvaluatedDescriptions = new ArrayList<EvaluatedDescription>(); + //get existing super classes + SortedSet<Description> existingSuperClasses = reasoner.getSuperClasses(classToDescribe); + if(!existingSuperClasses.isEmpty()){ + logger.info("Existing super classes: " + existingSuperClasses); + } + + Map<Individual, SortedSet<NamedClass>> ind2Types = new HashMap<Individual, SortedSet<NamedClass>>(); int limit = 1000; while(!terminationCriteriaSatisfied()){ @@ -114,7 +125,7 @@ } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + logger.info("...finished in {}ms. (Got {} rows)", (System.currentTimeMillis()-startTime), fetchedRows); } @Override @@ -185,10 +196,14 @@ EvaluatedDescription evalDesc; for(Entry<NamedClass, Integer> entry : sortByValues(result)){ - evalDesc = new EvaluatedDescription(entry.getKey(), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); - currentlyBestEvaluatedDescriptions.add(evalDesc); + if(!entry.getKey().getURI().equals(Thing.instance.getURI())){//omit owl:Thing + evalDesc = new EvaluatedDescription(entry.getKey(), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + currentlyBestEvaluatedDescriptions.add(evalDesc); + } + } + } private SortedSet<Entry<NamedClass, Integer>> sortByValues(Map<NamedClass, Integer> map){ Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java 2011-08-15 22:15:14 UTC (rev 3048) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java 2011-08-16 08:08:04 UTC (rev 3049) @@ -19,6 +19,7 @@ */ package org.dllearner.core.owl; +import java.net.URI; import java.util.Map; /** @@ -42,6 +43,8 @@ private static final long serialVersionUID = -880276915058868775L; public static final Thing instance = new Thing(); + private static final URI uri = URI.create("http://www.w3.org/2002/07/owl#Thing"); + public String toString(String baseURI, Map<String,String> prefixes) { return "TOP"; } @@ -57,7 +60,11 @@ //return "owl:Thing"; return "Thing"; - } + } + + public URI getURI(){ + return uri; + } public int getLength() { return 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-16 14:49:05
|
Revision: 3052 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3052&view=rev Author: lorenz_b Date: 2011-08-16 14:48:58 +0000 (Tue, 16 Aug 2011) Log Message: ----------- Continued enrichment vocabulary. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-16 10:08:40 UTC (rev 3051) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-16 14:48:58 UTC (rev 3052) @@ -54,6 +54,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -158,8 +159,10 @@ } private void addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ - String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); +// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a <%s>. ?ind a ?type} LIMIT %d OFFSET %d", classToDescribe.getName(), limit, offset); + String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind a <%s>} LIMIT %d OFFSET %d}}", classToDescribe.getName(), limit, offset); + ResultSet rs = new SparqlQuery(query, ks.getEndpoint()).send(); Individual ind; NamedClass newType; @@ -176,6 +179,7 @@ } types.add(newType); } + } private void createEvaluatedDescriptions(Map<Individual, SortedSet<NamedClass>> individual2Types){ Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-16 10:08:40 UTC (rev 3051) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-16 14:48:58 UTC (rev 3052) @@ -3,6 +3,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.commons.codec.digest.DigestUtils; @@ -13,6 +14,7 @@ import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAnnotationAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationSubject; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLNamedIndividual; @@ -57,9 +59,11 @@ ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer(pw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); OWLAxiom ax = OWLAPIConverter.getOWLAPIAxiom(axiom); ax.accept(r); + System.out.println(sw.toString()); OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); +// f.getOWLAnnotationAssertionAxiom(f.getOWLAnnotationProperty(IRI.create("annoProp")), ind.getIRI(), ax); OWLAxiom ax3 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.confidence, ind, score.getAccuracy()); List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-16 10:08:40 UTC (rev 3051) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-08-16 14:48:58 UTC (rev 3052) @@ -467,6 +467,22 @@ } return superClasses; } + + public SortedSet<Description> getSuperClasses(Description description, boolean direct){ + if(!(description instanceof NamedClass)){ + throw new IllegalArgumentException("Only named classes are supported."); + } + SortedSet<Description> superClasses = new TreeSet<Description>(); + //this query is virtuoso specific + String query = String.format("SELECT DISTINCT ?y WHERE {" + + "{ SELECT ?x ?y WHERE { ?x rdfs:subClassOf ?y } }" + + "OPTION ( TRANSITIVE, T_DISTINCT, t_in(?x), t_out(?y), t_step('path_id') as ?path, t_step(?x) as ?route, t_step('step_no') AS ?jump, T_DIRECTION 3 )" + + "FILTER ( ?x = <%s> )}", ((NamedClass)description).getURI().toString()); + + + + return superClasses; + } @Override public SortedSet<Description> getSubClasses(Description description) { Modified: trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-16 10:08:40 UTC (rev 3051) +++ trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-16 14:48:58 UTC (rev 3052) @@ -17,13 +17,19 @@ //the classes public static final OWLClass ChangeSet = factory.getOWLClass(IRI.create(NS + "ChangeSet")); + public static final OWLClass SuggestionSet = factory.getOWLClass(IRI.create(NS + "SuggestionSet")); + public static final OWLClass Suggestion = factory.getOWLClass(IRI.create(NS + "Suggestion")); public static final OWLClass Parameter = factory.getOWLClass(IRI.create(NS + "Parameter")); + public static final OWLClass Creation = factory.getOWLClass(IRI.create(NS + "Creation")); + public static final OWLClass AlgorithmRun = factory.getOWLClass(IRI.create(NS + "AlgorithmRun")); + + //the object properties - public static final OWLObjectProperty creation = factory.getOWLObjectProperty(IRI.create(NS + "creation")); + public static final OWLObjectProperty creator = factory.getOWLObjectProperty(IRI.create(NS + "creatr")); // public static final OWLObjectProperty hasAxiom = factory.getOWLObjectProperty(IRI.create(NS + "hasAxiom")); @@ -31,6 +37,8 @@ public static final OWLObjectProperty hasInput = factory.getOWLObjectProperty(IRI.create(NS + "hasInput")); + public static final OWLObjectProperty hasSuggestion = factory.getOWLObjectProperty(IRI.create(NS + "hasSuggestion")); + public static final OWLObjectProperty hasParameter = factory.getOWLObjectProperty(IRI.create(NS + "hasParameter")); public static final OWLObjectProperty usedAlgorithm = factory.getOWLObjectProperty(IRI.create(NS + "usedAlgorithm")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-17 08:26:39
|
Revision: 3055 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3055&view=rev Author: lorenz_b Date: 2011-08-17 08:26:33 +0000 (Wed, 17 Aug 2011) Log Message: ----------- Continued enrichment vocabulary and more readable output. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-17 07:07:55 UTC (rev 3054) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-17 08:26:33 UTC (rev 3055) @@ -3,20 +3,18 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.codec.digest.DigestUtils; import org.dllearner.core.owl.Axiom; import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.owl.OWLAPIConverter; -import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLAnnotation; -import org.semanticweb.owlapi.model.OWLAnnotationAxiom; -import org.semanticweb.owlapi.model.OWLAnnotationSubject; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLIndividual; import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.util.DefaultPrefixManager; @@ -47,11 +45,12 @@ return axiom + "(" + score.getAccuracy()+ ")"; } - public List<OWLAxiom> toRDF(){ + public Map<OWLIndividual, List<OWLAxiom>> toRDF(String defaultNamespace){ + Map<OWLIndividual, List<OWLAxiom>> ind2Axioms = new HashMap<OWLIndividual, List<OWLAxiom>>(); OWLDataFactory f = new OWLDataFactoryImpl(); String id = DigestUtils.md5Hex(axiom.toString()) + score.getAccuracy(); - OWLNamedIndividual ind = f.getOWLNamedIndividual(IRI.create(EnrichmentVocabulary.NS + id)); + OWLNamedIndividual ind = f.getOWLNamedIndividual(IRI.create(defaultNamespace + id)); StringWriter sw = new StringWriter(); @@ -59,7 +58,6 @@ ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer(pw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); OWLAxiom ax = OWLAPIConverter.getOWLAPIAxiom(axiom); ax.accept(r); - System.out.println(sw.toString()); OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); @@ -71,7 +69,9 @@ axioms.add(ax2); axioms.add(ax3); - return axioms; + ind2Axioms.put(ind, axioms); + + return ind2Axioms; } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-17 07:07:55 UTC (rev 3054) +++ trunk/components-core/src/main/java/org/dllearner/utilities/EnrichmentVocabulary.java 2011-08-17 08:26:33 UTC (rev 3055) @@ -29,7 +29,7 @@ //the object properties - public static final OWLObjectProperty creator = factory.getOWLObjectProperty(IRI.create(NS + "creatr")); + public static final OWLObjectProperty creator = factory.getOWLObjectProperty(IRI.create(NS + "creator")); // public static final OWLObjectProperty hasAxiom = factory.getOWLObjectProperty(IRI.create(NS + "hasAxiom")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-17 10:59:13
|
Revision: 3059 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3059&view=rev Author: jenslehmann Date: 2011-08-17 10:59:06 +0000 (Wed, 17 Aug 2011) Log Message: ----------- introduction of short names and versions for components Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -77,7 +77,7 @@ * @author Jens Lehmann * */ -@ComponentAnn(name="CELOE") +@ComponentAnn(name="CELOE", shortName="celoe", version=1.0) public class CELOE extends AbstractCELA { private static Logger logger = Logger.getLogger(CELOE.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -38,7 +38,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="dataproperty domain axiom learner") +@ComponentAnn(name="dataproperty domain axiom learner", shortName="dpldomain", version=0.1) public class DataPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -38,7 +38,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="dataproperty range learner") +@ComponentAnn(name="dataproperty range learner", shortName="dblrange", version=0.1) public class DataPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyRangeAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -35,7 +35,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="disjoint dataproperty axiom learner") +@ComponentAnn(name="disjoint dataproperty axiom learner", shortName="dpldisjoint", version=0.1) public class DisjointDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -35,7 +35,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="disjoint objectproperty axiom learner") +@ComponentAnn(name="disjoint objectproperty axiom learner", shortName="opldisjoint", version=0.1) public class DisjointObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -32,7 +32,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="equivalent dataproperty axiom learner") +@ComponentAnn(name="equivalent dataproperty axiom learner", shortName="dplequiv", version=0.1) public class EquivalentDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(EquivalentDataPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -34,7 +34,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -@ComponentAnn(name="equivalent objectproperty axiom learner") +@ComponentAnn(name="equivalent objectproperty axiom learner", shortName="oplequiv", version=0.1) public class EquivalentObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(EquivalentObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; -@ComponentAnn(name="functional dataproperty axiom learner") +@ComponentAnn(name="functional dataproperty axiom learner", shortName="dplfunc", version=0.1) public class FunctionalDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalDataPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; -@ComponentAnn(name="functional objectproperty axiom learner") +@ComponentAnn(name="functional objectproperty axiom learner", shortName="oplfunc", version=0.1) public class FunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; -@ComponentAnn(name="inversefunctional objectproperty axiom learner") +@ComponentAnn(name="inversefunctional objectproperty axiom learner", shortName="oplinvfunc", version=0.1) public class InverseFunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(InverseFunctionalObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; -@ComponentAnn(name="irreflexive objectproperty axiom learner") +@ComponentAnn(name="irreflexive objectproperty axiom learner", shortName="oplirrefl", version=0.1) public class IrreflexiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(IrreflexiveObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -39,7 +39,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="objectproperty domain axiom learner") +@ComponentAnn(name="objectproperty domain axiom learner", shortName="opldomain", version=0.1) public class ObjectPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -39,7 +39,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="objectproperty range learner") +@ComponentAnn(name="objectproperty range learner", shortName="oplrange", version=0.1) public class ObjectPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyRangeAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; -@ComponentAnn(name="reflexive objectproperty axiom learner") +@ComponentAnn(name="reflexive objectproperty axiom learner", shortName="oplrefl", version=0.1) public class ReflexiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ReflexiveObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -32,7 +32,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -@ComponentAnn(name="data subPropertyOf axiom learner") +@ComponentAnn(name="data subPropertyOf axiom learner", shortName="dplsubprop", version=0.1) public class SubDataPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -36,7 +36,7 @@ import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -@ComponentAnn(name="object subPropertyOf axiom learner") +@ComponentAnn(name="object subPropertyOf axiom learner", shortName="oplsubprop", version=0.1) public class SubObjectPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -28,7 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; -@ComponentAnn(name="symmetric objectproperty axiom learner") +@ComponentAnn(name="symmetric objectproperty axiom learner", shortName="oplsymm", version=0.1) public class SymmetricObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SymmetricObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -29,7 +29,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; -@ComponentAnn(name="transitive objectproperty axiom learner") +@ComponentAnn(name="transitive objectproperty axiom learner", shortName="opltrans", version=0.1) public class TransitiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(TransitiveObjectPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -40,4 +40,17 @@ */ String name(); + /** + * The short name of this component, which should exclusively consist of + * lower case ASCII symbols without whitespace. + * @return The short name of this component. + */ + String shortName(); + + /** + * The version of this component. 1.0 indicates a stable component. Developers + * should increase the version number in case of major implementation changes. + * @return A version number of this component. + */ + double version(); } Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-17 10:58:25 UTC (rev 3058) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-17 10:59:06 UTC (rev 3059) @@ -43,11 +43,11 @@ * The description of this config option * @return */ - String description(); + String description() default "no description available"; /** * An implementation of the Property Editor to use * @return */ - Class propertyEditorClass(); + Class<?> propertyEditorClass(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-18 09:22:22
|
Revision: 3067 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3067&view=rev Author: lorenz_b Date: 2011-08-18 09:22:16 +0000 (Thu, 18 Aug 2011) Log Message: ----------- Added axiom learning interface. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-18 08:55:11 UTC (rev 3066) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-18 09:22:16 UTC (rev 3067) @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -29,14 +30,18 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.NamedClassEditor; +import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; @@ -58,7 +63,7 @@ * */ @ComponentAnn(name = "disjoint classes learner", shortName = "cldisjoint", version = 0.1) -public class DisjointClassesLearner implements ClassExpressionLearningAlgorithm { +public class DisjointClassesLearner implements ClassExpressionLearningAlgorithm, AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DisjointClassesLearner.class); @@ -178,6 +183,30 @@ return currentlyBestEvaluatedDescriptions.subList(0, max); } + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + for(EvaluatedAxiom evAx : getCurrentlyBestEvaluatedAxioms(nrOfAxioms)){ + bestAxioms.add(evAx.getAxiom()); + } + + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + Set<Description> descriptions; + for(EvaluatedDescription ed : getCurrentlyBestEvaluatedDescriptions(nrOfAxioms)){ + descriptions = new HashSet<Description>(); + descriptions.add(classToDescribe); + descriptions.add(ed.getDescription()); + axioms.add(new EvaluatedAxiom(new DisjointClassesAxiom(descriptions), new AxiomScore(ed.getAccuracy()))); + } + return axioms; + } + private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, Set<NamedClass> allClasses){ List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); @@ -265,7 +294,5 @@ } - - } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-18 08:55:11 UTC (rev 3066) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-18 09:22:16 UTC (rev 3067) @@ -24,38 +24,33 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import java.util.Map.Entry; -import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; +import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.Score; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.NamedClassEditor; -import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.SubClassAxiom; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.learningproblems.ClassScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -67,7 +62,7 @@ * */ @ComponentAnn(name = "simple subclass learner", shortName = "clsub", version = 0.1) -public class SimpleSubclassLearner implements ClassExpressionLearningAlgorithm { +public class SimpleSubclassLearner implements ClassExpressionLearningAlgorithm, AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SimpleSubclassLearner.class); @@ -104,8 +99,28 @@ int max = Math.min(currentlyBestEvaluatedDescriptions.size(), nrOfDescriptions); return currentlyBestEvaluatedDescriptions.subList(0, max); } + + @Override + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + + for(EvaluatedAxiom evAx : getCurrentlyBestEvaluatedAxioms(nrOfAxioms)){ + bestAxioms.add(evAx.getAxiom()); + } + + return bestAxioms; + } @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + for(EvaluatedDescription ed : getCurrentlyBestEvaluatedDescriptions(nrOfAxioms)){ + axioms.add(new EvaluatedAxiom(new SubClassAxiom(classToDescribe, ed.getDescription()), new AxiomScore(ed.getAccuracy()))); + } + return axioms; + } + + @Override public void start() { logger.info("Start learning..."); startTime = System.currentTimeMillis(); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-08-18 08:55:11 UTC (rev 3066) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-08-18 09:22:16 UTC (rev 3067) @@ -52,8 +52,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return "DisjointClasses()"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-19 08:51:29
|
Revision: 3070 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3070&view=rev Author: lorenz_b Date: 2011-08-19 08:51:21 +0000 (Fri, 19 Aug 2011) Log Message: ----------- Added methods to get only axioms whose accuracy is above a specific threshold. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -30,7 +30,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; @@ -63,7 +63,7 @@ * */ @ComponentAnn(name = "disjoint classes learner", shortName = "cldisjoint", version = 0.1) -public class DisjointClassesLearner implements ClassExpressionLearningAlgorithm, AxiomLearningAlgorithm { +public class DisjointClassesLearner extends AbstractAxiomLearningAlgorithm implements ClassExpressionLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DisjointClassesLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -28,7 +28,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; @@ -62,7 +62,7 @@ * */ @ComponentAnn(name = "simple subclass learner", shortName = "clsub", version = 0.1) -public class SimpleSubclassLearner implements ClassExpressionLearningAlgorithm, AxiomLearningAlgorithm { +public class SimpleSubclassLearner extends AbstractAxiomLearningAlgorithm implements ClassExpressionLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SimpleSubclassLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,7 +17,6 @@ import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.Description; @@ -37,7 +34,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="dataproperty domain axiom learner", shortName="dpldomain", version=0.1) -public class DataPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class DataPropertyDomainAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyDomainAxiomLearner.class); @@ -107,25 +104,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -10,8 +10,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -36,7 +35,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="dataproperty range learner", shortName="dblrange", version=0.1) -public class DataPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class DataPropertyRangeAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataPropertyRangeAxiomLearner.class); @@ -106,25 +105,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -11,8 +10,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -20,10 +18,8 @@ import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; -import org.dllearner.core.owl.SubDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -36,7 +32,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="disjoint dataproperty axiom learner", shortName="dpldisjoint", version=0.1) -public class DisjointDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class DisjointDataPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @@ -133,25 +129,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -11,8 +10,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -20,13 +18,11 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SPARQLTasks; -import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -36,7 +32,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="disjoint objectproperty axiom learner", shortName="opldisjoint", version=0.1) -public class DisjointObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class DisjointObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @@ -132,27 +128,13 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - for(EvaluatedAxiom evAx : getCurrentlyBestEvaluatedAxioms(nrOfAxioms)){ - bestAxioms.add(evAx.getAxiom()); - } - - return bestAxioms; - } @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } + @Override public Configurator getConfigurator() { // TODO Auto-generated method stub @@ -238,12 +220,6 @@ return resultSet; } - public static void main(String[] args) throws Exception{ - DisjointObjectPropertyAxiomLearner l = new DisjointObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/assembly")); - l.init(); - l.start(); - System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); - } - + + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,7 +17,6 @@ import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -33,7 +30,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="equivalent dataproperty axiom learner", shortName="dplequiv", version=0.1) -public class EquivalentDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class EquivalentDataPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(EquivalentDataPropertyAxiomLearner.class); @@ -129,25 +126,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,12 +17,10 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -32,10 +28,9 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="equivalent objectproperty axiom learner", shortName="oplequiv", version=0.1) -public class EquivalentObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class EquivalentObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(EquivalentObjectPropertyAxiomLearner.class); @@ -131,25 +126,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional dataproperty axiom learner", shortName="dplfunc", version=0.1) -public class FunctionalDataPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class FunctionalDataPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalDataPropertyAxiomLearner.class); @@ -117,12 +114,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="functional objectproperty axiom learner", shortName="oplfunc", version=0.1) -public class FunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class FunctionalObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalObjectPropertyAxiomLearner.class); @@ -117,12 +114,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.InverseFunctionalObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="inversefunctional objectproperty axiom learner", shortName="oplinvfunc", version=0.1) -public class InverseFunctionalObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class InverseFunctionalObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(InverseFunctionalObjectPropertyAxiomLearner.class); @@ -117,12 +114,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="irreflexive objectproperty axiom learner", shortName="oplirrefl", version=0.1) -public class IrreflexiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class IrreflexiveObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(IrreflexiveObjectPropertyAxiomLearner.class); @@ -120,12 +117,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,17 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -21,8 +17,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -30,8 +24,6 @@ import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -41,7 +33,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="objectproperty domain axiom learner", shortName="opldomain", version=0.1) -public class ObjectPropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class ObjectPropertyDomainAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @@ -111,25 +103,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { @@ -238,6 +214,5 @@ ResultSet resultSet = queryExecution.execSelect(); return resultSet; } - } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,7 +17,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -37,7 +34,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="objectproperty range learner", shortName="oplrange", version=0.1) -public class ObjectPropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class ObjectPropertyRangeAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyRangeAxiomLearner.class); @@ -107,25 +104,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="reflexive objectproperty axiom learner", shortName="oplrefl", version=0.1) -public class ReflexiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class ReflexiveObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ReflexiveObjectPropertyAxiomLearner.class); @@ -110,12 +107,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,7 +17,6 @@ import org.dllearner.core.config.DataPropertyEditor; import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.SubDatatypePropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -33,7 +30,7 @@ import com.hp.hpl.jena.query.ResultSet; @ComponentAnn(name="data subPropertyOf axiom learner", shortName="dplsubprop", version=0.1) -public class SubDataPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class SubDataPropertyOfAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @@ -129,25 +126,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.AbstractComponent; -import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -19,7 +17,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -29,15 +26,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @ComponentAnn(name="object subPropertyOf axiom learner", shortName="oplsubprop", version=0.1) -public class SubObjectPropertyOfAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class SubObjectPropertyOfAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); @@ -133,25 +126,9 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - List<Axiom> bestAxioms = new ArrayList<Axiom>(); - - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); - } - - return bestAxioms; + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return currentlyBestAxioms; } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - int max = Math.min(currentlyBestAxioms.size(), nrOfAxioms); - - List<EvaluatedAxiom> bestAxioms = currentlyBestAxioms.subList(0, max); - - return bestAxioms; - } @Override public Configurator getConfigurator() { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -29,7 +26,7 @@ import com.hp.hpl.jena.vocabulary.OWL2; @ComponentAnn(name="symmetric objectproperty axiom learner", shortName="oplsymm", version=0.1) -public class SymmetricObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class SymmetricObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SymmetricObjectPropertyAxiomLearner.class); @@ -110,12 +107,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -1,11 +1,9 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.dllearner.core.AxiomLearningAlgorithm; -import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; @@ -13,7 +11,6 @@ import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; import org.dllearner.kb.SparqlEndpointKS; @@ -30,7 +27,7 @@ import com.hp.hpl.jena.vocabulary.OWL; @ComponentAnn(name="transitive objectproperty axiom learner", shortName="opltrans", version=0.1) -public class TransitiveObjectPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { +public class TransitiveObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(TransitiveObjectPropertyAxiomLearner.class); @@ -111,12 +108,7 @@ } @Override - public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { - return currentlyBestAxioms.isEmpty() ? Collections.<Axiom>emptyList() : Collections.singletonList(currentlyBestAxioms.get(0).getAxiom()); - } - - @Override - public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { return currentlyBestAxioms; } Added: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.ArrayList; +import java.util.List; + +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.owl.Axiom; + +/** + * @author Lorenz Bühmann + * @author Jens Lehmann + */ +public class AbstractAxiomLearningAlgorithm extends AbstractComponent implements AxiomLearningAlgorithm{ + + @Override + public void start() { + } + + @Override + public void init() throws ComponentInitException { + } + + @Override + public List<Axiom> getCurrentlyBestAxioms() { + return null; + } + + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { + return getCurrentlyBestAxioms(nrOfAxioms, 0.0); + } + + public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms, + double accuracyThreshold) { + List<Axiom> bestAxioms = new ArrayList<Axiom>(); + for(EvaluatedAxiom evAx : getCurrentlyBestEvaluatedAxioms(nrOfAxioms, accuracyThreshold)){ + bestAxioms.add(evAx.getAxiom()); + } + return bestAxioms; + } + + @Override + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms() { + return null; + } + + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { + return getCurrentlyBestEvaluatedAxioms(nrOfAxioms, 0.0); + } + + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms, + double accuracyThreshold) { + List<EvaluatedAxiom> returnList = new ArrayList<EvaluatedAxiom>(); + + //get the currently best evaluated axioms + List<EvaluatedAxiom> currentlyBestEvAxioms = getCurrentlyBestEvaluatedAxioms(); + + for(EvaluatedAxiom evAx : currentlyBestEvAxioms){ + if(evAx.getScore().getAccuracy() >= accuracyThreshold && returnList.size() < nrOfAxioms){ + returnList.add(evAx); + } + } + + return returnList; + } + + @Override + public Configurator getConfigurator() { + // TODO Auto-generated method stub + return null; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -6,16 +6,30 @@ public interface AxiomLearningAlgorithm extends LearningAlgorithm { + + /** + * @return The best axioms found by the learning algorithm so far. + */ + public List<Axiom> getCurrentlyBestAxioms(); + + /** * @param nrOfAxioms Limit for the number or returned axioms. * @return The best axioms found by the learning algorithm so far. */ public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms); /** + * @return The best evaluated axioms found by the learning algorithm so far. + */ + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(); + + /** * @param nrOfAxioms Limit for the number or returned evaluated axioms. * @return The best evaluated axioms found by the learning algorithm so far. */ public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms); + + } Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-18 14:49:21 UTC (rev 3069) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2011-08-19 08:51:21 UTC (rev 3070) @@ -63,9 +63,9 @@ ax.accept(r); OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); -// OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); + OWLAxiom ax2 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.hasAxiom, ind, sw.toString()); OWLAnnotation anno = f.getOWLAnnotation(EnrichmentVocabulary.belongsTo, ind.getIRI()); - OWLAxiom ax2 = ax.getAnnotatedAxiom(Collections.singleton(anno)); +// OWLAxiom ax2 = ax.getAnnotatedAxiom(Collections.singleton(anno)); OWLAxiom ax3 = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.confidence, ind, score.getAccuracy()); List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-19 11:07:06
|
Revision: 3071 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3071&view=rev Author: lorenz_b Date: 2011-08-19 11:07:00 +0000 (Fri, 19 Aug 2011) Log Message: ----------- Small changes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/SubClassAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-19 08:51:21 UTC (rev 3070) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-19 11:07:00 UTC (rev 3071) @@ -215,14 +215,15 @@ } } + //omit owl:Thing and classToDescribe + result.remove(new NamedClass(Thing.instance.getURI())); + result.remove(classToDescribe); + EvaluatedDescription evalDesc; for(Entry<NamedClass, Integer> entry : sortByValues(result)){ - if(!entry.getKey().getURI().equals(Thing.instance.getURI())){//omit owl:Thing - evalDesc = new EvaluatedDescription(entry.getKey(), - new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); - currentlyBestEvaluatedDescriptions.add(evalDesc); - } - + evalDesc = new EvaluatedDescription(entry.getKey(), + new AxiomScore(entry.getValue() / (double)individual2Types.keySet().size())); + currentlyBestEvaluatedDescriptions.add(evalDesc); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/SubClassAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/SubClassAxiom.java 2011-08-19 08:51:21 UTC (rev 3070) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/SubClassAxiom.java 2011-08-19 11:07:00 UTC (rev 3071) @@ -51,6 +51,6 @@ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { // TODO Auto-generated method stub - return "SUBCLASS NOT IMPLEMENTED"; + return subConcept.toManchesterSyntaxString(baseURI, prefixes) + " subClassOf: " + superConcept.toManchesterSyntaxString(baseURI, prefixes); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-24 11:12:15
|
Revision: 3110 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3110&view=rev Author: shadowtm Date: 2011-08-24 11:12:08 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Added back constructors that were in use by the Start program. Also added default initialization in case teh OWLAPIReasoner wasn't working. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 10:48:36 UTC (rev 3109) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 11:12:08 UTC (rev 3110) @@ -20,6 +20,7 @@ package org.dllearner.learningproblems; import java.util.Set; +import java.util.TreeSet; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; @@ -36,9 +37,9 @@ */ public abstract class PosNegLP extends AbstractLearningProblem { - protected Set<Individual> positiveExamples; - protected Set<Individual> negativeExamples; - protected Set<Individual> allExamples; + protected Set<Individual> positiveExamples = new TreeSet<Individual>(); + protected Set<Individual> negativeExamples = new TreeSet<Individual>(); + protected Set<Individual> allExamples = new TreeSet<Individual>(); @org.dllearner.core.config.ConfigOption(name = "useRetrievalForClassification", description = "\"Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.",defaultValue = "false", propertyEditorClass = BoolEditor.class) private boolean useRetrievalForClassification = false; Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 10:48:36 UTC (rev 3109) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 11:12:08 UTC (rev 3110) @@ -72,6 +72,10 @@ public PosNegLPStandard() { } + public PosNegLPStandard(AbstractReasonerComponent reasoningService){ + super(reasoningService); + } + public PosNegLPStandard(AbstractReasonerComponent reasoningService, SortedSet<Individual> positiveExamples, SortedSet<Individual> negativeExamples) { this.setReasoner(reasoningService); this.positiveExamples = positiveExamples; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-24 10:48:36 UTC (rev 3109) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-08-24 11:12:08 UTC (rev 3110) @@ -152,6 +152,10 @@ @Override public void init() throws ComponentInitException { + if(rc == null){ + rc = new OWLAPIReasoner(sources); + rc.init(); + } // try { atomicConcepts = rc.getNamedClasses(); datatypeProperties = rc.getDatatypeProperties(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-24 11:55:47
|
Revision: 3113 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3113&view=rev Author: jenslehmann Date: 2011-08-24 11:55:41 +0000 (Wed, 24 Aug 2011) Log Message: ----------- re-added createConfigOption methods Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-24 11:20:17 UTC (rev 3112) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-24 11:55:41 UTC (rev 3113) @@ -22,12 +22,15 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.URI; +import java.util.Collection; +import java.util.LinkedList; import org.apache.log4j.Logger; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.URLConfigOption; import org.dllearner.core.owl.KB; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -73,6 +76,15 @@ this.kb = kb; } + public static Collection<org.dllearner.core.options.ConfigOption<?>> createConfigOptions() { + Collection<org.dllearner.core.options.ConfigOption<?>> options = new LinkedList<org.dllearner.core.options.ConfigOption<?>>(); +// options.add(new StringConfigOption("filename", "pointer to the KB file on local file system",null, true, true)); + URLConfigOption urlOption = new URLConfigOption("url", "URL pointer to the KB file",null, false, true); + urlOption.setRefersToFile(true); + options.add(urlOption); + return options; + } + public static String getName() { return "KB file"; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 11:20:17 UTC (rev 3112) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 11:55:41 UTC (rev 3113) @@ -19,11 +19,17 @@ package org.dllearner.learningproblems; +import java.util.Collection; +import java.util.LinkedList; import java.util.Set; import java.util.TreeSet; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.options.StringSetConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.Helper; @@ -84,6 +90,20 @@ super(reasoningService); } + public static Collection<org.dllearner.core.options.ConfigOption<?>> createConfigOptions() { + Collection<org.dllearner.core.options.ConfigOption<?>> options = new LinkedList<org.dllearner.core.options.ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples",null, true, false)); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples",null, true, false)); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.", false)); + options.add(CommonConfigOptions.getPercentPerLenghtUnitOption(0.05)); + StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.","twoChecks"); + multiInstanceChecks.setAllowedValues(new String[] {"never", "twoChecks", "oneCheck"}); + options.add(multiInstanceChecks); + return options; + } /* * (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 11:20:17 UTC (rev 3112) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 11:55:41 UTC (rev 3113) @@ -19,7 +19,9 @@ package org.dllearner.learningproblems; +import java.util.Collection; import java.util.Iterator; +import java.util.LinkedList; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -28,6 +30,9 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics.HeuristicType; @@ -82,6 +87,18 @@ this.negativeExamples = negativeExamples; } + public static Collection<org.dllearner.core.options.ConfigOption<?>> createConfigOptions() { + Collection<org.dllearner.core.options.ConfigOption<?>> options = new LinkedList<org.dllearner.core.options.ConfigOption<?>>(PosNegLP.createConfigOptions()); + BooleanConfigOption approx = new BooleanConfigOption("useApproximations", "whether to use stochastic approximations for computing accuracy", false); + options.add(approx); + DoubleConfigOption approxAccuracy = new DoubleConfigOption("approxAccuracy", "accuracy of the approximation (only for expert use)", 0.05); + options.add(approxAccuracy); + StringConfigOption accMethod = new StringConfigOption("accuracyMethod", "Specifies, which method/function to use for computing accuracy.","predacc"); // or domain/range of a property. + accMethod.setAllowedValues(new String[] {"fmeasure", "predacc"}); + options.add(accMethod); + return options; + } + @Override public void init() { super.init(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-24 18:37:24
|
Revision: 3117 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3117&view=rev Author: lorenz_b Date: 2011-08-24 18:37:17 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Added more axioms to converter. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLLearnerAxiomConvertVisitor.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-24 14:38:09 UTC (rev 3116) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-08-24 18:37:17 UTC (rev 3117) @@ -22,9 +22,11 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -173,8 +175,12 @@ property2Count.remove(propertyToDescribe); EvaluatedAxiom evalAxiom; + Set<ObjectProperty> properties; for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ - evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(propertyToDescribe, entry.getKey()), + properties = new HashSet<ObjectProperty>(); + properties.add(propertyToDescribe); + properties.add(entry.getKey()); + evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties), new AxiomScore(entry.getValue() / (double)all)); axioms.add(evalAxiom); } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java 2011-08-24 14:38:09 UTC (rev 3116) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java 2011-08-24 18:37:17 UTC (rev 3117) @@ -19,40 +19,57 @@ package org.dllearner.core.owl; +import java.util.Iterator; import java.util.Map; +import java.util.Set; public class EquivalentObjectPropertiesAxiom extends PropertyAxiom { - /** - * - */ + private static final long serialVersionUID = -1085651734702155330L; - private ObjectProperty role; - private ObjectProperty equivRole; + private Set<ObjectProperty> equivalentProperties; - public EquivalentObjectPropertiesAxiom(ObjectProperty equivRole, ObjectProperty role) { - this.role = role; - this.equivRole = equivRole; + public EquivalentObjectPropertiesAxiom(Set<ObjectProperty> equivalentProperties) { + this.equivalentProperties = equivalentProperties; } - public ObjectProperty getRole() { - return role; + public Set<ObjectProperty> getEquivalentProperties() { + return equivalentProperties; } - public ObjectProperty getEquivalentRole() { - return equivRole; - } - public int getLength() { - return 1 + role.getLength() + equivRole.getLength(); + int length = 1; + for(ObjectProperty p: equivalentProperties) + length += p.getLength(); + return length; } public String toString(String baseURI, Map<String,String> prefixes) { - return "EquivalentObjectProperties(" + equivRole.toString(baseURI, prefixes) + "," + role.toString(baseURI, prefixes) + ")"; + StringBuffer sb = new StringBuffer(); + sb.append("EquivalentObjectProperties("); + Iterator<ObjectProperty> it = equivalentProperties.iterator(); + while(it.hasNext()){ + sb.append(it.next().toString(baseURI, prefixes)); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) { - return "EquivalentObjectProperties(" + equivRole.toKBSyntaxString(baseURI, prefixes) + "," + role.toKBSyntaxString(baseURI, prefixes) + ")"; + StringBuffer sb = new StringBuffer(); + sb.append("EquivalentObjectProperties("); + Iterator<ObjectProperty> it = equivalentProperties.iterator(); + while(it.hasNext()){ + sb.append(it.next().toKBSyntaxString(baseURI, prefixes)); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } @Override @@ -69,6 +86,16 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return equivRole.toString(baseURI, prefixes) + " EquivalentTo: " + role.toString(baseURI, prefixes); + StringBuffer sb = new StringBuffer(); + sb.append("EquivalentObjectProperties("); + Iterator<ObjectProperty> it = equivalentProperties.iterator(); + while(it.hasNext()){ + sb.append(it.next().toManchesterSyntaxString(baseURI, prefixes)); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLLearnerAxiomConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLLearnerAxiomConvertVisitor.java 2011-08-24 14:38:09 UTC (rev 3116) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLLearnerAxiomConvertVisitor.java 2011-08-24 18:37:17 UTC (rev 3117) @@ -20,18 +20,35 @@ package org.dllearner.utilities.owl; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.dllearner.core.owl.AsymmetricObjectPropertyAxiom; import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; +import org.dllearner.core.owl.DatatypePropertyRangeAxiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DisjointClassesAxiom; +import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; +import org.dllearner.core.owl.DisjointObjectPropertyAxiom; +import org.dllearner.core.owl.EquivalentClassesAxiom; +import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; +import org.dllearner.core.owl.EquivalentObjectPropertiesAxiom; +import org.dllearner.core.owl.FunctionalDatatypePropertyAxiom; +import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.InverseFunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.ObjectPropertyRangeAxiom; import org.dllearner.core.owl.ReflexiveObjectPropertyAxiom; import org.dllearner.core.owl.SubClassAxiom; +import org.dllearner.core.owl.SubDatatypePropertyAxiom; +import org.dllearner.core.owl.SubObjectPropertyAxiom; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; +import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom; import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom; @@ -42,6 +59,7 @@ import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyExpression; import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom; import org.semanticweb.owlapi.model.OWLDeclarationAxiom; @@ -63,6 +81,7 @@ import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLSameIndividualAxiom; @@ -164,9 +183,12 @@ } @Override - public void visit(OWLEquivalentObjectPropertiesAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLEquivalentObjectPropertiesAxiom ax) { + Set<ObjectProperty> properties = new HashSet<ObjectProperty>(); + for(OWLObjectPropertyExpression expr : ax.getProperties()){ + properties.add(new ObjectProperty(expr.asOWLObjectProperty().toStringID())); + } + axiom = new EquivalentObjectPropertiesAxiom(properties); } @Override @@ -182,21 +204,25 @@ } @Override - public void visit(OWLDisjointDataPropertiesAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLDisjointDataPropertiesAxiom ax) { + Iterator<OWLDataPropertyExpression> iter = ax.getProperties().iterator(); + DatatypeProperty p1 = new DatatypeProperty(iter.next().asOWLDataProperty().toStringID()); + DatatypeProperty p2 = new DatatypeProperty(iter.next().asOWLDataProperty().toStringID()); + axiom = new DisjointDatatypePropertyAxiom(p1, p2); } @Override - public void visit(OWLDisjointObjectPropertiesAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLDisjointObjectPropertiesAxiom ax) { + Iterator<OWLObjectPropertyExpression> iter = ax.getProperties().iterator(); + ObjectProperty p1 = new ObjectProperty(iter.next().asOWLObjectProperty().toStringID()); + ObjectProperty p2 = new ObjectProperty(iter.next().asOWLObjectProperty().toStringID()); + axiom = new DisjointObjectPropertyAxiom(p1, p2); } @Override - public void visit(OWLObjectPropertyRangeAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLObjectPropertyRangeAxiom ax) { + axiom = new ObjectPropertyRangeAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID()), + DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(ax.getRange())); } @Override @@ -206,14 +232,14 @@ } @Override - public void visit(OWLFunctionalObjectPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLFunctionalObjectPropertyAxiom ax) { + axiom = new FunctionalObjectPropertyAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID())); } @Override - public void visit(OWLSubObjectPropertyOfAxiom arg0) { - // TODO Auto-generated method stub + public void visit(OWLSubObjectPropertyOfAxiom ax) { + axiom = new SubObjectPropertyAxiom(new ObjectProperty(ax.getSubProperty().asOWLObjectProperty().toStringID()), + new ObjectProperty(ax.getSuperProperty().asOWLObjectProperty().toStringID())); } @@ -224,27 +250,27 @@ } @Override - public void visit(OWLSymmetricObjectPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLSymmetricObjectPropertyAxiom ax) { + axiom = new SymmetricObjectPropertyAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID())); } @Override - public void visit(OWLDataPropertyRangeAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLDataPropertyRangeAxiom ax) { + axiom = new DatatypePropertyRangeAxiom(new DatatypeProperty(ax.getProperty().asOWLDataProperty().toStringID()), + new Datatype(ax.getRange().asOWLDatatype().toStringID())); } @Override - public void visit(OWLFunctionalDataPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLFunctionalDataPropertyAxiom ax) { + axiom = new FunctionalDatatypePropertyAxiom(new DatatypeProperty(ax.getProperty().asOWLDataProperty().toStringID())); } @Override - public void visit(OWLEquivalentDataPropertiesAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLEquivalentDataPropertiesAxiom ax) { + Iterator<OWLDataPropertyExpression> iter = ax.getProperties().iterator(); + DatatypeProperty p1 = new DatatypeProperty(iter.next().asOWLDataProperty().toStringID()); + DatatypeProperty p2 = new DatatypeProperty(iter.next().asOWLDataProperty().toStringID()); + axiom = new EquivalentDatatypePropertiesAxiom(p1, p2); } @Override @@ -254,9 +280,11 @@ } @Override - public void visit(OWLEquivalentClassesAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLEquivalentClassesAxiom ax) { + Iterator<OWLClassExpression> iter = ax.getClassExpressions().iterator(); + Description d1 = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(iter.next()); + Description d2 = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(iter.next()); + axiom = new EquivalentClassesAxiom(d1, d2); } @Override @@ -266,27 +294,24 @@ } @Override - public void visit(OWLTransitiveObjectPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLTransitiveObjectPropertyAxiom ax) { + axiom = new TransitiveObjectPropertyAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID())); } @Override - public void visit(OWLIrreflexiveObjectPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLIrreflexiveObjectPropertyAxiom ax) { + axiom = new IrreflexiveObjectPropertyAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID())); } @Override - public void visit(OWLSubDataPropertyOfAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLSubDataPropertyOfAxiom ax) { + axiom = new SubDatatypePropertyAxiom(new DatatypeProperty(ax.getSubProperty().asOWLDataProperty().toStringID()), + new DatatypeProperty(ax.getSuperProperty().asOWLDataProperty().toStringID())); } @Override - public void visit(OWLInverseFunctionalObjectPropertyAxiom arg0) { - // TODO Auto-generated method stub - + public void visit(OWLInverseFunctionalObjectPropertyAxiom ax) { + axiom = new InverseFunctionalObjectPropertyAxiom(new ObjectProperty(ax.getProperty().asOWLObjectProperty().toStringID())); } @Override Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-24 14:38:09 UTC (rev 3116) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-08-24 18:37:17 UTC (rev 3117) @@ -49,6 +49,7 @@ import org.dllearner.core.owl.InverseObjectPropertyAxiom; import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; import org.dllearner.core.owl.KB; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyAssertion; import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.core.owl.ObjectPropertyRangeAxiom; @@ -268,11 +269,11 @@ @Override public void visit(EquivalentObjectPropertiesAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - IRI.create(axiom.getRole().getName())); - OWLObjectProperty equivRole = factory.getOWLObjectProperty( - IRI.create(axiom.getEquivalentRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLEquivalentObjectPropertiesAxiom(equivRole, role); + Set<OWLObjectProperty> properties = new HashSet<OWLObjectProperty>(); + for(ObjectProperty prop : axiom.getEquivalentProperties()){ + properties.add(factory.getOWLObjectProperty(IRI.create(prop.getName()))); + } + OWLAxiom axiomOWLAPI = factory.getOWLEquivalentObjectPropertiesAxiom(properties); addAxiom(axiomOWLAPI); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |