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.kb;
021    
022    import java.io.File;
023    import java.net.URI;
024    import java.util.Iterator;
025    import java.util.Set;
026    
027    import org.dllearner.core.AbstractKnowledgeSource;
028    import org.dllearner.core.OntologyFormat;
029    import org.dllearner.core.configurators.OWLAPIOntologyConfigurator;
030    import org.dllearner.core.options.ConfigEntry;
031    import org.dllearner.core.options.InvalidConfigOptionValueException;
032    import org.dllearner.core.owl.KB;
033    import org.semanticweb.owlapi.model.OWLClass;
034    import org.semanticweb.owlapi.model.OWLDataProperty;
035    import org.semanticweb.owlapi.model.OWLNamedIndividual;
036    import org.semanticweb.owlapi.model.OWLObjectProperty;
037    import org.semanticweb.owlapi.model.OWLOntology;
038    
039    public class OWLAPIOntology extends AbstractKnowledgeSource {
040    
041            private OWLAPIOntologyConfigurator configurator;
042            @Override
043            public OWLAPIOntologyConfigurator getConfigurator(){
044                    return configurator;
045            }
046            
047            private OWLOntology ontology;
048            private Set<OWLOntology> ontologies;
049            private Set<OWLClass> classes;
050            private Set<OWLObjectProperty> prop;
051            private Set<OWLDataProperty> dataProp;
052            private Set<OWLNamedIndividual> individuals;
053            
054            public OWLAPIOntology() {
055                    this(null);
056            }
057            
058            public OWLAPIOntology(OWLOntology onto)
059            {
060                    this.ontology = onto;
061                    classes = ontology.getClassesInSignature();
062                    prop = ontology.getObjectPropertiesInSignature();
063                    dataProp = ontology.getDataPropertiesInSignature();
064                    individuals = ontology.getIndividualsInSignature();
065                    this.configurator = new OWLAPIOntologyConfigurator(this);
066            }
067            
068            public static String getName() {
069                    return "OWL API Ontology";
070            }
071            
072            @Override
073            public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException 
074            {
075                    
076            }
077            
078            public OWLOntology getOWLOntolgy()
079            {
080                    return ontology;
081            }
082            
083            @Override
084            public KB toKB()
085            {
086                    throw new Error("OWL -> KB conversion not implemented yet.");
087            }
088            
089            @Override
090            public void init()
091            {
092                    
093            }
094            
095            @Override
096            public void export(File file, OntologyFormat format)
097            {
098                    
099            }
100            
101            @Override
102            public String toDIG(URI kbURI)
103            {
104                    return null;
105            }
106            
107            public void setOWLOntologies(Set<OWLOntology> onto) {
108                    ontologies = onto;
109                    System.out.println("ONTO: " + ontologies);
110                    Iterator<OWLOntology> it = ontologies.iterator();
111                    while(it.hasNext()) {
112                            OWLOntology ont = it.next();
113                            if(ont.getClassesInSignature() != null) {
114                                    classes.addAll(ont.getClassesInSignature());
115                            }
116                            if(ont.getObjectPropertiesInSignature() != null) {
117                                    prop.addAll(ont.getObjectPropertiesInSignature());
118                            }
119                            if(ont.getDataPropertiesInSignature() != null) {
120                                    dataProp.addAll(ont.getDataPropertiesInSignature());
121                            }
122                            if(ont.getIndividualsInSignature() != null) {
123                                    individuals.addAll(ont.getIndividualsInSignature());
124                            }
125                    }
126            }
127            
128            public Set<OWLOntology> getOWLOnntologies() {
129                    return ontologies;
130            }
131            
132            public Set<OWLClass> getOWLClasses() {
133                    return classes;
134            }
135            
136            public Set<OWLObjectProperty> getOWLObjectProperies() {
137                    return prop;
138            }
139            
140            public Set<OWLDataProperty> getOWLDataProperies() {
141                    return dataProp;
142            }
143            
144            public Set<OWLNamedIndividual> getOWLIndividuals() {
145                    return individuals;
146            }
147    }