From: <ton...@us...> - 2008-02-29 05:41:41
|
Revision: 668 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=668&view=rev Author: tonytacker Date: 2008-02-28 21:41:38 -0800 (Thu, 28 Feb 2008) Log Message: ----------- save file works 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/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/gui/ConfigLoad.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -62,9 +62,9 @@ public String getValueFormatting(Boolean value, Integer special) { if (value != null) { if (value) - return "true"; + return "true;"; else - return "false"; + 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-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-29 05:41:38 UTC (rev 668) @@ -57,12 +57,12 @@ * @return a formatted string */ public String toConfString(String componentName) { - if (option.getName() == "positiveExamples") { + if (option.getName().equalsIgnoreCase("positiveExamples")) { return option.getValueFormatting(value, 1); - } else if (option.getName() == "negativeExamples") { + } else if (option.getName().equalsIgnoreCase("negativeExamples")) { return option.getValueFormatting(value, 2); - } else - return componentName.toString() + "." + option.getName() + " = " + } + return componentName.toString() + "." + option.getName() + " = " + option.getValueFormatting(value, 0); } } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -110,7 +110,7 @@ @Override public String getValueFormatting(Double value, Integer special) { if (value != null) - return value.toString(); + 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-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -110,7 +110,7 @@ @Override public String getValueFormatting(Integer value, Integer special) { if (value != null) - return value.toString(); + 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-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -92,7 +92,7 @@ @Override public String getValueFormatting(String value, Integer special) { if (value != null) - return value.toString(); + 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-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -91,8 +91,13 @@ } // negative examples if (value != null && special == 2) { + Integer count = 0; for (String i : value) { - back += "\n-\"" + i + "\""; + count++; + if (count == 1) + back += "-\"" + i + "\""; + else + back += "\n-\"" + i + "\""; } return back + "\n"; } Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-29 05:41:38 UTC (rev 668) @@ -93,6 +93,7 @@ config.setKnowledgeSource(config.getKnowledgeSource()); Start.configureComponent(config.getComponentManager(), config.getKnowledgeSource(), componentPrefixMapping, parser); + startGUI.updateTabColors(); // init if (config.getKnowledgeSource() != null && config.isSetURL()) { try { Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-29 05:41:38 UTC (rev 668) @@ -31,6 +31,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.cli.*; +import java.io.PrintWriter; /** * Open a config file. @@ -57,9 +58,12 @@ /** * parse to file + * + * @param out + * is a PrintWriter to a file */ @SuppressWarnings("unchecked") - public void startParser() { + public void startParser(PrintWriter out) { // KNOWLEDGE SOURCE (sparql or nothing) if (config.getKnowledgeSource() != null) { // KBFile or OWLFile @@ -69,14 +73,19 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - System.out.println("import(\"" + url + "\");"); + if (url.startsWith("file")) + url = url.substring(url.lastIndexOf("/") + 1); + // System.out.println("import(\"" + url + "\");"); + out.println("import(\"" + url + "\");"); } // 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 + "\");"); + filename = filename.substring(filename.lastIndexOf("/") + 1); + // System.out.println("import(\"" + filename + "\");"); + out.println("import(\"" + filename + "\");"); } } } @@ -85,21 +94,22 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - setFileEntry(config.getKnowledgeSource()); + out.println("import(\"" + url + "\",\"SPARQL\");"); + setFileEntry(config.getKnowledgeSource(), out); } } } // REASONER if (config.getReasoner() != null) { - setFileEntry(config.getReasoner()); + setFileEntry(config.getReasoner(), out); } // LEARNING PROBLEM if (config.getLearningProblem() != null) { - setFileEntry(config.getLearningProblem()); + setFileEntry(config.getLearningProblem(), out); } // LEARNING ALGORITHM if (config.getLearningAlgorithm() != null) { - setFileEntry(config.getLearningAlgorithm()); + setFileEntry(config.getLearningAlgorithm(), out); } } @@ -111,7 +121,7 @@ * i.e. config.getKnowledgeSource(), config.getResaoner(), ... */ @SuppressWarnings("unchecked") - public void setFileEntry(Component component) { + public void setFileEntry(Component component, PrintWriter out) { // get prefix map Map<Class<? extends Component>, String> componentPrefixMapping = Start .createComponentPrefixMapping(); @@ -125,7 +135,7 @@ Object dflt = optionList.get(i).getDefaultValue(); Object value = config.getComponentManager().getConfigOptionValue(component, optionList.get(i).getName()); - // System.out.println("default: " + dflt); + // not for url or filename if (optionList.get(i).getName() != "url" && optionList.get(i).getName() != "filename" && value != null) { if (value != null) @@ -133,7 +143,7 @@ ConfigOption specialOption = config.getComponentManager() .getConfigOption(componentOption, optionList.get(i).getName()); ConfigEntry entry = new ConfigEntry(specialOption, value); - System.out.println(entry.toConfString(prefix)); + out.println(entry.toConfString(prefix)); } } } catch (InvalidConfigOptionValueException e) { Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-29 05:41:38 UTC (rev 668) @@ -33,6 +33,8 @@ import org.apache.log4j.SimpleLayout; import java.io.File; +import java.io.PrintWriter; +import java.io.FileWriter; import javax.swing.filechooser.FileFilter; /** @@ -59,7 +61,7 @@ private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); private JMenuItem openItem = new JMenuItem("Open Config"); - private JMenuItem saveItem = new JMenuItem("Save Config"); + private JMenuItem saveItem = new JMenuItem("Save As Config"); public StartGUI() { this.setTitle("DL-Learner"); @@ -140,10 +142,37 @@ configLoad.startParser(); } } - // save config file + // save as config file if (e.getSource() == saveItem) { - System.out.println("saveItem was pressed"); - configSave.startParser(); + JFileChooser fc = new JFileChooser(new File("examples/")); + // FileFilter only *.conf + fc.addChoosableFileFilter(new FileFilter() { + @Override + public boolean accept(File f) { + if (f.isDirectory()) + return true; + return f.getName().toLowerCase().endsWith(".conf"); + } + + @Override + public String getDescription() { + return "*.conf"; // name for filter + } + }); + if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { + // System.out.println("FILE: " + fc.getSelectedFile()); + File file = fc.getSelectedFile(); + try { + PrintWriter out = new PrintWriter(new FileWriter(file)); + // out.println("test"); + configSave.startParser(out); + out.flush(); + out.close(); + } catch (Exception ex2) { + System.out.println(ex2); + } + } + System.out.println("config file saved"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |