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 java.io.File;
023 import java.text.SimpleDateFormat;
024 import java.util.ArrayList;
025 import java.util.Date;
026 import java.util.HashMap;
027 import java.util.Set;
028 import java.util.TreeSet;
029
030 import org.apache.log4j.ConsoleAppender;
031 import org.apache.log4j.Level;
032 import org.apache.log4j.Logger;
033 import org.apache.log4j.SimpleLayout;
034 import org.dllearner.cli.QuickStart;
035 import org.dllearner.cli.Start;
036 import org.dllearner.core.ComponentInitException;
037 import org.dllearner.core.ComponentManager;
038 import org.dllearner.utilities.Helper;
039 import org.junit.Test;
040
041 /**
042 * Tests related to learning problems in the examples directory.
043 *
044 * @author Jens Lehmann
045 *
046 */
047 public class ExampleTests {
048
049 /**
050 * This test runs all conf files in the examples directory. Each conf file
051 * corresponds to one unit test, which is succesful if a concept was
052 * learned. This unit test takes several hours.
053 *
054 * @throws ComponentInitException
055 * If any component initialisation exception occurs in the
056 * process.
057 */
058 @Test
059 public void testAllConfFiles() throws ComponentInitException {
060 // we use a logger, which outputs few messages (warnings, errors)
061 SimpleLayout layout = new SimpleLayout();
062 ConsoleAppender consoleAppender = new ConsoleAppender(layout);
063 Logger logger = Logger.getRootLogger();
064 logger.removeAllAppenders();
065 logger.addAppender(consoleAppender);
066 logger.setLevel(Level.WARN);
067
068 // map containing a list of conf files for each path
069 HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>();
070 String exampleDir = "." + File.separator + "examples";
071 File f = new File(exampleDir);
072 QuickStart.getAllConfs(f, exampleDir, confFiles);
073
074 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
075
076 // ignore list (examples which are temporarily not working due
077 // to server downtime, lack of features etc., but should still
078 // remain in the example directory
079 Set<String> ignore = new TreeSet<String>();
080
081 // "standard" ignores (no problem to keep those)
082 ignore.add("./examples/krk/complete_no_draw.conf"); // refers to an OWL file, which has to be auto-generated
083 ignore.add("./examples/krk/test_ZERO_against_1to16.conf"); // see above
084 ignore.add("./examples/semantic_bible/sparqlbible.conf"); // requires local Joseki
085
086 // temporarily not working (have a look at those before next release)
087 ignore.add("./examples/family/father_posonly.conf"); // ArrayOutOfBoundsException in Pellet - main problem: pos only not working/supported
088
089 // ignored due to errors (should be fixed; in case of long running problems or
090 // our of memory, it is better to increase the noise parameter and add comments
091 // in the conf file about "optimal" parameters)
092
093 // problems before latest release (kept to see if errors re-occurr,
094 // delete before next release)
095 // ignore.add("./examples/sparql/govtrack.conf"); // HTTP 500 Server error
096 //working fine here ignore.add("./examples/sparql/SKOSTEST_local.conf"); // Out of Memory Error
097 // ignore.add("./examples/sparql/scrobble.conf"); // HTTP 502 Proxy Error
098 // ignore.add("./examples/family-benchmark/Cousin.conf"); // Out of Memory Error => disallowing ALL helps (TODO find out details)
099 //also working fine ignore.add("./examples/sparql/SilentBobWorking2.conf"); // Out of Memory Error
100 // ignore.add("./examples/sparql/difference/DBPediaSKOS_kohl_vs_angela.conf"); // Pellet: literal cannot be cast to individual
101 // ignore.add("./examples/family-benchmark/Aunt.conf"); // did not terminate so far (waited 45 minutes) => disallowing ALL helps (TODO find out details)
102 // ignore.add("./examples/krk/KRK_ZERO_against_1to5_fastInstance.conf"); // Out of Memory Error
103
104 int failedCounter = 0;
105 for (String path : confFiles.keySet()) {
106 for (String file : confFiles.get(path)) {
107 String conf = path + file + ".conf";
108 if(ignore.contains(conf)) {
109 System.out.println("Skipping " + conf + " (is on ignore list).");
110 } else {
111 System.out.println("Testing " + conf + " (time: " + sdf.format(new Date()) + ").");
112 long startTime = System.nanoTime();
113 boolean success = false;
114 try {
115 // start example
116 Start start = new Start(new File(conf));
117 start.start(false);
118 // test is successful if a concept was learned
119 assert (start.getLearningAlgorithm().getCurrentlyBestDescription() != null);
120 start.getReasonerComponent().releaseKB();
121 success = true;
122 } catch (Exception e) {
123 // unit test not succesful (exceptions are caught explicitly to find
124 assert ( false );
125 e.printStackTrace();
126 failedCounter++;
127 }
128 long timeNeeded = System.nanoTime() - startTime;
129 ComponentManager.getInstance().freeAllComponents();
130 if(!success) {
131 System.out.println("TEST FAILED.");
132 }
133 System.out.println("Test of " + conf + " completed in " + Helper.prettyPrintNanoSeconds(timeNeeded) + ".");
134 }
135 }
136 }
137 System.out.println("Finished. " + failedCounter + " tests failed.");
138
139 }
140
141 }