From: <jen...@us...> - 2010-09-21 12:02:28
|
Revision: 2321 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2321&view=rev Author: jenslehmann Date: 2010-09-21 12:02:21 +0000 (Tue, 21 Sep 2010) Log Message: ----------- moved tests from Maven main to test Modified Paths: -------------- trunk/scripts/pom.xml Added Paths: ----------- trunk/components-core/src/test/java/org/dllearner/test/ Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/test/ trunk/components-core/src/test/java/org/dllearner/junit/ trunk/components-core/src/test/java/org/dllearner/test/junit/ExampleTests.java trunk/components-core/src/test/java/org/dllearner/test/junit/OWLlinkTest.java trunk/components-core/src/test/java/org/dllearner/test/junit/ReasonerTests.java Deleted: trunk/components-core/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/test/junit/ExampleTests.java 2010-09-17 19:15:29 UTC (rev 2317) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ExampleTests.java 2010-09-21 12:02:21 UTC (rev 2321) @@ -1,200 +0,0 @@ -/** - * 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 java.io.File; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.TreeSet; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.cli.QuickStart; -import org.dllearner.cli.Start; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.utilities.Helper; -import org.junit.Test; - -/** - * Tests related to learning problems in the examples directory. - * - * @author Jens Lehmann - * - */ -public class ExampleTests { - - /** - * This test runs all conf files in the examples directory. Each conf file - * corresponds to one unit test, which is succesful if a concept was - * learned. This unit test takes several hours. - * - * @throws ComponentInitException - * If any component initialisation exception occurs in the - * process. - */ - @Test - public void testAllConfFiles() throws ComponentInitException { - - // if true, then examples are executed in random order (avoids the problem - // that the same examples are tested first on several runs); otherwise - // it runs the examples in alphabetical order - boolean randomize = true; - - // GPs can be excluded temporarily (because those tests are very time-consuming) - boolean testGP = false; - - // setting for SPARQL based tests (0 = no special treatment, 1 = test only SPARQL - // examples, 2 = skip SPARQL tests) - int sparql = 0; - - // we use a logger, which outputs few messages (warnings, errors) - SimpleLayout layout = new SimpleLayout(); - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - Logger logger = Logger.getRootLogger(); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.setLevel(Level.WARN); - - // map containing a list of conf files for each path - HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>(); - String exampleDir = "." + File.separator + "examples"; - File f = new File(exampleDir); - QuickStart.getAllConfs(f, exampleDir, confFiles); - - // put all examples in a flat list - List<String> examples = new LinkedList<String>(); - for(Map.Entry<String,ArrayList<String>> entry : confFiles.entrySet()) { - for(String file : entry.getValue()) { - examples.add(entry.getKey() + file + ".conf"); - } - } - - if(randomize) { - Collections.shuffle(examples, new Random()); - } else { - Collections.sort(examples); - } - - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); - - // ignore list (examples which are temporarily not working due - // to server downtime, lack of features etc., but should still - // remain in the example directory - Set<String> ignore = new TreeSet<String>(); - - // "standard" ignores (no problem to keep those) - ignore.add("./examples/krk/complete_no_draw.conf"); // refers to an OWL file, which has to be auto-generated - ignore.add("./examples/krk/test_ZERO_against_1to16.conf"); // see above - ignore.add("./examples/semantic_bible/sparqlbible.conf"); // requires local Joseki - - // temporarily not working (have a look at those before next release) - // ignore.add("./examples/family/father_posonly.conf"); // ArrayOutOfBoundsException in Pellet - main problem: pos only not working/supported - - // ignored due to errors (should be fixed; in case of long running problems or - // our of memory, it is better to increase the noise parameter and add comments - // in the conf file about "optimal" parameters) - ignore.add("./examples/sparql/govtrack.conf"); // blank node handling error - ignore.add("./examples/sparql/difference/DBPediaSKOS_kohl_vs_angela.conf"); // XML parse error (works sometimes) - - //working fine here ignore.add("./examples/sparql/SKOSTEST_local.conf"); // Out of Memory Error - // ignore.add("./examples/sparql/scrobble.conf"); // HTTP 502 Proxy Error - // ignore.add("./examples/family-benchmark/Cousin.conf"); // Out of Memory Error => disallowing ALL helps (TODO find out details) - //also working fine ignore.add("./examples/sparql/SilentBobWorking2.conf"); // Out of Memory Error - // ignore.add("./examples/sparql/difference/DBPediaSKOS_kohl_vs_angela.conf"); // Pellet: literal cannot be cast to individual - // ignore.add("./examples/family-benchmark/Aunt.conf"); // did not terminate so far (waited 45 minutes) => disallowing ALL helps (TODO find out details) -// ignore.add("examples/krk/KRK_ZERO_against_1to5_fastInstance.conf"); // stack overflow -// ignore.add("examples/krk/KRK_ONE_ZERO_fastInstance.conf"); // stack overflow -// ignore.add("examples/krk/"); // too many stack overflows - - int failedCounter = 0; - int counter = 1; - int total = examples.size(); - for(String conf : examples) { - boolean ignored = false; - for(String ignoredConfExpression : ignore) { - if(conf.contains(ignoredConfExpression)) { - ignored = true; - break; - } - } - if(ignored) { - System.out.println("Skipping " + conf + " (is on ignore list)."); - } else { - System.out.println("Testing " + conf + " (example " + counter + " of " + total + ", time: " + sdf.format(new Date()) + ")."); - long startTime = System.nanoTime(); - boolean success = false, started = false; - try { - // start example - Start start = new Start(new File(conf)); -// System.out.println("algorithm: " + start.getLearningAlgorithm()); - boolean isSparql = start.getSources().iterator().next() instanceof SparqlKnowledgeSource; - if((testGP || !(start.getLearningAlgorithm() instanceof GP)) && - (sparql == 0 || (sparql == 1 && isSparql) || (sparql == 2 && !isSparql) ) ) { - started = true; - start.start(false); - // test is successful if a concept was learned - assert (start.getLearningAlgorithm().getCurrentlyBestDescription() != null); - start.getReasonerComponent().releaseKB(); - success = true; - } else { - System.out.println("Test skipped, because of GP or SPARQL settings."); - } - } catch (Exception e) { - // unit test not succesful (exceptions are caught explicitly to find - assert ( false ); - e.printStackTrace(); - failedCounter++; - } - long timeNeeded = System.nanoTime() - startTime; - ComponentManager.getInstance().freeAllComponents(); - if(!success && started) { - System.out.println("TEST FAILED."); - } - if(started) { - System.out.println("Test of " + conf + " completed in " + Helper.prettyPrintNanoSeconds(timeNeeded) + "."); - } - } - counter++; - } - -// for (String path : confFiles.keySet()) { -// for (String file : confFiles.get(path)) { -// String conf = path + file + ".conf"; -// -// } -// } - System.out.println("Finished. " + failedCounter + " tests failed."); - - } - -} Deleted: trunk/components-core/src/test/java/org/dllearner/test/junit/OWLlinkTest.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/test/junit/OWLlinkTest.java 2010-09-17 19:15:29 UTC (rev 2317) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/OWLlinkTest.java 2010-09-21 12:02:21 UTC (rev 2321) @@ -1,85 +0,0 @@ -package org.dllearner.test.junit; - -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import org.dllearner.algorithms.gp.GP; -import org.dllearner.cli.QuickStart; -import org.dllearner.cli.Start; -import org.dllearner.core.ReasonerComponent; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.reasoning.OWLAPIReasoner; -import org.junit.Test; - -public class OWLlinkTest { - - private static final int EXAMPLE_COUNT = 5; - private static final boolean RANDOMIZE = true; - private static final String OWL_LINK_URL = "http://localhost:8080/"; - - @Test - public void testOWLlink(){ - try { - // map containing a list of conf files for each path - HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>(); - String exampleDir = "." + File.separator + "examples"; - File f = new File(exampleDir); - QuickStart.getAllConfs(f, exampleDir, confFiles); - - // put all examples in a flat list - List<String> examples = new LinkedList<String>(); - for(Map.Entry<String,ArrayList<String>> entry : confFiles.entrySet()) { - for(String file : entry.getValue()) { - examples.add(entry.getKey() + file + ".conf"); - } - } - - if(RANDOMIZE) { - Collections.shuffle(examples, new Random()); - } else { - Collections.sort(examples); - } - - int cnt = 0; - Start start; - ReasonerComponent rc; - for(String conf : examples) { - if(cnt == EXAMPLE_COUNT){ - break; - } - start = new Start(new File(conf)); - if(start.getLearningAlgorithm() instanceof GP || start.getSources().iterator().next() instanceof SparqlKnowledgeSource){ - continue; - } - rc = start.getReasonerComponent(); - if(rc instanceof OWLAPIReasoner){ - ((OWLAPIReasoner)rc).getConfigurator().setReasonerType("owllink"); - ((OWLAPIReasoner)rc).getConfigurator().setOwlLinkURL(new URL(OWL_LINK_URL)); - } else if(rc instanceof FastInstanceChecker){ - ((FastInstanceChecker)rc).getConfigurator().setReasonerType("owllink"); - ((FastInstanceChecker)rc).getConfigurator().setOwlLinkURL(new URL(OWL_LINK_URL)); - } else { - continue; - } - System.out.println("Testing " + conf); - rc.init(); - start.getLearningAlgorithm().start(); - cnt++; - } - } catch (Exception e) { - e.printStackTrace(); - assert ( false ); - } - - - } - -} Deleted: trunk/components-core/src/test/java/org/dllearner/test/junit/ReasonerTests.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/test/junit/ReasonerTests.java 2010-09-17 19:15:29 UTC (rev 2317) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ReasonerTests.java 2010-09-21 12:02:21 UTC (rev 2321) @@ -1,448 +0,0 @@ -/** - * 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 static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileNotFoundException; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.dllearner.cli.Start; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.EquivalentClassesAxiom; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.KB; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.Thing; -import org.dllearner.kb.KBFile; -import org.dllearner.kb.OWLFile; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.reasoning.OWLAPIReasoner; -import org.dllearner.reasoning.PelletReasoner; -import org.dllearner.reasoning.ProtegeReasoner; -import org.dllearner.test.junit.TestOntologies.TestOntology; -import org.dllearner.utilities.owl.ConceptComparator; -import org.junit.Test; - -/** - * A suite of JUnit tests related to the DL-Learner reasoning. - * - * @author Jens Lehmann - * - */ -public class ReasonerTests { - - private static Logger logger = Logger.getLogger(ReasonerTests.class); - - private String baseURI; - - private ConceptComparator comparator = new ConceptComparator(); - - public KB getSimpleKnowledgeBase() { - String kb = "person SUB TOP."; - kb += "man SUB person."; - kb += "man SUB male."; - kb += "woman SUB person."; - kb += "woman SUB female."; - kb += "(male AND female) = BOTTOM."; - kb += "man(stephen)."; - kb += "woman(maria)."; - kb += "hasChild(stephen,maria)."; - KB kbObject = null; - try { - kbObject = KBParser.parseKBFile(kb); - } catch (ParseException e) { - e.printStackTrace(); - } - return kbObject; - } - - /** - * Performs an instance checks on all reasoner components to verify that - * they all return the correct result. - */ - @Test - public void instanceCheckTest() { - - // DIG can be excluded from test since it requires a separate DIG reasoner and is no - // longer the default reasoning mechanism - boolean excludeDIG = true; - - try { - ComponentManager cm = ComponentManager.getInstance(); - KB kb = getSimpleKnowledgeBase(); - KnowledgeSource ks = new KBFile(kb); - ks.init(); - Description d; - // d = KBParser.parseConcept("man"); - d = KBParser.parseConcept("(person AND EXISTS hasChild.female)"); - Individual i = new Individual(KBParser.getInternalURI("stephen")); - List<Class<? extends ReasonerComponent>> reasonerClasses = cm.getReasonerComponents(); - for (Class<? extends ReasonerComponent> reasonerClass : reasonerClasses) { - //we skip the ProtegeReasoner, because the underlying OWLReasoner is not available in this test - if(reasonerClass.equals(ProtegeReasoner.class)){ - continue; - } - if(excludeDIG && reasonerClass.equals(DIGReasoner.class)) { - continue; - } - ReasonerComponent reasoner = cm.reasoner(reasonerClass, ks); - reasoner.init(); - //if it is the PelletReasoner we have to call a separate method to make the CWA - if(reasonerClass.equals(PelletReasoner.class)){ - ((PelletReasoner)reasoner).dematerialise(); - } -// long startTime = System.nanoTime(); - boolean result = false; -// for(int n=0; n<10000; n++) { - result = reasoner.hasType(d, i); -// } -// long time = System.nanoTime() - startTime; - logger.debug("instance check: " + reasoner + " " + d + " " + i + " " + result); - assertTrue(result); - } - } catch (ParseException e) { - e.printStackTrace(); -// } catch (ReasoningMethodUnsupportedException e) { -// e.printStackTrace(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } - } - - /** - * Test of fast instance check algorithm on carcinogenesis data set. - * @throws ComponentInitException - * @throws ParseException - */ - @Test - public void fastInstanceCheckTest() throws ComponentInitException, ParseException { - String file = "examples/carcinogenesis/carcinogenesis.owl"; - ComponentManager cm = ComponentManager.getInstance(); - KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); - try { - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - } catch (MalformedURLException e) { - // should never happen - e.printStackTrace(); - } - ks.init(); - ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks); - reasoner.init(); - baseURI = reasoner.getBaseURI(); - - List<Description> testDescriptions = new LinkedList<Description>(); - List<List<Individual>> posIndividuals = new LinkedList<List<Individual>>(); - List<List<Individual>> negIndividuals = new LinkedList<List<Individual>>(); - - // TODO manually verify that the results are indeed correct - testDescriptions.add(KBParser.parseConcept("(\"http://dl-learner.org/carcinogenesis#Compound\" AND ((\"http://dl-learner.org/carcinogenesis#amesTestPositive\" IS TRUE) OR >= 2 \"http://dl-learner.org/carcinogenesis#hasStructure\".\"http://dl-learner.org/carcinogenesis#Ar_halide\"))")); - posIndividuals.add(getIndSet("d113","d133","d171","d262","d265","d294","d68","d77","d79")); - negIndividuals.add(getIndSet("d139","d199","d202","d203","d283","d42")); - - // TODO add more descriptions and instances - - // make the specified assertions - for(int i=0; i<testDescriptions.size(); i++) { - Description description = testDescriptions.get(i); - List<Individual> pos = posIndividuals.get(i); - List<Individual> neg = negIndividuals.get(i); - - for(Individual ind : pos) { - System.out.println("description: " + description.toString(baseURI, null) + " individual: " + ind.toString(baseURI, null)); - assertTrue(reasoner.hasType(description, ind)); - } - - for(Individual ind : neg) { - System.out.println("description: " + description.toString(baseURI, null) + " individual: " + ind.toString(baseURI, null)); - assertTrue(!reasoner.hasType(description, ind)); - } - } - } - - @Test - public void fastInstanceCheck2() throws ComponentInitException, ParseException { - String file = "examples/epc/sap_epc.owl"; - ComponentManager cm = ComponentManager.getInstance(); - KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); - try { - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - } catch (MalformedURLException e) { - // should never happen - e.printStackTrace(); - } - ks.init(); - ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks); - reasoner.init(); - baseURI = reasoner.getBaseURI(); - - Description description = KBParser.parseConcept("(\"http://localhost/aris/sap_model.owl#EPC\" AND EXISTS \"http://localhost/aris/sap_model.owl#hasModelElements\".(\"http://localhost/aris/sap_model.owl#Event\" AND >= 2 \"http://localhost/aris/sap_model.owl#previousObjects\".TOP))"); - Individual ind = new Individual("http://localhost/aris/sap_model.owl#e4j0__6_____u__"); - boolean result = reasoner.hasType(description, ind); - System.out.println(result); - } - - // simple unit test for new retrieval algorithm - @Test - public void fastInstanceCheck3() throws MalformedURLException, ComponentInitException, ParseException { - String file = "examples/family/father_oe.owl"; - ComponentManager cm = ComponentManager.getInstance(); - KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - ks.init(); - ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks); - reasoner.init(); - baseURI = reasoner.getBaseURI(); - Description description = KBParser.parseConcept("(\"http://example.com/father#male\" AND EXISTS \"http://example.com/father#hasChild\".TOP)"); -// Description description = KBParser.parseConcept("EXISTS \"http://example.com/father#hasChild\".TOP"); - SortedSet<Individual> result = reasoner.getIndividuals(description); - assertTrue(result.size()==3); - assertTrue(result.contains(new Individual("http://example.com/father#markus"))); - assertTrue(result.contains(new Individual("http://example.com/father#martin"))); - assertTrue(result.contains(new Individual("http://example.com/father#stefan"))); -// System.out.println(result); - - Description description2 = KBParser.parseConcept("(\"http://example.com/father#male\" AND ALL \"http://example.com/father#hasChild\".\"http://example.com/father#father\")"); - SortedSet<Individual> result2 = reasoner.getIndividuals(description2); - assertTrue(result2.size()==2); - assertTrue(result2.contains(new Individual("http://example.com/father#heinz"))); - assertTrue(result2.contains(new Individual("http://example.com/father#stefan"))); - } - - @Test - public void domainTest() throws MalformedURLException, ComponentInitException, ParseException { - - ComponentManager cm = ComponentManager.getInstance(); - - String kb = "person SUB animal."; - kb += "man SUB (person AND male)."; - kb += "woman SUB (person AND female)."; - kb += "OPDOMAIN(hasChild) = (man AND woman)."; - kb += "male = male2."; - - - KB kbf = KBParser.parseKBFile(kb); - KnowledgeSource ks = new KBFile(kbf); - ks.init(); - ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner.init(); - ObjectProperty property = new ObjectProperty(KBParser.getInternalURI("hasChild")); - Description description = KBParser.parseConcept("man"); - assertTrue(reasoner.getDomain(property).equals(description)); - -// reasoner.releaseKB(); -// ks = new KBFile(getSimpleKnowledgeBase()); -// ks.init(); -// reasoner = cm.reasoner(OWLAPIReasoner.class,ks); -// reasoner.init(); -// property = new ObjectProperty(KBParser.getInternalURI("hasChild")); -// description = KBParser.parseConcept("TOP"); -// assertTrue(reasoner.getDomain(property).equals(description)); - - String file = "examples/family/father_oe.owl"; - ks = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - ks.init(); - reasoner = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner.init(); - property = new ObjectProperty(reasoner.getBaseURI() + "hasChild"); - description = new NamedClass(reasoner.getBaseURI() + "person"); - assertTrue(reasoner.getDomain(property).equals(description)); - - file = "examples/arch/arch.owl"; - ks = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - ks.init(); - reasoner = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner.init(); - property = new ObjectProperty(reasoner.getBaseURI() + "hasParallelpipe"); - description = new NamedClass(reasoner.getBaseURI() + "construction"); - assertTrue(reasoner.getDomain(property).equals(description)); - - - file = "test/ore/koala.owl"; - ks = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); - ks.init(); - reasoner = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner.init(); - DatatypeProperty dProperty = new DatatypeProperty(reasoner.getBaseURI() + "isHardWorking"); - description = new NamedClass(reasoner.getBaseURI() + "Person"); - assertTrue(reasoner.getDomain(dProperty).equals(description)); - - } - - @Test - public void pelletSlowConsistencyCheck() throws ParseException { - ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SWORE); - Description d = KBParser.parseConcept("<= 1 \"http://ns.softwiki.de/req/defines\".\"http://ns.softwiki.de/req/AbstractRequirement\""); - NamedClass nc = new NamedClass("http://ns.softwiki.de/req/AbstractComment"); - Axiom axiom = new EquivalentClassesAxiom(nc, d); - boolean res = rs.remainsSatisfiable(axiom); - System.out.println(res); - } - - @Test - public void multipleKnowledgeSourcesTest() throws ComponentInitException { - String file1 = "examples/father.owl"; - String file2 = "examples/lymphography/lymphography.owl"; - ComponentManager cm = ComponentManager.getInstance(); - KnowledgeSource ks1 = cm.knowledgeSource(OWLFile.class); - KnowledgeSource ks2 = cm.knowledgeSource(OWLFile.class); - try { - cm.applyConfigEntry(ks1, "url", new File(file1).toURI().toURL()); - cm.applyConfigEntry(ks2, "url", new File(file2).toURI().toURL()); - } catch (MalformedURLException e) { - // should never happen - e.printStackTrace(); - } - ks1.init(); - ks2.init(); - ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks1, ks2); - reasoner.init(); - baseURI = reasoner.getBaseURI(); - System.out.println(reasoner.getSubClasses(Thing.instance)); - assertTrue(reasoner.getSubClasses(Thing.instance).size()==55); - } - - @Test - public void compareReasoners() throws FileNotFoundException, ComponentInitException, ParseException{ - - ComponentManager cm = ComponentManager.getInstance(); - Start start; - FastInstanceChecker reasoner; - LearningProblem lp; - LearningAlgorithm la; - KnowledgeSource ks; - - for(File conf : getTestConfigFiles()){ - System.out.println("Test file: " + conf.getName()); - start = new Start(conf); - lp = start.getLearningProblem(); - la = start.getLearningAlgorithm(); - ks = start.getSources().iterator().next(); - - TreeSet<? extends EvaluatedDescription> result = new TreeSet<EvaluatedDescription>(); - - for(String type : getReasonerTypes()){ - System.out.println("Using " + type + " reasoner..."); - try { - reasoner = cm.reasoner(FastInstanceChecker.class, ks); - reasoner.getConfigurator().setReasonerType(type); - reasoner.init(); - - lp.changeReasonerComponent(reasoner); - lp.init(); - - la.init(); - la.start(); - if(!result.isEmpty()){ - assertTrue(compareTreeSets(la.getCurrentlyBestEvaluatedDescriptions(), result)); - } - - result = la.getCurrentlyBestEvaluatedDescriptions(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - - } - - public boolean compareTreeSets(TreeSet<? extends EvaluatedDescription> tree1, TreeSet<? extends EvaluatedDescription> tree2){ - boolean equal = true; - - List<? extends EvaluatedDescription> list1 = new ArrayList<EvaluatedDescription>(tree1); - List<? extends EvaluatedDescription> list2 = new ArrayList<EvaluatedDescription>(tree2); - - EvaluatedDescription d1; - EvaluatedDescription d2; - for(int i = 0; i < list1.size(); i++){ - d1 = list1.get(i); - d2 = list2.get(i); - if(!(comparator.compare(d1.getDescription(), d2.getDescription()) == 0) && - d1.getAccuracy() == d2.getAccuracy()){ - equal = false; - break; - } - } - - return equal; - } - - private Set<File> getTestConfigFiles(){ - Set<File> files = new HashSet<File>(); - File directory = new File("test" + File.separator + "testReasoners"); - for(File file : directory.listFiles()){ - if(file.toString().endsWith(".conf")){ - files.add(file); - } - } - return files; - } - - private List<String> getReasonerTypes(){ - List<String> reasonerTypes = new LinkedList<String>(); - reasonerTypes.add("pellet"); -// reasonerTypes.add("hermit"); too slow at the moment - reasonerTypes.add("fact"); - reasonerTypes.add("owllink"); - - return reasonerTypes; - } - - private List<Individual> getIndSet(String... inds) { - List<Individual> individuals = new LinkedList<Individual>(); - for(String ind : inds) { - individuals.add(new Individual(uri(ind))); - } - return individuals; - } - - private String uri(String name) { -// return "\""+baseURI+name+"\""; - return baseURI+name; - } - -} Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2010-09-21 11:44:50 UTC (rev 2320) +++ trunk/scripts/pom.xml 2010-09-21 12:02:21 UTC (rev 2321) @@ -24,7 +24,7 @@ <dependency> <groupId>org.dllearner</groupId> <artifactId>components-ext</artifactId> - </dependency> + </dependency> <dependency> <groupId>net.sourceforge.secondstring</groupId> <artifactId>secondstring</artifactId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |