From: <hee...@us...> - 2009-02-03 12:22:17
|
Revision: 1584 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1584&view=rev Author: heeroyuy Date: 2009-02-03 11:35:36 +0000 (Tue, 03 Feb 2009) Log Message: ----------- -started graphical display for coverage of learned concept -started own thread for selecting positive and negative examples Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/IndividualObject.java trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java trunk/src/dl-learner/org/dllearner/tools/protege/SuggestListItem.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanelHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/IndividualPoint.java trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -84,8 +84,7 @@ * DLlearner tab * @param i * id if it is a subclass or an equivalent class - * @param editor - * OWLEditorKit + * */ public ActionHandler(ActionHandler a, DLLearnerModel m, OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view, @@ -302,7 +301,13 @@ private Thread dlLearner; private DefaultListModel dm = new DefaultListModel(); + /** + * Errorlogger. + */ Logger logger = Logger.getLogger(SuggestionRetriever.class); + /** + * Errorlogger. + */ Logger rootLogger = Logger.getRootLogger(); @SuppressWarnings("unchecked") @@ -391,11 +396,11 @@ for(String ontology : ont) { if(eval.getDescription().toString().contains(ontology)) { if(model.isConsistent(eval)) { - dm.add(i, new SuggestListItem(colorGreen, eval.getDescription().toManchesterSyntaxString(ontology, null),eval.getAccuracy()*100)); + dm.add(i, new SuggestListItem(colorGreen, eval.getDescription().toManchesterSyntaxString(ontology, null), eval.getAccuracy()*100)); i++; break; } else { - dm.add(i, new SuggestListItem(colorRed, eval.getDescription().toManchesterSyntaxString(ontology, null),eval.getAccuracy()*100)); + dm.add(i, new SuggestListItem(colorRed, eval.getDescription().toManchesterSyntaxString(ontology, null), eval.getAccuracy()*100)); i++; view.setIsInconsistent(true); break; Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -38,7 +38,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -48,7 +47,6 @@ import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; -import org.jdesktop.swingx.JXTaskPane; import org.mindswap.pellet.exceptions.InconsistentOntologyException; import org.protege.editor.owl.OWLEditorKit; import org.protege.editor.owl.ui.frame.OWLFrame; @@ -90,7 +88,7 @@ // The Reasoning Service for the Reasoner - private ReasonerComponent rs; + //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"; @@ -102,7 +100,7 @@ // A Array of Concepts which the DL-Learner suggested - private Description[] description; + //private Description[] description; // The Learning problem that is used to learn new concepts @@ -114,7 +112,7 @@ // The Ontology which is currently used - private OWLOntology ontology; + //private OWLOntology ontology; // This is the learning algorithm @@ -182,7 +180,7 @@ // This is necessary to get the details of the suggested concept - private JXTaskPane detailPane; + //private JXTaskPane detailPane; private DefaultListModel posListModel; private DefaultListModel negListModel; private Set<KnowledgeSource> sources; @@ -225,8 +223,8 @@ ds = new HashSet<OWLDescription>(); suggestModel = new DefaultListModel(); ontologieURI = new HashSet<String>(); - detailPane = new JXTaskPane(); - detailPane.setTitle("Details"); + //detailPane = new JXTaskPane(); + //detailPane.setTitle("Details"); sources = new HashSet<KnowledgeSource>(); } @@ -272,10 +270,10 @@ * This method returns an array of descriptions learned by the DL-Learner. * * @return Array of descriptions learned by the DL-Learner. - */ + public Description[] getDescriptions() { return description; - } + }*/ /** * This Method returns a List of evaluated descriptions suggested by the @@ -292,8 +290,8 @@ * OWLAPIOntology will be available. */ public void setKnowledgeSource() { - Set<OWLOntology> ontologies = editor.getModelManager().getActiveOntologies(); - for(OWLOntology onto : ontologies) { + Set<OWLOntology> ontologieSet = editor.getModelManager().getActiveOntologies(); + for(OWLOntology onto : ontologieSet) { sources.add(new OWLAPIOntology(onto)); } } @@ -318,8 +316,19 @@ // rs = cm.reasoningService(reasoner); } - + + public FastInstanceChecker getReasoner() { + return reasoner; + } + /** + * This method returns the current concept. + * @return current concept + */ + public NamedClass getCurrentConcept() { + return currentConcept; + } + /** * This method sets the Learning problem for the learning process. * PosNegDefinitonLp for equivalent classes and PosNegInclusionLP for super * classes. @@ -361,7 +370,7 @@ Set<String> ignore = new TreeSet<String>(); ignore.add(currentConcept.toString()); if(id.equals(SUPER_CLASS_AXIOM_STRING)) { - Description currentClass = (Description)currentConcept; + Description currentClass = (Description) currentConcept; while(!(currentClass instanceof Thing)) { SortedSet<Description> superClasses = reasoner.getSuperClasses(currentClass); for(Description ignoredClass : superClasses) { @@ -393,10 +402,11 @@ * This method returns the Concepts from the DL-Learner. * * @return Array of learned Concepts. - */ + public Description[] getSolutions() { return description; - } + }*/ + /** * Starts the learning algorithm. */ @@ -499,8 +509,24 @@ individual = reasoner.getIndividuals(); } } - + /** + * This method sets the positive examples for learning. + * @param ind + */ + public void setIndividuals(Set<Individual> ind) { + this.individual = ind; + } + + /** + * This method sets the uri sting for the currently used + * for learning. + * @param uri + */ + public void setOntologyURIString(Set<String> uri) { + this.ontologieURI = uri; + } + /** * This Method checks if the selected class has any individuals. * * @return boolean hasIndividuals @@ -508,6 +534,14 @@ public boolean hasIndividuals() { return hasIndividuals; } + + /** + * Sets if the ontology has individuals. + * @param has + */ + public void setHasIndividuals(boolean has) { + this.hasIndividuals = has; + } /** * This method gets an Individual and checks if this individual belongs to @@ -517,7 +551,7 @@ * Individual to check if it belongs to the chosen concept * @return is Individual belongs to the concept which is chosen in protege. */ - public boolean setPositivExamplesChecked(String indi) { + private boolean setPositivExamplesChecked(String indi) { boolean isChecked = false; // checks if individuals are not empty if (individual != null) { @@ -548,10 +582,10 @@ * * @param list * Array of concepts from DL-Learner - */ + public void setDescriptionList(Description[] list) { description = list; - } + }*/ /** * This method returns the PosListModel. @@ -584,12 +618,12 @@ /** * This method resets the array of concepts from the DL_Learner. It is * called after the DL-Learner tab is closed. - */ + public void resetSuggestionList() { for (int i = 0; i < description.length; i++) { description[i] = null; } - } + }*/ /** * This method resets the model for the suggest panel. It is called befor @@ -617,10 +651,10 @@ * 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. @@ -639,6 +673,8 @@ * @return Old Concept in OWLDescription format. */ public OWLDescription getOldConceptOWLAPI() { + oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor + .getOWLDescription(currentConcept); return oldConceptOWLAPI; } @@ -714,10 +750,10 @@ * 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 @@ -778,7 +814,7 @@ * This method returns the currently used ontoloies including importet * ontologies. * - * @return Set<OWLAPIOntology> ontologies + * @return Set of OWLAPI ontologies */ public Set<OWLAPIOntology> getOWLOntologies() { return ontologies; @@ -786,7 +822,7 @@ /** * This method returns the Knowledgesources currenty used. - * @return Set<KnowledgSource> + * @return Set of Knowledgesources */ public Set<KnowledgeSource> getKnowledgeSources() { return sources; @@ -822,12 +858,45 @@ return ontologieURI; } /** - * This method reutrns a bollean if an ontology is inconsistent. + * This method returns a boolean if an ontology is inconsistent. * @return ontologyInconsistent */ public boolean getOntologyConsistent() { return ontologyConsistent; } + + /** + * Sets the positive examples. + * @param list + */ + public void setPosListModel(DefaultListModel list) { + this.posListModel = list; + } + + /** + * Sets the negative examples. + * @param list + */ + public void setNegListModel(DefaultListModel list) { + this.negListModel = list; + } + + /** + * Sets the individual vector. + * @param indi + */ + public void setIndividualVector(Vector<IndividualObject> indi) { + this.individualVector = indi; + } + + /** + * This sets the current concept. + * @param current + */ + public void setCurrentConcept(NamedClass current) { + this.currentConcept = current; + } +} -} + Added: trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -0,0 +1,204 @@ +package org.dllearner.tools.protege; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.geom.Ellipse2D; +import java.util.Set; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JPanel; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Individual; + +public class GraphicalCoveragePanel extends JPanel { + + private static final long serialVersionUID = 855436961912515267L; + private static final int height =250; + private static final int width = 250; + private static final int maxNumberOfIndividualPoints = 20; + private static final int gap = 20; + private int shiftXAxis; + private int distortion; + private Ellipse2D oldConcept; + private Ellipse2D newConcept; + + private EvaluatedDescription eval; + private DLLearnerModel model; + private String conceptNew; + private Vector<IndividualPoint> posCovIndVector; + private Vector<IndividualPoint> posNotCovIndVector; + private Vector<IndividualPoint> negCovIndVector; + private JButton allPositiveIndividuals; + private JButton allNegativeIndividuals; + + /** + * This is the constructor for the GraphicalCoveragePanel. + */ + public GraphicalCoveragePanel(EvaluatedDescription desc, DLLearnerModel m, String concept, int w, int h) { + setPreferredSize(new Dimension(width, height)); + setVisible(true); + setForeground(Color.GREEN); + repaint(); + eval = desc; + model = m; + conceptNew = concept; + posCovIndVector = new Vector<IndividualPoint>(); + posNotCovIndVector = new Vector<IndividualPoint>(); + negCovIndVector = new Vector<IndividualPoint>(); + this.computeGraphics(); + oldConcept = new Ellipse2D.Float(5, 25, 250, 250); + newConcept = new Ellipse2D .Float(5+shiftXAxis, 25, width+distortion, height+distortion); + allPositiveIndividuals = new JButton(); + //immer in der mitte und unten rauszubekommen mittels getMittelpunkt fuer x + //und getMaxY fuer y. + //allPositiveIndividuals.setBounds(arg0, arg1, arg2, arg3); + allNegativeIndividuals = new JButton(); + //allNegativeIndividuals.setBounds(arg0, arg1, arg2, arg3); + this.computeIndividualPoints(); + } + + public void drawCoverageForLearnedClassDescription( + Set<Individual> posCovInd, Set<Individual> posNotCovInd, + Set<Individual> negCovInd) { + + + } + + protected void paintComponent(Graphics g) { + g.setColor(Color.RED); + g.drawOval((5+shiftXAxis), 25, width+distortion, height+distortion); + g.drawString(conceptNew, 10 + width, 15); + g.setColor(Color.GREEN); + g.drawOval(5, 25, 250, 250); + g.drawString(model.getOldConceptOWLAPI().toString(), 10, 15); + + for(int i = 0; i < posCovIndVector.size(); i++) { + g.setColor(Color.BLACK); + g.drawString(posCovIndVector.get(i).getPoint(), posCovIndVector.get(i).getXAxis(), posCovIndVector.get(i).getYAxis()); + } + + for(int i = 0; i < posNotCovIndVector.size(); i++) { + g.setColor(Color.BLACK); + g.drawString(posNotCovIndVector.get(i).getPoint(), posNotCovIndVector.get(i).getXAxis(), posNotCovIndVector.get(i).getYAxis()); + } + + for(int i = 0; i < negCovIndVector.size(); i++) { + g.setColor(Color.BLACK); + g.drawString(negCovIndVector.get(i).getPoint(), negCovIndVector.get(i).getXAxis(), negCovIndVector.get(i).getYAxis()); + } + + } + + private void computeGraphics(){ + int posGes = model.getPosListModel().size(); + int notCovPos = eval.getNotCoveredPositives().size(); + int covNeg = 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); + } + + } + + private void computeIndividualPoints() { + Set<Individual> posInd = eval.getCoveredPositives(); + int i = 0; + double x = 20; + double y = 20; + for(Individual ind : posInd) { + if(i<maxNumberOfIndividualPoints) { + i++; + if(x >= oldConcept.getMaxX()) { + x = (int) oldConcept.getMinX(); + y = y + gap; + } + + if(y >= oldConcept.getMaxY()) { + y = (int) oldConcept.getMinY(); + } + + if(x >= newConcept.getMaxX()) { + x = (int) newConcept.getMinX(); + y = y + gap; + } + + if(y >= newConcept.getMaxY()) { + y = (int) newConcept.getMinY(); + } + + 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; + } + } + } + } + + Set<Individual> posNotCovInd = eval.getNotCoveredPositives(); + int j = 0; + for(Individual ind : posNotCovInd) { + if(j<maxNumberOfIndividualPoints) { + j++; + if(x >= oldConcept.getMaxX()) { + x = (int) oldConcept.getMinX(); + y = y + gap; + } + + if(y >= oldConcept.getMaxY()) { + y = (int) oldConcept.getMinY(); + } + + while(x < oldConcept.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; + } + } + } + } + + Set<Individual> negCovInd = eval.getCoveredNegatives(); + int k = 0; + for(Individual ind : negCovInd) { + if(k<maxNumberOfIndividualPoints) { + k++; + if(x >= newConcept.getMaxX()) { + x = (int) newConcept.getMinX(); + y = y + gap; + } + + if(y >= newConcept.getMaxY()) { + y = (int) newConcept.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; + } + } + } + } + } + + +} Added: trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanelHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanelHandler.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanelHandler.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -0,0 +1,6 @@ +package org.dllearner.tools.protege; + +//hier irgendwie umsetzen das wenn ueber individual fahre das name angezeigt wird. +public class GraphicalCoveragePanelHandler { + +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/IndividualObject.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/IndividualObject.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/IndividualObject.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -55,7 +55,7 @@ } /** - * This method sets the example positive or negative if changed to the othe list. + * This method sets the example positive or negative if changed to the other list. * @param pos boolean */ public void setExamplePositive(boolean pos) { Added: trunk/src/dl-learner/org/dllearner/tools/protege/IndividualPoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/IndividualPoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/IndividualPoint.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -0,0 +1,59 @@ +package org.dllearner.tools.protege; + +public class IndividualPoint { + + private String point; + private int xAxis; + private int yAxis; + private String individual; + + public IndividualPoint(String p, int x, int y, String ind) { + this.point = p; + this.xAxis = x; + this.yAxis = y; + this.individual = ind; + } + + /** + * @param point the point to set + */ + public void setPoint(String point) { + this.point = point; + } + + /** + * @return the point + */ + public String getPoint() { + return point; + } + + /** + * @param xAxis the xAxis to set + */ + public void setXAxis(int xAxis) { + this.xAxis = xAxis; + } + + /** + * @return the xAxis + */ + public int getXAxis() { + return xAxis; + } + + /** + * @param yAxis the yAxis to set + */ + public void setYAxis(int yAxis) { + this.yAxis = yAxis; + } + + /** + * @return the yAxis + */ + public int getYAxis() { + return yAxis; + } + +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -37,11 +37,12 @@ /** * This class shows more details of the suggested concepts. It shows the positive and negative examples - * that are covered and that are not covered by the suggested concepts. It also shows the accuracya of the + * that are covered and that are not covered by the suggested concepts. It also shows the accuracy of the * selected concept. * @author Christian Koetteritzsch * */ + public class MoreDetailForSuggestedConceptsPanel extends JPanel { private static final long serialVersionUID = 785272797932584581L; @@ -113,6 +114,9 @@ private JTextArea conceptText; private final Color colorRed = new Color(139, 0, 0); private final Color colorGreen = new Color(0, 139, 0); + private static final int height = 500; + private static final int width = 600; + private GraphicalCoveragePanel p; /** * This is the constructor for the Panel. * @param model DLLearnerModel @@ -120,7 +124,7 @@ public MoreDetailForSuggestedConceptsPanel(DLLearnerModel model) { super(); setLayout(null); - setPreferredSize(new Dimension(600, 500)); + setPreferredSize(new Dimension(width, height)); this.model = model; @@ -150,6 +154,7 @@ negNotCoveredScroll.setBounds(300, 325, 280, 140); eval = desc; concept = new JTextArea("Class Description:"); + concept.setEditable(false); coveredPositiveExamples = new JLabel("Covered Positive Examples:"); coveredPositiveExamples.setForeground(colorGreen); @@ -168,7 +173,7 @@ conceptPanel.setBounds(5, 0, 600, 50); accuracyPanel = new JPanel(new GridLayout(0, 1)); accuracyPanel.setBounds(5, 60, 600, 50); - + posCoveredPanel = new JPanel(new GridLayout(0, 1)); posNotCoveredPanel = new JPanel(new GridLayout(0, 1)); negCoveredPanel = new JPanel(new GridLayout(0, 1)); @@ -199,8 +204,10 @@ //panel for the informations of the selected concept //this method adds the informations for the selected concept to the panel setInformation(); + p = new GraphicalCoveragePanel(eval, model, conceptText.getText(), width, height); + p.setBounds(5, 110, 600, 650); detailPopup = new JDialog(); - detailPopup.setSize(600, 500); + detailPopup.setSize(width, height); //window will be disposed if the x button is pressed detailPopup.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); detailPopup.setVisible(true); @@ -219,6 +226,8 @@ add(conceptPanel); add(accuracyPanel); + add(p); + /* add(coveredPositiveExamples); add(notCoveredPositiveExamples); add(coveredNegativeExamples); @@ -226,7 +235,7 @@ add(posCoveredScroll); add(posNotCoveredScroll); add(negCoveredScroll); - add(negNotCoveredScroll); + add(negNotCoveredScroll);*/ detailPopup.add(this); } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -360,6 +360,7 @@ // This is the Panel for more details of the suggested concept private MoreDetailForSuggestedConceptsPanel detail; private OWLFrame<OWLClass> frame; + private ReadingOntologyThread readThread; /** * The constructor for the DL-Learner tab in the class description @@ -437,26 +438,10 @@ model.clearVector(); hint.setText("To get suggestions for class descriptions, please click the button above."); isInconsistent = false; - model.unsetListModel(); - model.initReasoner(); - if(!isInconsistent) { - - model.checkURI(); - model.setPosVector(); - if (model.hasIndividuals()) { - run.setEnabled(true); - } else { - run.setEnabled(false); - hint.setVisible(false); - String message ="There are no Instances for "+ frame.getRootObject()+" available. Please insert some Instances."; - renderErrorMessage(message); - } - posPanel.setExampleList(model.getPosListModel(), model.getNegListModel()); - } else { - hint.setForeground(Color.RED); - run.setEnabled(false); - hint.setText("The ontology is inconsistent and suggestions for class descriptions can only \nbe computed on consistent ontologies. Please repair the ontology first"); - } + readThread = new ReadingOntologyThread(editorKit, frame, this, model); + readThread.start(); + //TODO: runbutton wird auf enable gesetzt obwohl keine instanzdaten vorhanden sind. + hint.setVisible(true); advanced.setIcon(icon); accept.setEnabled(false); @@ -512,7 +497,9 @@ public void setHintMessage(String message) { hint.setText(message); } - + public JTextArea getHintPanel() { + return hint; + } /** * This Method returns the DL_Learner tab. * @return JComponent @@ -604,6 +591,10 @@ 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; } Added: trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -0,0 +1,215 @@ +package org.dllearner.tools.protege; + +import java.awt.Color; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.Vector; + +import javax.swing.DefaultListModel; + +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Thing; +import org.dllearner.reasoning.FastInstanceChecker; +import org.protege.editor.owl.OWLEditorKit; +import org.protege.editor.owl.ui.frame.OWLFrame; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLOntology; + +public class ReadingOntologyThread extends Thread { + + + private boolean hasIndividuals; + private OWLFrame<OWLClass> current; + private FastInstanceChecker reasoner; + private NamedClass currentConcept; + private Set<Individual> individual; + private Set<String> ontologieURI; + private OWLEditorKit editor; + private DefaultListModel posListModel; + private DefaultListModel negListModel; + private DLLearnerModel model; + private boolean isInconsistent; + private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; + private Vector<IndividualObject> individualVector; + + public ReadingOntologyThread(OWLEditorKit editorKit, OWLFrame<OWLClass> h, OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView v, DLLearnerModel m) { + posListModel = new DefaultListModel(); + negListModel = new DefaultListModel(); + ontologieURI = new HashSet<String>(); + individualVector = new Vector<IndividualObject>(); + this.editor = editorKit; + this.current = h; + this.view = v; + this.model = m; + + } + /** + * This method sets the individuals that belong to the concept which is + * chosen in protege. + */ + private 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); + model.setIndividuals(individual); + model.setCurrentConcept(currentConcept); + break; + } + } + } + } + } + } + } else { + if (reasoner.getIndividuals().size() > 0) { + hasIndividuals = true; + + } + individual = reasoner.getIndividuals(); + model.setIndividuals(individual); + model.setHasIndividuals(hasIndividuals); + } + } + + /** + * This Method checks if the selected class has any individuals. + * + * @return boolean hasIndividuals + */ + public boolean hasIndividuals() { + return hasIndividuals; + } + + /** + * Checks the URI if a "#" is in it. + */ + private 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; + } + } + } + } + model.setOntologyURIString(ontologieURI); + } + + /** + * This method sets the check boxes for the positive check boxes checked if + * the individuals matches the concept that is chosen in protege. + */ + private 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; + } + } + } + } + view.getPosAndNegSelectPanel().setExampleList(posListModel, negListModel); + model.setPosListModel(posListModel); + model.setNegListModel(negListModel); + model.setIndividualVector(individualVector); + } + + /** + * 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; + + } + + public void run() { + model.unsetListModel(); + model.initReasoner(); + reasoner = model.getReasoner(); + isInconsistent = false; + if(!isInconsistent) { + + this.checkURI(); + this.setPositiveConcept(); + this.setPosVector(); + if (this.hasIndividuals()) { + view.getRunButton().setEnabled(true); + } else { + view.getRunButton().setEnabled(false); + view.getHintPanel().setVisible(false); + String message ="There are no Instances for "+ current.getRootObject()+" available. Please insert some Instances."; + view.renderErrorMessage(message); + } + view.getPosAndNegSelectPanel().setExampleList(model.getPosListModel(), model.getNegListModel()); + } else { + view.getHintPanel().setForeground(Color.RED); + view.getRunButton().setEnabled(false); + view.setHintMessage("The ontology is inconsistent and suggestions for class descriptions can only \nbe computed on consistent ontologies. Please repair the ontology first"); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/SuggestListItem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/SuggestListItem.java 2009-01-26 11:55:26 UTC (rev 1583) +++ trunk/src/dl-learner/org/dllearner/tools/protege/SuggestListItem.java 2009-02-03 11:35:36 UTC (rev 1584) @@ -34,6 +34,7 @@ * Constructor for the SuggestListItem. * @param c Color Color in which the text is painted. * @param s String text that is shown. + * @param acc Accuracy of the concept */ public SuggestListItem( Color c, String s, double acc) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |