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.reasoning;
021
022 import java.util.HashSet;
023 import java.util.Map;
024 import java.util.Set;
025 import java.util.SortedSet;
026 import java.util.TreeSet;
027
028 import org.dllearner.core.ComponentInitException;
029 import org.dllearner.core.AbstractKnowledgeSource;
030 import org.dllearner.core.AbstractReasonerComponent;
031 import org.dllearner.core.ReasoningMethodUnsupportedException;
032 import org.dllearner.core.configurators.ComponentFactory;
033 import org.dllearner.core.configurators.FastRetrievalReasonerConfigurator;
034 import org.dllearner.core.options.ConfigEntry;
035 import org.dllearner.core.options.InvalidConfigOptionValueException;
036 import org.dllearner.core.owl.Description;
037 import org.dllearner.core.owl.FlatABox;
038 import org.dllearner.core.owl.Individual;
039 import org.dllearner.core.owl.NamedClass;
040 import org.dllearner.core.owl.ObjectProperty;
041 import org.dllearner.utilities.Helper;
042 import org.dllearner.utilities.datastructures.SortedSetTuple;
043
044 /**
045 *
046 * Reasoner for fast retrieval inference (other tasks redirected to OWL API reasoner). Not actively used anymore.
047 *
048 * @author Jens Lehmann
049 *
050 */
051 public class FastRetrievalReasoner extends AbstractReasonerComponent {
052
053 private FastRetrievalReasonerConfigurator configurator;
054 @Override
055 public FastRetrievalReasonerConfigurator getConfigurator(){
056 return configurator;
057 }
058
059 FlatABox abox;
060 FastRetrieval fastRetrieval;
061 Set<NamedClass> atomicConcepts;
062 Set<ObjectProperty> atomicRoles;
063 SortedSet<Individual> individuals;
064
065 AbstractReasonerComponent rc;
066
067 public FastRetrievalReasoner(Set<AbstractKnowledgeSource> sources) {
068 super(sources);
069 this.configurator = new FastRetrievalReasonerConfigurator(this);
070
071 rc = ComponentFactory.getOWLAPIReasoner(sources);
072 try {
073 rc.init();
074 } catch (ComponentInitException e1) {
075 // TODO Auto-generated catch block
076 e1.printStackTrace();
077 }
078 atomicConcepts = rc.getNamedClasses();
079 atomicRoles = rc.getObjectProperties();
080 individuals = rc.getIndividuals();
081 // rs = new ReasonerComponent(rc);
082 try {
083 abox = Helper.createFlatABox(rc);
084 } catch (ReasoningMethodUnsupportedException e) {
085 // TODO Auto-generated catch block
086 e.printStackTrace();
087 }
088 fastRetrieval = new FastRetrieval(abox);
089 }
090
091 public FastRetrievalReasoner(FlatABox abox) {
092 super(null);
093 this.configurator = new FastRetrievalReasonerConfigurator(this);
094 this.abox = abox;
095 fastRetrieval = new FastRetrieval(abox);
096
097 // atomare Konzepte und Rollen initialisieren
098 atomicConcepts = new HashSet<NamedClass>();
099 for(String concept : abox.concepts) {
100 atomicConcepts.add(new NamedClass(concept));
101 }
102 atomicRoles = new HashSet<ObjectProperty>();
103 for(String role : abox.roles) {
104 atomicRoles.add(new ObjectProperty(role));
105 }
106 individuals = new TreeSet<Individual>();
107 for(String individualName : abox.domain)
108 individuals.add(new Individual(individualName));
109
110 }
111
112 @Override
113 public ReasonerType getReasonerType() {
114 return ReasonerType.FAST_RETRIEVAL;
115 }
116
117 @Override
118 public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept) {
119 return Helper.getIndividualTuple(fastRetrieval.calculateSets(concept));
120 }
121
122 // @Override
123 // public SortedSetTuple<Individual> doubleRetrieval(Description concept, Description adc) {
124 // SortedSetTuple<String> adcSet = fastRetrieval.calculateSets(adc);
125 // return Helper.getIndividualTuple(fastRetrieval.calculateSetsADC(concept, adcSet));
126 // }
127
128 @Override
129 public SortedSet<Individual> getIndividualsImpl(Description concept) {
130 return Helper.getIndividualSet(fastRetrieval.calculateSets(concept).getPosSet());
131 }
132
133 public Set<NamedClass> getNamedClasses() {
134 return atomicConcepts;
135 }
136
137 @Override
138 public Set<ObjectProperty> getObjectProperties() {
139 return atomicRoles;
140 }
141
142 public SortedSet<Individual> getIndividuals() {
143 return individuals;
144 }
145
146 public FlatABox getFlatAbox() {
147 return abox;
148 }
149
150 // C \sqsubseteq D is rewritten to a retrieval for \not C \sqcap D
151 @Override
152 public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) {
153 // Negation neg = new Negation(subConcept);
154 // Intersection c = new Intersection(neg,superConcept);
155 // return fastRetrieval.calculateSets(c).getPosSet().isEmpty();
156 return rc.isSuperClassOf(superConcept, subConcept);
157 }
158
159 // @Override
160 // public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) {
161 // rs.prepareRoleHierarchy(allowedRoles);
162 // }
163
164 // @Override
165 // public ObjectPropertyHierarchy getRoleHierarchy() {
166 // return rs.getRoleHierarchy();
167 // }
168
169 // public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) {
170 // rs.prepareSubsumptionHierarchy(allowedConcepts);
171 // }
172
173 // @Override
174 // public ClassHierarchy getClassHierarchy() {
175 // return rs.getClassHierarchy();
176 // }
177
178 @Override
179 public boolean isSatisfiableImpl() {
180 return rc.isSatisfiable();
181 }
182
183 @Override
184 public boolean hasTypeImpl(Description concept, Individual individual) {
185 return fastRetrieval.calculateSets(concept).getPosSet().contains(individual.getName());
186 }
187
188 public static String getName() {
189 return "fast retrieval reasoner";
190 }
191
192
193
194 /* (non-Javadoc)
195 * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry)
196 */
197 @Override
198 public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException {
199 // TODO Auto-generated method stub
200
201 }
202
203 /* (non-Javadoc)
204 * @see org.dllearner.core.Component#init()
205 */
206 @Override
207 public void init() {
208 // TODO Auto-generated method stub
209
210 }
211
212 /* (non-Javadoc)
213 * @see org.dllearner.core.Reasoner#getBaseURI()
214 */
215 public String getBaseURI() {
216 return rc.getBaseURI();
217 }
218
219 /* (non-Javadoc)
220 * @see org.dllearner.core.Reasoner#getPrefixes()
221 */
222 public Map<String, String> getPrefixes() {
223 return rc.getPrefixes();
224 }
225
226 /* (non-Javadoc)
227 * @see org.dllearner.core.ReasonerComponent#releaseKB()
228 */
229 @Override
230 public void releaseKB() {
231 rc.releaseKB();
232 }
233
234
235 // @Override
236 // public boolean hasDatatypeSupport() {
237 // return true;
238 // }
239 }