001 /**
002 * Copyright (C) 2007-2008, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 *
019 */
020 package org.dllearner.test.junit;
021
022 import static org.junit.Assert.assertTrue;
023
024 import java.io.File;
025 import java.net.MalformedURLException;
026 import java.util.Set;
027
028 import org.dllearner.core.ComponentInitException;
029 import org.dllearner.core.ComponentManager;
030 import org.dllearner.core.KnowledgeSource;
031 import org.dllearner.core.ReasonerComponent;
032 import org.dllearner.core.owl.Description;
033 import org.dllearner.kb.OWLFile;
034 import org.dllearner.parser.KBParser;
035 import org.dllearner.parser.ParseException;
036 import org.dllearner.reasoning.OWLAPIReasoner;
037 import org.dllearner.refinementoperators.RhoDRDown;
038 import org.dllearner.test.junit.TestOntologies.TestOntology;
039 import org.junit.Test;
040
041 /**
042 * A suite of JUnit tests related to refinement operators.
043 *
044 * @author Jens Lehmann
045 *
046 */
047 public class RefinementOperatorTests {
048
049 private String baseURI;
050
051 /**
052 * Applies the RhoDRDown operator to a concept and checks that the number of
053 * refinements is correct.
054 *
055 */
056 @Test
057 public void rhoDRDownTest() {
058 try {
059 String file = "examples/carcinogenesis/carcinogenesis.owl";
060 ComponentManager cm = ComponentManager.getInstance();
061 KnowledgeSource ks = cm.knowledgeSource(OWLFile.class);
062 try {
063 cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL());
064 } catch (MalformedURLException e) {
065 // should never happen
066 e.printStackTrace();
067 }
068 ks.init();
069 ReasonerComponent rc = cm.reasoner(OWLAPIReasoner.class, ks);
070 rc.init();
071 baseURI = rc.getBaseURI();
072 // ReasonerComponent rs = cm.reasoningService(rc);
073
074 // TODO the following two lines should not be necessary
075 // rs.prepareSubsumptionHierarchy();
076 // rs.prepareRoleHierarchy();
077
078 RhoDRDown op = new RhoDRDown(rc);
079 Description concept = KBParser.parseConcept(uri("Compound"));
080 Set<Description> results = op.refine(concept, 4, null);
081
082 for(Description result : results) {
083 System.out.println(result);
084 }
085
086 int desiredResultSize = 141;
087 if(results.size() != desiredResultSize) {
088 System.out.println(results.size() + " results found, but should be " + desiredResultSize + ".");
089 }
090 assertTrue(results.size()==desiredResultSize);
091 } catch(ComponentInitException e) {
092 e.printStackTrace();
093 } catch (ParseException e) {
094 e.printStackTrace();
095 }
096 }
097
098 @Test
099 public void rhoDRDownTest2() throws ParseException {
100 ReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.EPC_OE);
101 baseURI = reasoner.getBaseURI();
102
103 RhoDRDown op = new RhoDRDown(reasoner);
104 Description concept = KBParser.parseConcept("(\"http://localhost/aris/sap_model.owl#EPC\" AND EXISTS \"http://localhost/aris/sap_model.owl#hasModelElements\".\"http://localhost/aris/sap_model.owl#Object\")");
105 Set<Description> results = op.refine(concept, 6);
106
107 for(Description result : results) {
108 System.out.println(result);
109 }
110
111 int desiredResultSize = 141;
112 if(results.size() != desiredResultSize) {
113 System.out.println(results.size() + " results found, but should be " + desiredResultSize + ".");
114 }
115 assertTrue(results.size()==desiredResultSize);
116 }
117
118 private String uri(String name) {
119 return "\""+baseURI+name+"\"";
120 }
121 }