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 learning on SWORE ontology.
041     * 
042     * @author Jens Lehmann
043     * 
044     */
045    public class SworeTest {
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/swore/swore.rdf";
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://ns.softwiki.de/req/important");
071                    positiveExamples.add("http://ns.softwiki.de/req/very_important");
072                    Set<String> negativeExamples = new TreeSet<String>();
073                    negativeExamples.add("http://ns.softwiki.de/req/Topic");
074                    cm.applyConfigEntry(lp, "positiveExamples", positiveExamples);
075                    cm.applyConfigEntry(lp, "negativeExamples", negativeExamples);
076                    lp.init();
077                    
078                    // create the learning algorithm
079                    LearningAlgorithm la = null;
080                    try {
081                            la = cm.learningAlgorithm(ROLComponent2.class, lp, reasoner);
082                            la.init();
083                    } catch (LearningProblemUnsupportedException e) {
084                            e.printStackTrace();
085                    }
086            
087                    // start the algorithm and print the best concept found
088                    la.start();
089                    System.out.println(la.getCurrentlyBestEvaluatedDescriptions(10, 0.8, true));
090            }
091    
092    }