From: <jen...@us...> - 2010-02-10 09:27:36
|
Revision: 2000 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2000&view=rev Author: jenslehmann Date: 2010-02-10 09:27:28 +0000 (Wed, 10 Feb 2010) Log Message: ----------- - implemented refinement operator inverter (turns downward refinement operator into upward refinement operator and vice versa) - rho DR operator can be set to drop disjuncts - jUnit test case for the above features Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/Description.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/refinementoperators/OperatorInverter.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/Description.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2010-02-09 15:51:12 UTC (rev 1999) +++ trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2010-02-10 09:27:28 UTC (rev 2000) @@ -164,6 +164,11 @@ children.remove(child); } + public void removeChild(int index) { + children.get(index).setParent(null); + children.remove(index); + } + public void replaceChild(int index, Description newChild) { children.remove(index); children.add(index, newChild); Added: trunk/src/dl-learner/org/dllearner/refinementoperators/OperatorInverter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/OperatorInverter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/OperatorInverter.java 2010-02-10 09:27:28 UTC (rev 2000) @@ -0,0 +1,93 @@ +/** + * 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.refinementoperators; + +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Negation; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; + +/** + * The class uses an existing refinement operator and inverts it, i.e. a + * downward refinement operator is turned into an upward refinement operator + * and vice versa. + * + * @author Jens Lehmann + * + */ +public class OperatorInverter implements RefinementOperator { + + private RefinementOperator operator; + private ConceptComparator cc = new ConceptComparator(); + private boolean useNegationNormalForm = true; + private boolean guaranteeLength = true; + + public OperatorInverter(RefinementOperator operator) { + this.operator = operator; + } + + @Override + public Set<Description> refine(Description description) { + Set<Description> refinements = operator.refine(getNegation(description)); + TreeSet<Description> results = new TreeSet<Description>(cc); + for(Description d : refinements) { + results.add(getNegation(d)); + } + return results; + } + + @Override + public Set<Description> refine(Description description, int maxLength) { + Description negatedDescription = getNegation(description); + // concept length can change because of the conversion process; as a heuristic + // we increase maxLength by the length difference of negated and original concept + int lengthDiff = Math.max(0, negatedDescription.getLength() - description.getLength()); + Set<Description> refinements = operator.refine(negatedDescription, maxLength+lengthDiff); + TreeSet<Description> results = new TreeSet<Description>(cc); + for(Description d : refinements) { + Description dNeg = getNegation(d); + // to satisfy the guarantee that the method does not return longer + // concepts, we perform an additional check + if(!guaranteeLength || dNeg.getLength() <= maxLength) { + results.add(dNeg); + } + } + return results; + } + + @Override + public Set<Description> refine(Description description, int maxLength, + List<Description> knownRefinements) { + throw new Error("Method not implemented."); + } + + private Description getNegation(Description description) { + Description negatedDescription = new Negation(description); + if(useNegationNormalForm) { + negatedDescription = ConceptTransformation.transformToNegationNormalForm(negatedDescription); + } + return negatedDescription; + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2010-02-09 15:51:12 UTC (rev 1999) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2010-02-10 09:27:28 UTC (rev 2000) @@ -184,6 +184,8 @@ private boolean disjointChecks = true; private boolean instanceBasedDisjoints = true; + private boolean dropDisjuncts = false; + // caches for reasoner queries private Map<Description,Map<Description,Boolean>> cachedDisjoints = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator); @@ -513,6 +515,23 @@ } + // if enabled, we can remove elements of the disjunction + if(dropDisjuncts) { + // A1 OR A2 => {A1,A2} + if(description.getChildren().size() == 2) { + refinements.add(description.getChild(0)); + refinements.add(description.getChild(1)); + } else { + // copy children list and remove a different element in each turn + for(int i=0; i<description.getChildren().size(); i++) { + List<Description> newChildren = new LinkedList<Description>(description.getChildren()); + newChildren.remove(i); + Union md = new Union(newChildren); + refinements.add(md); + } + } + } + } else if (description instanceof ObjectSomeRestriction) { ObjectPropertyExpression role = ((ObjectQuantorRestriction)description).getRole(); Description range = opRanges.get(role); @@ -788,6 +807,17 @@ return true; } + /** + * By default, the operator does not specialize e.g. (A or B) to A, because + * it only guarantees weak completeness. Under certain circumstances, e.g. + * refinement of a fixed given concept, it can be useful to allow such + * refinements, which can be done by passing the parameter true to this method. + * @param dropDisjuncts Whether to remove disjuncts in refinement process. + */ + public void setDropDisjuncts(boolean dropDisjuncts) { + this.dropDisjuncts = dropDisjuncts; + } + private void computeTopRefinements(int maxLength) { computeTopRefinements(maxLength, null); } Modified: trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2010-02-09 15:51:12 UTC (rev 1999) +++ trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2010-02-10 09:27:28 UTC (rev 2000) @@ -42,7 +42,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.OWLAPIReasoner; -import org.dllearner.refinementoperators.ELDown2; +import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.test.junit.TestOntologies.TestOntology; @@ -188,6 +188,21 @@ } } + @Test + public void invertedOperatorTest() throws ParseException { + ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.RHO1); + RhoDRDown rho = new RhoDRDown(rs); + rho.setDropDisjuncts(true); + RefinementOperator operator = new OperatorInverter(rho); + Description concept = KBParser.parseConcept("(limo AND EXISTS hasOwner.man)"); + Set<Description> refinements = operator.refine(concept, 6); + for(Description refinement : refinements) { + System.out.println(refinement); + } + // we should get four upward refinements + // (replacing limo => car, man => person, or drop one of the intersects) + assertTrue(refinements.size()==4); + } private String uri(String name) { return "\""+baseURI+name+"\""; Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2010-02-09 15:51:12 UTC (rev 1999) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2010-02-10 09:27:28 UTC (rev 2000) @@ -31,7 +31,6 @@ import org.dllearner.kb.OWLFile; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.OWLAPIReasoner; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |