From: <ton...@us...> - 2008-02-28 23:17:46
|
Revision: 665 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=665&view=rev Author: tonytacker Date: 2008-02-28 15:17:17 -0800 (Thu, 28 Feb 2008) Log Message: ----------- save config (only system.out.println) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,10 +19,9 @@ */ package org.dllearner.core.config; - /** * @author Jens Lehmann - * + * */ public class BooleanConfigOption extends ConfigOption<Boolean> { @@ -33,8 +32,10 @@ public BooleanConfigOption(String name, String description, boolean defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -42,7 +43,9 @@ return (object instanceof Boolean); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -50,12 +53,20 @@ return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Boolean value) { - return value.toString(); + public String getValueFormatting(Boolean value, Integer special) { + if (value != null) { + if (value) + return "true"; + else + return "false"; + } else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,45 +19,50 @@ */ package org.dllearner.core.config; - /** * A config entry is a configuration option and a value for the option. * * @author Jens Lehmann - * + * */ public class ConfigEntry<T> { private ConfigOption<T> option; private T value; - + public ConfigEntry(ConfigOption<T> option, T value) throws InvalidConfigOptionValueException { - if(!option.isValidValue(value)) { + if (!option.isValidValue(value)) { throw new InvalidConfigOptionValueException(option, value); } else { this.option = option; this.value = value; } } - + public ConfigOption<T> getOption() { return option; } - + public String getOptionName() { return option.getName(); } - + public T getValue() { return value; } - + /** * Get a string to save into a configuration file. * * @return a formatted string */ public String toConfString(String componentName) { - return componentName.toString() + "." + option.getName() + " = " + option.getValueFormatting(value); + if (option.getName().equalsIgnoreCase("positiveExamples")) { + return option.getValueFormatting(value, 1); + } else if (option.getName() == "negativeExamples") { + return option.getValueFormatting(value, 2); + } else + return componentName.toString() + "." + option.getName() + " = " + + option.getValueFormatting(value, 0); } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -23,68 +23,81 @@ * This class represents a configuration option (without a value for the * option). * - * Note: Currently, handling the type of a configuration option is not - * straightforward to implement, because Java Generics information is - * erased at runtime. This will be fixed in Java 7, in particular JSR 308, - * which is due at approx. the end of 2008. + * Note: Currently, handling the type of a configuration option is not + * straightforward to implement, because Java Generics information is erased at + * runtime. This will be fixed in Java 7, in particular JSR 308, which is due at + * approx. the end of 2008. * * @author Jens Lehmann - * + * */ public abstract class ConfigOption<T> { protected String name; - + protected String description; - + protected T defaultValue; - + public ConfigOption(String name, String description) { this(name, description, null); } - + public ConfigOption(String name, String description, T defaultValue) { this.name = name; this.description = description; this.defaultValue = defaultValue; } - + public String getName() { return name; } - + public String getDescription() { return description; - } - + } + /** * @return the defaultValue */ public T getDefaultValue() { return defaultValue; - } - + } + /** - * Checks whether the object has the correct type to be used as - * a value for this option (this method is necessary, because - * generic information is erased at runtime in Java). - * - * @param object The object to check. + * Checks whether the object has the correct type to be used as a value for + * this option (this method is necessary, because generic information is + * erased at runtime in Java). + * + * @param object + * The object to check. * @return */ public abstract boolean checkType(Object object); - + public abstract boolean isValidValue(T value); - + public String getAllowedValuesDescription() { return getClass().toString(); } - + @Override public String toString() { - return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; + return "option name: " + name + "\ndescription: " + description + "\nvalues: " + + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; } - - public abstract String getValueFormatting(T value); + /** + * Get a formatted value to put into configuration file. + * + * @param value + * @param special + * 0 for normal output. + * 1 for positiveExamples. + * 2 for negativeExamples. + * + * @return a string to put into a file + */ + public abstract String getValueFormatting(T value, Integer special); + } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,38 +19,39 @@ */ package org.dllearner.core.config; - /** - * Represents a configuration option with values of type value. Similar - * to the integer option a minimum and a maximum value can specified. + * Represents a configuration option with values of type value. Similar to the + * integer option a minimum and a maximum value can specified. * * @author Jens Lehmann - * + * */ public class DoubleConfigOption extends ConfigOption<Double> { private double lowerLimit = Double.MIN_VALUE; private double upperLimit = Double.MAX_VALUE; - + public DoubleConfigOption(String name, String description) { super(name, description); } - + public DoubleConfigOption(String name, String description, double defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(Double value) { - if(value >= lowerLimit && value <= upperLimit) + if (value >= lowerLimit && value <= upperLimit) return true; else - return false; + return false; } - + /** * @return the The lowest possible value for this configuration option. */ @@ -59,7 +60,8 @@ } /** - * @param lowerLimit The lowest possible value for this configuration option. + * @param lowerLimit + * The lowest possible value for this configuration option. */ public void setLowerLimit(double lowerLimit) { this.lowerLimit = lowerLimit; @@ -73,26 +75,29 @@ } /** - * @param upperLimit The highest possible value for this configuration option. + * @param upperLimit + * The highest possible value for this configuration option. */ public void setUpperLimit(double upperLimit) { this.upperLimit = upperLimit; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { return (object instanceof Double); } - + @Override public String getAllowedValuesDescription() { String str = getClass().toString(); - if(lowerLimit != Double.MIN_VALUE) + if (lowerLimit != Double.MIN_VALUE) str += " min " + lowerLimit; - if(upperLimit != Double.MAX_VALUE) + if (upperLimit != Double.MAX_VALUE) str += " max " + upperLimit; return str; } @@ -103,8 +108,11 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Double value) { - return value.toString(); + public String getValueFormatting(Double value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -108,7 +108,10 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Integer value) { - return value.toString(); + public String getValueFormatting(Integer value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -90,8 +90,11 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(String value) { - return value.toString(); + public String getValueFormatting(String value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -68,8 +68,34 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Set<String> value) { - return value.toString(); + public String getValueFormatting(Set<String> value, Integer special) { + String back = ""; + if (value != null && special == 0) { + Integer count = 0; + back = "{"; + for (String i : value) { + if (count > 0) + back += ","; + back += "\n\"" + i + "\""; + count++; + } + back += "};"; + return back; + } + // positive examples + if (value != null && special == 1) { + for (String i : value) { + back += "\n+" + i; + } + return back + "\n"; + } + // negative examples + if (value != null && special == 2) { + for (String i : value) { + back += "\n-" + i; + } + return back + "\n"; + } + return null; } - } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -75,8 +75,20 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(List<StringTuple> value) { - return value.toString(); + public String getValueFormatting(List<StringTuple> value, Integer special) { + Integer count = 0; + if (value != null) { + String back = "["; + for (StringTuple i : value) { + if (count > 0) + back += ","; + back += "\n(\"" + i.a + "\",\"" + i.b + "\")"; + count++; + } + back += "];"; + return back; + } else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-28 23:17:17 UTC (rev 665) @@ -23,19 +23,15 @@ //import java.io.File; //import java.net.URL; import java.util.List; //import java.util.Map; -//import java.util.SortedSet; -//import org.dllearner.core.ComponentInitException; +import java.util.Map; + import org.dllearner.core.ComponentManager; //import org.dllearner.core.KnowledgeSource; -//import org.dllearner.core.LearningProblemUnsupportedException; -//import org.dllearner.learningproblems.PosOnlyDefinitionLP; -//import org.dllearner.parser.ConfParser; import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.cli.*; -//import org.dllearner.cli.ConfFileOption; -//import org.dllearner.cli.Start; -//import org.dllearner.core.config.*; - /** * Open a config file. * @@ -62,11 +58,10 @@ /** * parse to file */ + @SuppressWarnings("unchecked") public void startParser() { - // KNOWLEDGE SOURCE + // KNOWLEDGE SOURCE (sparql or nothing) if (config.getKnowledgeSource() != null) { - // System.out.println("knowledge_source: " + - // config.getKnowledgeSource().getClass()); // KBFile or OWLFile if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile") || config.getKnowledgeSource().getClass().toString().endsWith("OWLFile")) { @@ -76,11 +71,13 @@ if (url != null) { System.out.println("import(\"" + url + "\");"); } - // filename - String filename = (String) config.getComponentManager().getConfigOptionValue( - config.getKnowledgeSource(), "filename"); - if (filename != null) { - System.out.println("import(\"" + filename + "\");"); + // filename (only for KBFile) + if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile")) { + String filename = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "filename"); + if (filename != null) { + System.out.println("import(\"" + filename + "\");"); + } } } // sparql @@ -88,36 +85,59 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - System.out.println("import(\"" + url + "\",\"SPARQL\");"); - // widgets - String prefix = "sparql"; - Component component = config.getKnowledgeSource(); + setFileEntry(config.getKnowledgeSource()); + } + } + } + // REASONER + if (config.getReasoner() != null) { + setFileEntry(config.getReasoner()); + } + // LEARNING PROBLEM + if (config.getLearningProblem() != null) { + setFileEntry(config.getLearningProblem()); + } + // LEARNING ALGORITHM + if (config.getLearningAlgorithm() != null) { + setFileEntry(config.getLearningAlgorithm()); + } - Class<? extends Component> componentOption = component.getClass(); // config.getKnowledgeSource().getClass(); - List<ConfigOption<?>> optionList; - optionList = ComponentManager.getConfigOptions(componentOption); - // System.out.println(optionList); - // System.out.println(config.getComponentManager().getConfigOptionValue(component, - // optionName)); - for (int i = 0; i < optionList.size(); i++) { - // if - // (optionList.get(i).getClass().toString().contains("IntegerConfigOption")) - // { - // widgetPanel = new WidgetPanelInteger(config, - // component, oldComponent, componentOption, - // optionList.get(i)); - // System.out.println(optionList.get(i)); - System.out.println(prefix - + "." - + optionList.get(i).getName() - + " = " - + config.getComponentManager().getConfigOptionValue(component, - optionList.get(i).getName())); - System.out.println(config.getComponentManager().getKnowledgeSources() - .get(0)); - // } - } + } + + /** + * Set all entrys to file. + * + * @param component + * i.e. config.getKnowledgeSource(), config.getResaoner(), ... + */ + @SuppressWarnings("unchecked") + public void setFileEntry(Component component) { + // get prefix map + Map<Class<? extends Component>, String> componentPrefixMapping = Start + .createComponentPrefixMapping(); + String prefix = componentPrefixMapping.get(component.getClass()); + if (prefix == null) + return; + Class<? extends Component> componentOption = component.getClass(); + List<ConfigOption<?>> optionList = ComponentManager.getConfigOptions(componentOption); + for (int i = 0; i < optionList.size(); i++) { + try { + Object dflt = optionList.get(i).getDefaultValue(); + Object value = config.getComponentManager().getConfigOptionValue(component, + optionList.get(i).getName()); + // System.out.println("default: " + dflt); + if (optionList.get(i).getName() != "url" + && optionList.get(i).getName() != "filename" && value != null) { + if (value != null) + if (!value.equals(dflt)) { + ConfigOption specialOption = config.getComponentManager() + .getConfigOption(componentOption, optionList.get(i).getName()); + ConfigEntry entry = new ConfigEntry(specialOption, value); + System.out.println(entry.toConfString(prefix)); + } } + } catch (InvalidConfigOptionValueException e) { + e.printStackTrace(); } } } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-28 23:17:17 UTC (rev 665) @@ -69,7 +69,10 @@ } public void actionPerformed(ActionEvent e) { - + if (cb.getSelectedIndex() == 0) + value = false; + else + value = true; setEntry(); } @@ -100,14 +103,14 @@ else setEntry(); // set cb-index - if (value == false) + if (!value) cb.setSelectedIndex(0); else cb.setSelectedIndex(1); } } // default value - if (value != null && configOption.getDefaultValue() != null) { + else if (value != null && configOption.getDefaultValue() != null) { value = (Boolean) configOption.getDefaultValue(); } // value == null? @@ -115,12 +118,11 @@ value = false; } // set cb-index - if (value == false) + if (!value) cb.setSelectedIndex(0); else cb.setSelectedIndex(1); cb.addActionListener(this); - widgetPanel.add(cb); } // UNKNOWN @@ -139,10 +141,6 @@ @Override public void setEntry() { BooleanConfigOption specialOption; - if (cb.getSelectedIndex() == 0) - value = false; - else - value = true; specialOption = (BooleanConfigOption) config.getComponentManager().getConfigOption( componentOption, configOption.getName()); if (specialOption.isValidValue(value)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |