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;
021
022 import java.io.File;
023 import java.net.MalformedURLException;
024 import java.util.Set;
025 import java.util.TreeSet;
026
027 import org.dllearner.algorithms.refinement2.ROLComponent2;
028 import org.dllearner.core.ComponentInitException;
029 import org.dllearner.core.ComponentManager;
030 import org.dllearner.core.KnowledgeSource;
031 import org.dllearner.core.LearningAlgorithm;
032 import org.dllearner.core.LearningProblem;
033 import org.dllearner.core.LearningProblemUnsupportedException;
034 import org.dllearner.core.ReasonerComponent;
035 import org.dllearner.kb.OWLFile;
036 import org.dllearner.learningproblems.PosNegLPStandard;
037 import org.dllearner.reasoning.OWLAPIReasoner;
038
039 /**
040 * Test for component based design.
041 *
042 * @author Jens Lehmann
043 *
044 */
045 public class ComponentTest {
046
047 /**
048 * @param args
049 * @throws ComponentInitException
050 * @throws MalformedURLException
051 */
052 public static void main(String[] args) throws ComponentInitException, MalformedURLException {
053
054 // get singleton instance of component manager
055 ComponentManager cm = ComponentManager.getInstance();
056
057 // create knowledge source
058 KnowledgeSource source = cm.knowledgeSource(OWLFile.class);
059 String example = "examples/family/uncle.owl";
060 cm.applyConfigEntry(source, "url", new File(example).toURI().toURL());
061 source.init();
062
063 // create OWL API reasoning service with standard settings
064 ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source);
065 reasoner.init();
066
067 // create a learning problem and set positive and negative examples
068 LearningProblem lp = cm.learningProblem(PosNegLPStandard.class, reasoner);
069 Set<String> positiveExamples = new TreeSet<String>();
070 positiveExamples.add("http://localhost/foo#heinz");
071 positiveExamples.add("http://localhost/foo#alex");
072 Set<String> negativeExamples = new TreeSet<String>();
073 negativeExamples.add("http://localhost/foo#jan");
074 negativeExamples.add("http://localhost/foo#anna");
075 negativeExamples.add("http://localhost/foo#hanna");
076 cm.applyConfigEntry(lp, "positiveExamples", positiveExamples);
077 cm.applyConfigEntry(lp, "negativeExamples", negativeExamples);
078 lp.init();
079
080 // create the learning algorithm
081 LearningAlgorithm la = null;
082 try {
083 la = cm.learningAlgorithm(ROLComponent2.class, lp, reasoner);
084 la.init();
085 } catch (LearningProblemUnsupportedException e) {
086 e.printStackTrace();
087 }
088
089 // start the algorithm and print the best concept found
090 la.start();
091 System.out.println(la.getCurrentlyBestEvaluatedDescriptions(10, 0.8, true));
092 }
093
094 }