From: <jen...@us...> - 2010-04-08 16:34:00
|
Revision: 2142 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2142&view=rev Author: jenslehmann Date: 2010-04-08 16:33:52 +0000 (Thu, 08 Apr 2010) Log Message: ----------- started ISLE learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/components.ini trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java Added Paths: ----------- trunk/lib/lucene-core-3.0.1.jar trunk/src/dl-learner/org/dllearner/algorithms/isle/ trunk/src/dl-learner/org/dllearner/algorithms/isle/EntityTextRetriever.java trunk/src/dl-learner/org/dllearner/algorithms/isle/ISLE.java trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneDocument.java trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneIndexer.java trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneSearcher.java trunk/src/dl-learner/org/dllearner/algorithms/isle/NLPHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/isle/Relevances.java trunk/src/dl-learner/org/dllearner/core/configurators/ISLEConfigurator.java Added: trunk/lib/lucene-core-3.0.1.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/lucene-core-3.0.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/EntityTextRetriever.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/EntityTextRetriever.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/EntityTextRetriever.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2007-2010, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.algorithms.isle; + +import java.util.Map; + +import org.dllearner.core.owl.Entity; + +/** + * Interface for methods, which retrieve relevant texts given an entity + * in an ontology. An entity text retriever can do simple operations such + * as converting the URI into text or retrieving an rdfs:label, but could + * also search web pages for textual explanations of an entity. + * + * @author Jens Lehmann + * + */ +public interface EntityTextRetriever { + + /** + * The method retrieves a string or a set of strings, which is weighted by + * importance with respect to the entity. For instance, an rdfs:label of + * an entity can be given more weight than an rdfs:comment, which in turn + * can be more important than a description retrieved from a web page. + * + * @param entity The entity to handle. + * @return A weighted set of strings. For a value x, we need to have 0 <= x <= 1. + */ + public Map<String, Integer> getRelevantText(Entity entity); + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/ISLE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/ISLE.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/ISLE.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,736 @@ +/** + * Copyright (C) 2007-2010, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.algorithms.isle; + +import java.text.DecimalFormat; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.celoe.OEHeuristicRuntime; +import org.dllearner.algorithms.celoe.OENode; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.configurators.CELOEConfigurator; +import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.configurators.ISLEConfigurator; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Restriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.ClassLearningProblem; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.refinementoperators.OperatorInverter; +import org.dllearner.refinementoperators.RefinementOperator; +import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.owl.DescriptionMinimizer; +import org.dllearner.utilities.owl.EvaluatedDescriptionSet; +import org.dllearner.utilities.owl.PropertyContext; + +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + +/** + * ISLE - *I*nductive and *S"tatistical *L*earning of OWL Class *E*xpressions + * + * @author Jens Lehmann + * + */ +public class ISLE extends LearningAlgorithm { + + private static Logger logger = Logger.getLogger(CELOE.class); + private ISLEConfigurator configurator; + + private boolean isRunning = false; + private boolean stop = false; + +// private OEHeuristicStable heuristicStable = new OEHeuristicStable(); +// private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); + + private RefinementOperator operator; + private DescriptionMinimizer minimizer; + + // all nodes in the search tree (used for selecting most promising node) + private TreeSet<OENode> nodes; + private NLPHeuristic heuristic = new NLPHeuristic(); + // root of search tree + private OENode startNode; + // the class with which we start the refinement process + private Description startClass; + + // all descriptions in the search tree plus those which were too weak (for fast redundancy check) + private TreeSet<Description> descriptions; + + private EvaluatedDescriptionSet bestEvaluatedDescriptions; + + // if true, then each solution is evaluated exactly instead of approximately + // private boolean exactBestDescriptionEvaluation = false; + private boolean singleSuggestionMode; + private Description bestDescription; + private double bestAccuracy = Double.MIN_VALUE; + + private NamedClass classToDescribe; + // examples are either 1.) instances of the class to describe 2.) positive examples + // 3.) union of pos.+neg. examples depending on the learning problem at hand + private Set<Individual> examples; + + // CELOE was originally created for learning classes in ontologies, but also + // works for other learning problem types + private boolean isClassLearningProblem; + private boolean isEquivalenceProblem; + + private long nanoStartTime; + + // important parameters + private double noise; + private double maxDepth; + private boolean filterFollowsFromKB; + + // utility variables + private String baseURI; + private Map<String, String> prefixes; + private DecimalFormat dfPercent = new DecimalFormat("0.00%"); + private ConceptComparator descriptionComparator = new ConceptComparator(); + + // statistical variables + private int expressionTests = 0; + private int minHorizExp = 0; + private int maxHorizExp = 0; + + @Override + public ISLEConfigurator getConfigurator() { + return configurator; + } + + public ISLE(LearningProblem problem, ReasonerComponent reasoner) { + super(problem, reasoner); + configurator = new ISLEConfigurator(this); + } + + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(LearningProblem.class); + return problems; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(CommonConfigOptions.useAllConstructor()); + options.add(CommonConfigOptions.useExistsConstructor()); + options.add(CommonConfigOptions.useHasValueConstructor()); + options.add(CommonConfigOptions.useDataHasValueConstructor()); + options.add(CommonConfigOptions.valueFreqencyThreshold()); + options.add(CommonConfigOptions.useCardinalityRestrictions()); + options.add(CommonConfigOptions.cardinalityLimit()); + // by default, we do not use negation (should be configurable in GUI) + options.add(CommonConfigOptions.useNegation(false)); + options.add(CommonConfigOptions.useBooleanDatatypes()); + options.add(CommonConfigOptions.useDoubleDatatypes()); + options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10)); + options.add(CommonConfigOptions.getNoisePercentage()); + options.add(CommonConfigOptions.getMaxDepth(7)); + options.add(CommonConfigOptions.maxNrOfResults(10)); + options.add(new BooleanConfigOption("singleSuggestionMode", "Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.", false)); + options.add(CommonConfigOptions.getInstanceBasedDisjoints()); + options.add(new BooleanConfigOption("filterDescriptionsFollowingFromKB", "If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.", false)); + options.add(new BooleanConfigOption("reuseExistingDescription", "If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.", false)); + return options; + } + + public static String getName() { + return "ISLE"; + } + + @Override + public void init() throws ComponentInitException { + // copy class hierarchy and modify it such that each class is only + // reachable via a single path + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); + classHierarchy.thinOutSubsumptionHierarchy(); + + minimizer = new DescriptionMinimizer(reasoner); + + startClass = Thing.instance; + + singleSuggestionMode = configurator.getSingleSuggestionMode(); + + // create refinement operator + operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); + baseURI = reasoner.getBaseURI(); + prefixes = reasoner.getPrefixes(); + + bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults()); + + isClassLearningProblem = (learningProblem instanceof ClassLearningProblem); + + // we put important parameters in class variables + noise = configurator.getNoisePercentage()/100d; + maxDepth = configurator.getMaxDepth(); + // (filterFollowsFromKB is automatically set to false if the problem + // is not a class learning problem + filterFollowsFromKB = configurator.getFilterDescriptionsFollowingFromKB() + && isClassLearningProblem; + + // actions specific to ontology engineering + if(isClassLearningProblem) { + ClassLearningProblem problem = (ClassLearningProblem) learningProblem; + classToDescribe = problem.getClassToDescribe(); + isEquivalenceProblem = problem.isEquivalenceProblem(); + + examples = reasoner.getIndividuals(classToDescribe); + + // start class: intersection of super classes for definitions (since it needs to + // capture all instances), but owl:Thing for learning subclasses (since it is + // superfluous to add super classes in this case) + if(isEquivalenceProblem) { + Set<Description> existingDefinitions = reasoner.getAssertedDefinitions(classToDescribe); + if(configurator.getReuseExistingDescription() && (existingDefinitions.size() > 0)) { + // the existing definition is reused, which in the simplest case means to + // use it as a start class or, if it is already too specific, generalise it + + // pick the longest existing definition as candidate + Description existingDefinition = null; + int highestLength = 0; + for(Description exDef : existingDefinitions) { + if(exDef.getLength() > highestLength) { + existingDefinition = exDef; + highestLength = exDef.getLength(); + } + } + + LinkedList<Description> startClassCandidates = new LinkedList<Description>(); + startClassCandidates.add(existingDefinition); + ((RhoDRDown)operator).setDropDisjuncts(true); + RefinementOperator upwardOperator = new OperatorInverter(operator); + + // use upward refinement until we find an appropriate start class + boolean startClassFound = false; + Description candidate; + do { + candidate = startClassCandidates.pollFirst(); + if(((ClassLearningProblem)learningProblem).getRecall(candidate)<1.0) { + // add upward refinements to list + Set<Description> refinements = upwardOperator.refine(candidate, candidate.getLength()); +// System.out.println("ref: " + refinements); + LinkedList<Description> refinementList = new LinkedList<Description>(refinements); +// Collections.reverse(refinementList); +// System.out.println("list: " + refinementList); + startClassCandidates.addAll(refinementList); +// System.out.println("candidates: " + startClassCandidates); + } else { + startClassFound = true; + } + } while(!startClassFound); + startClass = candidate; + + if(startClass.equals(existingDefinition)) { + logger.info("Reusing existing description " + startClass.toManchesterSyntaxString(baseURI, prefixes) + " as start class for learning algorithm."); + } else { + logger.info("Generalised existing description " + existingDefinition.toManchesterSyntaxString(baseURI, prefixes) + " to " + startClass.toManchesterSyntaxString(baseURI, prefixes) + ", which is used as start class for the learning algorithm."); + } + +// System.out.println("start class: " + startClass); +// System.out.println("existing def: " + existingDefinition); +// System.out.println(reasoner.getIndividuals(existingDefinition)); + + ((RhoDRDown)operator).setDropDisjuncts(false); + + } else { + Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); + if(superClasses.size() > 1) { + startClass = new Intersection(new LinkedList<Description>(superClasses)); + } else if(superClasses.size() == 1){ + startClass = (Description) superClasses.toArray()[0]; + } else { + startClass = Thing.instance; + logger.warn(classToDescribe + " is equivalent to owl:Thing. Usually, it is not " + + "sensible to learn a description in this case."); + } + } + } + } else if(learningProblem instanceof PosOnlyLP) { + examples = ((PosOnlyLP)learningProblem).getPositiveExamples(); + } else if(learningProblem instanceof PosNegLP) { + examples = Helper.union(((PosNegLP)learningProblem).getPositiveExamples(),((PosNegLP)learningProblem).getNegativeExamples()); + } + } + + @Override + public Description getCurrentlyBestDescription() { + EvaluatedDescription ed = getCurrentlyBestEvaluatedDescription(); + return ed == null ? null : ed.getDescription(); + } + + @Override + public List<Description> getCurrentlyBestDescriptions() { + return bestEvaluatedDescriptions.toDescriptionList(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return bestEvaluatedDescriptions.getBest(); + } + + @Override + public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + return bestEvaluatedDescriptions.getSet(); + } + + @Override + public void start() { +// System.out.println(configurator.getMaxExecutionTimeInSeconds()); + + stop = false; + isRunning = true; + reset(); + nanoStartTime = System.nanoTime(); + + // highest accuracy so far + double highestAccuracy = 0.0; + OENode nextNode; + + addNode(startClass, null); + + int loop = 0; + while (!terminationCriteriaSatisfied()) { + + if(!singleSuggestionMode && bestEvaluatedDescriptions.getBestAccuracy() > highestAccuracy) { + highestAccuracy = bestEvaluatedDescriptions.getBestAccuracy(); + logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); + } + + // chose best node according to heuristics + nextNode = getNextNodeToExpand(); + int horizExp = nextNode.getHorizontalExpansion(); + + // apply operator + Monitor mon = MonitorFactory.start("refineNode"); + TreeSet<Description> refinements = refineNode(nextNode); + mon.stop(); + +// System.out.println("next node: " + nextNode); +// for(Description refinement : refinements) { +// System.out.println("refinement: " + refinement); +// } + + while(refinements.size() != 0) { + // pick element from set + Description refinement = refinements.pollFirst(); + int length = refinement.getLength(); + + // we ignore all refinements with lower length and too high depth + // (this also avoids duplicate node children) + if(length > horizExp && refinement.getDepth() <= maxDepth) { + +// System.out.println("potentially adding " + refinement + " to search tree as child of " + nextNode + " " + new Date()); + Monitor mon2 = MonitorFactory.start("addNode"); + addNode(refinement, nextNode); + mon2.stop(); + // adding nodes is potentially computationally expensive, so we have + // to check whether max time is exceeded + if(terminationCriteriaSatisfied()) { + break; + } +// System.out.println("addNode finished" + " " + new Date()); + } + +// System.out.println(" refinement queue length: " + refinements.size()); + } + + updateMinMaxHorizExp(nextNode); + +// System.out.println(loop); + loop++; + } + + if (stop) { + logger.info("Algorithm stopped ("+expressionTests+" descriptions tested). " + nodes.size() + " nodes in the search tree.\n"); + } else { + logger.info("Algorithm terminated successfully ("+expressionTests+" descriptions tested). " + nodes.size() + " nodes in the search tree.\n"); + } + + if(singleSuggestionMode) { + bestEvaluatedDescriptions.add(bestDescription, bestAccuracy, learningProblem); + } + + // print solution(s) + logger.info("solutions:\n" + getSolutionString()); + +// System.out.println(startNode.toTreeString(baseURI)); + + isRunning = false; +// System.out.println("isRunning: " + isRunning); + } + + private OENode getNextNodeToExpand() { + // we expand the best node of those, which have not achieved 100% accuracy + // already and have a horizontal expansion equal to their length + // (rationale: further extension is likely to add irrelevant syntactical constructs) + Iterator<OENode> it = nodes.descendingIterator(); + while(it.hasNext()) { + OENode node = it.next(); + if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) { + return node; + } + } + + // this should practically never be called, since for any reasonable learning + // task, we will always have at least one node with less than 100% accuracy + return nodes.last(); + } + + // expand node horizontically + private TreeSet<Description> refineNode(OENode node) { + // we have to remove and add the node since its heuristic evaluation changes through the expansion + // (you *must not* include any criteria in the heuristic which are modified outside of this method, + // otherwise you may see rarely occurring but critical false ordering in the nodes set) + nodes.remove(node); +// System.out.println("refining: " + node); + int horizExp = node.getHorizontalExpansion(); + TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); + node.incHorizontalExpansion(); + node.setRefinementCount(refinements.size()); + nodes.add(node); + return refinements; + } + + // add node to search tree if it is not too weak + // returns true if node was added and false otherwise + private boolean addNode(Description description, OENode parentNode) { + +// System.out.println(description); + + // redundancy check (return if redundant) + boolean nonRedundant = descriptions.add(description); + if(!nonRedundant) { + return false; + } + + // check whether the description is allowed + if(!isDescriptionAllowed(description, parentNode)) { + return false; + } + +// System.out.println("Test " + new Date()); + // quality of description (return if too weak) + double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); + // issue a warning if accuracy is not between 0 and 1 or -1 (too weak) + if(accuracy > 1.0 || (accuracy < 0.0 && accuracy != -1)) { + logger.warn("Invalid accuracy value " + accuracy + " for description " + description + ". This could be caused by a bug in the heuristic measure and should be reported to the DL-Learner bug tracker."); + System.exit(0); + } + +// System.out.println("Test2 " + new Date()); + expressionTests++; +// System.out.println("acc: " + accuracy); +// System.out.println(description + " " + accuracy); + if(accuracy == -1) { + return false; + } + + OENode node = new OENode(parentNode, description, accuracy); + + // link to parent (unless start node) + if(parentNode == null) { + startNode = node; + } else { + parentNode.addChild(node); + } + + nodes.add(node); +// System.out.println("Test3 " + new Date()); + + // in some cases (e.g. mutation) fully evaluating even a single description is too expensive + // due to the high number of examples -- so we just stick to the approximate accuracy + if(singleSuggestionMode) { + if(accuracy > bestAccuracy) { + bestAccuracy = accuracy; + bestDescription = description; + logger.info("more accurate (" + dfPercent.format(bestAccuracy) + ") class expression found: " + descriptionToString(bestDescription)); // + getTemporaryString(bestDescription)); + } + return true; + } + + // maybe add to best descriptions (method keeps set size fixed); + // we need to make sure that this does not get called more often than + // necessary since rewriting is expensive + boolean isCandidate = !bestEvaluatedDescriptions.isFull(); + if(!isCandidate) { + EvaluatedDescription worst = bestEvaluatedDescriptions.getWorst(); + double accThreshold = worst.getAccuracy(); + isCandidate = + (accuracy > accThreshold || + (accuracy >= accThreshold && description.getLength() < worst.getDescriptionLength())); + } + +// System.out.println("Test4 " + new Date()); + if(isCandidate) { + Description niceDescription = rewriteNode(node); + ConceptTransformation.transformToOrderedForm(niceDescription, descriptionComparator); +// Description niceDescription = node.getDescription(); + + // another test: none of the other suggested descriptions should be + // a subdescription of this one unless accuracy is different + boolean shorterDescriptionExists = false; + for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet()) { + if(Math.abs(ed.getAccuracy()-accuracy) <= 0.00001 && ConceptTransformation.isSubdescription(niceDescription, ed.getDescription())) { + shorterDescriptionExists = true; + break; + } + } + + if(!shorterDescriptionExists) { + if(!filterFollowsFromKB || !((ClassLearningProblem)learningProblem).followsFromKB(niceDescription)) { + bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem); +// System.out.println("acc: " + accuracy); +// System.out.println(bestEvaluatedDescriptions); + } + } + + } + +// System.out.println("Test5 " + new Date()); +// System.out.println("best evaluated descriptions size: " + bestEvaluatedDescriptions.size() + " worst: " + bestEvaluatedDescriptions.getWorst()); + return true; + } + + // checks whether the description is allowed + private boolean isDescriptionAllowed(Description description, OENode parentNode) { + if(isClassLearningProblem) { + if(isEquivalenceProblem) { + // the class to learn must not appear on the outermost property level + if(occursOnFirstLevel(description, classToDescribe)) { + return false; + } + } else { + // none of the superclasses of the class to learn must appear on the + // outermost property level + TreeSet<Description> toTest = new TreeSet<Description>(descriptionComparator); + toTest.add(classToDescribe); + while(!toTest.isEmpty()) { + Description d = toTest.pollFirst(); + if(occursOnFirstLevel(description, d)) { + return false; + } + toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d)); + } + } + } + + // perform forall sanity tests + if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) { + // we have an additional \forall construct, so we now fetch the contexts + // in which it occurs + SortedSet<PropertyContext> contexts = ConceptTransformation.getForallContexts(description); + SortedSet<PropertyContext> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription()); + contexts.removeAll(parentContexts); +// System.out.println("parent description: " + parentNode.getDescription()); +// System.out.println("description: " + description); +// System.out.println("contexts: " + contexts); + // we now have to perform sanity checks: if \forall is used, then there + // should be at least on class instance which has a filler at the given context + for(PropertyContext context : contexts) { + // transform [r,s] to \exists r.\exists s.\top + Description existentialContext = context.toExistentialContext(); + boolean fillerFound = false; + for(Individual instance : examples) { + if(reasoner.hasType(existentialContext, instance)) { +// System.out.println(instance + " " + existentialContext); + fillerFound = true; + break; + } + } + // if we do not find a filler, this means that putting \forall at + // that position is not meaningful + if(!fillerFound) { + return false; + } + } + } + + // we do not want to have negations of sibling classes on the outermost level + // (they are expressed more naturally by saying that the siblings are disjoint, + // so it is reasonable not to include them in solutions) +// Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe); +// for now, we just disable negation + + return true; + } + + // determine whether a named class occurs on the outermost level, i.e. property depth 0 + // (it can still be at higher depth, e.g. if intersections are nested in unions) + private boolean occursOnFirstLevel(Description description, Description clazz) { + if(description instanceof NamedClass) { + if(description.equals(clazz)) { + return true; + } + } + + if(description instanceof Restriction) { + return false; + } + + for(Description child : description.getChildren()) { + if(occursOnFirstLevel(child, clazz)) { + return true; + } + } + + return false; + } + + // check whether the node is a potential solution candidate + private Description rewriteNode(OENode node) { + Description description = node.getDescription(); + // minimize description (expensive!) - also performes some human friendly rewrites + Description niceDescription = minimizer.minimizeClone(description); + // replace \exists r.\top with \exists r.range(r) which is easier to read for humans + ConceptTransformation.replaceRange(niceDescription, reasoner); + return niceDescription; + } + + private boolean terminationCriteriaSatisfied() { + return stop || ((System.nanoTime() - nanoStartTime) >= (configurator.getMaxExecutionTimeInSeconds()*1000000000l)); + } + + private void reset() { + // set all values back to their default values (used for running + // the algorithm more than once) + nodes = new TreeSet<OENode>(heuristic); + descriptions = new TreeSet<Description>(new ConceptComparator()); + bestEvaluatedDescriptions.getSet().clear(); + expressionTests = 0; + } + + @Override + public boolean isRunning() { + return isRunning; + } + + @Override + public void stop() { + stop = true; + } + + public OENode getSearchTreeRoot() { + return startNode; + } + + // central function for printing description + private String descriptionToString(Description description) { + return description.toManchesterSyntaxString(baseURI, prefixes); + } + + @SuppressWarnings("unused") + private String bestDescriptionToString() { + EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); + return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")"; + } + + private String getSolutionString() { + int current = 1; + String str = ""; + for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { + // temporary code + if(learningProblem instanceof PosNegLPStandard) { + str += current + ": " + descriptionToString(ed.getDescription()) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(ed.getDescription(),1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(ed.getDescription(),1)) + ")\n"; + } else { + str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n"; +// System.out.println(ed); + } + current++; + } + return str; + } + +// private String getTemporaryString(Description description) { +// return descriptionToString(description) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(description,1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(description,1)) + ")"; +// } + + private void updateMinMaxHorizExp(OENode node) { + int newHorizExp = node.getHorizontalExpansion(); + + // update maximum value + maxHorizExp = Math.max(maxHorizExp, newHorizExp); + + // we just expanded a node with minimum horizontal expansion; + // we need to check whether it was the last one + if(minHorizExp == newHorizExp - 1) { + + // the best accuracy that a node can achieve + double scoreThreshold = heuristic.getNodeScore(node) + 1 - node.getAccuracy(); + + for(OENode n : nodes.descendingSet()) { + if(n != node) { + if(n.getHorizontalExpansion() == minHorizExp) { + // we can stop instantly when another node with min. + return; + } + if(heuristic.getNodeScore(n) < scoreThreshold) { + // we can stop traversing nodes when their score is too low + break; + } + } + } + + // inc. minimum since we found no other node which also has min. horiz. exp. + minHorizExp++; + +// System.out.println("minimum horizontal expansion is now " + minHorizExp); + } + } + + public int getMaximumHorizontalExpansion() { + return maxHorizExp; + } + + public int getMinimumHorizontalExpansion() { + return minHorizExp; + } + + /** + * @return the expressionTests + */ + public int getClassExpressionTests() { + return expressionTests; + } + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneDocument.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneDocument.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneDocument.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,24 @@ + +package org.dllearner.algorithms.isle; + +import java.io.File; +import java.io.FileReader; + +import org.apache.lucene.document.DateTools; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; + + +public class LuceneDocument { + + public static Document Document( File f ) throws java.io.FileNotFoundException { + Document doc = new Document(); + doc.add( new Field( "path", f.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); + doc.add( new Field( "modified", + DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE), + Field.Store.YES, Field.Index.NOT_ANALYZED)); + doc.add( new Field( "contents", new FileReader(f) ) ); + return doc; + } +} + Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneIndexer.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneIndexer.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneIndexer.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,77 @@ + +package org.dllearner.algorithms.isle; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Date; + +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.util.Version; + + +public class LuceneIndexer { + + static final File INDEX = new File( "index" ); + + public static void main( String[] args ) { + if( INDEX.exists() ) + { + System.out.println("<delete index!>"); + System.exit(1); + } + final File docDir = new File( args[0] ); + LuceneIndexer indexer = new LuceneIndexer( docDir ); + } + + public LuceneIndexer( File docDir ){ + System.out.println( "LuceneIndex: "+ docDir ); + Date start = new Date(); + try { + IndexWriter writer = new IndexWriter( FSDirectory.open( INDEX ), + new StandardAnalyzer( Version.LUCENE_CURRENT ), true, IndexWriter.MaxFieldLength.LIMITED ); + System.out.println( "Creating index ..." ); + index( writer, docDir ); + System.out.println( "Optimizing index ..." ); + writer.optimize(); + writer.close(); + Date end = new Date(); + System.out.println( end.getTime() - start.getTime() + " total milliseconds" ); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + private void index( IndexWriter writer, File file ) throws IOException { + // System.out.println( "LuceneIndexer.index: "+ file ); + if( file.canRead() ) + { + if( file.isDirectory() ) + { + String[] files = file.list(); + if( files != null ) + { + for( int i = 0; i < files.length; i++ ) { + index( writer, new File( file, files[i] ) ); + } + } + } + else { + // System.out.println( "Indexer.index: adding " + file ); + try { + writer.addDocument( LuceneDocument.Document( file ) ); + } + catch (FileNotFoundException fnfe) { + fnfe.printStackTrace(); + } + } + } + else { + System.out.println( "<cannot read file!>" ); + } + } + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneSearcher.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneSearcher.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/LuceneSearcher.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,126 @@ + +package org.dllearner.algorithms.isle; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Scorer; +import org.apache.lucene.search.Searcher; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.util.Version; + +public class LuceneSearcher { + + private String INDEX = "index"; + private String FIELD = "contents"; + + private IndexReader m_reader = null; + private Searcher m_searcher = null; + private Analyzer m_analyzer = null; + private QueryParser m_parser = null; + + private Map<Document,Float> m_results = null; + + + public static void main( String[] args ) throws Exception { + String sQuery = args[0]; + LuceneSearcher searcher = new LuceneSearcher(); + List<Document> docs = searcher.search( sQuery ); + System.out.println( "\nquery='"+ sQuery +"' all="+ searcher.indexSize() +" hits="+ docs.size() ); + for( Document doc : docs ) + { + String sDoc = doc.toString(); + float score = searcher.getScore( doc ); + System.out.println( "score="+ score +" doc="+ doc ); + } + } + + public LuceneSearcher() throws Exception { + m_reader = IndexReader.open( FSDirectory.open( new File( INDEX ) ), true ); + m_searcher = new IndexSearcher( m_reader ); + m_analyzer = new StandardAnalyzer( Version.LUCENE_CURRENT ); + m_parser = new QueryParser( Version.LUCENE_CURRENT, FIELD, m_analyzer ); + } + + public void close() throws Exception { + m_reader.close(); + } + + public int indexSize(){ + return m_reader.numDocs(); + } + + public List<Document> search( String sQuery ) throws Exception { + m_results = new HashMap<Document,Float>(); + Query query = m_parser.parse( sQuery ); + search( query ); + // m_reader.close(); + return getDocuments(); + } + + public int count( String sQuery ) throws Exception { + return search( sQuery ).size(); + } + + public List<Document> getDocuments(){ + List<Document> docs = new ArrayList<Document>(); + for( Document doc: m_results.keySet() ){ + docs.add( doc ); + } + Collections.sort( docs, new Comparator<Document>(){ + public int compare( Document d1, Document d2 ){ + float s1 = getScore( d1 ); + float s2 = getScore( d2 ); + if( s1 > s2 ) return -1; + else if( s1 < s2 ) return 1; + return 0; + } + public boolean equals( Object obj ){ + return false; + } + } ); + return docs; + } + + public float getScore( Document doc ){ + return m_results.get( doc ); + } + + private void search( Query query ) throws IOException { + Collector collector = new Collector() + { + private Scorer scorer; + private int docBase; + private Map<Document,Float> results = new HashMap<Document,Float>(); + + public void collect(int doc) throws IOException { + // System.out.println("doc=" + doc + docBase + " score=" + scorer.score()); + m_results.put( m_searcher.doc( doc ), scorer.score() ); + } + public boolean acceptsDocsOutOfOrder() { + return true; + } + public void setNextReader( IndexReader reader, int docBase ) throws IOException { + this.docBase = docBase; + } + public void setScorer(Scorer scorer) throws IOException { + this.scorer = scorer; + } + }; + m_searcher.search( query, collector ); + } +} Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/NLPHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/NLPHeuristic.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/NLPHeuristic.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2007-2010, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.algorithms.isle; + +import java.util.Comparator; + +import org.dllearner.algorithms.celoe.OENode; +import org.dllearner.utilities.owl.ConceptComparator; + +/** + * + * TODO: NLP-Heuristiken in Statistik integrieren + * + * @author Jens Lehmann + * + */ +public class NLPHeuristic implements Comparator<OENode> { + // strong penalty for long descriptions + private double expansionPenaltyFactor = 0.1; + // bonus for being better than parent node + private double gainBonusFactor = 0.3; + // penalty if a node description has very many refinements since exploring + // such a node is computationally very expensive + private double nodeRefinementPenalty = 0.0001; + // syntactic comparison as final comparison criterion + private ConceptComparator conceptComparator = new ConceptComparator(); + + @Override + public int compare(OENode node1, OENode node2) { +// System.out.println("node1 " + node1); +// System.out.println("score: " + getNodeScore(node1)); +// System.out.println("node2 " + node2); +// System.out.println("score: " + getNodeScore(node2)); + + double diff = getNodeScore(node1) - getNodeScore(node2); + + if(diff>0) { + return 1; + } else if(diff<0) { + return -1; + } else { + return conceptComparator.compare(node1.getDescription(), node2.getDescription()); + } + } + + public double getNodeScore(OENode node) { + // accuracy as baseline + double score = node.getAccuracy(); + // being better than the parent gives a bonus; + if(!node.isRoot()) { + double parentAccuracy = node.getParent().getAccuracy(); + score += (parentAccuracy - score) * gainBonusFactor; + } + // penalty for horizontal expansion + score -= node.getHorizontalExpansion() * expansionPenaltyFactor; + // penalty for having many child nodes (stuck prevention) + score -= node.getRefinementCount() * nodeRefinementPenalty; + return score; + } + + public double getExpansionPenaltyFactor() { + return expansionPenaltyFactor; + } + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/isle/Relevances.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/isle/Relevances.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/isle/Relevances.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,146 @@ + +package org.dllearner.algorithms.isle; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLNamedObject; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; + + +public class Relevances { + + private LuceneSearcher m_searcher = null; + + private OWLOntologyManager m_manager; + private OWLOntology m_ontology; + + private Set<OWLEntity> m_entities; + private Set<OWLClass> m_classes; + + + public static void main( String args[] ) throws Exception { + Relevances relevances = new Relevances( args[0] ); + relevances.printScores(); + } + + public void printScores() throws Exception { + for( OWLClass c: m_classes ) + { + Map<OWLEntity,Double> hmEntity2Score = getEntityRelevance(c); + // normalization per class? + hmEntity2Score = normalize( hmEntity2Score ); + for( OWLEntity e : hmEntity2Score.keySet() ) + { + double dScore = hmEntity2Score.get(e); + System.out.println( "P( "+ getLabel(c) +", "+ getLabel(e) +" ) = "+ dScore ); + } + } + m_searcher.close(); + } + + public Relevances( String sOntologyURI ) throws Exception { + m_searcher = new LuceneSearcher(); + loadOntology( sOntologyURI ); + } + + public Map<OWLEntity,Double> normalize( Map<OWLEntity,Double> hmEntity2Score ){ + Map<OWLEntity,Double> hmEntity2Norm = new HashMap<OWLEntity,Double>(); + double dMin = Double.MAX_VALUE; + Double dMax = Double.MIN_VALUE; + for( OWLEntity e : hmEntity2Score.keySet() ) + { + double dValue = hmEntity2Score.get(e); + if( dValue < dMin ){ + dMin = dValue; + } + else if( dValue > dMax ){ + dMax = dValue; + } + } + // System.out.println( "min="+ dMin +" max="+ dMax ); + for( OWLEntity e : hmEntity2Score.keySet() ) + { + double dValue = hmEntity2Score.get(e); + double dNorm = 0; + if( dMin == dMax ){ + dNorm = dValue; + } + else { + dNorm = ( dValue - dMin ) / ( dMax - dMin ); + } + hmEntity2Norm.put( e, dNorm ); + } + return hmEntity2Norm; + } + + public Map<OWLEntity,Double> getEntityRelevance( OWLClass c ) throws Exception { + // computes relevance of entity for this class + // conditional probability: P(C,E)=f(C,E)/f(E) + // PMI(C,E)=log( P(C,E) / P(C) ) + Map<OWLEntity,Double> hmEntity2Score = new HashMap<OWLEntity,Double>(); + String sClass = getLabel(c); + int iClass = m_searcher.count( sClass ); + int iAll = m_searcher.indexSize(); + double dPClass = (double) iClass / (double) iAll; + for( OWLEntity e: m_entities ) + { + String sEntity = getLabel(e); + int iEntity = m_searcher.count( sEntity ); + int iEntityClass = m_searcher.count( sClass +" AND "+ sEntity ); + double dPEntity = (double)iEntity / (double)iAll; + double dPClassEntity = (double) iEntityClass / (double)iEntity; + double dPMI = Math.log( dPClassEntity / dPClass ); + if( !Double.isNaN( dPMI ) && !Double.isInfinite( dPMI ) ){ + hmEntity2Score.put( e, dPMI ); + } + } + return hmEntity2Score; + } + + /* private String getLabel( OWLEntity e ){ + System.out.println( "getLabel: "+ e ); + OWLDataFactory factory = m_manager.getOWLDataFactory(); + OWLAnnotationProperty label = factory.getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI() ); + Set<OWLAnnotation> anns = e.getAnnotations( m_ontology, label ); + for( OWLAnnotation annotation: anns ) + { + System.out.println( "annotation="+ annotation ); + if( annotation.getValue() instanceof OWLLiteral ) + { + OWLLiteral val = (OWLLiteral) annotation.getValue(); + if( !val.isOWLTypedLiteral() ){ + if (val.asOWLStringLiteral().getLang().equals("en")) { + return val.getLiteral(); + } + } + return val.getLiteral(); + } + } + return null; + } */ + + private String getLabel( OWLEntity e ){ + if( e instanceof OWLNamedObject ){ + String sIRI = ((OWLNamedObject)e).getIRI().toString(); + return sIRI.substring( sIRI.indexOf( "#" )+1 ); + } + return null; + } + + private void loadOntology( String sOntologyURI ) throws Exception { + m_manager = OWLManager.createOWLOntologyManager(); + IRI ontologyIRI = IRI.create( sOntologyURI ); + m_ontology = m_manager.loadOntology( ontologyIRI ); + m_classes = m_ontology.getClassesInSignature(); + m_entities = m_ontology.getSignature(); + System.out.println( "classes="+ m_classes.size() +" entities="+ m_entities.size() ); + // m_manager.removeOntology( ontology ); + } +} \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/components.ini =================================================================== --- trunk/src/dl-learner/org/dllearner/components.ini 2010-03-30 21:45:14 UTC (rev 2141) +++ trunk/src/dl-learner/org/dllearner/components.ini 2010-04-08 16:33:52 UTC (rev 2142) @@ -25,3 +25,4 @@ org.dllearner.algorithms.el.ELLearningAlgorithm org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive org.dllearner.algorithms.celoe.CELOE +org.dllearner.algorithms.isle.ISLE Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2010-03-30 21:45:14 UTC (rev 2141) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -28,6 +28,7 @@ import org.dllearner.algorithms.el.ELLearningAlgorithm; import org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive; import org.dllearner.algorithms.gp.GP; +import org.dllearner.algorithms.isle.ISLE; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.algorithms.refinement2.ROLComponent2; import org.dllearner.core.KnowledgeSource; @@ -229,6 +230,16 @@ * @param learningProblem see LearningProblem * @param reasoningService see ReasoningService * @throws LearningProblemUnsupportedException see +* @return a component ready for initialization ISLE +**/ +public static ISLE getISLE(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { +return ISLEConfigurator.getISLE(learningProblem, reasoningService); +} + +/** +* @param learningProblem see LearningProblem +* @param reasoningService see ReasoningService +* @throws LearningProblemUnsupportedException see * @return a component ready for initialization ROLearner **/ public static ROLearner getROLearner(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { Added: trunk/src/dl-learner/org/dllearner/core/configurators/ISLEConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ISLEConfigurator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ISLEConfigurator.java 2010-04-08 16:33:52 UTC (rev 2142) @@ -0,0 +1,395 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package org.dllearner.core.configurators; + +import org.dllearner.algorithms.isle.ISLE; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.configurators.RefinementOperatorConfigurator; + +/** +* automatically generated, do not edit manually. +* run org.dllearner.scripts.ConfigJavaGenerator to update +**/ +@SuppressWarnings("all") +public class ISLEConfigurator extends RefinementOperatorConfigurator implements Configurator { + +private boolean reinitNecessary = false; +@SuppressWarnings("unused") + +private ISLE iSLE; + +/** +* @param iSLE see ISLE +**/ +public ISLEConfigurator(ISLE iSLE){ +this.iSLE = iSLE; +} + +/** +* @param reasoningService see reasoningService +* @param learningProblem see learningProblem +* @throws LearningProblemUnsupportedException see +* @return ISLE +**/ +public static ISLE getISLE(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException{ +ISLE component = ComponentManager.getInstance().learningAlgorithm(ISLE.class, learningProblem, reasoningService); +return component; +} + +/** +* useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getUseAllConstructor() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useAllConstructor") ; +} +/** +* useExistsConstructor specifies whether the existential concept constructor is used in the learning algorithm. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getUseExistsConstructor() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useExistsConstructor") ; +} +/** +* useHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getUseHasValueConstructor() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useHasValueConstructor") ; +} +/** +* useDataHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm in combination with data properties. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getUseDataHasValueConstructor() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useDataHasValueConstructor") ; +} +/** +* valueFrequencyThreshold specifies how often an object must occur as value in order to be considered for hasValue restrictions. +* mandatory: false| reinit necessary: true +* default value: 3 +* @return int +**/ +public int getValueFrequencyThreshold() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(iSLE, "valueFrequencyThreshold") ; +} +/** +* useCardinalityRestrictions specifies whether CardinalityRestrictions is used in the learning algorithm. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getUseCardinalityRestrictions() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useCardinalityRestrictions") ; +} +/** +* cardinalityLimit Gives the maximum number used in cardinality restrictions.. +* mandatory: false| reinit necessary: true +* default value: 5 +* @return int +**/ +public int getCardinalityLimit() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(iSLE, "cardinalityLimit") ; +} +/** +* useNegation specifies whether negation is used in the learning algorothm. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getUseNegation() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useNegation") ; +} +/** +* useBooleanDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getUseBooleanDatatypes() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useBooleanDatatypes") ; +} +/** +* useDoubleDatatypes specifies whether boolean datatypes are used in the learning algorothm. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getUseDoubleDatatypes() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "useDoubleDatatypes") ; +} +/** +* maxExecutionTimeInSeconds algorithm will stop after specified seconds. +* mandatory: false| reinit necessary: true +* default value: 10 +* @return int +**/ +public int getMaxExecutionTimeInSeconds() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(iSLE, "maxExecutionTimeInSeconds") ; +} +/** +* noisePercentage the (approximated) percentage of noise within the examples. +* mandatory: false| reinit necessary: true +* default value: 0.0 +* @return double +**/ +public double getNoisePercentage() { +return (Double) ComponentManager.getInstance().getConfigOptionValue(iSLE, "noisePercentage") ; +} +/** +* maxDepth maximum depth of description. +* mandatory: false| reinit necessary: true +* default value: 7 +* @return int +**/ +public int getMaxDepth() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(iSLE, "maxDepth") ; +} +/** +* maxNrOfResults Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).. +* mandatory: false| reinit necessary: true +* default value: 10 +* @return int +**/ +public int getMaxNrOfResults() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(iSLE, "maxNrOfResults") ; +} +/** +* singleSuggestionMode Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getSingleSuggestionMode() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "singleSuggestionMode") ; +} +/** +* instanceBasedDisjoints Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator.. +* mandatory: false| reinit necessary: true +* default value: true +* @return boolean +**/ +public boolean getInstanceBasedDisjoints() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "instanceBasedDisjoints") ; +} +/** +* filterDescriptionsFollowingFromKB If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getFilterDescriptionsFollowingFromKB() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "filterDescriptionsFollowingFromKB") ; +} +/** +* reuseExistingDescription If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.. +* mandatory: false| reinit necessary: true +* default value: false +* @return boolean +**/ +public boolean getReuseExistingDescription() { +return (Boolean) ComponentManager.getInstance().getConfigOptionValue(iSLE, "reuseExistingDescription") ; +} + +/** +* @param useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. +* mandatory: false| reinit necessary: true +* default value: true +**/ +public void setUseAllConstructor(boolean useAllConstructor) { +ComponentManager.getInstance().applyConfigEntry(iSLE, "useAllConstructor", useAllConstructor); +reinitNecessary = true; +} +/** +* @param useExistsConstructor specifies whether the existenti... [truncated message content] |