001/** 002 * Copyright (C) 2007 - 2016, 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 */ 019package org.dllearner.kb; 020 021import org.dllearner.core.AbstractKnowledgeSource; 022import org.dllearner.utilities.owl.OntologyToByteConverter; 023import org.dllearner.utilities.owl.SimpleOntologyToByteConverter; 024import org.semanticweb.owlapi.model.IRI; 025import org.semanticweb.owlapi.model.OWLOntology; 026import org.semanticweb.owlapi.model.OWLOntologyCreationException; 027import org.semanticweb.owlapi.model.OWLOntologyManager; 028 029import java.util.Collections; 030 031/** 032 * This class provides a wrapper around a single OWL Ontology. However, due to threading issues it is not safe 033 * to allow access to ontologies created with an Ontology Manager which we do not control. 034 */ 035// not for conf 036public class OWLAPIOntology extends AbstractKnowledgeSource implements OWLOntologyKnowledgeSource{ 037 038 private byte[] ontologyBytes; 039 private OntologyToByteConverter converter = new SimpleOntologyToByteConverter(); 040 private OWLOntology ontology; 041 042 043 public OWLAPIOntology(OWLOntology ontology) { 044 this.ontology = ontology; 045// ontologyBytes = converter.convert(ontology); 046 } 047 048 @Override 049 public OWLOntology createOWLOntology(OWLOntologyManager manager) { 050 OWLOntology copy = null; 051 try { 052 IRI iri; 053 if(ontology.getOntologyID().isAnonymous()){ 054 iri = IRI.generateDocumentIRI(); 055 } else { 056 iri = ontology.getOntologyID().getOntologyIRI().orNull(); 057 if(iri == null) { 058 iri = IRI.generateDocumentIRI(); 059 } 060 } 061 copy = manager.createOntology(iri, Collections.singleton(ontology)); 062 } catch (OWLOntologyCreationException e) { 063 e.printStackTrace(); 064 } 065// return converter.convert(ontologyBytes, manager); 066 return copy; 067 } 068 069 @Override 070 public void init() 071 { 072 initialized = true; 073 } 074 075 076 /** 077 * Get the OntologyToByteConverter associated with this object. 078 * 079 * @return The OntologyToByteConverter associated with this object. 080 */ 081 public OntologyToByteConverter getConverter() { 082 return converter; 083 } 084 085 /** 086 * Set the OntologyToByteConverter associated with this object. 087 * 088 * @param converter the OntologyToByteConverter to associate with this object. 089 */ 090 public void setConverter(OntologyToByteConverter converter) { 091 this.converter = converter; 092 } 093 094 /** 095 * @return the ontology 096 */ 097 public OWLOntology getOntology() { 098 return ontology; 099 } 100}