From: <jen...@us...> - 2008-06-28 07:28:20
|
Revision: 991 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=991&view=rev Author: jenslehmann Date: 2008-06-28 00:28:11 -0700 (Sat, 28 Jun 2008) Log Message: ----------- - comparator for evaluated descriptions - fixed some warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) @@ -1,3 +1,22 @@ +/** + * 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.algorithms; import java.util.*; @@ -4,79 +23,80 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.Score; import org.dllearner.core.owl.*; -public class SimpleSuggestionLearningAlgorithm extends LearningAlgorithm implements Runnable{ +/** + * TODO: Javadoc + * TODO: Extend such that it can really be used as learning algorithm. + * + * @author Christian Kötteritzsch + * + */ +public class SimpleSuggestionLearningAlgorithm extends LearningAlgorithm implements Runnable { -private Score solutionScore; -private boolean stop = false; -private Description bestSollution; -private Set<Description> simpleSuggestions; -private LearningProblem learningProblem; + private boolean stop = false; + private Score solutionScore; + private Description bestSollution; + private Set<Description> simpleSuggestions; - public SimpleSuggestionLearningAlgorithm() - { - //this.learningProblem = learningProblem; + public SimpleSuggestionLearningAlgorithm() { + // this.learningProblem = learningProblem; } - - public Description getCurrentlyBestDescription() - { + + @Override + public Description getCurrentlyBestDescription() { return bestSollution; - } - - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() - { + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { return new EvaluatedDescription(bestSollution, solutionScore); } - - - public void stop() - { + + @Override + public void stop() { stop = true; } - - public void start() - { - + + @Override + public void start() { + } - - public <T> void applyConfigEntry(ConfigEntry<T> entry) - { - + + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) { + } - - public void init() - { - + + @Override + public void init() { + } - - public Score getSolutionScore() - { + + @Override + public Score getSolutionScore() { return solutionScore; } - - public void run() - { - + + public void run() { + } - - public Set<Description> getSimpleSuggestions(ReasoningService rs,Set<Individual> indi) { + + public Set<Description> getSimpleSuggestions(ReasoningService rs, Set<Individual> indi) { // EXISTS property.TOP // ESISTS hasChild // EXISTS hasChild.male - simpleSuggestions= new HashSet<Description>(); - List<ObjectProperty> test=rs.getAtomicRolesList(); - while(test.iterator().hasNext()) - { - test.iterator().next(); - Description d1 = new ObjectSomeRestriction(test.iterator().next(), new Thing()); - test.remove(rs.getAtomicRolesList().iterator().next()); - simpleSuggestions.add(d1); + simpleSuggestions = new HashSet<Description>(); + List<ObjectProperty> test = rs.getAtomicRolesList(); + while (test.iterator().hasNext()) { + test.iterator().next(); + Description d1 = new ObjectSomeRestriction(test.iterator().next(), new Thing()); + test.remove(rs.getAtomicRolesList().iterator().next()); + simpleSuggestions.add(d1); } return simpleSuggestions; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-28 07:28:11 UTC (rev 991) @@ -398,7 +398,7 @@ } @Override - public synchronized SortedSet<Description> getCurrentlyBestDescriptions() { + public synchronized List<Description> getCurrentlyBestDescriptions() { return algorithm.getCurrentlyBestDescriptions(); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-28 07:28:11 UTC (rev 991) @@ -50,6 +50,7 @@ import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; /** * Implements the example based refinement operator learning @@ -167,6 +168,8 @@ // comparator used to create ordered sets of concepts private ConceptComparator conceptComparator = new ConceptComparator(); + // comparator for evaluated descriptions + private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator(); // utility variables private DecimalFormat df = new DecimalFormat(); @@ -1059,8 +1062,8 @@ return candidatesStable.last().getConcept(); } - public SortedSet<Description> getCurrentlyBestDescriptions() { - SortedSet<Description> best = new TreeSet<Description>(); + public List<Description> getCurrentlyBestDescriptions() { + List<Description> best = new LinkedList<Description>(); int i=0; int nrOfSolutions = 200; for(ExampleBasedNode n : candidatesStable.descendingSet()) { @@ -1075,7 +1078,7 @@ public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { int count = 0; SortedSet<ExampleBasedNode> rev = candidatesStable.descendingSet(); - SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(); + SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator); for(ExampleBasedNode eb : rev) { cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); // return a maximum of 200 elements (we need a maximum, because the Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-28 07:28:11 UTC (rev 991) @@ -88,8 +88,8 @@ /** * @see #getCurrentlyBestEvaluatedDescriptions() */ - public SortedSet<Description> getCurrentlyBestDescriptions() { - TreeSet<Description> ds = new TreeSet<Description>(); + public List<Description> getCurrentlyBestDescriptions() { + List<Description> ds = new LinkedList<Description>(); ds.add(getCurrentlyBestDescription()); return ds; } @@ -105,7 +105,7 @@ * @see #getCurrentlyBestEvaluatedDescriptions(int,double,boolean) */ public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions, boolean filterNonMinimalDescriptions) { - SortedSet<Description> currentlyBest = getCurrentlyBestDescriptions(); + List<Description> currentlyBest = getCurrentlyBestDescriptions(); List<Description> returnList = new LinkedList<Description>(); int count = 0; for(Description ed : currentlyBest) { Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-06-28 07:28:11 UTC (rev 991) @@ -34,7 +34,6 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DataRange; Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-28 07:28:11 UTC (rev 991) @@ -89,7 +89,7 @@ s.makeExamples(prim, percentOfSKOSSet, negfactor, sparqlResultSize); - SortedSet<Description> conceptresults = s.learn(); + List<Description> conceptresults = s.learn(); logger.debug("found nr of concepts: "+conceptresults.size()); System.out.println(conceptresults); @@ -249,7 +249,7 @@ logger.debug(fullPosSetWithoutPosExamples); } - public SortedSet<Description> learn(){ + public List<Description> learn(){ SortedSet<String> instances = new TreeSet<String>(); instances.addAll(this.posExamples); Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-28 07:28:11 UTC (rev 991) @@ -24,7 +24,6 @@ import java.util.TreeSet; import org.dllearner.algorithms.DBpediaNavigationSuggestor; -import org.dllearner.algorithms.RandomGuesser; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; @@ -35,7 +34,6 @@ import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.OWLAPIReasoner; /** Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java 2008-06-27 16:49:46 UTC (rev 990) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/ResultConceptSorter.java 2008-06-28 07:28:11 UTC (rev 991) @@ -2,8 +2,7 @@ import java.util.SortedSet; -import org.dllearner.core.owl.Description; - +// class is not used anywhere and is not documented - delete? public class ResultConceptSorter implements Comparable<ResultConceptSorter> { String concept; SortedSet<String> instances; Added: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2008-06-28 07:28:11 UTC (rev 991) @@ -0,0 +1,61 @@ +/** + * 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.utilities.owl; + +import java.util.Comparator; + +import org.dllearner.core.EvaluatedDescription; + +/** + * Comparator for evaluated descriptions, which orders them by + * accuracy as first criterion, length as second criterion, and + * syntactic structure as third criterion. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescriptionComparator implements Comparator<EvaluatedDescription> { + + ConceptComparator cc = new ConceptComparator(); + + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(EvaluatedDescription ed1, EvaluatedDescription ed2) { + double acc1 = ed1.getAccuracy(); + double acc2 = ed2.getAccuracy(); + if(acc1 > acc2) + return 1; + else if(acc1 < acc2) + return -1; + else { + int length1 = ed1.getDescriptionLength(); + int length2 = ed2.getDescriptionLength(); + if(length1 < length2) + return 1; + else if(length1 > length2) + return -1; + else + return cc.compare(ed1.getDescription(), ed2.getDescription()); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |