From: <hee...@us...> - 2009-02-23 16:07:18
|
Revision: 1623 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1623&view=rev Author: heeroyuy Date: 2009-02-23 16:07:10 +0000 (Mon, 23 Feb 2009) Log Message: ----------- -adjusting the graphicalCoveragePanel to the new learning algorithm -started new view for the more integrated version of the plugin 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/GraphicalCoveragePanel.java trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanelHandler.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 trunk/src/dl-learner/org/dllearner/tools/protege/ProtegePlugin.java trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerView.java Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -40,8 +40,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -//import org.apache.log4j.Logger; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; +import org.dllearner.algorithms.EvaluatedDescriptionClass; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.owl.Description; @@ -87,9 +86,7 @@ * id if it is a subclass or an equivalent class * */ - public ActionHandler(ActionHandler a, DLLearnerModel m, - OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view, - String i) { + public ActionHandler(ActionHandler a, DLLearnerModel m, OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view, String i) { this.view = view; this.id = i; this.model = m; @@ -108,12 +105,10 @@ if (z.getActionCommand().equals(id)) { model.setKnowledgeSource(); model.setReasoner(); - model.setPositiveAndNegativeExamples(); model.setLearningProblem(); model.setLearningAlgorithm(); view.getRunButton().setEnabled(false); view.renderErrorMessage("learning started"); - //view.getPosAndNegSelectPanel().setCheckBoxesEnable(false); retriever = new SuggestionRetriever(); retriever.execute(); @@ -132,7 +127,6 @@ } String message = "class description added"; view.renderErrorMessage(message); - view.updateWindow(); } if (z.getActionCommand().equals("")) { if (!toggled) { @@ -302,14 +296,6 @@ private Thread dlLearner; private DefaultListModel dm = new DefaultListModel(); - /** - * Errorlogger. - */ - //Logger logger = Logger.getLogger(SuggestionRetriever.class); - /** - * Errorlogger. - */ - //Logger rootLogger = Logger.getRootLogger(); @SuppressWarnings("unchecked") @Override @@ -321,8 +307,7 @@ @Override public void run() { if (la != null) { - publish(la.getCurrentlyBestEvaluatedDescriptions(view.getPosAndNegSelectPanel().getOptionPanel().getNrOfConcepts() - , view.getPosAndNegSelectPanel().getOptionPanel().getMinAccuracy(), true)); + publish(la.getCurrentlyBestEvaluatedDescriptions(view.getPosAndNegSelectPanel().getOptionPanel().getNrOfConcepts(), view.getPosAndNegSelectPanel().getOptionPanel().getMinAccuracy(), true)); } } @@ -382,7 +367,6 @@ private void updateList(final List<? extends EvaluatedDescription> result) { - //logger.debug("update list with " + result); Runnable doUpdateList = new Runnable() { @@ -396,12 +380,13 @@ Set<String> ont = model.getOntologyURIString(); for(String ontology : ont) { if(eval.getDescription().toString().contains(ontology)) { + //dm.add(i, new SuggestListItem(colorGreen, eval.getDescription().toManchesterSyntaxString(ontology, null), ((EvaluatedDescriptionClass)eval).getAccuracy()*100)); if(model.isConsistent(eval)) { - dm.add(i, new SuggestListItem(colorGreen, eval.getDescription().toManchesterSyntaxString(ontology, null), ((EvaluatedDescriptionPosNeg)eval).getAccuracy()*100)); + dm.add(i, new SuggestListItem(colorGreen, eval.getDescription().toManchesterSyntaxString(ontology, null), ((EvaluatedDescriptionClass)eval).getAccuracy()*100)); i++; break; } else { - dm.add(i, new SuggestListItem(colorRed, eval.getDescription().toManchesterSyntaxString(ontology, null), ((EvaluatedDescriptionPosNeg)eval).getAccuracy()*100)); + dm.add(i, new SuggestListItem(colorRed, eval.getDescription().toManchesterSyntaxString(ontology, null), ((EvaluatedDescriptionClass)eval).getAccuracy()*100)); i++; view.setIsInconsistent(true); break; Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -19,6 +19,7 @@ */ package org.dllearner.tools.protege; +import org.protege.editor.owl.OWLEditorKit; import org.protege.editor.owl.ui.frame.AbstractOWLFrame; import org.protege.editor.owl.ui.frame.InheritedAnonymousClassesFrameSection; import org.protege.editor.owl.ui.frame.OWLClassAssertionAxiomIndividualSection; @@ -26,7 +27,6 @@ //import org.protege.editor.owl.ui.frame.OWLEquivalentClassesAxiomFrameSection; //import org.protege.editor.owl.ui.frame.OWLSubClassAxiomFrameSection; import org.semanticweb.owl.model.OWLClass; -import org.protege.editor.owl.OWLEditorKit; /** * This class manages the list of the lists for equivalent classes and so on. @@ -39,6 +39,7 @@ public class ButtonList extends AbstractOWLFrame<OWLClass> { private OWLEquivalentClassesAxiomFrameSection equi; private OWLSubClassAxiomFrameSection sub; + //private DLLearnerView view; /** * Constructor of the Buttonlist. * @@ -48,6 +49,11 @@ super(editorKit.getModelManager().getOWLOntologyManager()); equi = new OWLEquivalentClassesAxiomFrameSection(editorKit, this); + //view = new DLLearnerView(equi.getName(), editorKit); + //OWLFrameSectionRowObjectEditor<OWLDescription> edit = equi.getObjectEditor(); + //OWLClassDescriptionEditor ed = (OWLClassDescriptionEditor)edit; + //ed.addPanel(view); + //equi.getEditor().getEditorComponent().validate(); sub = new OWLSubClassAxiomFrameSection(editorKit, this); // own OWLEquivalentClassesAxiomFrameSection to add the dllearner plugin // to the Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -24,14 +24,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import java.util.Vector; import javax.swing.DefaultListModel; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; -import org.dllearner.algorithms.refinement2.ROLComponent2; +import org.dllearner.algorithms.EvaluatedDescriptionClass; +import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; @@ -42,19 +40,15 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Thing; import org.dllearner.kb.OWLAPIOntology; -import org.dllearner.learningproblems.PosNegInclusionLP; -import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.mindswap.pellet.exceptions.InconsistentOntologyException; 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.AddAxiom; import org.semanticweb.owl.model.OWLAxiom; -import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataFactory; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLOntology; @@ -76,11 +70,9 @@ "org.dllearner.reasoning.OWLAPIReasoner", "org.dllearner.reasoning.FastInstanceChecker", "org.dllearner.reasoning.FastRetrievalReasoner", - "org.dllearner.learningproblems.PosNegInclusionLP", - "org.dllearner.learningproblems.PosNegDefinitionLP", "org.dllearner.algorithms.RandomGuesser", "org.dllearner.algorithms.refinement.ROLearner", - "org.dllearner.algorithms.refinement2.ROLComponent2", + "org.dllearner.algorithms.celoe.CELOE", "org.dllearner.algorithms.gp.GP", "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.ClassLearningProblem"}; @@ -88,22 +80,15 @@ private ComponentManager cm; - // The Reasoning Service for the Reasoner - - //private ReasonerComponent rs; private static final String EQUIVALENT_CLASS_AXIOM_STRING = "Suggest equivalent class"; private static final String SUPER_CLASS_AXIOM_STRING = "Suggest super class"; + private static final String EQUIVALENT_CLASS_LEARNING = "equivalence"; + private static final String SUPER_CLASS_LEARNING = "superClass"; // The View of the DL-Learner Plugin private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; - // This is the count of Concepts which you get after learning - - // A Array of Concepts which the DL-Learner suggested - - //private Description[] description; - // The Learning problem that is used to learn new concepts private LearningProblem lp; @@ -112,10 +97,6 @@ private boolean alreadyLearned = false; - // The Ontology which is currently used - - //private OWLOntology ontology; - // This is the learning algorithm private LearningAlgorithm la = null; @@ -124,10 +105,6 @@ private OWLEditorKit editor; - // Necessary to get the BaseUri of the currently loaded Ontology - - private OWLFrame<OWLClass> current; - // The Reasoner which is used to learn private FastInstanceChecker reasoner; @@ -136,14 +113,6 @@ private Set<OWLDescription> owlDescription; - // This set stores the positive examples. - - private Set<String> positiveExamples; - - // This set stores the negative examples that doesn't belong to the concept. - - private Set<String> negativeExamples; - // The most fitting Description in OWL Syntax which the DL-Learner suggested private OWLDescription desc; @@ -172,6 +141,7 @@ private Set<Individual> individual; private Set<OWLAPIOntology> ontologies; + private int instancesCount; // The error message which is rendered when an error occured @@ -182,7 +152,6 @@ // This is necessary to get the details of the suggested concept - //private JXTaskPane detailPane; private DefaultListModel posListModel; private DefaultListModel negListModel; private Set<KnowledgeSource> sources; @@ -191,7 +160,6 @@ private Vector<IndividualObject> individualVector; private Set<String> ontologieURI; private boolean ontologyConsistent; - //private String learning; // This is a List of evaluated descriptions to get more information of the // suggested concept @@ -209,15 +177,12 @@ * @param view * current view of the DL-Learner tab */ - public DLLearnerModel(OWLEditorKit editorKit, OWLFrame<OWLClass> h, - String id, - OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view) { + public DLLearnerModel(OWLEditorKit editorKit, String id, OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view) { editor = editorKit; - current = h; this.id = id; this.view = view; ontologyConsistent = true; - //learning = ""; + instancesCount = 0; owlDescription = new HashSet<OWLDescription>(); posListModel = new DefaultListModel(); negListModel = new DefaultListModel(); @@ -227,8 +192,6 @@ ds = new HashSet<OWLDescription>(); suggestModel = new DefaultListModel(); ontologieURI = new HashSet<String>(); - //detailPane = new JXTaskPane(); - //detailPane.setTitle("Details"); sources = new HashSet<KnowledgeSource>(); } @@ -244,24 +207,6 @@ } /** - * This method checks which positive and negative examples are checked and - * puts the checked examples into a tree set. - */ - public void setPositiveAndNegativeExamples() { - positiveExamples = new TreeSet<String>(); - negativeExamples = new TreeSet<String>(); - for (int i = 0; i < individualVector.size(); i++) { - if (individualVector.get(i).isPositiveExample()) { - positiveExamples.add(individualVector.get(i) - .getIndividualString()); - } else { - negativeExamples.add(individualVector.get(i) - .getIndividualString()); - } - } - } - - /** * This method returns the data for the suggest panel. * * @return Model for the suggest panel. @@ -338,26 +283,18 @@ * classes. */ public void setLearningProblem() { + lp = cm.learningProblem(ClassLearningProblem.class, reasoner); + cm.applyConfigEntry(lp, "classToDescribe", currentConcept.toString()); if (id.equals(EQUIVALENT_CLASS_AXIOM_STRING)) { // sets the learning problem to PosNegDefinitionLP when the // dllearner should suggest an equivalent class - lp = cm.learningProblem(PosNegLPStandard.class, reasoner); - //learning = "equivalence"; + cm.applyConfigEntry(lp, "type", EQUIVALENT_CLASS_LEARNING); } if (id.equals(SUPER_CLASS_AXIOM_STRING)) { // sets the learning problem to PosNegInclusionLP when the dllearner // should suggest a subclass - //Slearning = "superClass"; - lp = cm.learningProblem(PosNegInclusionLP.class, reasoner); + cm.applyConfigEntry(lp, "type", SUPER_CLASS_LEARNING); } - System.out.println("CURRENT: " + currentConcept); - //lp = cm.learningProblem(ClassLearningProblem.class, reasoner); - //cm.applyConfigEntry(lp, "classToDescribe", currentConcept); - //cm.applyConfigEntry(lp, "type", learning); - // adds the positive examples - cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); - // adds the negative examples - cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); try { lp.init(); } catch (ComponentInitException e) { @@ -370,32 +307,14 @@ */ public void setLearningAlgorithm() { try { - // sets the learning algorithm to ROlearner - this.la = cm.learningAlgorithm(ROLComponent2.class, lp, + this.la = cm.learningAlgorithm(CELOE.class, lp, reasoner); } catch (LearningProblemUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } - Set<String> ignore = new TreeSet<String>(); - ignore.add(currentConcept.toString()); - if(id.equals(SUPER_CLASS_AXIOM_STRING)) { - Description currentClass = (Description) currentConcept; - while(!(currentClass instanceof Thing)) { - SortedSet<Description> superClasses = reasoner.getSuperClasses(currentClass); - for(Description ignoredClass : superClasses) { - if(!(ignoredClass instanceof Thing)) { - ignore.add(ignoredClass.toString()); - } - currentClass = ignoredClass; - } - } - cm.applyConfigEntry(la, "useNegation", false); - } - cm.applyConfigEntry(la, "ignoredConcepts", ignore); + cm.applyConfigEntry(la, "useNegation", false); cm.applyConfigEntry(la, "noisePercentage", 5.0); - cm.applyConfigEntry(la, "terminateOnNoiseReached", false); - cm.applyConfigEntry(la, "negationPenalty", 2); cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", view .getPosAndNegSelectPanel().getOptionPanel() .getMaxExecutionTime()); @@ -423,42 +342,7 @@ public void run() { la.start(); } - /** - * This method sets the check boxes for the positive check boxes checked if - * the individuals matches the concept that is chosen in protege. - */ - public void setPosVector() { - setPositiveConcept(); - SortedSet<Individual> reasonerIndi = reasoner.getIndividuals(); - for(Individual ind : reasonerIndi) { - Set<String> onto = ontologieURI; - for(String ont : onto) { - String indiv = ind.toString(); - // checks if individual belongs to the selected concept - if (setPositivExamplesChecked(indiv)) { - if (indiv.contains(ont)) { - // when yes then it sets the positive example checked - // OWLExpressionCheckerFactory - posListModel.add(0, ind.toManchesterSyntaxString(ont, null)); - individualVector.add(new IndividualObject(indiv, true)); - break; - } - - } else { - // When no it unchecks the positive example - if (indiv.contains(ont)) { - individualVector - .add(new IndividualObject(indiv, false)); - negListModel.add(0, ind.toManchesterSyntaxString(ont, null)); - break; - } - } - } - } - - } - /** * This method resets the Concepts that are learned. */ @@ -478,54 +362,11 @@ } /** - * This method sets the individuals that belong to the concept which is - * chosen in protege. - */ - public void setPositiveConcept() { - SortedSet<Individual> individuals = null; - hasIndividuals = false; - // checks if selected concept is thing when yes then it selects all - // individuals - if (!(current.getRootObject() instanceof Thing)) { - List<NamedClass> classList = reasoner.getAtomicConceptsList(); - for(NamedClass concept : classList) { - // if individuals is null - if (individuals == null) { - // checks if the concept is the selected concept in protege - for(String onto : ontologieURI) { - if (concept.toString().contains(onto)) { - if (concept.toString().equals( - onto + current.getRootObject().toString())) { - // if individuals is not null it gets all - // individuals of - // the concept - currentConcept = concept; - if (reasoner.getIndividuals(concept) != null) { - if (reasoner.getIndividuals(concept).size() > 0) { - hasIndividuals = true; - } - individual = reasoner.getIndividuals(concept); - break; - } - } - } - } - } - } - } else { - if (reasoner.getIndividuals().size() > 0) { - hasIndividuals = true; - } - individual = reasoner.getIndividuals(); - } - } - - /** * This method sets the positive examples for learning. * @param ind */ public void setIndividuals(Set<Individual> ind) { - this.individual = ind; + individual = ind; } /** @@ -554,28 +395,6 @@ } /** - * This method gets an Individual and checks if this individual belongs to - * the concept chosen in protege. - * - * @param indi - * Individual to check if it belongs to the chosen concept - * @return is Individual belongs to the concept which is chosen in protege. - */ - private boolean setPositivExamplesChecked(String indi) { - boolean isChecked = false; - // checks if individuals are not empty - if (individual != null) { - // checks if the delivered individual belongs to the individuals of - // the selected concept - if (individual.toString().contains(indi)) { - isChecked = true; - } - } - return isChecked; - - } - - /** * This method resets the vectors where the check boxes for positive and * negative Examples are stored. It is called when the DL-Learner View is * closed. @@ -658,15 +477,6 @@ } /** - * This method returns the current OWLOntology that is loaded in protege. - * - * @return current ontology - - public OWLOntology getOWLOntology() { - return ontology; - } */ - - /** * This method returns a set of concepts that are learned by the DL-Learner. * They are already converted into the OWLDescription format. * @@ -687,7 +497,10 @@ .getOWLDescription(currentConcept); return oldConceptOWLAPI; } - + + public Set<OWLDescription> getDescriptions() { + return ds; + } /** * This method returns the currently learned description in OWLDescription * format. @@ -757,15 +570,6 @@ } /** - * This method returns the currently used reasoning service. - * - * @return current reasoning service - - public ReasonerComponent getReasonerComponent() { - return rs; - }*/ - - /** * This method gets the status if the DL-Learner has already learned. It is * only for reseting the suggest panel. * @@ -785,10 +589,10 @@ */ public boolean isConsistent(EvaluatedDescription eDescription) { boolean isConsistent = false; - if (((EvaluatedDescriptionPosNeg)eDescription).getNotCoveredPositives().isEmpty()) { - isConsistent = true; - } else { + if (((EvaluatedDescriptionClass)eDescription).getCoveredInstances().size() < instancesCount) { isConsistent = false; + } else { + isConsistent = true; } return isConsistent; } @@ -839,28 +643,6 @@ } /** - * Checks the URI if a "#" is in it. - */ - public void checkURI() { - Set<OWLOntology> ont = editor.getModelManager().getActiveOntologies(); - Set<Individual> indi = reasoner.getIndividuals(); - for(OWLOntology onto : ont) { - String ontURI = onto.getURI().toString(); - for(Individual ind : indi) { - if(ind.toString().contains(ontURI)) { - if(ind.toString().contains("#")) { - ontologieURI.add(onto.getURI().toString()+"#"); - break; - } else { - ontologieURI.add(onto.getURI().toString()); - break; - } - } - } - } - } - - /** * This method returns the Strings of the Ontology uri's that are currently used. * @return ontologieURI */ @@ -907,6 +689,17 @@ this.currentConcept = current; } + /** + * @return the individual + */ + public Set<Individual> getIndividual() { + return individual; + } + + public void setInstancesCount(int i) { + instancesCount = i; + } + } Added: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerView.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerView.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerView.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -0,0 +1,415 @@ +package org.dllearner.tools.protege; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.ActionListener; +import java.net.URL; +import java.util.Set; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JToggleButton; + +import org.protege.editor.core.ui.util.InputVerificationStatusChangedListener; +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.editor.OWLDescriptionEditor; +import org.semanticweb.owl.model.OWLDescription; + +public class DLLearnerView extends JPanel implements OWLDescriptionEditor{ + + + private static final long serialVersionUID = 624829578325729385L; + //private OWLClassDescriptionEditorWithDLLearnerTab mainWindow; + // this is the Component which shows the view of the dllearner + private static final String TITLE = "DL-Learner"; + private JComponent learner; + + // Accept button to add the learned concept to the owl + + private JButton accept; + + // Runbutton to start the learning algorithm + + private JButton run; + + // This is the label for the advanced button. + + private JLabel adv; + + // This is the color for the error message. It is red. + + private final Color colorRed = Color.red; + + // This is the text area for the error message when an error occurred + + private JTextArea errorMessage; + + // Advanced Button to activate/deactivate the example select panel + + private JToggleButton advanced; + + // Action Handler that manages the Button actions + + private ActionHandler action; + + // This is the model of the dllearner plugin which includes all data + + private DLLearnerModel model; + + // Panel for the suggested concepts + + private SuggestClassPanel sugPanel; + + // Selection panel for the positive and negative examples + + private PosAndNegSelectPanel posPanel; + + // Picture for the advanced button when it is not toggled + + private ImageIcon icon; + + // Picture of the advanced button when it is toggled + private JPanel addButtonPanel; + private JLabel wikiPane; + private ImageIcon toggledIcon; + private JTextArea hint; + private boolean isInconsistent; + // This is the Panel for more details of the suggested concept + private MoreDetailForSuggestedConceptsPanel detail; + //private OWLFrame<OWLClass> frame; + private ReadingOntologyThread readThread; + //private OWLEditorKit editorKit; + + /** + * The constructor for the DL-Learner tab in the class description + * editor. + * + * @param current OWLFrame + * @param label String + * @param dlLearner OWLClassDescriptionEditorWithDLLearnerTab + */ + public DLLearnerView(String label, OWLEditorKit editor) { + //mainWindow = dlLearner; + //editorKit = editor; + wikiPane = new JLabel("<html>See <a href=\"http://dl-learner.org/wiki/ProtegePlugin\">http://dl-learner.org/wiki/ProtegePlugin</a> for an introduction.</html>"); + URL iconUrl = this.getClass().getResource("arrow.gif"); + icon = new ImageIcon(iconUrl); + URL toggledIconUrl = this.getClass().getResource("arrow2.gif"); + toggledIcon = new ImageIcon(toggledIconUrl); + //model = new DLLearnerModel(editorKit, label, this); + sugPanel = new SuggestClassPanel(); + //action = new ActionHandler(this.action, model, this, label); + adv = new JLabel("Advanced Settings"); + advanced = new JToggleButton(icon); + advanced.setVisible(true); + run = new JButton(label); + accept = new JButton("ADD"); + addButtonPanel = new JPanel(new BorderLayout()); + sugPanel.addSuggestPanelMouseListener(action); + errorMessage = new JTextArea(); + errorMessage.setEditable(false); + hint = new JTextArea(); + hint.setEditable(false); + hint.setText("To get suggestions for class descriptions, please click the button above."); + learner = new JPanel(); + advanced.setSize(20, 20); + learner.setLayout(null); + learner.setPreferredSize(new Dimension(600, 520)); + accept.setPreferredSize(new Dimension(290, 50)); + advanced.setName("Advanced"); + //posPanel = new PosAndNegSelectPanel(model, action, this); + addAcceptButtonListener(this.action); + addRunButtonListener(this.action); + addAdvancedButtonListener(this.action); + + + } + /** + * This method returns the SuggestClassPanel. + * @return SuggestClassPanel + */ + public SuggestClassPanel getSuggestClassPanel() { + return sugPanel; + } + /** + * This method returns the PosAndNegSelectPanel. + * @return PosAndNegSelectPanel + */ + public PosAndNegSelectPanel getPosAndNegSelectPanel() { + return posPanel; + } + + /** + * Returns the Mainwindow where the Plugin is integratet. + * @return OWLClassDescriptionWithDLLearnerTab MainWindow + */ + //public OWLClassDescriptionEditorWithDLLearnerTab getMainWindow() { + // return mainWindow; + //} + /** + * This Method renders the view of the plugin. + */ + public void makeView() { + run.setEnabled(false); + model.clearVector(); + hint.setText("To get suggestions for class descriptions, please click the button above."); + isInconsistent = false; + //readThread = new ReadingOntologyThread(editorKit, this, model); + readThread.start(); + //TODO: runbutton wird auf enable gesetzt obwohl keine instanzdaten vorhanden sind. + + hint.setVisible(true); + advanced.setIcon(icon); + accept.setEnabled(false); + action.resetToggled(); + addButtonPanel.add("North", accept); + sugPanel.setSuggestList(model.getSuggestList()); + sugPanel = sugPanel.updateSuggestClassList(); + advanced.setSelected(false); + sugPanel.setBounds(10, 35, 490, 110); + adv.setBounds(40, 200, 200, 20); + wikiPane.setBounds(220, 0, 350, 30); + addButtonPanel.setBounds(510, 40, 80, 110); + run.setBounds(10, 0, 200, 30); + advanced.setBounds(10, 200, 20, 20); + sugPanel.setVisible(true); + posPanel.setVisible(false); + //posPanel.getAddToNegPanelButton().setEnabled(false); + //posPanel.getAddToPosPanelButton().setEnabled(false); + posPanel.setBounds(10, 230, 490, 250); + accept.setBounds(510, 40, 80, 110); + hint.setBounds(10, 150, 490, 35); + errorMessage.setBounds(10, 180, 490, 20); + learner.add(run); + learner.add(wikiPane); + learner.add(adv); + learner.add(advanced); + learner.add(sugPanel); + learner.add(addButtonPanel); + learner.add(hint); + learner.add(errorMessage); + learner.add(posPanel); + detail = new MoreDetailForSuggestedConceptsPanel(model); + add(learner); + + } + /** + * This method sets the right icon for the advanced Panel. + * @param toggled boolean + */ + public void setIconToggled(boolean toggled) { + if (toggled) { + advanced.setIcon(toggledIcon); + } + if (!toggled) { + advanced.setIcon(icon); + } + } + + /** + * This Method changes the hint message. + * @param message String hintmessage + */ + public void setHintMessage(String message) { + hint.setText(message); + } + public JTextArea getHintPanel() { + return hint; + } + /** + * This Method returns the DL_Learner tab. + * @return JComponent + */ + public JComponent getLearnerPanel() { + return learner; + } + + /** + * Sets the panel to select/deselect the examples visible/invisible. + * @param visible boolean + */ + public void setExamplePanelVisible(boolean visible) { + posPanel.setVisible(visible); + } + + /** + * Returns nothing. + * @return null + */ + public JPanel getOptionPanel() { + return null; + } + + /** + * Returns the AddButton. + * @return JButton + */ + public JButton getAddButton() { + return accept; + } + /** + * This Method updates the the view of protege after + * adding a new concept. + */ + //public void updateWindow() { + // mainWindow.getHandler().handleEditingFinished(mainWindow.getEditedObjects()); + //} + /** + * Returns all added descriptions. + * @return Set(OWLDescription) + */ + public Set<OWLDescription> getSollutions() { + + return model.getNewOWLDescription(); + } + + /** + * Returns the last added description. + * @return OWLDescription + */ + public OWLDescription getSollution() { + return model.getSolution(); + } + + /** + * Destroys everything in the view after the plugin is closed. + */ + public void unsetEverything() { + run.setEnabled(true); + model.unsetNewConcepts(); + action.destroyDLLearnerThread(); + errorMessage.setText(""); + //posPanel.unsetPosAndNegPanel(); + learner.removeAll(); + } + + /** + * Renders the error message when an error occured. + * @param s String + */ + public void renderErrorMessage(String s) { + errorMessage.setForeground(colorRed); + errorMessage.setText(s); + } + /** + * This Method returns the panel for more details for the chosen concept. + * @return MoreDetailForSuggestedConceptsPanel + */ + public MoreDetailForSuggestedConceptsPanel getMoreDetailForSuggestedConceptsPanel() { + return detail; + } + + /** + * This Method returns the run button. + * @return JButton + */ + public JButton getRunButton() { + return run; + } + + /** + * This method sets if ontology is inconsistent or not. + * @param isIncon boolean if ontology is consisten + */ + public void setIsInconsistent(boolean isIncon) { + this.isInconsistent = isIncon; + } + /** + * Destroys the view after the plugin is closed. + */ + @Override + public void dispose() { + run.removeActionListener(action); + accept.removeActionListener(action); + advanced.removeActionListener(action); + //posPanel.removeListeners(action); + //posPanel.removeHelpButtonListener(action); + } + + /** + * Adds Actionlistener to the run button. + * @param a ActionListener + */ + public void addRunButtonListener(ActionListener a) { + run.addActionListener(a); + } + + /** + * Adds Actionlistener to the add button. + * @param a ActionListener + */ + public void addAcceptButtonListener(ActionListener a) { + accept.addActionListener(a); + } + + /** + * Adds Actionlistener to the advanced button. + * @param a ActionListener + */ + public void addAdvancedButtonListener(ActionListener a) { + advanced.addActionListener(a); + } + + /** + * This method sets the run button enable after learning. + */ + public void algorithmTerminated() { + String error = "learning succesful"; + String message = ""; + if(isInconsistent) { + message = "Class descriptions marked red will lead to an inconsistent ontology. \nPlease double click on them to view detail information."; + } else { + message = "To view details about why a class description was suggested, please doubleclick on it."; + } + run.setEnabled(true); + // start the algorithm and print the best concept found + renderErrorMessage(error); + setHintMessage(message); + } + + @Override + public JComponent getComponent() { + return this; + } + + @Override + public Set<OWLDescription> getDescriptions() { + return model.getDescriptions(); + } + + @Override + public String getEditorName() { + return TITLE; + } + + @Override + public boolean isValidInput() { + return true; + } + + @Override + public boolean setDescription(OWLDescription arg0) { + // TODO Auto-generated method stub + return true; + } + + @Override + public void addStatusChangedListener( + InputVerificationStatusChangedListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void removeStatusChangedListener( + InputVerificationStatusChangedListener arg0) { + // TODO Auto-generated method stub + + } + +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -10,7 +10,7 @@ import javax.swing.JPanel; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; +import org.dllearner.algorithms.EvaluatedDescriptionClass; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.owl.Individual; @@ -22,7 +22,7 @@ private static final int maxNumberOfIndividualPoints = 20; private static final int gap = 20; private int shiftXAxis; - private int distortion; + private int distortionOld; private Ellipse2D oldConcept; private Ellipse2D newConcept; @@ -31,9 +31,9 @@ private String conceptNew; private Vector<IndividualPoint> posCovIndVector; private Vector<IndividualPoint> posNotCovIndVector; - private Vector<IndividualPoint> negCovIndVector; private Vector<IndividualPoint> points; private GraphicalCoveragePanelHandler handler; + private int adjustment; private MoreDetailForSuggestedConceptsPanel panel; /** @@ -50,14 +50,12 @@ conceptNew = concept; posCovIndVector = new Vector<IndividualPoint>(); posNotCovIndVector = new Vector<IndividualPoint>(); - negCovIndVector = new Vector<IndividualPoint>(); points = new Vector<IndividualPoint>(); this.computeGraphics(); handler = new GraphicalCoveragePanelHandler(this); - oldConcept = new Ellipse2D.Float(5, 25, 250, 250); - newConcept = new Ellipse2D.Float(5+shiftXAxis, 25, width+distortion, height+distortion); + oldConcept = new Ellipse2D.Float(5, 25+adjustment, width-distortionOld, height-distortionOld); + newConcept = new Ellipse2D.Float(5+shiftXAxis, 25, width, height); this.computeIndividualPoints(); - //this.addMouseListener(handler); this.addMouseMotionListener(handler); this.addPropertyChangeListener(handler); } @@ -73,15 +71,15 @@ protected void paintComponent(Graphics g) { Graphics2D g2D; g2D = (Graphics2D) g; - + g2D.setColor(Color.GREEN); + g2D.draw (oldConcept); + g2D.drawString(model.getOldConceptOWLAPI().toString(), 10, 15); g2D.setColor(Color.RED); g2D.draw (newConcept); - //g.drawOval((5+shiftXAxis), 25, width+distortion, height+distortion); g2D.drawString(conceptNew, 10 + width, 15); - g2D.setColor(Color.GREEN); - g2D.draw (oldConcept); - g2D.drawString(model.getOldConceptOWLAPI().toString(), 10, 15); + + for(int i = 0; i < posCovIndVector.size(); i++) { g2D.setColor(Color.BLACK); g2D.drawString(posCovIndVector.get(i).getPoint(), posCovIndVector.get(i).getXAxis(), posCovIndVector.get(i).getYAxis()); @@ -91,123 +89,138 @@ g2D.setColor(Color.BLACK); g2D.drawString(posNotCovIndVector.get(i).getPoint(), posNotCovIndVector.get(i).getXAxis(), posNotCovIndVector.get(i).getYAxis()); } - - for(int i = 0; i < negCovIndVector.size(); i++) { - g2D.setColor(Color.BLACK); - g2D.drawString(negCovIndVector.get(i).getPoint(), negCovIndVector.get(i).getXAxis(), negCovIndVector.get(i).getYAxis()); - } } private void computeGraphics(){ - int posGes = model.getPosListModel().size(); - int notCovPos = ((EvaluatedDescriptionPosNeg)eval).getNotCoveredPositives().size(); - //int covNeg = ((EvaluatedDescriptionPosNeg)eval).getCoveredNegatives().size(); - //int negGes = model.getNegListModel().size(); - double notCov = notCovPos; - float shift = (float) (width*(notCov/posGes)); - shiftXAxis = Math.round(shift); - distortion = 0; - //if(shiftXAxis == 0) { - // distortion = Math.round((width*(covNeg/negGes))/4); - //} - + int add = ((EvaluatedDescriptionClass)eval).getAdditionalInstances().size(); + distortionOld = 0; + adjustment = 0; + double additional = ((EvaluatedDescriptionClass)eval).getAddition(); + double coverage = ((EvaluatedDescriptionClass)eval).getCoverage(); + shiftXAxis = (int) Math.round(width* (1-coverage)); + if(add != 0) { + distortionOld = (int) Math.round(width*additional); + newConcept = new Ellipse2D.Float(5+shiftXAxis, 25, width, height); + adjustment = (int) Math.round(newConcept.getCenterY()/4); + + } + } private void computeIndividualPoints() { - Set<Individual> posInd = ((EvaluatedDescriptionPosNeg)eval).getCoveredPositives(); + Set<Individual> posInd = ((EvaluatedDescriptionClass)eval).getCoveredInstances(); + int i = 0; double x = 20; double y = 20; + boolean flag = true; for(Individual ind : posInd) { + flag = true; if(i<maxNumberOfIndividualPoints) { - i++; - if(x >= oldConcept.getMaxX()) { - x = (int) oldConcept.getMinX(); - y = y + gap; - } + while(flag) { + if(x >= oldConcept.getMaxX()) { + x = (int) oldConcept.getMinX(); + y = y + gap; + } - if(y >= oldConcept.getMaxY()) { - y = (int) oldConcept.getMinY(); - } + if(y >= oldConcept.getMaxY()) { + y = (int) oldConcept.getMinY(); + } - if(x >= newConcept.getMaxX()) { - x = (int) newConcept.getMinX(); - y = y + gap; - } + if(x >= newConcept.getMaxX()) { + x = (int) newConcept.getMinX(); + y = y + gap; + } - if(y >= newConcept.getMaxY()) { - y = (int) newConcept.getMinY(); - } + if(y >= newConcept.getMaxY()) { + y = (int) newConcept.getMinY(); + } - while(x < newConcept.getMaxX()) { + while(x < newConcept.getMaxX()) { - if(newConcept.contains(x, y) && oldConcept.contains(x, y)) { - posCovIndVector.add(new IndividualPoint("+",(int)x,(int)y,ind.toString())); - x = x + gap; - break; - } else { - x = x + gap; + if(newConcept.contains(x, y) && oldConcept.contains(x, y)) { + posCovIndVector.add(new IndividualPoint("+",(int)x,(int)y,ind.toString())); + i++; + flag = false; + x = x + gap; + break; + } else { + x = x + gap; + } } } } } - Set<Individual> posNotCovInd = ((EvaluatedDescriptionPosNeg)eval).getNotCoveredPositives(); + Set<Individual> posNotCovInd = ((EvaluatedDescriptionClass)eval).getAdditionalInstances(); int j = 0; + x = 20; + y = 20; for(Individual ind : posNotCovInd) { + flag = true; if(j<maxNumberOfIndividualPoints) { - j++; - if(x >= oldConcept.getMaxX()) { - x = (int) oldConcept.getMinX(); - y = y + gap; - } + while(flag) { + if(x >= newConcept.getMaxX()) { + x = (int) oldConcept.getMinX(); + y = y + gap; + } - if(y >= oldConcept.getMaxY()) { - y = (int) oldConcept.getMinY(); - } + if(y >= newConcept.getMaxY()) { + y = (int) oldConcept.getMinY(); + } - while(x < oldConcept.getMaxX()) { + while(x < newConcept.getMaxX()) { - if(oldConcept.contains(x, y)&&!newConcept.contains(x, y)) { - posNotCovIndVector.add(new IndividualPoint("-",(int)x,(int)y,ind.toString())); - x = x + gap; - break; - } else { - x = x + gap; + if(!oldConcept.contains(x, y) && newConcept.contains(x, y)) { + posNotCovIndVector.add(new IndividualPoint("-",(int)x,(int)y,ind.toString())); + j++; + flag = false; + x = x + gap; + break; + } else { + x = x + gap; + } } } } } - Set<Individual> negCovInd = ((EvaluatedDescriptionPosNeg)eval).getCoveredNegatives(); + Set<Individual> notCovInd = model.getReasoner().getIndividuals(model.getCurrentConcept()); + notCovInd.removeAll(posInd); int k = 0; - for(Individual ind : negCovInd) { + x = 20; + y = 20; + for(Individual ind : notCovInd) { + flag = true; if(k<maxNumberOfIndividualPoints) { - k++; - if(x >= newConcept.getMaxX()) { - x = (int) newConcept.getMinX(); - y = y + gap; - } + while(flag) { + if(x >= oldConcept.getMaxX()) { + x = (int) oldConcept.getMinX(); + y = y + gap; + } - if(y >= newConcept.getMaxY()) { - y = (int) newConcept.getMinY(); - } + if(y >= oldConcept.getMaxY()) { + y = (int) oldConcept.getMinY(); + } - while(x < newConcept.getMaxX()) { - if(newConcept.contains(x, y) && !oldConcept.contains(x, y)) { - negCovIndVector.add(new IndividualPoint("o",(int)x,(int)y,ind.toString())); - x = x + gap; - break; - } else { - x = x + gap; + while(x < oldConcept.getMaxX()) { + + if(oldConcept.contains(x, y) && !newConcept.contains(x, y)) { + posNotCovIndVector.add(new IndividualPoint("-",(int)x,(int)y,ind.toString())); + k++; + flag = false; + x = x + gap; + break; + } else { + x = x + gap; + } } } } } points.addAll(posCovIndVector); points.addAll(posNotCovIndVector); - points.addAll(negCovIndVector); } public Vector<IndividualPoint> getIndividualVector() { Modified: trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -31,9 +31,8 @@ import javax.swing.JTextArea; import javax.swing.WindowConstants; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; +import org.dllearner.algorithms.EvaluatedDescriptionClass; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.owl.Individual; @@ -279,11 +278,11 @@ } //sets the accuracy of the concept - double acc = ((EvaluatedDescriptionPosNeg)eval).getAccuracy()*100; + double acc = ((EvaluatedDescriptionClass)eval).getAccuracy()*100; accuracyText.setText(String.valueOf(acc)+"%"); //Sets positive Covered Examples for the detail panel - Set<Individual> indi = ((EvaluatedDescriptionPosNeg)eval).getCoveredPositives(); + /*Set<Individual> indi = ((EvaluatedDescriptionPosNeg)eval).getCoveredPositives(); for(Individual ind : indi) { for(String ontology : ontologiesStrings) { if(ind.toString().contains(ontology)) { @@ -335,7 +334,7 @@ break; } } - } + }*/ } } } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanelHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanelHandler.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanelHandler.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -7,6 +7,7 @@ import javax.swing.JOptionPane; +import org.dllearner.algorithms.EvaluatedDescriptionClass; import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.owl.Individual; @@ -38,7 +39,8 @@ } if(a.getActionCommand().equals(NEW_BUTTON_LABEL)) { - Set<Individual> posInd = ((EvaluatedDescriptionPosNeg)eval).getCoveredPositives(); + Set<Individual> posInd = ((EvaluatedDescriptionClass)eval).getCoveredInstances(); + posInd.addAll(((EvaluatedDescriptionClass)eval).getAdditionalInstances()); Set<String> uri = model.getOntologyURIString(); String toolTip = "This are the Individuals beloning to\n "; for(String u : uri) { Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -95,7 +95,7 @@ private ObjectRestrictionCreatorPanel restrictionCreatorPanel; - // private OWLDescription initialDescription; + //private OWLDescription initialDescription; private Set<InputVerificationStatusChangedListener> listeners = new HashSet<InputVerificationStatusChangedListener>(); @@ -114,12 +114,12 @@ public OWLClassDescriptionEditorWithDLLearnerTab(OWLEditorKit editorKit, OWLDescription description, OWLFrame<OWLClass> frame, String label) { this.editorKit = editorKit; - // this.initialDescription = description; - //checker = new OWLDescriptionChecker(editorKit); + //this.initialDescription = description; + //checker = new OWLDescriptionChecker(editorKit.getModelManager()); editor = new ExpressionEditor<OWLDescription>(editorKit, editorKit.getModelManager().getOWLExpressionCheckerFactory().getOWLDescriptionChecker()); editor.setExpressionObject(description); - action = new ActionHandler(this.action, null, dllearner, null); + action = new ActionHandler(this.action, null, dllearner, label); tabbedPane = new JTabbedPane(); tabbedPane.setFocusable(false); editingComponent = new JPanel(new BorderLayout()); @@ -380,7 +380,7 @@ icon = new ImageIcon(iconUrl); URL toggledIconUrl = this.getClass().getResource("arrow2.gif"); toggledIcon = new ImageIcon(toggledIconUrl); - model = new DLLearnerModel(editorKit, current, label, this); + model = new DLLearnerModel(editorKit, label, this); sugPanel = new SuggestClassPanel(); action = new ActionHandler(this.action, model, this, label); adv = new JLabel("Advanced Settings"); Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -26,11 +26,11 @@ import java.util.Set; import org.protege.editor.owl.OWLEditorKit; -import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection; import org.protege.editor.owl.ui.frame.OWLEquivalentClassesAxiomFrameSectionRow; import org.protege.editor.owl.ui.frame.OWLFrame; import org.protege.editor.owl.ui.frame.OWLFrameSectionRow; import org.protege.editor.owl.ui.frame.OWLFrameSectionRowObjectEditor; +import org.protege.editor.owl.ui.frame.cls.AbstractOWLClassAxiomFrameSection; import org.semanticweb.owl.inference.OWLReasonerException; import org.semanticweb.owl.inference.UnsupportedReasonerOperationException; import org.semanticweb.owl.model.AddAxiom; @@ -52,145 +52,147 @@ * Date: 19-Jan-2007<br> * <br> */ -public class OWLEquivalentClassesAxiomFrameSection - extends - AbstractOWLFrameSection<OWLClass, OWLEquivalentClassesAxiom, OWLDescription> { +public class OWLEquivalentClassesAxiomFrameSection extends AbstractOWLClassAxiomFrameSection<OWLEquivalentClassesAxiom, OWLDescription> { - private static final String LABEL = "equivalent classes"; + private static final String LABEL = "equivalent classes"; - private Set<OWLClass> added; + private Set<OWLDescription> added = new HashSet<OWLDescription>(); - private boolean inferredEquivalentClasses = true; - private OWLClassDescriptionEditorWithDLLearnerTab dlLearner; + private boolean inferredEquivalentClasses = true; + + private OWLFrame<OWLClass> frame; - private OWLFrame<OWLClass> frame; - /** - * Constructor of the OWLEquivalentClassesAxiomFrameSection. - * @param editorKit OWLEditorKit - * @param frame OWLFrame - */ - public OWLEquivalentClassesAxiomFrameSection(OWLEditorKit editorKit, - OWLFrame<OWLClass> frame) { - super(editorKit, LABEL, frame); - added = new HashSet<OWLClass>(); - this.frame = frame; - } - @Override - protected void clear() { - added.clear(); - } + public OWLEquivalentClassesAxiomFrameSection(OWLEditorKit editorKit, OWLFrame<OWLClass> frame) { + super(editorKit, LABEL, "Equivalent class", frame); + this.frame = frame; + } - /** - * Refills the section with rows. This method will be called by the system - * and should be directly called. - * @param ontology OWLOntology - */ - @Override - 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()); - } - } - } - } - @Override - 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(); - } - } + protected void clear() { + added.clear(); + } - @Override - public void visit(OWLEquivalentClassesAxiom axiom) { - if (axiom.getDescriptions().contains(getRootObject())) { - reset(); - } - } - @Override - protected OWLEquivalentClassesAxiom createAxiom(OWLDescription object) { - return getOWLDataFactory().getOWLEquivalentClassesAxiom( - CollectionFactory.createSet(getRootObject(), object)); - } + protected void addAxiom(OWLEquivalentClassesAxiom ax, OWLOntology ontology) { + addRow(new OWLEquivalentClassesAxiomFrameSectionRow(getOWLEditorKit(), + this, + ontology, + getRootObject(), + ax)); + for (OWLDescription desc : ax.getDescriptions()) { + added.add(desc); + } + } - @Override - public OWLFrameSectionRowObjectEditor<OWLDescription> getObjectEditor() { - // Own OWLClassDescriptionEditor to integrate the dllearner in protege - // This is to suggest equivalent classes - dlLearner = new OWLClassDescriptionEditorWithDLLearnerTab(getOWLEditorKit(), - null, frame, LABEL); - return dlLearner; - } - @Override - public boolean canAcceptDrop(List<OWLObject> objects) { - for (OWLObject obj : objects) { - if (!(obj instanceof OWLDescription)) { - return false; - } - } - return true; - } + protected Set<OWLEquivalentClassesAxiom> getClassAxioms(OWLDescription descr, OWLOntology ont) { + if (!descr.isAnonymous()){ + return ont.getEquivalentClassesAxioms(descr.asOWLClass()); + } + else{ + Set<OWLEquivalentClassesAxiom> axioms = new HashSet<OWLEquivalentClassesAxiom>(); + for (OWLAxiom ax : ont.getGeneralClassAxioms()){ + if (ax instanceof OWLEquivalentClassesAxiom && + ((OWLEquivalentClassesAxiom)ax).getDescriptions().contains(descr)){ + axioms.add((OWLEquivalentClassesAxiom)ax); + } + } + return axioms; + } + } - @Override - 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; - } -} + 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())))); + } + else{ + for (OWLDescription 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<OWLDescription, OWLEquivalentClassesAxiom, OWLDescription>> getRowComparator() { + return null; + } +} \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java 2009-02-23 08:13:57 UTC (rev 1622) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java 2009-02-23 16:07:10 UTC (rev 1623) @@ -26,8 +26,11 @@ import java.util.Set; import org.protege.editor.owl.OWLEditorKit; -import org.protege.editor.owl.ui.f... [truncated message content] |