From: <Jen...@us...> - 2008-10-24 05:25:08
|
Revision: 1420 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1420&view=rev Author: JensLehmann Date: 2008-10-24 05:25:02 +0000 (Fri, 24 Oct 2008) Log Message: ----------- added more EL tests; fixed some bugs Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.NavigableSet; @@ -225,24 +226,24 @@ protected void updateSimulation(Set<ELDescriptionNode> nUpdate) { // create a stack and initialize it with the nodes to be updated - Stack<ELDescriptionNode> stack = new Stack<ELDescriptionNode>(); - stack.addAll(nUpdate); + LinkedList<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>(); + list.addAll(nUpdate); - while(stack.size() != 0) { + while(list.size() != 0) { // take element from bottom of stack (to ensure that all nodes on the // same level are tested before any node of a lower level is tested) - ELDescriptionNode v = stack.peek(); // TODO: lookup whether peek is correct (had no Javadoc here) + ELDescriptionNode v = list.pollFirst(); // loop through all nodes on same level for(ELDescriptionNode w : levelNodeMapping.get(v.getLevel())) { if(!v.out.contains(w) && v.outSC1.contains(w) && checkSC2(v,w)) { extendSimulation(v,w); - stack.add(v.getParent()); - stack.add(w.getParent()); + list.add(v.getParent()); + list.add(w.getParent()); } if(!w.out.contains(v) && w.outSC1.contains(v) && checkSC2(w,v)) { extendSimulation(w,v); - stack.add(v.getParent()); - stack.add(w.getParent()); + list.add(v.getParent()); + list.add(w.getParent()); } } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -28,11 +28,14 @@ import org.dllearner.algorithms.el.ELDescriptionTreeComparator; import org.dllearner.algorithms.el.Simulation; import org.dllearner.algorithms.el.TreeTuple; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; +import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; @@ -47,10 +50,10 @@ @Test public void simulationTest() { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); Simulation s = new Simulation(); - // TODO we need to add background knowledge (possibly empty) - ELDescriptionTree tree1 = null; // new ELDescriptionTree(); - ELDescriptionTree tree2 = null; // new ELDescriptionTree(); + ELDescriptionTree tree1 = new ELDescriptionTree(rs); + ELDescriptionTree tree2 = new ELDescriptionTree(rs); ELDescriptionNode t1 = new ELDescriptionNode(tree1); ELDescriptionNode t2 = new ELDescriptionNode(tree2); TreeTuple tuple1 = new TreeTuple(t1,t2); @@ -65,11 +68,21 @@ } @Test + public void minimalityTest() throws ParseException, ComponentInitException { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.SIMPLE); + // the following should be recognized as non-minimal + Description d = KBParser.parseConcept("(human AND (EXISTS has.animal AND EXISTS has.TOP))"); + ConceptTransformation.cleanConcept(d); + ELDescriptionTree tree = new ELDescriptionTree(rs, d); + assertFalse(tree.isMinimal()); + } + + @Test public void cloneTest() throws ParseException { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); Description d = KBParser.parseConcept("(male AND (human AND EXISTS hasChild.(female AND EXISTS hasChild.male)))"); ConceptTransformation.cleanConcept(d); - // TODO needs to be updated (trees now require background knowledge) - ELDescriptionTree tree = null; // new ELDescriptionTree(rs, d); + ELDescriptionTree tree = new ELDescriptionTree(rs, d); ELDescriptionTree treeCloned = tree.clone(); ELDescriptionTreeComparator comparator = new ELDescriptionTreeComparator(); assertTrue(comparator.compare(tree, treeCloned) == 0); Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -24,23 +24,17 @@ import java.util.TreeSet; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.KB; -import org.dllearner.kb.KBFile; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.ELDown; +import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; -import static org.junit.Assert.*; - /** * Tests related to the EL downward refinement operator. * @@ -59,36 +53,12 @@ */ @Test public void refinementTest() throws ParseException, ComponentInitException { - ComponentManager cm = ComponentManager.getInstance(); + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.SIMPLE); - // background knowledge - String kbString = ""; - kbString += "OPDOMAIN(hasChild) = human.\n"; - kbString += "OPRANGE(hasChild) = human.\n"; - kbString += "OPDOMAIN(hasPet) = human.\n"; - kbString += "OPRANGE(hasPet) = animal.\n"; - kbString += "Subrole(hasChild, has).\n"; - kbString += "Subrole(hasPet, has).\n"; - kbString += "bird SUB animal.\n"; - kbString += "cat SUB animal.\n"; - kbString += "(human AND animal) = BOTTOM.\n"; - KB kb = KBParser.parseKBFile(kbString); - // input description Description input = KBParser.parseConcept("(human AND EXISTS has.animal)"); - System.out.println("refining: " + input); + System.out.println("refining: " + input); - // create reasoner - KBFile source = new KBFile(kb); - ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source); - ReasoningService rs = cm.reasoningService(rc); - source.init(); - rc.init(); - // TODO there shouldn't be a need to call this explicitly! - // (otherwise we get a NullPointerException, because the hierarchy is not created) - rs.prepareSubsumptionHierarchy(); - rs.prepareRoleHierarchy(); - // TODO For this test, we need to turn instance based disjoints // off! (We do not have any instances here.) ELDown operator = new ELDown(rs); @@ -129,9 +99,18 @@ // refinement must be in the set of desired refinements // assertTrue(refinements.size() == desired.size()); for(Description refinement : refinements) { - System.out.println(refinement); + boolean ok = desired.contains(refinement); + System.out.println(ok + ": " + refinement); // assertTrue(desired.contains(refinement)); } + + // generated by operator (and currently corresponding to its definition): + // false (http://localhost/foo#human AND EXISTS http://localhost/foo#has.(http://localhost/foo#animal AND http://localhost/foo#human + // false (http://localhost/foo#animal AND http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal + // solution: element of ncc should be tested for disjointness with any other candidate (here: animal and human) + + // edge added, but refinement not recognized as being minimal + // (http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal AND EXISTS http://localhost/foo#has.TOP) } } Added: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -0,0 +1,84 @@ +/** + * 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.test.junit; + +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.KB; +import org.dllearner.kb.KBFile; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.FastInstanceChecker; + +/** + * Some ontologies to simplify unit tests. + * + * @author Jens Lehmann + * + */ +public final class TestOntologies { + + public enum TestOntology { EMPTY, SIMPLE }; + + public static ReasoningService getTestOntology(TestOntology ont) { + String kbString = ""; + + if(ont.equals(TestOntology.EMPTY)) { + // no background knowledge + } else if(ont.equals(TestOntology.SIMPLE)) { + // background knowledge used in EL paper + kbString += "OPDOMAIN(hasChild) = human.\n"; + kbString += "OPRANGE(hasChild) = human.\n"; + kbString += "OPDOMAIN(hasPet) = human.\n"; + kbString += "OPRANGE(hasPet) = animal.\n"; + kbString += "Subrole(hasChild, has).\n"; + kbString += "Subrole(hasPet, has).\n"; + kbString += "bird SUB animal.\n"; + kbString += "cat SUB animal.\n"; + kbString += "(human AND animal) = BOTTOM.\n"; + } + + try { + KB kb = KBParser.parseKBFile(kbString); + + // create reasoner + ComponentManager cm = ComponentManager.getInstance(); + KBFile source = new KBFile(kb); + ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source); + ReasoningService rs = cm.reasoningService(rc); + source.init(); + rc.init(); + // TODO there shouldn't be a need to call this explicitly! + // (otherwise we get a NullPointerException, because the hierarchy is not created) + rs.prepareSubsumptionHierarchy(); + rs.prepareRoleHierarchy(); + return rs; + } catch(ParseException e) { + e.printStackTrace(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + + throw new Error("Test ontology could not be created."); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |