From: <ton...@us...> - 2008-01-18 16:40:04
|
Revision: 393 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=393&view=rev Author: tonytacker Date: 2008-01-18 08:40:00 -0800 (Fri, 18 Jan 2008) Log Message: ----------- - add negative Examples - add all LearningProblems 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/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-18 16:40:00 UTC (rev 393) @@ -46,8 +46,8 @@ private String uri; private ReasonerComponent reasoner; private ReasoningService rs; - private String[] kbBoxItems = {"Pleae select a type", "KBFile", "OWLFile", "SparqleEndpoint"}; - private Set<String> exampleSet = new HashSet<String>(); + private Set<String> posExampleSet = new HashSet<String>(); + private Set<String> negExampleSet = new HashSet<String>(); private LearningProblem lp; private LearningAlgorithm la; @@ -106,10 +106,6 @@ rs = input; } - protected String[] getKBBoxItems() { - return kbBoxItems; - } - protected KnowledgeSource getKnowledgeSource() { return source; } @@ -119,15 +115,24 @@ source = input; } - protected void setExampleSet(Set<String> input) { + protected void setPosExampleSet(Set<String> posExampleSet) { status[5] = true; - exampleSet = input; + this.posExampleSet = posExampleSet; } - protected Set<String> getExampleSet () { - return exampleSet; + protected Set<String> getPosExampleSet () { + return this.posExampleSet; } + protected void setNegExampleSet(Set<String> negExampleSet) { + status[5] = true; + this.negExampleSet = negExampleSet; + } + + protected Set<String> getNegExampleSet () { + return this.negExampleSet; + } + protected void setLearningProblem (LearningProblem input) { status[6] = true; lp = input; Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -71,7 +71,7 @@ fileDisplay = new JTextField(35); fileDisplay.setEditable(true); - // update config if textfield changed + // update config if textfield fileDisplay changed fileDisplay.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { config.setURI(fileDisplay.getText()); @@ -84,10 +84,9 @@ } }); - // parse + // add to comboBox for (int i=0; i<sources.size(); i++) { - String ksClass = sources.get(i).toString().substring(23).concat(".class"); - cb.addItem(ksClass); + cb.addItem(sources.get(i).getSimpleName()); } cb.addActionListener(this); @@ -119,7 +118,7 @@ int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String URI = "file://"; - URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI's + URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI config.setURI(URI); //save variable fileDisplay.setText(URI); } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -21,12 +21,23 @@ */ import java.awt.BorderLayout; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; -import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.dl.Individual; +//import org.dllearner.learningproblems.*; /** * LearningProblemPanel @@ -39,32 +50,166 @@ private static final long serialVersionUID = -3819627680918930203L; + private List<Class<? extends LearningProblem>> problems; + private String[] lpBoxItems = {}; + private JComboBox cb = new JComboBox(lpBoxItems); + private JPanel choosePanel = new JPanel(); + private JPanel centerPanel = new JPanel(); private JPanel lpPanel = new JPanel(); - private JButton lpButton; + private JLabel posLabel = new JLabel("positive Examples"); + private JLabel negLabel = new JLabel("negative Examples"); + private JButton initButton, readListButton; + private int choosenClassIndex; + private List<Individual> individuals; + private JList posList = new JList(); + private JList negList = new JList(); private Config config; - LearningProblemPanel(Config config) { + LearningProblemPanel(final Config config) { super(new BorderLayout()); this.config = config; - lpButton = new JButton("Use PosOnlyDefinitionLP"); - lpButton.addActionListener(this); + initButton = new JButton("Init LearningProblem"); + initButton.addActionListener(this); - lpPanel.add(lpButton); - add(lpPanel, BorderLayout.PAGE_START); + readListButton = new JButton("Read List"); + readListButton.addActionListener(this); + + choosePanel.add(cb); + choosePanel.add(readListButton); + lpPanel.add(initButton); + add(choosePanel, BorderLayout.PAGE_START); + add(centerPanel, BorderLayout.CENTER); + add(lpPanel, BorderLayout.PAGE_END); + + problems = config.getComponentManager().getLearningProblems(); + + // add into comboBox + for (int i=0; i<problems.size(); i++) { + cb.addItem(problems.get(i).getSimpleName()); + } + + // read choosen LearningProblem + choosenClassIndex = cb.getSelectedIndex(); + + // create a scrollable list of positive examples + posList = new JList(); + posList.setLayoutOrientation(JList.VERTICAL); + posList.setVisibleRowCount(-1); + JScrollPane posListScroller = new JScrollPane(posList); + posListScroller.setPreferredSize(new Dimension(300, 200)); + + // create a scrollable list of negative examples + negList = new JList(); + negList.setLayoutOrientation(JList.VERTICAL); + negList.setVisibleRowCount(-1); + JScrollPane negListScroller = new JScrollPane(negList); + negListScroller.setPreferredSize(new Dimension(300, 200)); + + // define GridBag + GridBagLayout gridbag = new GridBagLayout(); + centerPanel.setLayout(gridbag); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + + buildConstraints(constraints, 0, 0, 1, 1, 100, 100); + gridbag.setConstraints(posLabel, constraints); + centerPanel.add(posLabel); + + buildConstraints(constraints, 1, 0, 1, 1, 100, 100); + gridbag.setConstraints(negLabel, constraints); + centerPanel.add(negLabel); + + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(posListScroller, constraints); + centerPanel.add(posListScroller); + + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(negListScroller, constraints); + centerPanel.add(negListScroller); + + add(centerPanel, BorderLayout.CENTER); + + // listener for posList + posList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> posExampleSet = new HashSet<String>(); + int[] selectedIndices = posList.getSelectedIndices(); + for(int i : selectedIndices) + posExampleSet.add(individuals.get(i).toString()); + config.setPosExampleSet(posExampleSet); + System.out.println("posList: " + config.getPosExampleSet() ); + } + }); + + // listener for negList + negList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> negExampleSet = new HashSet<String>(); + int[] selectedIndices = negList.getSelectedIndices(); + for(int i : selectedIndices) + negExampleSet.add(individuals.get(i).toString()); + config.setNegExampleSet(negExampleSet); + System.out.println("negList: " + config.getNegExampleSet() ); + } + }); } public void actionPerformed(ActionEvent e) { - if (e.getSource() == lpButton) { + // read selected LearningProblemClass + choosenClassIndex = cb.getSelectedIndex(); + + // later for read options + //List a = config.getComponentManager().getConfigOptions(problems.get(cb.getSelectedIndex())); + //System.out.println("optionName: " + a); + + // get list after reasoner init + if (e.getSource() == readListButton) { + // fill lists + if (config.getStatus(4)) { // only with a reasoner + Set<Individual> individualsSet = config.getReasoningService().getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + DefaultListModel listModel = new DefaultListModel(); + for(Individual ind : individuals) { + listModel.addElement(ind); + } + posList.setModel(listModel); + negList.setModel(listModel); + } + } + + //init + if (e.getSource() == initButton) { if (config.getStatus(5)) { - System.out.println(config.getExampleSet()); - config.setLearningProblem(config.getComponentManager().learningProblem(PosOnlyDefinitionLP.class, config.getReasoningService())); - config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", config.getExampleSet()); + config.setLearningProblem(config.getComponentManager().learningProblem(problems.get(choosenClassIndex), config.getReasoningService())); + config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", config.getPosExampleSet()); + config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "negativeExamples", config.getNegExampleSet()); config.getLearningProblem().init(); + System.out.println("init LearningProblem with \n" + problems.get(choosenClassIndex) + "\nand " + "\nposExample: " + + config.getPosExampleSet() + "\nand negExample: " + config.getNegExampleSet()); } } } + /* + * Define GridBagConstraints + */ + private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { + gbc.gridx = gx; + gbc.gridy = gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -21,18 +21,11 @@ */ import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; import javax.swing.*; -import javax.swing.event.*; -import org.dllearner.core.dl.Individual; import org.dllearner.reasoning.DIGReasoner; //import org.dllearner.core.ReasonerComponent; @@ -53,10 +46,7 @@ private static final long serialVersionUID = -7678275020058043937L; private JPanel digPanel = new JPanel(); - private JPanel centerPanel = new JPanel(); - private JButton digButton; - private JList digList = new JList(); - private List<Individual> individuals; + private JButton initButton; private Config config; ReasonerPanel(final Config config) { @@ -64,67 +54,30 @@ this.config = config; - digButton = new JButton("Use DIG by default"); - digButton.addActionListener(this); + initButton = new JButton("Use DIG by default"); + initButton.addActionListener(this); - // create a scrollable list of examples - digList = new JList(); - digList.setLayoutOrientation(JList.VERTICAL); - digList.setVisibleRowCount(-1); - JScrollPane listScroller = new JScrollPane(digList); - listScroller.setPreferredSize(new Dimension(550, 350)); - - digPanel.add(digButton); + digPanel.add(initButton); add(digPanel, BorderLayout.PAGE_START); - - centerPanel.add(listScroller); - add(centerPanel, BorderLayout.CENTER); - - digList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent evt) { - if (evt.getValueIsAdjusting()) - return; - //System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); - // detect which examples have been selected - Set<String> exampleSet = new HashSet<String>(); - int[] selectedIndices = digList.getSelectedIndices(); - for(int i : selectedIndices) - exampleSet.add(individuals.get(i).toString()); - config.setExampleSet(exampleSet); //error - System.out.println("digList: " + config.getExampleSet() ); //error - } - }); - } public void actionPerformed(ActionEvent e) { - if (e.getSource() == digButton) { - // set reasoner - config.setReasoner(config.getComponentManager().reasoner(DIGReasoner.class, config.getKnowledgeSource())); - //System.out.println(StartGUI.myconfig.getKnowledgeSource()); - config.getReasoner().init(); - //System.out.println(StartGUI.myconfig.getReasoner()); + if (e.getSource() == initButton) { + if (config.getStatus(2)) { // no check if button init was used + // set reasoner + config.setReasoner(config.getComponentManager().reasoner(DIGReasoner.class, config.getKnowledgeSource())); + config.getReasoner().init(); - // set ReasoningService - config.setReasoningService(config.getComponentManager().reasoningService(config.getReasoner())); - - // get list from ReasoningService - Set<Individual> individualsSet = config.getReasoningService().getIndividuals(); - //System.out.println("IndividualsSet: " + individualsSet); - individuals = new LinkedList<Individual>(individualsSet); - //System.out.println("individuals: " + individuals); - - // make list - DefaultListModel listModel = new DefaultListModel(); - for(Individual ind : individuals) - listModel.addElement(ind); - - digList.setModel(listModel); - - // graphic - digList.setModel(listModel); - StartGUI.myrun.renew(); + // set ReasoningService + config.setReasoningService(config.getComponentManager().reasoningService(config.getReasoner())); + } + if (config.getStatus(3)) { // Reasoner is set + System.out.println("Reasoner: " + config.getReasoner()); + } + if (config.getStatus(4)) { // ReasoningServic is set + System.out.println("ReasoningService: " + config.getReasoningService()); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |