001 /**
002 * Copyright (C) 2007-2008, 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.cli;
021
022 import java.util.HashMap;
023 import java.util.Map;
024 import java.util.Set;
025 import java.util.TreeMap;
026 import java.util.TreeSet;
027 import java.util.Map.Entry;
028
029 import org.dllearner.algorithms.BruteForceLearner;
030 import org.dllearner.algorithms.RandomGuesser;
031 import org.dllearner.algorithms.celoe.CELOE;
032 import org.dllearner.algorithms.el.ELLearningAlgorithm;
033 import org.dllearner.algorithms.gp.GP;
034 import org.dllearner.algorithms.refinement.ROLearner;
035 import org.dllearner.algorithms.refinement2.ROLComponent2;
036 import org.dllearner.core.Component;
037 import org.dllearner.core.KnowledgeSource;
038 import org.dllearner.core.LearningAlgorithm;
039 import org.dllearner.core.LearningProblem;
040 import org.dllearner.core.ReasonerComponent;
041 import org.dllearner.kb.OWLFile;
042 import org.dllearner.kb.sparql.SparqlKnowledgeSource;
043 import org.dllearner.learningproblems.ClassLearningProblem;
044 import org.dllearner.learningproblems.PosNegLPStandard;
045 import org.dllearner.learningproblems.PosNegLPStrict;
046 import org.dllearner.learningproblems.PosOnlyLP;
047 import org.dllearner.reasoning.DIGReasoner;
048 import org.dllearner.reasoning.FastInstanceChecker;
049 import org.dllearner.reasoning.FastRetrievalReasoner;
050 import org.dllearner.reasoning.OWLAPIReasoner;
051
052 /**
053 * Contains mappings from component classes to strings.
054 * Developer please edit the buildMappings() function to add new
055 * CLI mappings.
056 *
057 * TODO: For the web service, it may be interesting to hide some components
058 * and/or configuration options or even limit the maximum value of certain
059 * options.
060 *
061 * @author Jens Lehmann
062 *
063 */
064 public class ConfMapper {
065
066 // mappings between component classes and their names in conf files
067 private static Map<String,Class<? extends KnowledgeSource>> knowledgeSourceMapping = new TreeMap<String,Class<? extends KnowledgeSource>>();
068 private static Map<String,Class<? extends ReasonerComponent>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponent>>();
069 private static Map<String,Class<? extends LearningProblem>> learningProblemMapping = new TreeMap<String,Class<? extends LearningProblem>>();
070 private static Map<String,Class<? extends LearningAlgorithm>> learningAlgorithmMapping = new TreeMap<String,Class<? extends LearningAlgorithm>>();
071 private static TreeMap<String,Class<? extends Component>> componentMapping = new TreeMap<String,Class<? extends Component>>();
072 private static HashMap<Class<? extends Component>, String> inverseMapping = new HashMap<Class<? extends Component>, String>();
073
074 // component types
075 private static Map<String,Class<? extends Component>> componentTypeMapping = new TreeMap<String,Class<? extends Component>>();
076 private static Map<Class<? extends Component>, String> inverseTypeMapping = new HashMap<Class<? extends Component>,String>();
077
078 // set of available components
079 private static Set<String> components = new TreeSet<String>();
080
081 public ConfMapper() {
082 buildMappings();
083 buildKeys();
084 }
085
086 private static void buildMappings() {
087 // edit this part manually
088 knowledgeSourceMapping.put("owlfile", OWLFile.class);
089 knowledgeSourceMapping.put("sparql", SparqlKnowledgeSource.class);
090 reasonerMapping.put("digReasoner", DIGReasoner.class);
091 reasonerMapping.put("owlAPIReasoner", OWLAPIReasoner.class);
092 reasonerMapping.put("fastInstanceChecker", FastInstanceChecker.class);
093 reasonerMapping.put("fastRetrievalReasoner", FastRetrievalReasoner.class);
094 learningProblemMapping.put("posNegLPStandard", PosNegLPStandard.class);
095 learningProblemMapping.put("posNegLPStrict", PosNegLPStrict.class);
096 learningProblemMapping.put("classLearning", ClassLearningProblem.class);
097 learningProblemMapping.put("posOnlyLP", PosOnlyLP.class);
098 learningAlgorithmMapping.put("random", RandomGuesser.class);
099 learningAlgorithmMapping.put("bruteForce", BruteForceLearner.class);
100 learningAlgorithmMapping.put("gp", GP.class);
101 learningAlgorithmMapping.put("refinement", ROLearner.class);
102 learningAlgorithmMapping.put("refexamples", ROLComponent2.class);
103 learningAlgorithmMapping.put("el", ELLearningAlgorithm.class);
104 learningAlgorithmMapping.put("celoe", CELOE.class);
105
106 // you do not need to edit anything below
107
108 // build union of all
109 componentMapping.putAll(knowledgeSourceMapping);
110 componentMapping.putAll(reasonerMapping);
111 componentMapping.putAll(learningProblemMapping);
112 componentMapping.putAll(learningAlgorithmMapping);
113
114 // build inverse mapping
115 for(Entry<String, Class<? extends Component>> entry : componentMapping.entrySet()) {
116 inverseMapping.put(entry.getValue(), entry.getKey());
117 }
118
119 components = componentTypeMapping.keySet();
120 }
121
122 private static void buildKeys() {
123 // edit this part manually
124 componentTypeMapping.put("import", KnowledgeSource.class);
125 componentTypeMapping.put("reasoner", ReasonerComponent.class);
126 componentTypeMapping.put("problem", LearningProblem.class);
127 componentTypeMapping.put("algorithm", LearningAlgorithm.class);
128
129 // you do not need to edit anything below
130 // build inverse mapping
131 for(Entry<String, Class<? extends Component>> entry : componentTypeMapping.entrySet()) {
132 inverseTypeMapping.put(entry.getValue(), entry.getKey());
133 }
134 }
135
136 public Class<? extends KnowledgeSource> getKnowledgeSourceClass(String confString) {
137 return knowledgeSourceMapping.get(confString);
138 }
139
140 public Class<? extends ReasonerComponent> getReasonerComponentClass(String confString) {
141 return reasonerMapping.get(confString);
142 }
143
144 public Class<? extends LearningProblem> getLearningProblemClass(String confString) {
145 return learningProblemMapping.get(confString);
146 }
147
148 public Class<? extends LearningAlgorithm> getLearningAlgorithmClass(String confString) {
149 return learningAlgorithmMapping.get(confString);
150 }
151
152 public Class<? extends Component> getComponentClass(String confString) {
153 return componentMapping.get(confString);
154 }
155
156 public String getComponentString(Class<? extends Component> clazz) {
157 return inverseMapping.get(clazz);
158 }
159
160 public Class<? extends Component> getComponentTypeClass(String typeString) {
161 return componentTypeMapping.get(typeString);
162 }
163
164 public String getComponentTypeString(Class<? extends Component> typeClass) {
165 return inverseTypeMapping.get(typeClass);
166 }
167
168 public Set<String> getKnowledgeSources() {
169 return knowledgeSourceMapping.keySet();
170 }
171
172 public Set<String> getReasoners() {
173 return reasonerMapping.keySet();
174 }
175
176 public Set<String> getLearningProblems() {
177 return learningProblemMapping.keySet();
178 }
179
180 public Set<String> getLearningAlgorithms() {
181 return learningAlgorithmMapping.keySet();
182 }
183
184 public Set<String> getComponents() {
185 return components;
186 }
187
188 }