001    /***************************************************************************/
002    /*  Copyright (C) 2010-2011, Sebastian Hellmann                            */
003    /*  Note: If you need parts of NLP2RDF in another licence due to licence   */
004    /*  incompatibility, please mail hellmann@informatik.uni-leipzig.de        */
005    /*                                                                         */
006    /*  This file is part of NLP2RDF.                                          */
007    /*                                                                         */
008    /*  NLP2RDF is free software; you can redistribute it and/or modify        */
009    /*  it under the terms of the GNU General Public License as published by   */
010    /*  the Free Software Foundation; either version 3 of the License, or      */
011    /*  (at your option) any later version.                                    */
012    /*                                                                         */
013    /*  NLP2RDF is distributed in the hope that it will be useful,             */
014    /*  but WITHOUT ANY WARRANTY; without even the implied warranty of         */
015    /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           */
016    /*  GNU General Public License for more details.                           */
017    /*                                                                         */
018    /*  You should have received a copy of the GNU General Public License      */
019    /*  along with this program. If not, see <http://www.gnu.org/licenses/>.   */
020    /***************************************************************************/
021    
022    package org.nlp2rdf.ontology.impl;
023    
024    import com.hp.hpl.jena.ontology.OntModel;
025    import com.hp.hpl.jena.ontology.OntModelSpec;
026    import com.hp.hpl.jena.rdf.model.ModelFactory;
027    import org.apache.log4j.Logger;
028    import org.nlp2rdf.ontology.OntologyLoader;
029    
030    import java.util.HashSet;
031    import java.util.Set;
032    
033    /**
034     * @author Sebastian Hellmann - http://bis.informatik.uni-leipzig.de/SebastianHellmann
035     */
036    public class SimpleLoader implements OntologyLoader {
037        private static final Logger log = Logger.getLogger(SimpleLoader.class);
038    
039        @Override
040        public OntModel loadOntology(String ontologyUri) {
041            return loadOntology(ontologyUri, OntModelSpec.OWL_DL_MEM);
042        }
043    
044        @Override
045        public OntModel loadOntology(String ontologyUri, OntModelSpec spec) {
046            OntModel model = ModelFactory.createOntologyModel(spec);
047            model.read(ontologyUri);
048            return model;
049        }
050    
051        @Override
052        public void loadImports(OntModel m) {
053            Set<String> loaded = new HashSet<String>();
054            for (String one : m.listImportedOntologyURIs()) {
055                if (loaded.add(one) == false) {
056                    log.debug("skipping " + one + " (already load)");
057                    continue;
058                }
059                OntModel sm = loadOntology(one);
060                loadImports(sm);
061                m.addSubModel(sm);
062            }
063        }
064    }