From: <ton...@us...> - 2008-02-25 17:58:43
|
Revision: 638 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=638&view=rev Author: tonytacker Date: 2008-02-25 09:58:40 -0800 (Mon, 25 Feb 2008) Log Message: ----------- first try to save config, add method toConfString in ConfigEntry 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/StartGUI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -50,4 +50,12 @@ return true; } + /* (non-Javadoc) + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Boolean value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-25 17:58:40 UTC (rev 638) @@ -52,4 +52,12 @@ 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); + } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -85,4 +85,6 @@ return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; } + public abstract String getValueFormatting(T value); + } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -97,4 +97,14 @@ return str; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Double value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -19,38 +19,39 @@ */ package org.dllearner.core.config; - /** * A configuration option, which allows values of type integer. A minimum and * maximum value of the argument can optionally be specified. * * @author Jens Lehmann - * + * */ public class IntegerConfigOption extends ConfigOption<Integer> { private int lowerLimit = Integer.MIN_VALUE; private int upperLimit = Integer.MAX_VALUE; - + public IntegerConfigOption(String name, String description) { super(name, description); } - + public IntegerConfigOption(String name, String description, int defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(Integer 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(int lowerLimit) { this.lowerLimit = lowerLimit; @@ -73,13 +75,16 @@ } /** - * @param upperLimit The highest possible value for this configuration option. + * @param upperLimit + * The highest possible value for this configuration option. */ public void setUpperLimit(int upperLimit) { this.upperLimit = upperLimit; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -90,11 +95,20 @@ @Override public String getAllowedValuesDescription() { String str = getClass().toString(); - if(lowerLimit != Integer.MIN_VALUE) + if (lowerLimit != Integer.MIN_VALUE) str += " min " + lowerLimit; - if(upperLimit != Integer.MAX_VALUE) + if (upperLimit != Integer.MAX_VALUE) str += " max " + upperLimit; return str; - } - + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Integer value) { + return value.toString(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -23,37 +23,38 @@ import java.util.Set; import java.util.TreeSet; - /** * A configuration option, which allows values of type String. Optionally a set * of allowed strings can be set. By default all strings are allowed. * * @author Jens Lehmann - * + * */ public class StringConfigOption extends ConfigOption<String> { private Set<String> allowedValues = new TreeSet<String>();; - + public StringConfigOption(String name, String description) { super(name, description); } - + public StringConfigOption(String name, String description, String defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(String value) { - if(allowedValues.size() == 0 || allowedValues.contains(value)) + if (allowedValues.size() == 0 || allowedValues.contains(value)) return true; else return false; - } - + } + /** * @return the allowedValues */ @@ -62,7 +63,8 @@ } /** - * @param allowedValues the allowedValues to set + * @param allowedValues + * the allowedValues to set */ public void setAllowedValues(Set<String> allowedValues) { this.allowedValues = allowedValues; @@ -71,8 +73,10 @@ public void setAllowedValues(String[] allowedValues) { this.allowedValues = new TreeSet<String>(Arrays.asList(allowedValues)); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -80,4 +84,14 @@ return (object instanceof String); } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(String value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -21,20 +21,21 @@ import java.util.Set; - /** * A set of strings. * * @author Jens Lehmann - * + * */ public class StringSetConfigOption extends ConfigOption<Set<String>> { public StringSetConfigOption(String name, String description) { super(name, description); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -42,21 +43,33 @@ return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { - if(!(object instanceof Set)) + if (!(object instanceof Set)) return false; - + Set<?> set = (Set<?>) object; - for(Object element : set) { - if(!(element instanceof String)) + for (Object element : set) { + if (!(element instanceof String)) return false; } - + return true; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Set<String> value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -24,8 +24,8 @@ import org.dllearner.utilities.StringTuple; /** - * A list if string tuples, for instance for specifying several - * parameters or replacement rules. + * A list if string tuples, for instance for specifying several parameters or + * replacement rules. * * @author Jens Lehmann */ @@ -34,29 +34,34 @@ public StringTupleListConfigOption(String name, String description) { this(name, description, null); } - - public StringTupleListConfigOption(String name, String description, List<StringTuple> defaultValue) { + + public StringTupleListConfigOption(String name, String description, + List<StringTuple> defaultValue) { super(name, description, defaultValue); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { - if(!(object instanceof List)) + if (!(object instanceof List)) return false; - + List<?> set = (List<?>) object; - for(Object element : set) { - if(!(element instanceof StringTuple)) + for (Object element : set) { + if (!(element instanceof StringTuple)) return false; } - + return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -64,4 +69,14 @@ return true; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(List<StringTuple> value) { + return value.toString(); + } + } Added: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-25 17:58:40 UTC (rev 638) @@ -0,0 +1,125 @@ +package org.dllearner.gui; + +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +//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 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.ConfigOption; + +//import org.dllearner.cli.ConfFileOption; +//import org.dllearner.cli.Start; +//import org.dllearner.core.config.*; + +/** + * Open a config file. + * + * @author Tilo Hielscher + */ +public class ConfigSave { + + // private File file; + private Config config; + + // private StartGUI startGUI; + + /** + * set config and startGUI + * + * @param config + * @param startGUI + */ + public ConfigSave(Config config, StartGUI startGUI) { + this.config = config; + // this.startGUI = startGUI; + } + + /** + * parse to file + */ + public void startParser() { + // KNOWLEDGE SOURCE + 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")) { + // url + String url = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "url"); + 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 + "\");"); + } + } + // sparql + if (config.getKnowledgeSource().getClass().toString().endsWith("SparqlKnowledgeSource")) { + 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(); + + 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)); + // } + } + } + } + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-25 17:58:40 UTC (rev 638) @@ -48,6 +48,7 @@ private Config config = new Config(); private ConfigLoad configLoad = new ConfigLoad(config, this);; + private ConfigSave configSave = new ConfigSave(config, this);; private KnowledgeSourcePanel tab0; private ReasonerPanel tab1; @@ -142,6 +143,7 @@ // save config file if (e.getSource() == saveItem) { System.out.println("saveItem was pressed"); + configSave.startParser(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |