001    /**
002     * Copyright (C) 2007-2011, 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.utilities.components;
021    
022    import java.io.File;
023    import java.net.MalformedURLException;
024    import java.net.URL;
025    
026    import org.dllearner.core.ComponentInitException;
027    import org.dllearner.core.ComponentManager;
028    import org.dllearner.core.AbstractReasonerComponent;
029    import org.dllearner.kb.OWLFile;
030    import org.dllearner.reasoning.FastInstanceChecker;
031    import org.dllearner.reasoning.OWLAPIReasoner;
032    import org.dllearner.reasoning.ReasonerType;
033    
034    /**
035     * Factory class for reasoners.
036     * 
037     * @author Sebastian Hellmann
038     * @author Jens Lehmann
039     */
040    public class ReasonerComponentFactory {
041    
042            /**
043             * Simple method for creating a reasoner component.
044             * 
045             * @param ontologyFile URI or path to OWL ontology file.
046             * @param type Reasoner type.
047             * @return A reasoner component.
048             */
049            public static AbstractReasonerComponent getReasonerComponent(String ontologyFile, ReasonerType type) {
050                    ComponentManager cm = ComponentManager.getInstance();
051                    AbstractReasonerComponent rc = null;
052    
053                    try {
054                            // knowledge source
055                            OWLFile ks = cm.knowledgeSource(OWLFile.class);
056                            URL fileURL = new File(ontologyFile).toURI().toURL();
057                            ks.getConfigurator().setUrl(fileURL);
058                            ks.init();
059    
060                            // reasoner component
061                            switch (type) {
062                            case FAST_INSTANCE_CHECKER:
063                                    rc = cm.reasoner(FastInstanceChecker.class, ks);
064                                    break;
065                            case OWLAPI_FACT:
066                                    rc = cm.reasoner(OWLAPIReasoner.class, ks);
067                                    ((OWLAPIReasoner) rc).getConfigurator().setReasonerType("fact");
068                                    break;
069                            case OWLAPI_PELLET:
070                                    rc = cm.reasoner(OWLAPIReasoner.class, ks);
071                                    ((OWLAPIReasoner) rc).getConfigurator().setReasonerType("pellet");
072                                    break;
073                            default:
074                                    rc = cm.reasoner(FastInstanceChecker.class, ks);
075                                    break;
076                            }
077                            rc.init();
078                    } catch (MalformedURLException e) {
079                            e.printStackTrace();
080                    } catch (ComponentInitException e) {
081                            e.printStackTrace();
082                    }
083    
084                    return rc;
085            }
086    
087    }