From: <sha...@us...> - 2011-08-24 04:53:24
|
Revision: 3105 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3105&view=rev Author: shadowtm Date: 2011-08-24 04:53:15 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Made modifications to components used by the Father example. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java 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/learningproblems/PosNegLPStrict.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown2.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/Utility.java trunk/components-core/src/main/java/org/dllearner/utilities/Helper.java trunk/components-core/src/main/java/org/dllearner/utilities/components/ReasonerComponentFactory.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SortedSetTuple.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java trunk/components-core/src/test/java/org/dllearner/test/FuzzyDLLTest_noFuzzyTrains.java trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/gui/TreeWindow.java trunk/interfaces/src/test/java/org/dllearner/test/junit/OWLlinkTest.java trunk/interfaces/src/test/java/org/dllearner/test/junit/ReasonerTests.java trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java Added Paths: ----------- trunk/interfaces/src/test/java/org/dllearner/cli/ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/pom.xml 2011-08-24 04:53:15 UTC (rev 3105) @@ -285,5 +285,9 @@ <artifactId>commons-codec</artifactId> <version>20041127.091804</version> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + </dependency> </dependencies> </project> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,13 +19,7 @@ package org.dllearner.algorithms.el; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; @@ -113,8 +107,8 @@ private double posWeight = 1.2; // 2; private int startPosExamplesSize; // private int startNegExamplesSize; - private SortedSet<Individual> currentPosExamples; - private SortedSet<Individual> currentNegExamples; + private Set<Individual> currentPosExamples; + private Set<Individual> currentNegExamples; private SearchTreeNode bestCurrentNode; private double bestCurrentScore = 0; private long treeStartTime; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,12 +19,7 @@ package org.dllearner.algorithms.gp; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.SortedSet; -import java.util.TreeMap; +import java.util.*; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; @@ -474,7 +469,7 @@ private static ScoreThreeValued getScore(int conceptLength, AbstractLearningProblem learningProblem, AbstractReasonerComponent rs, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! - SortedSet<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified); // learningProblem.getReasoner().getIndividuals(); // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); 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-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -340,10 +340,10 @@ // warn the user if he/she sets any non-standard heuristic, because it will just be ignored if(learningProblem instanceof PosNegLPStandard) { - if(((PosNegLPStandard)learningProblem).getConfigurator().getUseApproximations()) { + if(((PosNegLPStandard)learningProblem).isUseApproximations()) { System.err.println("You actived approximations for the considered learning problem, but OCEL does not support it. Option will be ignored. (Recommendation: Use CELOE instead.)"); } - if(!((PosNegLPStandard)learningProblem).getConfigurator().getAccuracyMethod().equals("predacc")) { + if(!((PosNegLPStandard)learningProblem).getAccuracyMethod().equals("predacc")) { System.err.println("You have chosen a non-standard (predictive accuracy) heuristic in your learning problem, but OCEL does not support it. Option will be ignored. (Recommendation: Use CELOE instead.)"); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -34,13 +34,12 @@ */ public abstract class AbstractLearningProblem extends AbstractComponent implements LearningProblem { + private AbstractReasonerComponent reasoner; + + public AbstractLearningProblem(){ + + } /** - * Implementations of learning problems can use this class - * variable to perform reasoner operations. - */ - protected AbstractReasonerComponent reasoner; - - /** * Constructs a learning problem using a reasoning service for * querying the background knowledge. It can be used for * evaluating solution candidates. @@ -109,5 +108,17 @@ * @return A value between 0 and 1 indicating the quality (of a class description) * or -1 as described above. */ - public abstract double getAccuracyOrTooWeak(Description description, double noise); + public abstract double getAccuracyOrTooWeak(Description description, double noise); + + /** + * Implementations of learning problems can use this class + * variable to perform reasoner operations. + */ + public AbstractReasonerComponent getReasoner() { + return reasoner; + } + + public void setReasoner(AbstractReasonerComponent reasoner) { + this.reasoner = reasoner; + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -121,6 +121,10 @@ */ protected Set<AbstractKnowledgeSource> sources; + + public AbstractReasonerComponent(){ + + } /** * Constructs a new reasoner component. * @@ -140,6 +144,10 @@ return sources; } + public void setSources(Set<AbstractKnowledgeSource> sources){ + this.sources = sources; + } + /** * Method to exchange the reasoner underlying the learning problem. * Implementations, which do not only use the provided sources class 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 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,19 +20,14 @@ package org.dllearner.kb; import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; -import java.util.Collection; -import java.util.LinkedList; import org.apache.log4j.Logger; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.configurators.KBFileConfigurator; -import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.InvalidConfigOptionValueException; -import org.dllearner.core.options.URLConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.KB; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -55,8 +50,10 @@ private KB kb; - @org.dllearner.core.config.ConfigOption(name = "url", description = "URL pointer to the KB file", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) + @ConfigOption(name = "url", description = "URL pointer to the KB file", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) private String url; + @ConfigOption(name = "baseDir", description = "Base Directory to look for the file in", defaultValue = ".", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String baseDir; /** * Default constructor (needed for reflection in ComponentManager). @@ -83,8 +80,18 @@ @Override public void init() throws ComponentInitException { try { + if (getUrl() != null) { - kb = KBParser.parseKBFile(getUrl()); + String fileString = getUrl(); + if (fileString.startsWith("http:") || fileString.startsWith("file:")) { + /** Leave it as is */ + kb = KBParser.parseKBFile(getUrl()); + } else { + File f = new File(baseDir, getUrl()); + setUrl(f.toURI().toString()); + kb = KBParser.parseKBFile(f); + } + logger.trace("KB File " + getUrl() + " parsed successfully."); } else { throw new ComponentInitException("No URL option or kb object given. Cannot initialise KBFile component."); @@ -92,6 +99,8 @@ } catch (ParseException e) { throw new ComponentInitException("KB file " + getUrl() + " could not be parsed correctly.", e); + }catch (FileNotFoundException e) { + throw new ComponentInitException("KB file " + getUrl() + " could not be found.", e); } } @@ -131,4 +140,12 @@ public void setUrl(String url) { this.url = url; } + + public String getBaseDir() { + return baseDir; + } + + public void setBaseDir(String baseDir) { + this.baseDir = baseDir; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -152,14 +152,14 @@ // useFMeasure = configurator.getAccuracyMethod().equals("fmeasure"); approxDelta = configurator.getApproxAccuracy(); - if(!reasoner.getNamedClasses().contains(classToDescribe)) { + if(!getReasoner().getNamedClasses().contains(classToDescribe)) { throw new ComponentInitException("The class \"" + configurator.getClassToDescribe() + "\" does not exist. Make sure you spelled it correctly."); } - classInstances = new LinkedList<Individual>(reasoner.getIndividuals(classToDescribe)); + classInstances = new LinkedList<Individual>(getReasoner().getIndividuals(classToDescribe)); // sanity check if(classInstances.size() == 0) { - throw new ComponentInitException("Class " + classToDescribe + " has 0 instances according to \"" + ComponentManager.getInstance().getComponentName(reasoner.getClass()) + "\". Cannot perform class learning with 0 instances."); + throw new ComponentInitException("Class " + classToDescribe + " has 0 instances according to \"" + ComponentManager.getInstance().getComponentName(getReasoner().getClass()) + "\". Cannot perform class learning with 0 instances."); } classInstancesSet = new TreeSet<Individual>(classInstances); @@ -174,10 +174,10 @@ // we compute the instances of the super class to perform // optimisations later on - Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); - TreeSet<Individual> superClassInstancesTmp = new TreeSet<Individual>(reasoner.getIndividuals()); + Set<Description> superClasses = getReasoner().getClassHierarchy().getSuperClasses(classToDescribe); + TreeSet<Individual> superClassInstancesTmp = new TreeSet<Individual>(getReasoner().getIndividuals()); for(Description superClass : superClasses) { - superClassInstancesTmp.retainAll(reasoner.getIndividuals(superClass)); + superClassInstancesTmp.retainAll(getReasoner().getIndividuals(superClass)); } // we create one list, which includes instances of the class (an instance of the class is also instance of all super classes) ... classAndSuperClassInstances = new LinkedList<Individual>(superClassInstancesTmp); @@ -194,7 +194,7 @@ Description classToDescribeNeg = new Negation(classToDescribe); negatedClassInstances = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(classToDescribeNeg, ind)) { + if(getReasoner().hasType(classToDescribeNeg, ind)) { negatedClassInstances.add(ind); } } @@ -213,7 +213,7 @@ // overhang Set<Individual> additionalInstances = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances.add(ind); } } @@ -221,7 +221,7 @@ // coverage Set<Individual> coveredInstances = new TreeSet<Individual>(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances.add(ind); } } @@ -292,7 +292,7 @@ int instancesNotCovered = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -309,7 +309,7 @@ for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } testsPerformed++; @@ -346,7 +346,7 @@ int upperEstimateA = classInstances.size(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -416,7 +416,7 @@ for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } @@ -487,7 +487,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -502,7 +502,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().hasType(description, negExample)) { negClassifiedAsNeg++; } nrOfNegChecks++; @@ -537,7 +537,7 @@ // computing R(A) TreeSet<Individual> coveredInstancesSet = new TreeSet<Individual>(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstancesSet.add(ind); } if(terminationTimeExpired()){ @@ -554,7 +554,7 @@ // computing R(C) restricted to relevant instances TreeSet<Individual> additionalInstancesSet = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstancesSet.add(ind); } if(terminationTimeExpired()){ @@ -570,7 +570,7 @@ // computing R(C) restricted to relevant instances int additionalInstances = 0; for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } if(terminationTimeExpired()){ @@ -581,7 +581,7 @@ // computing R(A) int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } if(terminationTimeExpired()){ @@ -635,9 +635,9 @@ Description descriptionNeg = new Negation(description); // loop through all relevant instances for(Individual ind : classAndSuperClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { icPos.add(ind); - } else if(reasoner.hasType(descriptionNeg, ind)) { + } else if(getReasoner().hasType(descriptionNeg, ind)) { icNeg.add(ind); } if(terminationTimeExpired()){ @@ -712,7 +712,7 @@ public double getRecall(Description description) { int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -723,14 +723,14 @@ int additionalInstances = 0; for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } } int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -834,10 +834,10 @@ } else { axiom = new SubClassAxiom(classToDescribe, description); } - return reasoner.remainsSatisfiable(axiom); + return getReasoner().remainsSatisfiable(axiom); } public boolean followsFromKB(Description description) { - return equivalence ? reasoner.isEquivalentClass(description, classToDescribe) : reasoner.isSuperClassOf(description, classToDescribe); + return equivalence ? getReasoner().isEquivalentClass(description, classToDescribe) : getReasoner().isSuperClassOf(description, classToDescribe); } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,6 +20,7 @@ package org.dllearner.learningproblems; import java.util.Map; +import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; @@ -104,7 +105,7 @@ } private SortedSetTuple<Individual> handleMultiConjunction(Intersection mc) { - SortedSet<Individual> pos = cache.get(mc.getChild(0)); + Set<Individual> pos = cache.get(mc.getChild(0)); for(int i=1; i<mc.getChildren().size(); i++) { pos = Helper.intersection(pos, cache.get(mc.getChild(i))); } 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 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,24 +19,16 @@ package org.dllearner.learningproblems; -import java.util.Collection; -import java.util.LinkedList; import java.util.Set; -import java.util.SortedSet; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.CommonConfigMappings; -import org.dllearner.core.options.CommonConfigOptions; -import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.InvalidConfigOptionValueException; -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; +import org.springframework.beans.propertyeditors.StringTrimmerEditor; +import sun.beans.editors.BoolEditor; +import sun.beans.editors.DoubleEditor; /** * @author Jens Lehmann @@ -44,15 +36,19 @@ */ public abstract class PosNegLP extends AbstractLearningProblem { - protected SortedSet<Individual> positiveExamples; - protected SortedSet<Individual> negativeExamples; - protected SortedSet<Individual> allExamples; - - protected boolean useRetrievalForClassification = false; - protected UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - protected double percentPerLengthUnit = 0.05; + protected Set<Individual> positiveExamples; + protected Set<Individual> negativeExamples; + protected Set<Individual> allExamples; - /** + @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; + @org.dllearner.core.config.ConfigOption(name = "useMultiInstanceChecks", description = "Use The Multi Instance Checks", defaultValue = "UseMultiInstanceChecks.TWOCHECKS", required = false, propertyEditorClass = StringTrimmerEditor.class) + private UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + @org.dllearner.core.config.ConfigOption(name = "percentPerLengthUnit", description = "Percent Per Length Unit", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) + private double percentPerLengthUnit = 0.05; + + + /** * If instance checks are used for testing concepts (e.g. no retrieval), then * there are several options to do this. The enumeration lists the supported * options. These options are only important if the reasoning mechanism @@ -77,59 +73,20 @@ */ ONECHECK }; - + + + public PosNegLP(){ + + } + public PosNegLP(AbstractReasonerComponent reasoningService) { super(reasoningService); } - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<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) * - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if (name.equals("positiveExamples")) - positiveExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("negativeExamples")) - negativeExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("useRetrievalForClassficiation")) { - useRetrievalForClassification = (Boolean) entry.getValue(); - } else if (name.equals("percentPerLengthUnit")) - percentPerLengthUnit = (Double) entry.getValue(); - else if (name.equals("useMultiInstanceChecks")) { - String value = (String) entry.getValue(); - if(value.equals("oneCheck")) - useMultiInstanceChecks = UseMultiInstanceChecks.ONECHECK; - else if(value.equals("twoChecks")) - useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - else - useMultiInstanceChecks = UseMultiInstanceChecks.NEVER; - } - } - - /* - * (non-Javadoc) - * * @see org.dllearner.core.Component#init() */ @Override @@ -137,19 +94,19 @@ allExamples = Helper.union(positiveExamples, negativeExamples); } - public SortedSet<Individual> getNegativeExamples() { + public Set<Individual> getNegativeExamples() { return negativeExamples; } - public SortedSet<Individual> getPositiveExamples() { + public Set<Individual> getPositiveExamples() { return positiveExamples; } - public void setNegativeExamples(SortedSet<Individual> set) { + public void setNegativeExamples(Set<Individual> set) { this.negativeExamples=set; } - public void setPositiveExamples(SortedSet<Individual> set) { + public void setPositiveExamples(Set<Individual> set) { this.positiveExamples=set; } @@ -158,5 +115,26 @@ public double getPercentPerLengthUnit() { return percentPerLengthUnit; } - + + public void setPercentPerLengthUnit(double percentPerLengthUnit) { + this.percentPerLengthUnit = percentPerLengthUnit; + } + + public boolean isUseRetrievalForClassification() { + return useRetrievalForClassification; + } + + public void setUseRetrievalForClassification(boolean useRetrievalForClassification) { + this.useRetrievalForClassification = useRetrievalForClassification; + } + + public UseMultiInstanceChecks getUseMultiInstanceChecks() { + return useMultiInstanceChecks; + } + + public void setUseMultiInstanceChecks(UseMultiInstanceChecks useMultiInstanceChecks) { + this.useMultiInstanceChecks = useMultiInstanceChecks; + } + + } 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 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,24 +19,22 @@ 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; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.configurators.PosNegLPStandardConfigurator; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.DoubleConfigOption; -import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.utilities.Helper; +import org.springframework.beans.propertyeditors.StringTrimmerEditor; +import sun.beans.editors.BoolEditor; +import sun.beans.editors.DoubleEditor; /** * The aim of this learning problem is to learn a concept definition such that @@ -51,43 +49,40 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "PosNegLPStandard", shortName = "posNegStandard", version = 0.8) public class PosNegLPStandard extends PosNegLP { - private PosNegLPStandardConfigurator configurator; - + // approximation and F-measure // (taken from class learning => super class instances corresponds to negative examples // and class instances to positive examples) + @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false, propertyEditorClass = BoolEditor.class) private boolean useApproximations; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) + private String accuracyMethod = "predacc"; + // private boolean useFMeasure; private boolean useOldDIGOptions = false; private HeuristicType heuristic = HeuristicType.PRED_ACC; - public PosNegLPStandardConfigurator getConfigurator() { - return configurator; - } - public PosNegLPStandard(AbstractReasonerComponent reasoningService) { - super(reasoningService); - this.configurator = new PosNegLPStandardConfigurator(this); + public PosNegLPStandard() { } public PosNegLPStandard(AbstractReasonerComponent reasoningService, SortedSet<Individual> positiveExamples, SortedSet<Individual> negativeExamples) { - super(reasoningService); + this.setReasoner(reasoningService); this.positiveExamples = positiveExamples; this.negativeExamples = negativeExamples; - this.configurator = new PosNegLPStandardConfigurator(this); } - + @Override public void init() { super.init(); - useApproximations = configurator.getUseApproximations(); - approxDelta = configurator.getApproxAccuracy(); - - String accM = configurator.getAccuracyMethod(); + + String accM = getAccuracyMethod(); if(accM.equals("standard")) { heuristic = HeuristicType.AMEASURE; } else if(accM.equals("fmeasure")) { @@ -121,19 +116,7 @@ public static String getName() { return "pos neg learning problem"; } - - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<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; - } - + /** * This method computes (using the reasoner) whether a concept is too weak. * If it is not weak, it returns the number of covered negative examples. It @@ -150,9 +133,9 @@ @Override public int coveredNegativeExamplesOrTooWeak(Description concept) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + if (isUseRetrievalForClassification()) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // the set is constructed piecewise to avoid expensive set @@ -170,21 +153,21 @@ else return negAsPos.size(); } else { - if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (getUseMultiInstanceChecks() != UseMultiInstanceChecks.NEVER) { // two checks - if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { - Set<Individual> s = reasoner.hasType(concept, positiveExamples); + if (getUseMultiInstanceChecks() == UseMultiInstanceChecks.TWOCHECKS) { + Set<Individual> s = getReasoner().hasType(concept, positiveExamples); // if the concept is too weak, then do not query negative // examples if (s.size() != positiveExamples.size()) return -1; else { - s = reasoner.hasType(concept, negativeExamples); + s = getReasoner().hasType(concept, negativeExamples); return s.size(); } // one check } else { - Set<Individual> s = reasoner.hasType(concept, allExamples); + Set<Individual> s = getReasoner().hasType(concept, allExamples); // test whether all positive examples are covered if (s.containsAll(positiveExamples)) return s.size() - positiveExamples.size(); @@ -196,12 +179,12 @@ SortedSet<Individual> negAsPos = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (!reasoner.hasType(concept, example)) + if (!getReasoner().hasType(concept, example)) return -1; // posAsNeg.add(example); } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); } @@ -229,10 +212,10 @@ @Override public ScorePosNeg computeScore(Description concept) { if(useOldDIGOptions) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + if (isUseRetrievalForClassification()) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // piecewise set construction @@ -245,18 +228,18 @@ if (!posClassified.contains(negExample)) negAsNeg.add(negExample); } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification } else { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + Set<Individual> posAsPos = new TreeSet<Individual>(); + Set<Individual> posAsNeg = new TreeSet<Individual>(); + Set<Individual> negAsPos = new TreeSet<Individual>(); + Set<Individual> negAsNeg = new TreeSet<Individual>(); - if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoner.hasType(concept, - allExamples); - SortedSet<Individual> negClassified = Helper.difference(allExamples, + if (getUseMultiInstanceChecks() != UseMultiInstanceChecks.NEVER) { + SortedSet<Individual> posClassified = getReasoner().hasType(concept, + allExamples); + Set<Individual> negClassified = Helper.difference(allExamples, posClassified); posAsPos = Helper.intersection(positiveExamples, posClassified); posAsNeg = Helper.intersection(positiveExamples, negClassified); @@ -265,24 +248,24 @@ // System.out.println("pos classified: " + posClassified); - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); } else { for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); } } @@ -294,14 +277,14 @@ SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -310,7 +293,7 @@ // TODO: this computes accuracy twice - more elegant method should be implemented double accuracy = getAccuracyOrTooWeakExact(concept,1); - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg, accuracy); } @@ -373,7 +356,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -388,7 +371,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().hasType(description, negExample)) { negClassifiedAsNeg++; } nrOfNegChecks++; @@ -415,7 +398,7 @@ int instancesNotCovered = 0; for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -432,7 +415,7 @@ for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } testsPerformed++; @@ -499,7 +482,7 @@ int notCoveredNeg = 0; for (Individual example : positiveExamples) { - if (!reasoner.hasType(description, example)) { + if (!getReasoner().hasType(description, example)) { notCoveredPos++; if(notCoveredPos >= maxNotCovered) { return -1; @@ -507,7 +490,7 @@ } } for (Individual example : negativeExamples) { - if (!reasoner.hasType(description, example)) { + if (!getReasoner().hasType(description, example)) { notCoveredNeg++; } } @@ -524,14 +507,14 @@ public double getFMeasureOrTooWeakExact(Description description, double noise) { int additionalInstances = 0; for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } } int coveredInstances = 0; for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -566,7 +549,7 @@ int upperEstimateA = positiveExamples.size(); for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -629,7 +612,7 @@ for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } @@ -685,6 +668,29 @@ private double getFMeasure(double recall, double precision) { return 2 * precision * recall / (precision + recall); - } - + } + + public double getApproxDelta() { + return approxDelta; + } + + public void setApproxDelta(double approxDelta) { + this.approxDelta = approxDelta; + } + + public boolean isUseApproximations() { + return useApproximations; + } + + public void setUseApproximations(boolean useApproximations) { + this.useApproximations = useApproximations; + } + + public String getAccuracyMethod() { + return accuracyMethod; + } + + public void setAccuracyMethod(String accuracyMethod) { + this.accuracyMethod = accuracyMethod; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,6 +20,7 @@ package org.dllearner.learningproblems; import java.util.Collection; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -44,7 +45,7 @@ */ public class PosNegLPStrict extends PosNegLP { - private SortedSet<Individual> neutralExamples; + private Set<Individual> neutralExamples; private boolean penaliseNeutralExamples = false; private static final double defaultAccuracyPenalty = 1; @@ -104,7 +105,7 @@ // compute neutral examples, i.e. those which are neither positive // nor negative (we have to take care to copy sets instead of // modifying them) - neutralExamples = Helper.intersection(reasoner.getIndividuals(),positiveExamples); + neutralExamples = Helper.intersection(getReasoner().getIndividuals(),positiveExamples); neutralExamples.retainAll(negativeExamples); } @@ -113,23 +114,23 @@ */ @Override public ScorePosNeg computeScore(Description concept) { - if(useRetrievalForClassification) { - if(reasoner.getReasonerType() == ReasonerType.FAST_RETRIEVAL) { - SortedSetTuple<Individual> tuple = reasoner.doubleRetrieval(concept); + if(isUseRetrievalForClassification()) { + if(getReasoner().getReasonerType() == ReasonerType.FAST_RETRIEVAL) { + SortedSetTuple<Individual> tuple = getReasoner().doubleRetrieval(concept); // this.defPosSet = tuple.getPosSet(); // this.defNegSet = tuple.getNegSet(); - SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoner.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); - } else if(reasoner.getReasonerType() == ReasonerType.KAON2) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> negClassified = reasoner.getIndividuals(new Negation(concept)); - SortedSet<Individual> neutClassified = Helper.intersection(reasoner.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersectionTuple(getReasoner().getIndividuals(),tuple); + return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + } else if(getReasoner().getReasonerType() == ReasonerType.KAON2) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + SortedSet<Individual> negClassified = getReasoner().getIndividuals(new Negation(concept)); + Set<Individual> neutClassified = Helper.intersection(getReasoner().getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } else { - if(reasoner.getReasonerType() == ReasonerType.KAON2) { + if(getReasoner().getReasonerType() == ReasonerType.KAON2) { if(penaliseNeutralExamples) throw new Error("It does not make sense to use single instance checks when" + "neutral examples are penalized. Use Retrievals instead."); @@ -144,28 +145,28 @@ // umstellen // pos => pos for(Individual example : positiveExamples) { - if(reasoner.hasType(concept, example)) + if(getReasoner().hasType(concept, example)) posClassified.add(example); } // neg => pos for(Individual example: negativeExamples) { - if(reasoner.hasType(concept, example)) + if(getReasoner().hasType(concept, example)) posClassified.add(example); } // pos => neg for(Individual example : positiveExamples) { - if(reasoner.hasType(new Negation(concept), example)) + if(getReasoner().hasType(new Negation(concept), example)) negClassified.add(example); } // neg => neg for(Individual example : negativeExamples) { - if(reasoner.hasType(new Negation(concept), example)) + if(getReasoner().hasType(new Negation(concept), example)) negClassified.add(example); } - SortedSet<Individual> neutClassified = Helper.intersection(reasoner.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersection(getReasoner().getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } @@ -179,7 +180,7 @@ throw new UnsupportedOperationException("Method not implemented for three valued definition learning problem."); } - public SortedSet<Individual> getNeutralExamples() { + public Set<Individual> getNeutralExamples() { return neutralExamples; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -116,7 +116,7 @@ // reasoning options (i.e. options are the same up to reversed example sets) // definitionLP.init(); - individuals = new LinkedList<Individual>(reasoner.getIndividuals()); + individuals = new LinkedList<Individual>(getReasoner().getIndividuals()); positiveExamplesShuffled = new LinkedList<Individual>(positiveExamples); Random rand = new Random(1); Collections.shuffle(individuals, rand); @@ -144,7 +144,7 @@ */ @Override public ScorePosOnly computeScore(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); + Set<Individual> retrieval = getReasoner().getIndividuals(description); Set<Individual> instancesCovered = new TreeSet<Individual>(); Set<Individual> instancesNotCovered = new TreeSet<Individual>(); @@ -178,7 +178,7 @@ */ @Override public double getAccuracy(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); + Set<Individual> retrieval = getReasoner().getIndividuals(description); int instancesCovered = 0; for(Individual ind : positiveExamples) { @@ -215,7 +215,7 @@ int upperEstimateA = positiveExamples.size(); for(Individual ind : positiveExamplesShuffled) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -267,7 +267,7 @@ for(Individual ind : individuals) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -21,7 +21,6 @@ import java.text.DecimalFormat; import java.util.Set; -import java.util.SortedSet; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.Helper; @@ -55,12 +54,12 @@ private boolean showCorrectClassifications = false; private static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - private SortedSet<Individual> posClassified; - private SortedSet<Individual> neutClassified; - private SortedSet<Individual> negClassified; - private SortedSet<Individual> posExamples; - private SortedSet<Individual> neutExamples; - private SortedSet<Individual> negExamples; + private Set<Individual> posClassified; + private Set<Individual> neutClassified; + private Set<Individual> negClassified; + private Set<Individual> posExamples; + private Set<Individual> neutExamples; + private Set<Individual> negExamples; private Set<Individual> posAsNeg; private Set<Individual> negAsPos; @@ -86,12 +85,12 @@ double errorPenalty, boolean penaliseNeutralExamples, double percentPerLengthUnit, - SortedSet<Individual> posClassified, - SortedSet<Individual> neutClassified, - SortedSet<Individual> negClassified, - SortedSet<Individual> posExamples, - SortedSet<Individual> neutExamples, - SortedSet<Individual> negExamples) { + Set<Individual> posClassified, + Set<Individual> neutClassified, + Set<Individual> negClassified, + Set<Individual> posExamples, + Set<Individual> neutExamples, + Set<Individual> negExamples) { this.conceptLength = conceptLength; this.accuracyPenalty = accuracyPenalty; this.errorPenalty = errorPenalty; @@ -207,11 +206,11 @@ return str; } - public SortedSet<Individual> getNegClassified() { + public Set<Individual> getNegClassified() { return negClassified; } - public SortedSet<Individual> getPosClassified() { + public Set<Individual> getPosClassified() { return posClassified; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,13 +19,7 @@ package org.dllearner.learningproblems.fuzzydll; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Scanner; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; @@ -41,7 +35,6 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.Heuristics; -import org.dllearner.learningproblems.fuzzydll.FuzzyPosNegLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.learningproblems.Heuristics.HeuristicType; @@ -248,9 +241,9 @@ public ScorePosNeg computeScore(Description concept) { if(useOldDIGOptions) { if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // piecewise set construction @@ -266,13 +259,13 @@ return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification } else { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + Set<Individual> posAsPos = new TreeSet<Individual>(); + Set<Individual> posAsNeg = new TreeSet<Individual>(); + Set<Individual> negAsPos = new TreeSet<Individual>(); + Set<Individual> negAsNeg = new TreeSet<Individual>(); if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoner.hasType(concept, allExamples); + SortedSet<Individual> posClassified = getReasoner().hasType(concept, allExamples); SortedSet<Individual> negClassified = Helper.difference(allExamples, posClassified); posAsPos = Helper.intersection(positiveExamples, posClassified); posAsNeg = Helper.intersection(positiveExamples, negClassified); @@ -286,14 +279,14 @@ } else { for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -310,14 +303,14 @@ SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -388,7 +381,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -403,7 +396,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().has... [truncated message content] |