From: <hee...@us...> - 2008-04-18 11:15:58
|
Revision: 798 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=798&view=rev Author: heeroyuy Date: 2008-04-18 04:15:47 -0700 (Fri, 18 Apr 2008) Log Message: ----------- -small design change -add thread to rum learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassView.java Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-04-18 11:15:47 UTC (rev 798) @@ -1,24 +1,49 @@ package org.dllearner.tools.protege; + + import java.awt.event.*; -public class ActionHandler implements ActionListener, ItemListener{ +import java.util.Observable; +public class ActionHandler extends Observable implements ActionListener, ItemListener { private DLLearnerModel model; - - public ActionHandler(ActionHandler a,DLLearnerModel m) + private SuggestEquivalentClassView view; + private Thread dlLearner; + public ActionHandler(ActionHandler a,DLLearnerModel m, SuggestEquivalentClassView s) { + view = s; model = m; } public void actionPerformed(ActionEvent z){ + if(z.getActionCommand().equals("RUN")) { - model.configDLLearner(); - model.DLLearnerStart(); - //setChanged(); - //notifyObservers(model.getSolutions()); - System.out.println(model.getSolutions()); - //config.setDescriptionList(model.getSolutions()); + dlLearner = new Thread(model); + System.out.println("test"); + view.getStartButton().setEnabled(false); + view.getStopButton().setEnabled(true); + dlLearner.start(); } - } + + if(z.getActionCommand().equals("Cancel")) + { + System.out.println(dlLearner.isInterrupted()); + model.getLearningAlgorithm().stop(); + view.destroyListener(); + view.getStartButton().setEnabled(true); + view.getStopButton().setEnabled(false); + System.out.println(dlLearner.isInterrupted()); + String error = "Learning aborted"; + dlLearner.interrupt(); + System.out.println(dlLearner.isInterrupted()); + view.renderErrorMessage(error); + } + + if(z.getActionCommand().equals("ADD")) + { + String message ="Ausgezeichnet *Mr.Burns*"; + view.renderErrorMessage(message); + } + } public void itemStateChanged(ItemEvent i) @@ -26,5 +51,15 @@ } - + public void textValueChanged(TextEvent t) + { + + + } + + public void destroyThread() + { + view.getStartButton().setEnabled(true); + view.getStopButton().setEnabled(false); + } } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2008-04-18 11:15:47 UTC (rev 798) @@ -17,7 +17,6 @@ addSection(new OWLEquivalentClassesAxiomFrameSection(editorKit, this)); addSection(new SuggestEquivalentClassButton(editorKit, this)); addSection(new OWLSubClassAxiomFrameSection(editorKit, this)); - //addSection(new SuggestClassButton(editorKit, this)); addSection(new InheritedAnonymousClassesFrameSection(editorKit, this)); addSection(new OWLClassAssertionAxiomIndividualSection(editorKit, this)); addSection(new OWLDisjointClassesAxiomFrameSection(editorKit, this)); Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-04-18 11:15:47 UTC (rev 798) @@ -14,7 +14,7 @@ import org.dllearner.reasoning.*; import org.dllearner.learningproblems.*; -public class DLLearnerModel extends Observable{ +public class DLLearnerModel extends Observable implements Runnable{ private String[] componenten={"org.dllearner.kb.OWLFile","org.dllearner.reasoning.OWLAPIReasoner", "org.dllearner.reasoning.DIGReasoner","org.dllearner.reasoning.FastRetrievalReasoner","org.dllearner.learningproblems.PosNegInclusionLP" ,"org.dllearner.learningproblems.PosNegDefinitionLP","org.dllearner.algorithms.RandomGuesser","org.dllearner.algorithms.BruteForceLearner","org.dllearner.algorithms.refinement.ROLearner","org.dllearner.algorithms.refexamples.ExampleBasedROLComponent","org.dllearner.algorithms.gp.GP"}; @@ -26,7 +26,8 @@ private ReasoningService rs; private static final int anzahl = 10; private String[] description = new String[anzahl]; - + private LearningProblem lp; + private LearningAlgorithm la = null; public DLLearnerModel() { @@ -43,8 +44,14 @@ negativ=neg; uri=s; } - public void configDLLearner() + + + public void startPosNegDefinitionReasoning() { + + } + public void run() + { ComponentManager.setComponentClasses(componenten); // get singleton instance of component manager cm = ComponentManager.getInstance(); @@ -67,16 +74,9 @@ } rs = cm.reasoningService(reasoner); - } - - public void startPosNegDefinitionReasoning() - { - - } - public void DLLearnerStart() - { + lp = cm.learningProblem(PosNegDefinitionLP.class, rs); // create a learning problem and set positive and negative examples - LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + Set<String> positiveExamples = new TreeSet<String>(); for(int i=0;i<positiv.size();i++) { @@ -103,9 +103,8 @@ } // create the learning algorithm - LearningAlgorithm la = null; try { - la = cm.learningAlgorithm(ROLearner.class, lp, rs); + this.la = cm.learningAlgorithm(ROLearner.class, lp, rs); } catch (LearningProblemUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -121,6 +120,7 @@ // start the algorithm and print the best concept found la.start(); + System.out.println(la.getSolutionScore()); description[0]=la.getBestSolution().toString(); setChanged(); notifyObservers(description); @@ -181,5 +181,10 @@ return description; } + public LearningAlgorithm getLearningAlgorithm() + { + return la; + } + } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-04-18 11:15:47 UTC (rev 798) @@ -6,7 +6,7 @@ Bundle-Description: blablabla Bundle-Vendor: blablabla Bundle-DocURL: blablabla -Bundle-ClassPath: .,lib/xbean.jar,lib/dig1.1-xmlbeans.jar,lib/junit-4.4.jar,log4j.jar,lib/components.ini,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.jar +Bundle-ClassPath: .,lib/junit-4.4.jar,log4j.jar,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.jar Import-Package: org.osgi.framework,org.apache.log4j Export-Package: lib Bundle-Version: 1.0.0 Modified: trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java 2008-04-18 11:15:47 UTC (rev 798) @@ -18,6 +18,7 @@ private static final String LABEL = "Suggest a equivalent Class"; private OWLFrame<OWLClass> frame; + private SuggestEquivalentClassView view; public SuggestEquivalentClassButton(OWLEditorKit editorKit, OWLFrame<OWLClass> frame) { super(editorKit, LABEL, frame); @@ -52,7 +53,9 @@ public OWLFrameSectionRowObjectEditor<OWLDescription> getObjectEditor() { - return new SuggestEquivalentClassView(getOWLEditorKit(), null, frame); + view = new SuggestEquivalentClassView(getOWLEditorKit(), null, frame); + view.setView(view); + return view; } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassView.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassView.java 2008-04-17 13:02:17 UTC (rev 797) +++ trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassView.java 2008-04-18 11:15:47 UTC (rev 798) @@ -6,18 +6,15 @@ import java.util.*; import org.semanticweb.owl.model.OWLClass; -import org.dllearner.core.owl.Description; import org.protege.editor.owl.ui.frame.OWLFrame; import javax.swing.JButton; import javax.swing.JCheckBox; +import java.awt.*; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.JList; -import javax.swing.JSplitPane; - import org.protege.editor.owl.OWLEditorKit; import org.protege.editor.owl.ui.frame.AbstractOWLFrameSectionRowObjectEditor; import org.semanticweb.owl.model.OWLDescription; @@ -30,56 +27,58 @@ private Vector<JCheckBox> positive = new Vector<JCheckBox>(); private Vector<JCheckBox> negative = new Vector<JCheckBox>(); private JComponent learner; - private JSplitPane split; private JButton accept; private JButton run; private OWLEditorKit editor; private JPanel option; - private JPanel listPanel; - private JScrollPane test; private JList suggest; - private JPanel vorschlag; - private Object[] blub; + private Object[] instances; private JLabel neg; + private final static Color Color_RED = Color.red; + private JButton cancel; + private JLabel errorMessage; private ActionHandler action; private DLLearnerModel model; - private OWLFrame<OWLClass> aktuell; - private JPanel panel; - + private String[] descriptions = new String[10]; + //private OWLFrame<OWLClass> aktuell; + private SuggestEquivalentClassView view; + public void update(Observable m,Object c) { if( model != m) return; draw(); } - //TODO: Layout selber festlegen denn die standartlayouts sind scheisse + //TODO: MVC Achitektur erstellen //TODO: herrausfinden wie das mit dem scrollen geht public SuggestEquivalentClassView(OWLEditorKit editorKit, OWLDescription description, OWLFrame<OWLClass> h) { editor = editorKit; - aktuell = h; - split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false); + //aktuell = h; model = new DLLearnerModel(); - model.addObserver( this); - vorschlag = new JPanel(); - panel = new JPanel(new GridLayout(0,1)); - panel.setPreferredSize(new Dimension(290,490)); - suggest = new JList(); - //positiv.setPreferredSize(new Dimension(190,200)); - //negativ.setPreferredSize(new Dimension(190,200)); + errorMessage = new JLabel(); + errorMessage.setForeground(Color_RED); + suggest = new JList(descriptions); learner = new JPanel(); - listPanel = new JPanel(); - learner.setPreferredSize(new Dimension(600, 500)); - split.setResizeWeight(0.5); + learner.setLayout(null); + learner.setPreferredSize(new Dimension(600, 480)); pos = new JLabel("Positive Examples"); neg = new JLabel("Negative Examples"); run = new JButton("RUN"); + cancel = new JButton("Cancel"); accept = new JButton("ADD"); - //accept.setSize(190, 20); accept.setPreferredSize(new Dimension(290,50)); - action = new ActionHandler(this.action, model); + option = new JPanel(new GridLayout(0,2)); + cancel.setEnabled(false); + option.setPreferredSize(new Dimension(290,0)); + model.addObserver(this); + } - + public void setView(SuggestEquivalentClassView v) + { + view = v; + action = new ActionHandler(this.action, model,view); + } public OWLDescription getEditedObject() { String expression = "JUHU"; @@ -94,38 +93,38 @@ public void makeView() { - test= new JScrollPane(); - option = new JPanel(new GridLayout(0,1)); - option.setPreferredSize(new Dimension(290,0)); + suggest = new JList(descriptions); option.add(pos); - blub=editor.getOWLModelManager().getActiveOntology().getReferencedIndividuals().toArray(); - for(int j = 0; j<blub.length;j++) + option.add(neg); + instances=editor.getOWLModelManager().getActiveOntology().getReferencedIndividuals().toArray(); + for(int j = 0; j<instances.length;j++) { - positive.add(new JCheckBox(editor.getOWLModelManager().getActiveOntology().getURI().toString()+"#"+blub[j].toString())); + positive.add(new JCheckBox(editor.getOWLModelManager().getActiveOntology().getURI().toString()+"#"+instances[j].toString())); } + for(int j = 0; j<instances.length;j++) + { + negative.add(new JCheckBox(editor.getOWLModelManager().getActiveOntology().getURI().toString()+"#"+instances[j].toString())); + } for(int j=0; j<positive.size();j++) { option.add(positive.get(j)); + option.add(negative.get(j)); } - option.add(neg); - for(int j = 0; j<blub.length;j++) - { - negative.add(new JCheckBox(editor.getOWLModelManager().getActiveOntology().getURI().toString()+"#"+blub[j].toString())); - } - for(int i=0;i<negative.size();i++) - { - option.add(negative.get(i)); - } - //individuals.add(negative); - option.add(run); - panel.add(suggest); - panel.add(accept); - test.add(option); - split.setLeftComponent(option); - split.setRightComponent(panel); - learner.add(split); - System.out.println(aktuell.getRootObject()); + //test.add(option); + option.setBounds(0, 0, 490, 250); + run.setBounds(0,260,200,30); + cancel.setBounds(210,260,200,30); + suggest.setBounds(0,300,490,110); + accept.setBounds(0,420,200,30); + errorMessage.setBounds(210,420,300,30); + System.out.println("blub2"); + learner.add(option); + learner.add(run); + learner.add(cancel); + learner.add(suggest); + learner.add(accept); + learner.add(errorMessage); addListener(); model.setDLLearnerModel(positive,negative,getUri()); } @@ -140,18 +139,18 @@ */ public void clear() { - if(split!=null) - { - split.removeAll(); - panel.removeAll(); + if(option!=null) { option.removeAll(); } suggest.removeAll(); - vorschlag.removeAll(); positive.removeAllElements(); negative.removeAllElements(); + errorMessage.setText(""); + for(int i=0; i<descriptions.length;i++) + { + descriptions[i]=""; } } /** @@ -161,7 +160,7 @@ { run.addActionListener(this.action); accept.addActionListener(this.action); - + cancel.addActionListener(this.action); for(int i=0;i<positive.size();i++) { positive.get(i).addItemListener(action); @@ -171,8 +170,28 @@ { negative.get(i).addItemListener(action); } - } - + } + public void destroyListener() + { + run.removeActionListener(this.action); + accept.removeActionListener(this.action); + System.out.println("hihihihi"); + cancel.removeActionListener(this.action); + for(int i=0;i<positive.size();i++) + { + positive.get(i).removeItemListener(action); + } + + for(int i=0;i<negative.size();i++) + { + negative.get(i).removeItemListener(action); + } + } + public void setSuggestedClass() + { + //TODO: Description umwandeln und in ontologie einfuegen + //editor.getOWLModelManager().getActiveOntology().getClassAxioms().add(e); + } public void dispose(){ } public String getUri() @@ -186,22 +205,8 @@ return uri; } - public void setSuggestionList(java.util.List<Description> list) - { - System.out.println(list.isEmpty()); - if(list.isEmpty()) - { - listPanel.add(new JLabel("No Suggestions")); - } - else - { - for(int i = 0; i<list.size();i++) - { - listPanel.add(new JLabel(list.get(i).toString())); - } - } - } + public Set<OWLDescription> getEditedObjects() { @@ -210,10 +215,12 @@ private void resetPanel() { option.removeAll(); + System.out.println("blub1"); positive.removeAllElements(); negative.removeAllElements(); - panel.removeAll(); + learner.removeAll(); } + public void release() { model.deleteObserver( this); @@ -222,12 +229,35 @@ protected void draw() { if (model != null) { - String desc[] = ((DLLearnerModel)model).getSolutions(); - - suggest = new JList(desc); - System.out.println("Hallo Welt"); + run.setEnabled(true); + cancel.setEnabled(false); + System.out.println("blub"); + descriptions = ((DLLearnerModel)model).getSolutions(); resetPanel(); makeView(); } } + + public void disableRunButtons() + { + run.setEnabled(false); + cancel.setEnabled(true); + resetPanel(); + makeView(); + } + + public void renderErrorMessage(String s) + { + errorMessage.setText(s); + } + + public JButton getStartButton() + { + return run; + } + + public JButton getStopButton() + { + return cancel; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |