From: <ton...@us...> - 2008-02-19 15:04:42
|
Revision: 612 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=612&view=rev Author: tonytacker Date: 2008-02-19 07:04:01 -0800 (Tue, 19 Feb 2008) Log Message: ----------- first try to load *.config Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-19 15:04:01 UTC (rev 612) @@ -27,6 +27,8 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasonerComponent; +// import org.dllearner.core.Component; + /** * Config save all together used variables: ComponentManager, KnowledgeSource, * Reasoner, ReasoningService, LearningProblem, LearningAlgorithm; also inits of @@ -38,7 +40,6 @@ private ComponentManager cm = ComponentManager.getInstance(); private KnowledgeSource source; private KnowledgeSource oldSource; - private String uri; private ReasonerComponent reasoner; private ReasonerComponent oldReasoner; private ReasoningService rs; @@ -60,23 +61,18 @@ /** * It is necessary for init KnowledgeSource. * - * @return URI + * @return true, if url was set otherwise false */ - public String getURI() { - return this.uri; + public Boolean isSetURL() { + // return this.isURL; + // String value = (String) cm.getConfigOptionValue(source, "url"); + if (cm.getConfigOptionValue(source, "url") != null) + return true; + else + return false; } /** - * Set an URI. - * - * @param uri - * it's a Link like "http://example.com" or "file://myfile" - */ - public void setURI(String uri) { - this.uri = uri; - } - - /** * Set KnowledgeSource. * * @param knowledgeSource Added: trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-19 15:04:01 UTC (rev 612) @@ -0,0 +1,161 @@ +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 org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; // import +// 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.parser.ConfParser; +import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.core.Component; + +/** + * Open a config file. + * + * @author Tilo Hielscher + */ +public class ConfigLoad { + + private File file; + private Config config; + private StartGUI startGUI; + + private Class<? extends KnowledgeSource> componentOption; + + /** + * set config and startGUI + * + * @param config + * @param startGUI + */ + public ConfigLoad(Config config, StartGUI startGUI) { + this.config = config; + this.startGUI = startGUI; + } + + /** + * set your file to read + * + * @param file + * @return true if file exist + */ + public boolean openFile(File file) { + this.file = file; + return file.exists(); + } + + /** + * parse file + */ + public void startParser() { + if (this.file.exists()) { + ConfParser parser = ConfParser.parseFile(file); + // KNOWLEDGE SOURCE + // filename + String value = parser.getFunctionCalls().get("import").get(0) + .get(0); + // only first of imported files + if (value.endsWith(".kb")) { + componentOption = KBFile.class; + } else if (value.endsWith(".owl")) { + componentOption = OWLFile.class; + } else if (parser.getFunctionCalls().get("import").get(0).size() > 1) { + if (parser.getFunctionCalls().get("import").get(0).get(1) + .equalsIgnoreCase("sparql")) { + System.out.println("IT IS SPARQL"); + componentOption = SparqlKnowledgeSource.class; + } + } + // check if class was set + if (componentOption != null) + config.setKnowledgeSource(config.getComponentManager() + .knowledgeSource(componentOption)); + // set url + // value = parser.getFunctionCalls().get("import").get(0).get(0); + value = makeURL(value); + Component component = config.getKnowledgeSource(); + StringConfigOption specialOption = (StringConfigOption) config + .getComponentManager().getConfigOption(componentOption, + "url"); + try { + ConfigEntry<String> specialEntry = new ConfigEntry<String>( + specialOption, value); + config.getComponentManager().applyConfigEntry(component, + specialEntry); + System.out.println("set String: " + "url" + " = " + value); + } catch (InvalidConfigOptionValueException s) { + s.printStackTrace(); + } + // startGUI.updateTabColors(); + // init + if (config.getKnowledgeSource() != null && config.isSetURL()) { + try { + config.getKnowledgeSource().init(); + config.setInitKnowledgeSource(true); + System.out.println("init KnowledgeSource"); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + } + + // update + 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()); + + // do it + // only url from first entry, ignore others + // parser.getFunctionCalls().get("import").get(0); + } + } + + /** + * If value is not a valid url and starts with "http://" or "file://" then + * add "file://" + * + * @param value + * is a string + * @return a valid url made from value + */ + public String makeURL(String value) { + if (!value.startsWith("http://") && !value.startsWith("file://")) + value = "file://".concat(file.getPath().replace(file.getName(), "") + .concat(value)); + return value; + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-19 15:04:01 UTC (rev 612) @@ -29,9 +29,10 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; +import org.dllearner.kb.*; /** - * KnowledgeSourcePanel, tab 1. Choose Source, change Options and final initiate + * KnowledgeSourcePanel, tab 0. Choose Source, change Options and final initiate * KnowledgeSource. * * @author Tilo Hielscher @@ -59,6 +60,8 @@ this.startGUI = startGUI; sources = config.getComponentManager().getKnowledgeSources(); + System.out.println("SOURCES: " + sources); + setButton = new JButton("Set"); setButton.addActionListener(this); initButton = new JButton("Init KnowledgeSource"); @@ -74,6 +77,8 @@ choosePanel.add(cb); choosePanel.add(setButton); + choosenClassIndex = cb.getSelectedIndex(); + optionPanel = new OptionPanel(config, config.getKnowledgeSource(), config.getOldKnowledgeSource(), sources.get(choosenClassIndex)); initPanel.add(initButton); @@ -82,9 +87,8 @@ add(optionPanel, BorderLayout.CENTER); add(initPanel, BorderLayout.PAGE_END); - choosenClassIndex = cb.getSelectedIndex(); - setSource(); - updateInitButtonColor(); + // setSource(); + updateAll(); } public void actionPerformed(ActionEvent e) { @@ -92,13 +96,13 @@ // choosenClassIndex = cb.getSelectedIndex(); if (choosenClassIndex != cb.getSelectedIndex()) { choosenClassIndex = cb.getSelectedIndex(); - config.setURI(null); // default null config.setInitKnowledgeSource(false); setSource(); } - if (e.getSource() == setButton) + if (e.getSource() == setButton) { setSource(); + } if (e.getSource() == initButton) init(); @@ -108,16 +112,31 @@ * after this, you can change widgets */ public void setSource() { - config.setKnowledgeSource(config.getComponentManager().knowledgeSource( - sources.get(choosenClassIndex))); - updateOptionPanel(); + System.out.println("cm: " + config.getComponentManager()); + System.out.println("setSOURCE :" + sources.get(choosenClassIndex)); + + config.setKnowledgeSource(config.getComponentManager().knowledgeSource(sources.get(choosenClassIndex))); +// KBFile.class doesn't work +// config.setKnowledgeSource(config.getComponentManager().knowledgeSource(KBFile.class)); + + + System.out.println("KNOWLEDGE_SOURCE: " + config.getKnowledgeSource()); + System.out + .println("ABC: " + + config.getComponentManager().getComponentName( + sources.get(0))); + + config.setInitKnowledgeSource(false); + updateAll(); } /** * after this, next tab can be used */ public void init() { - if (config.getKnowledgeSource() != null && config.getURI() != null) { + System.out.println("KNOWLEDGE_SOURCE: " + config.getKnowledgeSource()); + System.out.println("isSetURL: " + config.isSetURL()); + if (config.getKnowledgeSource() != null && config.isSetURL()) { try { config.getKnowledgeSource().init(); config.setInitKnowledgeSource(true); @@ -130,6 +149,29 @@ } /** + * updateAll + */ + public void updateAll() { + updateComboBox(); + updateOptionPanel(); + updateInitButtonColor(); + } + + /** + * set ComboBox to selected class + */ + public void updateComboBox() { + if (config.getKnowledgeSource() != null) + for (int i = 0; i < sources.size(); i++) + if (config.getKnowledgeSource().getClass().equals( + config.getComponentManager().getKnowledgeSources().get( + i))) { + cb.setSelectedIndex(i); + } + this.choosenClassIndex = cb.getSelectedIndex(); + } + + /** * update OptionPanel with new selection */ public void updateOptionPanel() { @@ -146,4 +188,5 @@ } else initButton.setForeground(Color.BLACK); } + } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-19 15:04:01 UTC (rev 612) @@ -32,7 +32,7 @@ import org.dllearner.core.LearningProblemUnsupportedException; /** - * LearningAlgorithmPanel, tab 4. Choose LearningAlgorithm, change Options and + * LearningAlgorithmPanel, tab 3. Choose LearningAlgorithm, change Options and * final initiate LearningAlgorithm. * * @author Tilo Hielscher Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-19 15:04:01 UTC (rev 612) @@ -31,7 +31,7 @@ import org.dllearner.core.LearningProblem; /** - * LearningProblemPanel tab 3. Choose LearingProblem, change Options and final + * LearningProblemPanel tab 2. Choose LearingProblem, change Options and final * initiate LearningProblem. * * @author Tilo Hielscher Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-19 15:04:01 UTC (rev 612) @@ -32,7 +32,7 @@ import org.dllearner.core.ReasonerComponent; /** - * ReasonerPanel, tab 2. Choose Resoner, change Options and final initiate + * ReasonerPanel, tab 1. Choose Resoner, change Options and final initiate * Reasoner and ReasoningService. * * @author Tilo Hielscher Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-19 15:04:01 UTC (rev 612) @@ -32,6 +32,9 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import java.io.File; +import javax.swing.filechooser.FileFilter; + /** * StartGUI * @@ -44,6 +47,7 @@ private JTabbedPane tabPane = new JTabbedPane(); private Config config = new Config(); + private ConfigLoad configLoad = new ConfigLoad(config, this);; private KnowledgeSourcePanel tab0; private ReasonerPanel tab1; @@ -61,10 +65,11 @@ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationByPlatform(true); this.setSize(800, 600); - + // set icon - setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("icon.gif"))); - + setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage( + this.getClass().getResource("icon.gif"))); + tab0 = new KnowledgeSourcePanel(config, this); tab1 = new ReasonerPanel(config, this); tab2 = new LearningProblemPanel(config, this); @@ -110,14 +115,37 @@ } public void actionPerformed(ActionEvent e) { + // open config file if (e.getSource() == openItem) { - System.out.println("openItem was pressed"); + // file dialog + JFileChooser fc = new JFileChooser(new File("examples/")); + // FileFilter only *.conf + fc.addChoosableFileFilter(new FileFilter() { + public boolean accept(File f) { + if (f.isDirectory()) + return true; + return f.getName().toLowerCase().endsWith(".conf"); + } + + public String getDescription() { + return "*.conf"; // name for filter + } + }); + if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + System.out.println("FILE: " + fc.getSelectedFile()); + configLoad.openFile(fc.getSelectedFile()); + configLoad.startParser(); + } } + // save config file if (e.getSource() == saveItem) { System.out.println("saveItem was pressed"); } } + /** + * Update colors of tabulators; red should be clicked, black for OK. + */ public void updateTabColors() { if (config.isInitKnowledgeSource()) tabPane.setForegroundAt(0, Color.BLACK); @@ -138,7 +166,7 @@ tabPane.setForegroundAt(3, Color.RED); tabPane.setForegroundAt(4, Color.RED); } - tab0.updateInitButtonColor(); + tab0.updateAll(); tab1.updateInitButtonColor(); tab2.updateInitButtonColor(); tab3.updateInitButtonColor(); Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-19 14:28:23 UTC (rev 611) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-19 15:04:01 UTC (rev 612) @@ -84,8 +84,6 @@ if (returnVal == JFileChooser.APPROVE_OPTION) { value = fc.getSelectedFile().toString(); stringField.setText(value); - config.setURI(value); // save variable - System.out.println("value: " + config.getURI()); } } setEntry(); @@ -93,7 +91,6 @@ // necessary for init knowledge source if (configOption.getName().equalsIgnoreCase("url") && !value.equalsIgnoreCase("")) { - config.setURI(value); } } } @@ -180,7 +177,7 @@ System.out.println("String: not valid value"); } - /* + /** * Widget filename getName() == filename you should open a file dialog in * ActionPerformed */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |