From: <ton...@us...> - 2008-02-22 00:38:34
|
Revision: 624 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=624&view=rev Author: tonytacker Date: 2008-02-21 16:38:27 -0800 (Thu, 21 Feb 2008) Log Message: ----------- new public method in startCLI - should be the best way for me - using this methods in configload.java and it works Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-21 21:21:21 UTC (rev 623) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-22 00:38:27 UTC (rev 624) @@ -167,62 +167,26 @@ // step 2: detect used reasoner ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); - Class<? extends ReasonerComponent> reasonerClass = null; - // default value - if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) - reasonerClass = DIGReasoner.class; - else if (reasonerOption.getStringValue().equals("owlAPI")) - reasonerClass = OWLAPIReasoner.class; - else if (reasonerOption.getStringValue().equals("fastRetrieval")) - reasonerClass = FastRetrievalReasoner.class; - else { - handleError("Unknown value " + reasonerOption.getStringValue() - + " for option \"reasoner\"."); - } - ReasonerComponent reasoner = cm.reasoner(reasonerClass, sources); + ReasonerComponent reasoner = cm.reasoner(getReasonerClass(reasonerOption), sources); configureComponent(cm, reasoner, componentPrefixMapping, parser); initComponent(cm, reasoner); rs = cm.reasoningService(reasoner); // step 3: detect learning problem ConfFileOption problemOption = parser.getConfOptionsByName("problem"); - Class<? extends LearningProblem> lpClass = null; - if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) - lpClass = PosNegDefinitionLP.class; - else if (problemOption.getStringValue().equals("posNegInclusion")) - lpClass = PosNegInclusionLP.class; - else if (problemOption.getStringValue().equals("posOnlyDefinition")) - lpClass = PosOnlyDefinitionLP.class; - else - handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); - - lp = cm.learningProblem(lpClass, rs); + lp = cm.learningProblem(getLearningProblemClass(problemOption), rs); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "positiveExamples", posExamples); - if (lpClass != PosOnlyDefinitionLP.class) + if (getLearningProblemClass(problemOption) != PosOnlyDefinitionLP.class) cm.applyConfigEntry(lp, "negativeExamples", negExamples); configureComponent(cm, lp, componentPrefixMapping, parser); initComponent(cm, lp); // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - Class<? extends LearningAlgorithm> laClass = null; - if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) - laClass = ROLearner.class; - else if (algorithmOption.getStringValue().equals("refexamples")) - laClass = ExampleBasedROLComponent.class; - else if (algorithmOption.getStringValue().equals("gp")) - laClass = GP.class; - else if (algorithmOption.getStringValue().equals("bruteForce")) - laClass = BruteForceLearner.class; - else if (algorithmOption.getStringValue().equals("randomGuesser")) - laClass = RandomGuesser.class; - else - handleError("Unknown value in " + algorithmOption); - try { - la = cm.learningAlgorithm(laClass, lp, rs); + la = cm.learningAlgorithm(getLearningAlgorithm(algorithmOption), lp, rs); } catch (LearningProblemUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -368,7 +332,7 @@ } /** - * detects all imported files and their format + * detects all imported files and their format */ public static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, String baseDir) { @@ -770,4 +734,73 @@ return rs; } + // edit by Tilo Hielscher + + /** + * Set Reasoner class. Define here all possible reasoners. + * + * @param reasonerOption + * from config file + * @return reasonerClass reasoner class + */ + public static Class<? extends ReasonerComponent> getReasonerClass(ConfFileOption reasonerOption) { + Class<? extends ReasonerComponent> reasonerClass = null; + if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) + reasonerClass = DIGReasoner.class; + else if (reasonerOption.getStringValue().equals("owlAPI")) + reasonerClass = OWLAPIReasoner.class; + else if (reasonerOption.getStringValue().equals("fastRetrieval")) + reasonerClass = FastRetrievalReasoner.class; + else { + handleError("Unknown value " + reasonerOption.getStringValue() + + " for option \"reasoner\"."); + } + return reasonerClass; + } + + /** + * Set LearningProblem class. Define here all possible problems. + * + * @param problemOption + * from config file + * @return lpClass learning problem class + */ + public static Class<? extends LearningProblem> getLearningProblemClass(ConfFileOption problemOption) { + Class<? extends LearningProblem> lpClass = null; + if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) + lpClass = PosNegDefinitionLP.class; + else if (problemOption.getStringValue().equals("posNegInclusion")) + lpClass = PosNegInclusionLP.class; + else if (problemOption.getStringValue().equals("posOnlyDefinition")) + lpClass = PosOnlyDefinitionLP.class; + else + handleError("Unknown value " + problemOption.getValue() + " for option \"problem\"."); + + return lpClass; + } + + /** + * Set LearningAlorithm class. Define here all possible learning algorithms. + * + * @param algorithmOption + * from config file + * @return laClass learning algorithm class + */ + public static Class<? extends LearningAlgorithm> getLearningAlgorithm(ConfFileOption algorithmOption) { + Class<? extends LearningAlgorithm> laClass = null; + if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) + laClass = ROLearner.class; + else if (algorithmOption.getStringValue().equals("refexamples")) + laClass = ExampleBasedROLComponent.class; + else if (algorithmOption.getStringValue().equals("gp")) + laClass = GP.class; + else if (algorithmOption.getStringValue().equals("bruteForce")) + laClass = BruteForceLearner.class; + else if (algorithmOption.getStringValue().equals("randomGuesser")) + laClass = RandomGuesser.class; + else + handleError("Unknown value in " + algorithmOption); + + return laClass; + } } Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-21 21:21:21 UTC (rev 623) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-22 00:38:27 UTC (rev 624) @@ -20,40 +20,16 @@ * */ -import java.io.File; // import java.net.URL; -import java.net.URL; // import java.util.HashSet; -import java.util.Map; // import java.util.Set; -import java.util.SortedSet; // import java.util.List; -// import java.util.Map; -import org.dllearner.algorithms.BruteForceLearner; -import org.dllearner.algorithms.RandomGuesser; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; -import org.dllearner.algorithms.refinement.ROLearner; +import java.io.File; +import java.net.URL; +import java.util.Map; +import java.util.SortedSet; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.KnowledgeSource; // import -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblem; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.ReasonerComponent; // org.dllearner.core.LearningProblem; -// import org.dllearner.core.ReasoningService; -// import org.dllearner.core.LearningAlgorithm; -// import org.dllearner.core.ReasonerComponent; -// import org.dllearner.core.config.ConfigEntry; -// import org.dllearner.core.config.InvalidConfigOptionValueException; -// import org.dllearner.core.config.StringConfigOption; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.parser.ConfParser; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastRetrievalReasoner; -import org.dllearner.reasoning.OWLAPIReasoner; // import -// org.dllearner.kb.KBFile; -// import org.dllearner.kb.OWLFile; -// import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.core.Component; // import -// org.dllearner.cli.ConfFileOption; +import org.dllearner.core.Component; import org.dllearner.cli.ConfFileOption; import org.dllearner.cli.Start; @@ -131,20 +107,8 @@ // REASONER ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); - Class<? extends ReasonerComponent> reasonerClass = null; - // default value - if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) - reasonerClass = DIGReasoner.class; - else if (reasonerOption.getStringValue().equals("owlAPI")) - reasonerClass = OWLAPIReasoner.class; - else if (reasonerOption.getStringValue().equals("fastRetrieval")) - reasonerClass = FastRetrievalReasoner.class; - else { - Start.handleError("Unknown value " + reasonerOption.getStringValue() - + " for option \"reasoner\"."); - } - config.setReasoner(config.getComponentManager().reasoner(reasonerClass, - config.getKnowledgeSource())); + config.setReasoner(config.getComponentManager().reasoner( + Start.getReasonerClass(reasonerOption), config.getKnowledgeSource())); Start.configureComponent(config.getComponentManager(), config.getReasoner(), componentPrefixMapping, parser); if (config.getKnowledgeSource() != null && config.getReasoner() != null) { @@ -164,23 +128,13 @@ // LEARNING PROBLEM ConfFileOption problemOption = parser.getConfOptionsByName("problem"); - Class<? extends LearningProblem> lpClass = null; - if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) - lpClass = PosNegDefinitionLP.class; - else if (problemOption.getStringValue().equals("posNegInclusion")) - lpClass = PosNegInclusionLP.class; - else if (problemOption.getStringValue().equals("posOnlyDefinition")) - lpClass = PosOnlyDefinitionLP.class; - else - Start.handleError("Unknown value " + problemOption.getValue() - + " for option \"problem\"."); - config.setLearningProblem(config.getComponentManager().learningProblem(lpClass, - config.getReasoningService())); + config.setLearningProblem(config.getComponentManager().learningProblem( + Start.getLearningProblemClass(problemOption), config.getReasoningService())); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", posExamples); - if (lpClass != PosOnlyDefinitionLP.class) + if (Start.getLearningProblemClass(problemOption) != PosOnlyDefinitionLP.class) config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "negativeExamples", negExamples); Start.configureComponent(config.getComponentManager(), config.getLearningProblem(), @@ -198,30 +152,17 @@ // LEARNING ALGORITHM ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - Class<? extends LearningAlgorithm> laClass = null; - if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) - laClass = ROLearner.class; - else if(algorithmOption.getStringValue().equals("refexamples")) - laClass = ExampleBasedROLComponent.class; - else if(algorithmOption.getStringValue().equals("gp")) - laClass = GP.class; - else if(algorithmOption.getStringValue().equals("bruteForce")) - laClass = BruteForceLearner.class; - else if(algorithmOption.getStringValue().equals("randomGuesser")) - laClass = RandomGuesser.class; - else - Start.handleError("Unknown value in " + algorithmOption); - if (config.getLearningProblem() != null && config.getReasoningService() != null) { try { config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm( - laClass, config.getLearningProblem(), - config.getReasoningService())); + Start.getLearningAlgorithm(algorithmOption), + config.getLearningProblem(), config.getReasoningService())); } catch (LearningProblemUnsupportedException e) { e.printStackTrace(); } } - Start.configureComponent(config.getComponentManager(), config.getLearningAlgorithm(), componentPrefixMapping, parser); + Start.configureComponent(config.getComponentManager(), config.getLearningAlgorithm(), + componentPrefixMapping, parser); if (config.getLearningProblem() != null) { try { config.getLearningAlgorithm().init(); @@ -231,15 +172,9 @@ e.printStackTrace(); } } - + // update graphic startGUI.updateTabColors(); - - //System.out.println("reasoner: " + parser.getConfOptionsByName("reasoner")); - //System.out.println("confoptions: " + parser.getConfOptions()); - //System.out.println("posExamples: " + parser.getPositiveExamples()); - //System.out.println("confoptionbyname: " + parser.getConfOptionsByName()); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |