From: <hee...@us...> - 2008-05-20 18:32:13
|
Revision: 909 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=909&view=rev Author: heeroyuy Date: 2008-05-20 11:32:00 -0700 (Tue, 20 May 2008) Log Message: ----------- -added own thread for learning -delete old classes -writes learned concept back to owl Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java Removed Paths: ------------- 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-05-20 16:43:05 UTC (rev 908) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-05-20 18:32:00 UTC (rev 909) @@ -3,36 +3,40 @@ import java.awt.event.*; -import java.util.Observable; +//TODO: Concepte und errormessages aus model holen +public class ActionHandler implements ActionListener, ItemListener, MouseListener{ + private DLLearnerModel model; -public class ActionHandler extends Observable implements ActionListener, ItemListener, MouseListener { - private DLLearnerModel model; - private SuggestEquivalentClassView view; + private String id; private Thread dlLearner; - public ActionHandler(ActionHandler a,DLLearnerModel m, SuggestEquivalentClassView s) + private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; + public ActionHandler(ActionHandler a,DLLearnerModel m,OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view ,String i) { - view = s; - model = m; + this.view = view; + this.id=i; + this.model = m; + + } public void actionPerformed(ActionEvent z){ - if(z.getActionCommand().equals("RUN")) + if(z.getActionCommand().equals("Suggest "+id)) { - model.setDLLearnerModel(view.getPositiveVector(), view.getNegativeVector(),view.getUri()); - dlLearner = new Thread(model); - view.getStartButton().setEnabled(false); - view.getStopButton().setEnabled(true); + this.dlLearner = new Thread(model); + view.getRunButton().setEnabled(false); + view.getCancelButton().setEnabled(true); dlLearner.start(); } if(z.getActionCommand().equals("Cancel")) { + view.getRunButton().setEnabled(true); + view.getCancelButton().setEnabled(false); + String error = "Learning aborted"; + view.renderErrorMessage(error); model.getLearningAlgorithm().stop(); - view.getStartButton().setEnabled(true); - view.getStopButton().setEnabled(false); - String error = "Learning aborted"; dlLearner.interrupt(); - view.renderErrorMessage(error); + } if(z.getActionCommand().equals("ADD")) @@ -43,7 +47,6 @@ if(model.getSolutions()[i].toString().equals(suggest)) { model.changeDLLearnerDescriptionsToOWLDescriptions(model.getSolutions()[i]); - System.out.println(model.getSolutions()[i].toString()); } } @@ -52,10 +55,14 @@ } } + public String getID() + { + return id; + } public void itemStateChanged(ItemEvent i) { - + //System.out.println(i.getItem()); } public void mouseReleased(MouseEvent m) @@ -70,7 +77,7 @@ public void mouseClicked(MouseEvent m) { - System.out.println("mouseClicked: "); + } public void mouseExited(MouseEvent m) @@ -87,5 +94,10 @@ } + public void destroyDLLearnerThread() + { + dlLearner =null; + } + } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-05-20 16:43:05 UTC (rev 908) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-05-20 18:32:00 UTC (rev 909) @@ -3,99 +3,101 @@ import org.dllearner.core.ComponentManager; import org.dllearner.kb.OWLFile; -import java.util.HashSet; import java.util.Observable; import java.util.Set; import java.util.TreeSet; import java.util.Vector; -import java.io.*; import org.dllearner.core.owl.Description; import javax.swing.JCheckBox; -import org.dllearner.algorithms.refinement.*; -//import org.coode.manchesterowlsyntax.ManchesterOWLSyntaxEditorParser; import org.dllearner.core.*; -import org.dllearner.reasoning.*; +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.frame.OWLFrame; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.*; import org.dllearner.learningproblems.*; -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.AddAxiom; -import org.semanticweb.owl.model.OWLAxiom; -import org.semanticweb.owl.model.OWLDataFactory; -import org.semanticweb.owl.model.OWLDescription; +import java.net.URI; +import org.dllearner.core.owl.*; +import org.dllearner.core.owl.NamedClass; import org.semanticweb.owl.model.OWLOntology; import org.dllearner.reasoning.OWLAPIReasoner; -import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyManager; -import org.semanticweb.owl.model.OWLOntologyStorageException; -import org.semanticweb.owl.model.UnknownOWLOntologyException; +import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; +import java.io.File; +import org.semanticweb.owl.model.OWLDescription; +import java.util.HashSet; +import java.util.*; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasoningService; +import org.dllearner.learningproblems.PosNegDefinitionLP; + 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"}; - private String uri; private Vector<JCheckBox> positiv; private Vector<JCheckBox> negativ; private ComponentManager cm; - //private ReasonerComponent reasoner; private ReasoningService rs; - private static final int anzahl = 10; + private KnowledgeSource source; + private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; + private static final int anzahl = 6; private Description[] description = new Description[anzahl]; private LearningProblem lp; + private OWLOntology ontology; private LearningAlgorithm la = null; - OWLAPIReasoner reasoner; + private OWLEditorKit editor; + private OWLFrame<OWLClass> aktuell; + private OWLAPIReasoner reasoner; + private Set<OWLDescription> OWLDescription; + private Set<String> positiveExamples; + private Set<String> negativeExamples; + private Vector<Individual> indis; + private OWLDescription desc; + private String id; + private OWLDescription newConceptOWLAPI; + private OWLDescription oldConceptOWLAPI; + private Set<OWLDescription> ds; + private Vector<Individual> individual; - public DLLearnerModel() + public DLLearnerModel(OWLEditorKit editorKit, OWLFrame<OWLClass> h,String id,OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view) { + editor=editorKit; + aktuell=h; + this.id=id; + this.view=view; + OWLDescription = new HashSet<OWLDescription>(); positiv = new Vector<JCheckBox>(); negativ = new Vector<JCheckBox>(); - + indis = new Vector<Individual>(); + individual = new Vector<Individual>(); + ComponentManager.setComponentClasses(componenten); + cm = ComponentManager.getInstance(); + ds = new HashSet<OWLDescription>(); + } - /** - * String um die Componenten des DL-Learners anzumelden - */ - public void setDLLearnerModel(Vector<JCheckBox> pos, Vector<JCheckBox> neg, String s) + public void initReasoner() { - positiv=pos; - negativ=neg; - uri=s; - } - - - public void startPosNegDefinitionReasoning() - { + setKnowledgeSource(); + setReasoner(); + SortedSet<Individual> pos=rs.getIndividuals(); + while(pos.iterator().hasNext()) + { + indis.add(pos.iterator().next()); + pos.remove(pos.iterator().next()); + } + //this.neg=rs.getIndividuals(); } - public void run() + public void setPositiveAndNegativeExamples() { - resetSuggestionList(); - ComponentManager.setComponentClasses(componenten); - // get singleton instance of component manager - cm = ComponentManager.getInstance(); - - // create knowledge source - KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(source, "url", new File(uri).toURI().toString()); - try{ - source.init(); - } - catch(Exception e){ - } - // create DIG reasoning service with standard settings - reasoner = cm.reasoner(OWLAPIReasoner.class, source); - // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); - try{ - reasoner.init(); - } - catch(Exception e){ - - } - rs = cm.reasoningService(reasoner); - lp = cm.learningProblem(PosNegDefinitionLP.class, rs); - // create a learning problem and set positive and negative examples - - Set<String> positiveExamples = new TreeSet<String>(); + positiveExamples = new TreeSet<String>(); for(int i=0;i<positiv.size();i++) { if(positiv.get(i).isSelected()) @@ -103,7 +105,7 @@ positiveExamples.add(positiv.get(i).getText()); } } - Set<String> negativeExamples = new TreeSet<String>(); + negativeExamples = new TreeSet<String>(); for(int i=0;i<negativ.size();i++) { if(negativ.get(i).isSelected()) @@ -111,16 +113,59 @@ negativeExamples.add(negativ.get(i).getText()); } } + + } + + public Description[] getDescriptions() + { + return description; + } + + public void setKnowledgeSource() + { + this.source = cm.knowledgeSource(OWLFile.class); + String uri=getUri(); + cm.applyConfigEntry(source, "url", new File(uri).toURI().toString()); + try{ + source.init(); + } + catch(ComponentInitException e){ + e.printStackTrace(); + } + } + + public void setReasoner() + { + this.reasoner =cm.reasoner(OWLAPIReasoner.class,source); + reasoner.init(); + rs = cm.reasoningService(reasoner); + } + + public void setLearningProblem() + { + System.out.println("das ist die id: "+id); + if(id.equals("Equivalent classes")) + { + lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + } + if(id.equals("Superclasses")) + { + lp = cm.learningProblem(PosNegInclusionLP.class, rs); + } + cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); try{ lp.init(); } - catch(Exception e){ - + catch(ComponentInitException e) + { + e.printStackTrace(); } - - // create the learning algorithm + } + + public void setLearningAlgorithm() + { try { this.la = cm.learningAlgorithm(ROLearner.class, lp, rs); } catch (LearningProblemUnsupportedException e) { @@ -132,10 +177,18 @@ try{ la.init(); } - catch(Exception e){ - + catch(ComponentInitException e){ + e.printStackTrace(); } - + } + + public void run() + { + setKnowledgeSource(); + setReasoner(); + setPositiveAndNegativeExamples();; + setLearningProblem(); + setLearningAlgorithm(); // start the algorithm and print the best concept found la.start(); description = new Description[la.getBestSolutions(anzahl).size()]; @@ -143,15 +196,14 @@ { description[j]=la.getBestSolutions(anzahl).get(j); } - setChanged(); - notifyObservers(description); - + view.draw(description); } public Description[] getSolutions() { return description; } + public Vector<JCheckBox> getPosVector() { return positiv; @@ -162,36 +214,107 @@ return negativ; } - public void setPosVector(Vector<JCheckBox> a) + + public void loadOntology(URI uri) { - positiv =a; + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + try{ + ontology = manager.loadOntology(uri); + } + catch(OWLOntologyCreationException e) + { + System.out.println("Can't create Ontology: "+ e); + } } - public void setNegVector(Vector<JCheckBox> b) + public void setPosVector() + { setPositiveConcept(); + for(int i = 0 ; i<indis.size() ; i++) + { + String ind = indis.get(i).toString(); + if(setPositivExamplesChecked(ind)) + { + positiv.add(new JCheckBox(ind.toString(),true)); + + } + else + { + positiv.add(new JCheckBox(ind.toString(),false)); + } + negativ.add(new JCheckBox(ind.toString())); + } + } + + + public void setNegVector() { - negativ = b; + } - public void addToPosVector(JCheckBox a) + public void setPositiveConcept() { - positiv.add(a); + //Set<OWLClassAssertionAxiom> test=editor.getOWLModelManager().getActiveOntology().getClassAssertionAxioms(aktuell.getRootObject()); + //OWLClassAssertionAxiom axio = test.iterator().next(); + Set<NamedClass> concepts = rs.getAtomicConcepts(); + System.out.println(concepts); + SortedSet<Individual> individuals = null; + while(concepts.iterator().hasNext()&&individuals==null) + { + NamedClass concept = concepts.iterator().next(); + //System.out.println(concept); + //System.out.println("test:"+concept.toString().endsWith("#"+aktuell.getRootObject().toString())); + if(concept.toString().endsWith("#"+aktuell.getRootObject().toString())) + { + individuals = rs.retrieval(concept); + } + concepts.remove(concept); + } + while(individuals.iterator().hasNext()) + { + individual.add(individuals.iterator().next()); + individuals.remove(individuals.iterator().next()); + } + } - public void addToNegVector(JCheckBox b) + public boolean setPositivExamplesChecked(String indi) { - negativ.add(b); + boolean isChecked = false; + for(int i = 0; i<individual.size()&& isChecked==false;i++) + { + String indi1=individual.get(i).getName(); + if(indi1.toString().equals(indi.toString())) + { + System.out.println("Check"); + isChecked = true; + } + else + { + System.out.println("Da bin ich"); + isChecked = false; + } + } + return isChecked; + } - + public void clearVector() { positiv.removeAllElements(); negativ.removeAllElements(); + indis.removeAllElements(); } public String getUri() - { - return uri; - } + { + char[] test = editor.getOWLModelManager().getOntologyPhysicalURI(editor.getOWLModelManager().getActiveOntology()).toString().toCharArray(); + String uri=""; + for(int i =6; i<test.length;i++) + { + uri=uri+test[i]; + } + return uri; + } public void setDescriptionList(Description[] list) { @@ -204,56 +327,150 @@ return la; } + public JCheckBox getPositivJCheckBox(int i) + { + return positiv.get(i); + } + public JCheckBox getNegativJCheckBox(int i) + { + return negativ.get(i); + } + public void resetSuggestionList() { - /*for(int i=0;i<description.length;i++) + for(int i=0;i<description.length;i++) { - description[i]=""; - }*/ + description[i]=null; + } } - public void changeDLLearnerDescriptionsToOWLDescriptions(Description desc) + public void unsetJCheckBoxen() { - OWLDescription newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); - System.out.println(newConceptOWLAPI); - //OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(concept); + for(int j=0;j<positiv.size();j++) + { + if(positiv.get(j).isSelected()) + { + JCheckBox i = positiv.get(j); + i.setSelected(false); + positiv.set(j, i); + } + } + for(int j=0;j<negativ.size();j++) + { + if(negativ.get(j).isSelected()) + { + JCheckBox i = negativ.get(j); + i.setSelected(false); + negativ.set(j, i); + } + } } + + public OWLOntology getOWLOntology() + { + return ontology; + } - public void addAxiomToOWL(Description desc,Description concept){ - OWLDescription newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); - OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(concept); + public Set<OWLDescription> getNewOWLDescription() + { + return OWLDescription; + } + + public OWLDescription getOldConceptOWLAPI() + { + return oldConceptOWLAPI; + } + + public Set<OWLDescription> getNewOWLDescriptions() + { + return null; + } + + public OWLDescription getSollution() + { + return desc; + } + + public void setNewConceptOWLAPI(Description desc) + { + for(int i = 0;i<description.length;i++) + { + + if(desc.toString().equals(description[i].toString())) + { + newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); + ds.add(newConceptOWLAPI); + } + this.desc = newConceptOWLAPI; + OWLDescription.add(newConceptOWLAPI); + } + } + + public void setOldConceptOWLAPI() + { + SortedSet<Individual> indi=rs.getIndividuals(); + while(positiveExamples.iterator().hasNext()) + { + String indi1=positiveExamples.iterator().next(); + + for(int i = 0; i<indi.size();i++) + { + Individual indi2 = indi.iterator().next(); + if(indi2.toString().equals(indi1.toString())) + { + Set<NamedClass> concept=reasoner.getConcepts(indi2); + while(concept.iterator().hasNext()) + { + OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(concept.iterator().next()); + concept.remove(concept.iterator().next()); + ds.add(oldConceptOWLAPI); + } + + } + indi.remove(indi2); + } + indi=rs.getIndividuals(); + positiveExamples.remove(indi1); + } + } + + public void changeDLLearnerDescriptionsToOWLDescriptions(Description desc) + { + setNewConceptOWLAPI(desc); + setOldConceptOWLAPI(); + //OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology ontology = reasoner.getOWLAPIOntologies().get(0); - - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - - OWLDataFactory factory = manager.getOWLDataFactory(); - - Set<OWLDescription> ds = new HashSet<OWLDescription>(); - ds.add(newConceptOWLAPI); - ds.add(oldConceptOWLAPI); - - OWLAxiom axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); - - - - AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); - try { + //OWLDataFactory factory = manager.getOWLDataFactory(); + //System.out.println("Manager: "+manager); + //OWLAxiom axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); + //OWLOntologyFormat format = new OWLOntologyFormat(); + //format = manager.getOntologyFormat(ontology); + //OWLOntology ontology = editor.getOWLModelManager().getActiveOntology(); + //System.out.println("Format: "+format); + //AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); + /*try { manager.applyChange(axiom); } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } + try { - manager.saveOntology(ontology); + manager.saveOntology(ontology,format,editor.getOWLModelManager().getActiveOntology().getURI()); } catch (UnknownOWLOntologyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (OWLOntologyStorageException e) { // TODO Auto-generated catch block e.printStackTrace(); + } */ } + + public ReasoningService getReasoningService() + { + return rs; } - -} + + + } \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerViewPanel.java 2008-05-20 18:32:00 UTC (rev 909) @@ -0,0 +1,42 @@ +package org.dllearner.tools.protege; + +import org.protege.editor.core.ui.view.ViewComponent; +import org.protege.editor.core.ui.view.ViewComponentPlugin; +import org.protege.editor.core.ui.view.ViewComponentPluginAdapter; +import org.protege.editor.core.ui.workspace.Workspace; +import org.protege.editor.owl.ui.clshierarchy.ToldOWLClassHierarchyViewComponent; +import org.protege.editor.owl.ui.selector.AbstractSelectorPanel; +import org.protege.editor.owl.OWLEditorKit; + +public class DLLearnerViewPanel extends AbstractSelectorPanel { + + + private ToldOWLClassHierarchyViewComponent viewComponent; + private final static long serialVersionUID = 3546352435L; + public DLLearnerViewPanel(OWLEditorKit editor) + { + super(editor); + } + + protected ViewComponentPlugin getViewComponentPlugin() { + + return new ViewComponentPluginAdapter() { + public String getLabel() { + return "OWL Asserted Class Hierarchy"; + } + + + public Workspace getWorkspace() { + return getOWLEditorKit().getOWLWorkspace(); + } + + + public ViewComponent newInstance() throws ClassNotFoundException, IllegalAccessException, + InstantiationException { + viewComponent = new ToldOWLClassHierarchyViewComponent(); + viewComponent.setup(this); + return viewComponent; + } + +}; + }} Added: trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2008-05-20 18:32:00 UTC (rev 909) @@ -0,0 +1,643 @@ +package org.dllearner.tools.protege; + +import org.dllearner.core.owl.Description; +import org.protege.editor.core.ui.util.ComponentFactory; +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.clsdescriptioneditor.ExpressionEditor; +import org.protege.editor.owl.ui.clsdescriptioneditor.OWLDescriptionChecker; +import org.protege.editor.owl.ui.selector.OWLClassSelectorPanel; +import org.protege.editor.owl.ui.selector.OWLObjectPropertySelectorPanel; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLException; +import org.semanticweb.owl.model.OWLObjectProperty; +import org.protege.editor.owl.ui.frame.*; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URI; +import java.util.*; +import java.util.List; + + +/** + * Author: Matthew Horridge<br> + * The University Of Manchester<br> + * Bio-Health Informatics Group<br> + * Date: 15-Feb-2007<br><br> + */ +public class OWLClassDescriptionEditorWithDLLearnerTab extends AbstractOWLFrameSectionRowObjectEditor<OWLDescription> + implements VerifiedInputEditor { + + private static final String CLASS_EXPRESSION_EDITOR_LABEL = "Class expression editor"; + private static final String CLASS_TREE_LABEL = "Class tree"; + private static final String RESTRICTION_CREATOR_LABEL = "Restriction creator"; + private static final String SUGGEST_EQUIVALENT_CLASS_LABEL = "Suggest a equivalent class"; + private static final String SUGGEST_SUBCLASS_LABEL = "Suggest a subclass"; + + private OWLEditorKit editorKit; + + private OWLDescriptionChecker checker; + + private ExpressionEditor<OWLDescription> editor; + + private JComponent editingComponent; + + private JTabbedPane tabbedPane; + + private DLLearnerView dllearner; + + private OWLClassSelectorPanel classSelectorPanel; + + private ObjectRestrictionCreatorPanel restrictionCreatorPanel; + + private OWLDescription initialDescription; + + private Set<InputVerificationStatusChangedListener> listeners = new HashSet<InputVerificationStatusChangedListener>(); + + private DocumentListener editorListener = new DocumentListener(){ + public void insertUpdate(DocumentEvent documentEvent) { + handleVerifyEditorContents(); + } + public void removeUpdate(DocumentEvent documentEvent) { + handleVerifyEditorContents(); + } + public void changedUpdate(DocumentEvent documentEvent) { + handleVerifyEditorContents(); + } + }; + + private ChangeListener changeListener = new ChangeListener(){ + public void stateChanged(ChangeEvent changeEvent) { + handleVerifyEditorContents(); + } + }; + + public OWLDescription getInitialDescription() + { + return initialDescription; + } + public OWLClassDescriptionEditorWithDLLearnerTab(OWLEditorKit editorKit, OWLDescription description,OWLFrame<OWLClass> frame, String label) { + this.editorKit = editorKit; + this.initialDescription = description; + checker = new OWLDescriptionChecker(editorKit); + editor = new ExpressionEditor<OWLDescription>(editorKit, checker); + dllearner = new DLLearnerView(frame,label); + editor.setExpressionObject(description); + editor.getDocument().addDocumentListener(editorListener); + + tabbedPane = new JTabbedPane(); + tabbedPane.setFocusable(false); + if(label.equals("Equivalent classes")) + { + tabbedPane.add(SUGGEST_EQUIVALENT_CLASS_LABEL,dllearner); + } + if(label.equals("Superclasses")) + { + tabbedPane.add(SUGGEST_SUBCLASS_LABEL,dllearner); + } + editingComponent = new JPanel(new BorderLayout()); + editingComponent.add(tabbedPane); + editingComponent.setPreferredSize(new Dimension(600, 490)); + tabbedPane.add(CLASS_EXPRESSION_EDITOR_LABEL, new JScrollPane(editor)); + + + if (description == null || !description.isAnonymous()) { + classSelectorPanel = new OWLClassSelectorPanel(editorKit); + tabbedPane.add(CLASS_TREE_LABEL, classSelectorPanel); + if (description != null) { + classSelectorPanel.setSelectedClass(description.asOWLClass()); + } + classSelectorPanel.addSelectionListener(changeListener); + + restrictionCreatorPanel = new ObjectRestrictionCreatorPanel(); + tabbedPane.add(RESTRICTION_CREATOR_LABEL, restrictionCreatorPanel); + restrictionCreatorPanel.classSelectorPanel.addSelectionListener(changeListener); + restrictionCreatorPanel.objectPropertySelectorPanel.addSelectionListener(changeListener); + //dllearner.DLLearnerViewPanel.addChangeListener(changeListener); + tabbedPane.addChangeListener(changeListener); + + } + } + + private void handleVerifyEditorContents() { + if (!listeners.isEmpty()){ + for (InputVerificationStatusChangedListener l : listeners){ + l.verifiedStatusChanged(isValidated()); + } + } + } + + + private boolean isValidated() { + boolean validated = false; + final String selectedTabTitle = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()); + if (selectedTabTitle.equals(CLASS_EXPRESSION_EDITOR_LABEL)){ + validated = editor.isWellFormed(); + } + else if (selectedTabTitle.equals(CLASS_TREE_LABEL)){ + validated = classSelectorPanel.getSelectedClass() != null; + } + else if (selectedTabTitle.equals(RESTRICTION_CREATOR_LABEL)){ + validated = restrictionCreatorPanel.classSelectorPanel.getSelectedClass() != null && + restrictionCreatorPanel.objectPropertySelectorPanel.getSelectedOWLObjectProperty() != null; + } + else if(selectedTabTitle.equals(SUGGEST_EQUIVALENT_CLASS_LABEL)){ + validated = dllearner.getSollution()!= null; + } + else if(selectedTabTitle.equals(SUGGEST_SUBCLASS_LABEL)){ + validated = dllearner.getSollution()!= null; + } + return validated; + } + + + public JComponent getInlineEditorComponent() { + // Same as general editor component + return editingComponent; + } + + + /** + * Gets a component that will be used to edit the specified + * object. + * @return The component that will be used to edit the object + */ + public JComponent getEditorComponent() { + return editingComponent; + } + + + public void clear() { + System.out.println("Und jetzt bin ich hier :-)"); + dllearner.unsetEverything(); + dllearner.makeView(); + initialDescription = null; + editor.setText(""); + } + + + public Set<OWLDescription> getEditedObjects() { + if (tabbedPane.getSelectedComponent() == classSelectorPanel) { + return classSelectorPanel.getSelectedClasses(); + } + else if (tabbedPane.getSelectedComponent() == restrictionCreatorPanel) { + return restrictionCreatorPanel.createRestrictions(); + } + else if(tabbedPane.getSelectedComponent() == dllearner){ + return dllearner.getSollutions(); + } + return super.getEditedObjects(); + } + + + /** + * Gets the object that has been edited. + * @return The edited object + */ + public OWLDescription getEditedObject() { + try { + if (!editor.isWellFormed()) { + return null; + } + String expression = editor.getText(); + if (editor.isWellFormed()) { + return editorKit.getOWLModelManager().getOWLDescriptionParser().createOWLDescription(expression); + } + if(!dllearner.getSollutions().isEmpty()){ + return dllearner.getSollution(); + } + else { + return null; + } + } + catch (OWLException e) { + return null; + } + } + + + public void dispose() { + if (classSelectorPanel != null) { + classSelectorPanel.dispose(); + } + if (restrictionCreatorPanel != null) { + restrictionCreatorPanel.dispose(); + } + if(dllearner !=null){ + dllearner.dispose(); + } + } + + + private OWLDataFactory getDataFactory() { + return editorKit.getOWLModelManager().getOWLDataFactory(); + } + + public void addStatusChangedListener(InputVerificationStatusChangedListener listener) { + listeners.add(listener); + listener.verifiedStatusChanged(isValidated()); + } + + + public void removeStatusChangedListener(InputVerificationStatusChangedListener listener) { + listeners.remove(listener); + } + + public class DLLearnerView extends JPanel{ + private JLabel pos; + private final static long serialVersionUID = 624829578325729385L; + private DLLearnerViewPanel panel; + private JComponent learner; + private JButton accept; + private JButton run; + private OWLEditorKit editor; + private JPanel option; + private JList suggest; + private JLabel neg; + private JScrollPane scrollPane; + private final Color Color_RED = Color.red; + private JButton cancel; + //private JPanel suggestPanel; + //private JButton helpForPosExamples; + //private JButton helpForNegExamples; + private JLabel errorMessage; + //private JScrollPane suggestScroll; + private JButton advanceButton; + private ActionHandler action; + private DLLearnerModel model; + private Description[] descriptions = new Description[10]; + + public DLLearnerViewPanel getDLLearnerViewPanel() + { + return panel; + } + + public DLLearnerView(OWLFrame<OWLClass> aktuell,String label){ + editor = editorKit; + model = new DLLearnerModel(editorKit,aktuell, label,this); + model.loadOntology(getUri()); + //helpPanel.setLayout(new GridLayout(0,4)); + panel = new DLLearnerViewPanel(editor); + action = new ActionHandler(this.action, model,this,label); + System.out.println("Hallo test"); + //helpForPosExamples = new JButton("?"); + //helpForNegExamples = new JButton("?"); + run = new JButton("Suggest "+label); + cancel = new JButton("Cancel"); + accept = new JButton("ADD"); + advanceButton = new JButton("Advanced"); + scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + //suggestScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + errorMessage = new JLabel(); + errorMessage.setForeground(Color_RED); + learner = new JPanel(); + learner.setLayout(null); + suggest = new JList(); + learner.setPreferredSize(new Dimension(600, 470)); + pos = new JLabel("Positive Examples"); + neg = new JLabel("Negative Examples"); + accept.setPreferredSize(new Dimension(290,50)); + option = new JPanel(new GridLayout(0,2)); + addAcceptButtonListener(this.action); + addRunButtonListener(this.action); + addCancelButtonListener(this.action); + + } + + public void makeView() + { + model.clearVector(); + model.initReasoner(); + model.setPosVector(); + model.setNegVector(); + suggest = new JList(); + cancel.setEnabled(false); + accept.setEnabled(false); + setJCheckBoxen(); + if(option.getComponentCount()<=2) + { + run.setEnabled(false); + } + scrollPane.setViewportView(option); + scrollPane.setBounds(10, 200, 490, 250); + suggest.setBounds(10,40,490,110); + suggest.setVisible(true); + run.setBounds(10,0,200,30); + cancel.setBounds(260,0,200,30); + advanceButton.setBounds(260,160,200,30); + accept.setBounds(10,160,200,30); + errorMessage.setBounds(260,160,300,30); + learner.add(run); + learner.add(cancel); + learner.add(suggest); + learner.add(accept); + learner.add(advanceButton); + learner.add(scrollPane); + add(learner); + addListener(); + } + + public JComponent getLearnerPanel() + { + return learner; + } + + public URI getUri() + { + URI uri = editor.getOWLModelManager().getOntologyPhysicalURI(editor.getOWLModelManager().getActiveOntology()); + return uri; + } + + public Set<OWLDescription> getSollutions() + { + return model.getNewOWLDescription(); + } + + public OWLDescription getSollution() + { + System.out.println("das ist die loesung: "+model.getSollution()); + return model.getSollution(); + } + + private void setJCheckBoxen() + { + option.add(pos); + option.add(neg); + for(int j=0; j<model.getPosVector().size();j++) + { + option.add(model.getPositivJCheckBox(j)); + option.add(model.getNegativJCheckBox(j)); + } + + } + + public void unsetEverything() + { + option.removeAll(); + run.setEnabled(true); + action.destroyDLLearnerThread(); + suggest.removeAll(); + errorMessage.setText(""); + learner.removeAll(); + } + + public void destroyListener() + { + //run.removeActionListener(this.action); + //accept.removeActionListener(this.action); + //cancel.removeActionListener(this.action); + } + + public void renderErrorMessage(String s) + { + errorMessage.setText(s); + } + + private void addListener() + { + for(int i=0;i<model.getPosVector().size();i++) + { + model.getPositivJCheckBox(i).addItemListener(action); + } + + for(int i=0;i<model.getNegVector().size();i++) + { + model.getNegativJCheckBox(i).addItemListener(action); + } + } + + public void update(Observable m,Object c) + { + if( model != m) return; + //draw(); + } + + protected void draw(Description[] desc) { + if (model != null) { + run.setEnabled(true); + cancel.setEnabled(false); + accept.setEnabled(true); + errorMessage.setText(""); + learner.remove(suggest); + //learner.remove(3); + descriptions = desc; + suggest=new JList(descriptions); + suggest.setBounds(10,40,490,110); + suggest.setVisible(true); + learner.add(suggest); + suggest.addMouseListener(action); + suggest.repaint(); + model.unsetJCheckBoxen(); + option.removeAll(); + setJCheckBoxen(); + + } + } + + public JList getSuggestionList() + { + return suggest; + } + + public JButton getRunButton() + { + return run; + } + + public JButton getCancelButton() + { + return cancel; + } + + public void dispose() { + + } + + public void addRunButtonListener(ActionListener a) + { + run.addActionListener(a); + } + + public void addCancelButtonListener(ActionListener a) + { + cancel.addActionListener(a); + } + + public void addAcceptButtonListener(ActionListener a) + { + accept.addActionListener(a); + } + + public void addAdvanceButtonListener(ActionListener a) + { + //advanceButton.addActionListener(a); + } + } + + private class ObjectRestrictionCreatorPanel extends JPanel { + + private OWLObjectPropertySelectorPanel objectPropertySelectorPanel; + private final static long serialVersionUID = 12435463243L; + private OWLClassSelectorPanel classSelectorPanel; + + private JSpinner cardinalitySpinner; + + private JComboBox typeCombo; + + + public ObjectRestrictionCreatorPanel() { + objectPropertySelectorPanel = new OWLObjectPropertySelectorPanel(editorKit); + objectPropertySelectorPanel.setBorder(ComponentFactory.createTitledBorder("Restricted properties")); + cardinalitySpinner = new JSpinner(new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1)); + JComponent cardinalitySpinnerEditor = cardinalitySpinner.getEditor(); + Dimension prefSize = cardinalitySpinnerEditor.getPreferredSize(); + cardinalitySpinnerEditor.setPreferredSize(new Dimension(50, prefSize.height)); + classSelectorPanel = new OWLClassSelectorPanel(editorKit); + classSelectorPanel.setBorder(ComponentFactory.createTitledBorder("Restriction fillers")); + setLayout(new BorderLayout()); + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false); + splitPane.setResizeWeight(0.5); + splitPane.setLeftComponent(objectPropertySelectorPanel); + splitPane.setRightComponent(classSelectorPanel); + add(splitPane); + splitPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + List<RestrictionCreator> types = new ArrayList<RestrictionCreator>(); + types.add(new RestrictionCreator("Some (existential)") { + public void createRestrictions(Set<OWLObjectProperty> properties, Set<OWLDescription> fillers, + Set<OWLDescription> result) { + for (OWLObjectProperty prop : properties) { + for (OWLDescription filler : fillers) { + result.add(getDataFactory().getOWLObjectSomeRestriction(prop, filler)); + } + } + } + }); + types.add(new RestrictionCreator("Only (universal)") { + public void createRestrictions(Set<OWLObjectProperty> properties, Set<OWLDescription> fillers, + Set<OWLDescription> result) { + for (OWLObjectProperty prop : properties) { + if (fillers.isEmpty()) { + return; + } + OWLDescription filler; + if (fillers.size() > 1) { + filler = getDataFactory().getOWLObjectUnionOf(fillers); + } + else { + filler = fillers.iterator().next(); + } + result.add(getDataFactory().getOWLObjectAllRestriction(prop, filler)); + } + } + }); + types.add(new CardinalityRestrictionCreator("Min (min cardinality)", cardinalitySpinner) { + public OWLDescription createRestriction(OWLObjectProperty prop, OWLDescription filler, int card) { + return getDataFactory().getOWLObjectMinCardinalityRestriction(prop, card, filler); + } + }); + types.add(new CardinalityRestrictionCreator("Exactly (exact cardinality)", cardinalitySpinner) { + public OWLDescription createRestriction(OWLObjectProperty prop, OWLDescription filler, int card) { + return getDataFactory().getOWLObjectExactCardinalityRestriction(prop, card, filler); + } + }); + types.add(new CardinalityRestrictionCreator("Max (max cardinality)", cardinalitySpinner) { + public OWLDescription createRestriction(OWLObjectProperty prop, OWLDescription filler, int card) { + return getDataFactory().getOWLObjectMaxCardinalityRestriction(prop, card, filler); + } + }); + typeCombo = new JComboBox(types.toArray()); + + + final JPanel typePanel = new JPanel(); + typePanel.setBorder(ComponentFactory.createTitledBorder("Restriction type")); + add(typePanel, BorderLayout.SOUTH); + typePanel.add(typeCombo); + typeCombo.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + cardinalitySpinner.setEnabled(typeCombo.getSelectedItem() instanceof CardinalityRestrictionCreator); + } + }); + JPanel spinnerHolder = new JPanel(new BorderLayout(4, 4)); + spinnerHolder.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + spinnerHolder.add(new JLabel("Cardinality"), BorderLayout.WEST); + spinnerHolder.add(cardinalitySpinner, BorderLayout.EAST); + JPanel spinnerAlignmentPanel = new JPanel(new BorderLayout()); + spinnerAlignmentPanel.add(spinnerHolder, BorderLayout.WEST); + typePanel.add(spinnerAlignmentPanel); + cardinalitySpinner.setEnabled(typeCombo.getSelectedItem() instanceof CardinalityRestrictionCreator); + } + + + public Set<OWLDescription> createRestrictions() { + Set<OWLDescription> result = new HashSet<OWLDescription>(); + RestrictionCreator creator = (RestrictionCreator) typeCombo.getSelectedItem(); + if (creator == null) { + return Collections.emptySet(); + } + creator.createRestrictions(objectPropertySelectorPanel.getSelectedOWLObjectProperties(), + classSelectorPanel.getSelectedClasses(), + result); + return result; + } + + + public void dispose() { + objectPropertySelectorPanel.dispose(); + classSelectorPanel.dispose(); + } + } + + + private abstract class RestrictionCreator { + + private String name; + + + protected RestrictionCreator(String name) { + this.name = name; + } + + + public String toString() { + return name; + } + + + abstract void createRestrictions(Set<OWLObjectProperty> properties, Set<OWLDescription> fillers, + Set<OWLDescription> result); + } + + + private abstract class CardinalityRestrictionCreator extends RestrictionCreator { + + private JSpinner cardinalitySpinner; + + + protected CardinalityRestrictionCreator(String name, JSpinner cardinalitySpinner) { + super(name); + this.cardinalitySpinner = cardinalitySpinner; + } + + + public void createRestrictions(Set<OWLObjectProperty> properties, Set<OWLDescription> fillers, + Set<OWLDescription> result) { + for (OWLObjectProperty prop : properties) { + for (OWLDescription desc : fillers) { + result.add(createRestriction(prop, desc, (Integer) cardinalitySpinner.getValue())); + } + } + } + + + public abstract OWLDescription createRestriction(OWLObjectProperty prop, OWLDescription filler, int card); + } + +} Added: trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java 2008-05-20 18:32:00 UTC (rev 909) @@ -0,0 +1,162 @@ +package org.dllearner.tools.protege; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.frame.*; +import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.inference.UnsupportedReasonerOperationException; +import org.semanticweb.owl.model.AddAxiom; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLEquivalentClassesAxiom; +import org.semanticweb.owl.model.OWLObject; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChange; +import org.semanticweb.owl.util.CollectionFactory; + + +/** + * Author: Matthew Horridge<br> + * The University Of Manchester<br> + * Bio-Health Informatics Group<br> + * Date: 19-Jan-2007<br><br> + */ +public class OWLEquivalentClassesAxiomFrameSection extends AbstractOWLFrameSection<OWLClass, OWLEquivalentClassesAxiom, OWLDescription> { + + private static final String LABEL = "Equivalent classes"; + + private Set<OWLClass> added; + + private boolean inferredEquivalentClasses = true; + + private OWLFrame<OWLClass> frame; + + public OWLEquivalentClassesAxiomFrameSection(OWLEditorKit editorKit, OWLFrame<OWLClass> frame) { + super(editorKit, LABEL, frame); + added = new HashSet<OWLClass>(); + this.frame=frame; + } + + + protected void clear() { + } + + + /** + * Refills the section with rows. This method will be called + * by the system and should be directly called. + */ + protected void refill(OWLOntology ontology) { + for (OWLEquivalentClassesAxiom ax : ontology.getEquivalentClassesAxioms(getRootObject())) { + addRow(new OWLEquivalentClassesAxiomFrameSectionRow(getOWLEditorKit(), + this, + ontology, + getRootObject(), + ax)); + for (OWLDescription desc : ax.getDescriptions()) { + if (!desc.isAnonymous()) { + added.add(desc.asOWLClass()); + } + } + } + } + + + protected void refillInferred() { + if (!inferredEquivalentClasses) { + return; + } + try { + if (!getOWLModelManager().getReasoner().isSatisfiable(getRootObject())) { + addRow(new OWLEquivalentClassesAxiomFrameSectionRow(getOWLEditorKit(), + this, + null, + getRootObject(), + getOWLDataFactory().getOWLEquivalentClassesAxiom( + CollectionFactory.createSet(getRootObject(), + getOWLModelManager().getOWLDataFactory().getOWLNothing())))); + return; + } + for (OWLClass cls : getOWLModelManager().getReasoner().getEquivalentClasses(getRootObject())) { + if (!added.contains(cls) && !cls.equals(getRootObject())) { + addRow(new OWLEquivalentClassesAxiomFrameSectionRow(getOWLEditorKit(), + this, + null, + getRootObject(), + getOWLDataFactory().getOWLEquivalentClassesAxiom( + CollectionFactory.createSet( + getRootObject(), + cls)))); + } + } + } + catch (UnsupportedReasonerOperationException e) { + inferredEquivalentClasses = false; + } + catch (OWLReasonerException e) { + e.printStackTrace(); + } + } + + + public void visit(OWLEquivalentClassesAxiom axiom) { + if (axiom.getDescriptions().contains(getRootObject())) { + reset(); + } + } + + + protected OWLEquivalentClassesAxiom createAxiom(OWLDescription object) { + return getOWLDataFactory().getOWLEquivalentClassesAxiom(CollectionFactory.createSet(getRootObject(), object)); + } + + + public OWLFrameSectionRowObjectEditor<OWLDescription> getObjectEditor() { + return new OWLClassDescriptionEditorWithDLLearnerTab(getOWLEditorKit(), null,frame,LABEL); + } + + + public boolean canAcceptDrop(List<OWLObject> objects) { + for (OWLObject obj : objects) { + if (!(obj instanceof OWLDescription)) { + return false; + } + } + return true; + } + + + public boolean dropObjects(List<OWLObject> objects) { + List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); + for (OWLObject obj : objects) { + if (obj instanceof OWLDescription) { + OWLDescription desc = (OWLDescription) obj; + OWLAxiom ax = getOWLDataFactory().getOWLEquivalentClassesAxiom(CollectionFactory.createSet(getRootObject(), + desc)); + changes.add(new AddAxiom(getOWLModelManager().getActiveOntology(), ax)); + } + else { + return false; + } + } + getOWLModelManager().applyChanges(changes); + return true; + } + + + /** + * Obtains a comparator which can be used to sort the rows + * in this section. + * @return A comparator if to sort the rows in this section, + * or <code>null</code> if the rows shouldn't be sorted. + */ + public Comparator<OWLFrameSectionRow<OWLClass, OWLEquivalentClassesAxiom, OWLDescription>> getRowComparator() { + return null; + } +} Added: trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java 2008-05-20 18:32:00 UTC (rev 909) @@ -0,0 +1,176 @@ +package org.dllearner.tools.protege; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.frame.*; +import org.protege.editor.owl.ui.OWLDescriptionComparator; +import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.model.AddAxiom; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLObject; +import org.semanticweb.owl.model.OWLObjectProperty; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChange; +import org.semanticweb.owl.model.OWLSubClassAxiom; + + +/** + * Author: Matthew Horridge<br> + * The University Of Manchester<br> + * Bio-Health Informatics Group<br> + * Date: 19-Jan-2007<br><br> + */ +public class OWLSubClassAxiomFrameSection extends AbstractOWLFrameSection<OWLClass, OWLSubClassAxiom, OWLDescription> { + + private static final String LABEL = "Superclasses"; + + private Set<OWLDescription> added = new HashSet<OWLDescription>(); + + private OWLFrame<OWLClass> frame; + public OWLSubClassAxiomFrameSection(OWLEditorKit editorKit, OWLFrame<OWLClass> frame) { + super(editorKit, LABEL, frame); + this.frame = frame; + } + + + protected void clear() { + added.clear(); + } + + + /** + * Refills the section with rows. This method will be called + * by the system and should be directly called. + */ + protected void refill(OWLOntology ontology) { + for (OWLSubClassAxiom ax : ontology.getSubClassAxiomsForLHS(getRootObject())) { + addRow(new OWLSubClassAxiomFrameSectionRow(getOWLEditorKit(), this, ontology, getRootObject(), ax)); + added.add(ax.getSuperClass()); + } + } + + + protected void refillInferred() { + try { + if (getOWLModelManager().getReasoner().isSatisfiable(getRootObject())) { + for (Set<OWLClass> descs : getOWLModelManager().getReasoner().getSuperClasses(getRootObject())) { + for (OWLClass desc : descs) { + if (!added.contains(desc)) { + addRow(new OWLSubClassAxiomFrameSectionRow(getOWLEditorKit(), + this, + null, + getRootObject(), + getOWLModelManager().getOWLDataFactory().getOWLSubClassAxiom( + getRootObject(), + desc))); + added.add(desc); + } + } + } + } + } + catch (OWLReasonerException e) { + throw new RuntimeException(e); + } + } + + + protected OWLSubClassAxiom createAxiom(OWLDescription object) { + return getOWLDataFactory().getOWLSubClassAxiom(getRootObject(), object); + } + + + public OWLFrameSectionRowObjectEditor<OWLDescription> getObjectEditor() { + return new OWLClassDescriptionEditorWithDLLearnerTab(getOWLEditorKit(), null, frame,LABEL); + } + + + public boolean canAcceptDrop(List<OWLObject> objects) { + for (OWLObject obj : objects) { + if (!(obj instanceof OWLDescription)) { + return false; + } + } + return true; + } + + + private OWLObjectProperty prop; + + + public boolean dropObjects(List<OWLObject> objects) { + List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); + for (OWLObject obj : objects) { + if (obj instanceof OWLDescription) { + OWLDescription desc; + if (prop != null) { + desc = getOWLDataFactory().getOWLObjectSomeRestriction(prop, (OWLDescription) obj); + } + else { + desc = (OWLDescription) obj; + } + OWLAxiom ax = getOWLDataFactory().getOWLSubClassAxiom(getRootObject(), desc); + changes.add(new AddAxiom(getOWLModelManager().getActiveOntology(), ax)); + } + else if (obj instanceof OWLObjectProperty) { + // Prime + prop = (OWLObjectProperty) obj; + } + else { + return false; + } + } + getOWLModelManager().applyChanges(changes); + return true; + } + + + public void visit(OWLSubClassAxiom axiom) { + if (axiom.getSubClass().equals(getRootObject())) { + reset(); + } + } + + + /** + * Obtains a comparator which can be used to sort the rows + * in this section. + * @return A comparator if to sort the rows in this section, + * or <code>null</code> if the rows shouldn't be sorted. + */ + public Comparator<OWLFrameSectionRow<OWLClass, OWLSubClassAxiom, OWLDescription>> getRowComparator() { + return new Comparator<OWLFrameSectionRow<OWLClass, OWLSubClassAxiom, OWLDescription>>() { + + private OWLDescriptionComparator comparator = new OWLDescriptionComparator(getOWLModelManager()); + + + public int compare(OWLFrameSectionRow<OWLClass, OWLSubClassAxiom, OWLDescription> o1, + OWLFrameSectionRow<OWLClass, OWLSubClassAxiom, OWLDescription> o2) { + int val = comparator.compare(o1.getAxiom().getSuperClass(), o2.getAxiom().getSuperClass()); + if (o1.isInferred()) { + if (o2.isInferred()) { + return val; + } + else { + return 1; + } + } + else { + if (o2.isInferred()) { + return -1; + } + else { + return val; + } + } + } + }; + } +} Deleted: trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java 2008-05-20 16:43:05 UTC (rev 908) +++ trunk/src/dl-learner/org/dllearner/tools/protege/SuggestEquivalentClassButton.java 2008-05-20 18:32:00 UTC (rev 909) @@ -1,67 +0,0 @@ -package org.dllearner.tools.protege; - -import java.util.Comparator; - -import org.protege.editor.owl.OWLEditorKit; -import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection; -import org.protege.editor.owl.ui.frame.OWLFrame; -import org.protege.editor.owl.ui.frame.OWLFrameSectionRow; -import org.protege.editor.owl.ui.frame.OWLFrameSection... [truncated message content] |