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.net.URL;
025 import java.util.Collection;
026 import java.util.LinkedList;
027
028 import org.apache.log4j.Logger;
029 import org.dllearner.core.ComponentInitException;
030 import org.dllearner.core.AbstractKnowledgeSource;
031 import org.dllearner.core.OntologyFormat;
032 import org.dllearner.core.OntologyFormatUnsupportedException;
033 import org.dllearner.core.configurators.OWLFileConfigurator;
034 import org.dllearner.core.options.ConfigEntry;
035 import org.dllearner.core.options.ConfigOption;
036 import org.dllearner.core.options.InvalidConfigOptionValueException;
037 import org.dllearner.core.options.URLConfigOption;
038 import org.dllearner.core.owl.KB;
039 import org.dllearner.reasoning.OWLAPIDIGConverter;
040
041 /**
042 * @author Jens Lehmann
043 *
044 */
045 public class OWLFile extends AbstractKnowledgeSource {
046
047 private static Logger logger = Logger
048 .getLogger(OWLFile.class);
049
050 // private URL url;
051 private OWLFileConfigurator configurator ;
052 @Override
053 public OWLFileConfigurator getConfigurator(){
054 return configurator;
055 }
056
057 public static String getName() {
058 return "OWL file";
059 }
060
061 public OWLFile(){
062 configurator = new OWLFileConfigurator(this);
063 }
064
065
066 public static Collection<ConfigOption<?>> createConfigOptions() {
067 Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>();
068 URLConfigOption urlOption = new URLConfigOption("url", "URL pointing to the OWL file", null, true, true);
069 urlOption.setRefersToFile(true);
070 options.add(urlOption);
071 return options;
072 }
073
074 /*
075 * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry)
076 */
077 @Override
078 public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException {
079
080 }
081
082 /* (non-Javadoc)
083 * @see org.dllearner.core.Component#init()
084 */
085 @Override
086 public void init() throws ComponentInitException {
087 if(configurator.getUrl() == null) {
088 logger.error("Cannot initialise OWL file with empty URL");
089 }
090
091 /*
092 try {
093 url = new URL(configurator.getUrl());
094 } catch (MalformedURLException e) {
095 logger.error(e.getMessage());
096 //throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + configurator.getUrl());
097 }
098 */
099
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see org.dllearner.core.KnowledgeSource#toDIG()
106 */
107 @Override
108 public String toDIG(URI kbURI) {
109 // TODO: need some handling for cases where the URL was not set
110 return OWLAPIDIGConverter.getTellsString(configurator.getUrl(), OntologyFormat.RDF_XML, kbURI);
111 }
112
113 public URL getURL() {
114 return configurator.getUrl();
115 }
116 public void setURL(URL url) {
117 // this.url = url;
118 configurator.setUrl(url);
119 }
120
121 /* (non-Javadoc)
122 * @see org.dllearner.core.KnowledgeSource#export(java.io.File, org.dllearner.core.OntologyFormat)
123 */
124 @Override
125 public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException {
126 // currently no export functions implemented, so we just throw an exception
127 throw new OntologyFormatUnsupportedException("export", format);
128 }
129
130 /* (non-Javadoc)
131 * @see org.dllearner.core.KnowledgeSource#toKB()
132 */
133 @Override
134 public KB toKB() {
135 throw new Error("OWL -> KB conversion not implemented yet.");
136 }
137
138 }