From: <lor...@us...> - 2008-06-17 10:56:44
|
Revision: 964 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=964&view=rev Author: lorenz_b Date: 2008-06-17 03:56:39 -0700 (Tue, 17 Jun 2008) Log Message: ----------- added some repair-methods and integrated in GUI Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java trunk/src/dl-learner/org/dllearner/tools/ore/RepairPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java 2008-06-17 10:56:39 UTC (rev 964) @@ -37,9 +37,10 @@ @Override public void aboutToDisplayPanel() { setNextButtonAccordingToConceptSelected(); - } + } + + - public void valueChanged(ListSelectionEvent e) { setNextButtonAccordingToConceptSelected(); if (!e.getValueIsAdjusting()) @@ -56,6 +57,10 @@ } } + + + + Modified: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-17 10:56:39 UTC (rev 964) @@ -4,7 +4,6 @@ import java.awt.event.ActionListener; import java.util.List; import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.ExecutionException; import javax.swing.SwingUtilities; @@ -14,6 +13,7 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectSomeRestriction; @@ -25,6 +25,7 @@ LearningPanel panel4; ResultSwingWorker worker; Timer timer; + Boolean canceled = false; public LearningPanelDescriptor() { @@ -56,32 +57,19 @@ LearningAlgorithm la; + @SuppressWarnings("unchecked") @Override public List<Description> doInBackground() { panel4.getResultList().setCellRenderer(new ColumnListCellRenderer(getWizardModel().getOre())); panel4.getLoadingLabel().setBusy(true); panel4.getStatusLabel().setText("Learning"); - getWizardModel().getOre().setNoise(panel4.getNoise()); - la = getWizardModel().getOre().start(); - - + la = getWizardModel().getOre().start();//started endlosen Algorithmus - timer = new Timer(); - timer.schedule(new TimerTask() { - - @SuppressWarnings("unchecked") - @Override - public void run() { - - publish(getWizardModel().getOre().getLearningResults(10)); + publish(la.getBestSolutions(10)); - } - - }, 0, 1000); - List<Description> result = getWizardModel().getOre().getLearningResults(10); return result; @@ -91,7 +79,6 @@ public void done() { - timer.cancel(); List<Description> result = null; try { result = get(); @@ -111,6 +98,7 @@ @Override protected void process(List<List<Description>> resultLists) { panel4.getModel().clear(); + for (List<Description> list : resultLists) { updateList(list); } @@ -123,6 +111,7 @@ panel4.getModel().clear(); for (Description d : result) { panel4.getModel().addElement(d); + } } @@ -177,6 +166,7 @@ worker.execute(); } else{ + canceled = true; panel4.getStopButton().setEnabled(false); getWizardModel().getOre().getLa().stop(); panel4.getStartButton().setEnabled(true); @@ -190,10 +180,25 @@ public void valueChanged(ListSelectionEvent e) { setNextButtonAccordingToConceptSelected(); - if (!e.getValueIsAdjusting()) + if (!e.getValueIsAdjusting()){ getWizardModel().getOre().setConceptToAdd((Description)(panel4.getResultList().getSelectedValue())); + for(Description d: getWizardModel().getOre().getAllChildren((Description)(panel4.getResultList().getSelectedValue()))){ + System.out.println(d + " : " + d.getClass()); + + if(d instanceof ObjectSomeRestriction){ + + + getWizardModel().getOre().getIndividualsOfPropertyRange((ObjectSomeRestriction)d); + + + + } + + } + } + } @Override Modified: trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/NegExampleRepairDialog.java 2008-06-17 10:56:39 UTC (rev 964) @@ -1,7 +1,6 @@ package org.dllearner.tools.ore; import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; @@ -10,7 +9,6 @@ import java.awt.event.ActionListener; import java.util.Set; -import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; @@ -19,13 +17,15 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSeparator; -import javax.swing.JTextArea; -import javax.swing.UIManager; +import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.reasoning.OWLAPIReasoner; public class NegExampleRepairDialog extends JDialog implements ActionListener{ @@ -39,34 +39,41 @@ private JPanel statsPanel; private JPanel actionsPanel; private JPanel ok_cancelPanel; - + private JPanel action_stats_Panel; + + private JButton okButton; private JButton cancelButton; - private JTextArea classesField; - private JScrollPane scrollPane; private ORE ore; private Individual ind; private OWLAPIReasoner reasoner; + private Description actualDesc; + private Description newDesc; + private Individual object; + public NegExampleRepairDialog(Individual ind, JDialog dialog, ORE ore){ - super(dialog, "Auswahl", true); + super(dialog, "Repair negative example", true); this.ind = ind; this.ore = ore; - this.reasoner = ore.reasoner; + this.reasoner = ore.reasoner2; init(); } public void init(){ setSize(700, 700); - setLayout(new GridLayout(3, 0)); + setLayout(new BorderLayout()); + action_stats_Panel = new JPanel(); + action_stats_Panel.setLayout(new GridLayout(2,0)); + statsPanel = new JPanel(); statsPanel.setBorder(new TitledBorder("stats")); - getContentPane().add(statsPanel); + GridBagLayout gbl = new GridBagLayout(); statsPanel.setLayout(gbl); @@ -80,25 +87,18 @@ JLabel descLb1 = new JLabel(ore.conceptToAdd.toString()); JLabel indLb1 = new JLabel(ind.getName()); - Set<NamedClass> t = reasoner.getConcepts(ind); - classesField = new JTextArea(); - String classes = new String(); - for(NamedClass nc : t) - classes += nc.getName() +"\n"; - classesField.setText(classes); - - scrollPane = new JScrollPane(); - scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - scrollPane.setViewportBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - scrollPane.setPreferredSize(new Dimension(150,100)); - classesField.setBackground(UIManager.getDefaults().getColor("control")); - classesField.setColumns(20); - classesField.setEditable(false); - classesField.setLineWrap(true); - classesField.setRows(5); - classesField.setWrapStyleWord(true); - scrollPane.setViewportView(classesField); + Set<NamedClass> t = null; + + JPanel classesPanel = new JPanel(new GridLayout(0, 1)); + + t = reasoner.getConcepts(ind); + t.add(ore.getConcept()); + for(NamedClass nc : t) + classesPanel.add(new JLabel(nc.getName())); + + + gbc.gridx = 0; // first column gbc.gridy = 0; // first row gbc.gridwidth = 1; // occupies only one column @@ -160,43 +160,73 @@ gbl.setConstraints(indLb1, gbc); statsPanel.add(indLb1); - gbc.gridx = 2; // third column + gbc.gridx = 1; // second column gbc.gridy = 2; // third row gbc.gridwidth = 1; // occupies only one column gbc.gridheight = 1; // occupies only one row gbc.weightx = 0; // horizontal size for the column is defined already! gbc.weighty = 0; // vertical size for the row is defined already! gbc.fill = GridBagConstraints.HORIZONTAL; // fill horizontally entire cell - gbc.anchor = GridBagConstraints.WEST; // west aligning + gbc.anchor = GridBagConstraints.CENTER; // center aligning - gbl.setConstraints(scrollPane, gbc); - statsPanel.add(scrollPane); +// gbl.setConstraints(scrollPane, gbc); +// statsPanel.add(scrollPane); + gbl.setConstraints(classesPanel, gbc); + statsPanel.add(classesPanel); + - actionsPanel = new JPanel(); + actionsPanel = new JPanel(new GridLayout(0, 1)); + + + actionsPanel.setBorder(new TitledBorder("actions")); JButton delete = new JButton("delete instance"); delete.addActionListener(this); actionsPanel.add(delete); - JButton save = new JButton("save"); - save.addActionListener(this); - actionsPanel.add(save); - getContentPane().add(actionsPanel, java.awt.BorderLayout.EAST); + for(Description d :ore.getCriticalDescriptions(ind, ore.getConceptToAdd())){ + + if(!(d instanceof Negation)){ + if(d instanceof NamedClass){ + actionsPanel.add(new DescriptionButton("remove class assertion to " + d.toString(), d ,this)); + actionsPanel.add(new DescriptionButton("move class assertion " + d.toString() + " to ...", d, this)); + } + else if(d instanceof ObjectSomeRestriction) + actionsPanel.add(new DescriptionButton("remove property assertion " + d.toString(), d, this)); + } + else if(d instanceof Negation){ + if(d.getChild(0) instanceof NamedClass) + actionsPanel.add(new DescriptionButton("add class assertion to " + d.getChild(0).toString(), d, this)); + else if(d.getChild(0) instanceof ObjectSomeRestriction) + actionsPanel.add(new DescriptionButton("add property " + d.toString(), d, this)); + } + } + JScrollPane scroll = new JScrollPane(); + scroll.setViewportView(statsPanel); + action_stats_Panel.add(scroll); + action_stats_Panel.add(actionsPanel); + JSeparator separator = new JSeparator(); Box buttonBox = new Box(BoxLayout.X_AXIS); + ok_cancelPanel = new JPanel(); ok_cancelPanel.setLayout(new BorderLayout()); ok_cancelPanel.add(separator, BorderLayout.NORTH); okButton = new JButton("Ok"); cancelButton = new JButton("Cancel"); + + getContentPane().add(ok_cancelPanel, java.awt.BorderLayout.SOUTH); + getContentPane().add(action_stats_Panel, java.awt.BorderLayout.CENTER); + + buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); buttonBox.add(okButton); buttonBox.add(Box.createHorizontalStrut(10)); buttonBox.add(cancelButton); ok_cancelPanel.add(buttonBox, BorderLayout.EAST); - getContentPane().add(ok_cancelPanel); + getContentPane().add(ok_cancelPanel, BorderLayout.SOUTH); setModal(true); @@ -205,18 +235,52 @@ } public void actionPerformed(ActionEvent e) { - System.out.println(e.getActionCommand()); + + if(e.getActionCommand().equals("delete instance")){ ore.modi.deleteIndividual(ind); + } + else{ + actualDesc = ((DescriptionButton)e.getSource()).getDescription(); + if(e.getActionCommand().startsWith("remove class")){ + ore.modi.removeClassAssertion(ind, actualDesc); + } + else if(e.getActionCommand().startsWith("move class")){ + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + newDesc = (Description)new ChooseDialog(ore, ind).getSelectedElement(); + } + + }); + if(newDesc != null) + ore.modi.moveIndividual(ind, actualDesc, newDesc); + + } + else if(e.getActionCommand().equals("add property")){ + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + object = (Individual)new ChooseDialog(ore, actualDesc).getSelectedElement(); + } + + }); + if(newDesc != null) + + ore.modi.addObjectProperty(ind, (ObjectSomeRestriction)actualDesc, object); + } } - if(e.getActionCommand().equals("save")){ - ore.modi.saveOntology(); - } - - } + + + + + + } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-17 10:56:39 UTC (rev 964) @@ -15,11 +15,14 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.Union; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; @@ -36,16 +39,19 @@ private PosNegDefinitionLP lp; private ComponentManager cm; - OWLAPIReasoner reasoner; + FastInstanceChecker reasoner; + OWLAPIReasoner reasoner2; SortedSet<Individual> posExamples; SortedSet<Individual> negExamples; NamedClass concept; Description conceptToAdd; OntologyModifierOWLAPI modi; Set<NamedClass> allAtomicConcepts; - private double noise; + private double noise = 0.0; + Thread t; + public ORE() { cm = ComponentManager.getInstance(); @@ -60,7 +66,7 @@ ks = cm.knowledgeSource(owl); cm.applyConfigEntry(ks, "url", f.toURI().toString()); - + try { ks.init(); } catch (ComponentInitException e) { @@ -74,11 +80,20 @@ public void detectReasoner(){ - reasoner = cm.reasoner(OWLAPIReasoner.class, ks); - reasoner.init(); - + reasoner = cm.reasoner(FastInstanceChecker.class, ks); + try { + reasoner.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + rs = cm.reasoningService(reasoner); - modi = new OntologyModifierOWLAPI(reasoner); + reasoner2 = cm.reasoner(OWLAPIReasoner.class, ks); + reasoner2.init(); + + modi = new OntologyModifierOWLAPI(reasoner2); } public ReasoningService getReasoningService(){ @@ -124,6 +139,7 @@ t.add(concept.getName()); cm.applyConfigEntry(la, "ignoredConcepts", t ); cm.applyConfigEntry(la, "noisePercentage", noise); + cm.applyConfigEntry(la, "guaranteeXgoodDescriptions", 5); try { la.init(); } catch (ComponentInitException e) { @@ -145,7 +161,7 @@ this.setLearningAlgorithm(); la.start(); - + return la; } @@ -291,52 +307,160 @@ this.allAtomicConcepts = allAtomicConcepts; } - public void getAllChildren(Description desc){ - - if(desc.getNumberOfNodes() >= 2) - for(Description d: desc.getChildren()) - getAllChildren(d); - System.out.println(desc); - } - + public Set<Description> getAllChildren(Description desc){ + Set<Description> allChildren = new HashSet<Description>(); + List<Description> children = desc.getChildren(); + + if(children.size() >= 2) + for(Description d : children) + allChildren.addAll(getAllChildren(d)); + else + allChildren.add(desc); + + return allChildren; + } + public Set<Description> getCriticalDescriptions(Individual ind, Description desc){ + Set<Description> criticals = new HashSet<Description>(); List<Description> children = desc.getChildren(); - if(desc instanceof Intersection){ - criticals.addAll(children); - } - if(desc instanceof Union){ - for(Description d: children) - if(reasoner.instanceCheck(d, ind)) - criticals.add(d); - } +// if(desc instanceof Negation){ +// if(!(desc.getChild(0) instanceof NamedClass) &&!(desc.getChild(0) instanceof ObjectQuantorRestriction)){ +// negation = !negation; +// criticals.addAll(getCriticalDescriptions(ind, desc.getChild(0))); +// } +// else{ +// if(negation) +// criticals.add(desc.getChild(0)); +// else +// criticals.add(desc); +// +// } +// +// } +// else{ +// +// if(children.size() >= 2){ +// +// if(desc instanceof Intersection){ +// for(Description d: children) +// criticals.addAll(getCriticalDescriptions(ind, d)); +// +// } +// else if(desc instanceof Union){ +// for(Description d: children) +// try { +// if(reasoner.instanceCheck(d, ind)) +// criticals.addAll(getCriticalDescriptions(ind, d)); +// } catch (ReasoningMethodUnsupportedException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } +// } +// else{ +// +// if(negation) +// criticals.add(new Negation(desc)); +// else +// criticals.add(desc); +// +// } +// +// +// +// } + if(children.size() >= 2){ + + if(desc instanceof Intersection){ + for(Description d: children) + criticals.addAll(getCriticalDescriptions(ind, d)); + + } + else if(desc instanceof Union){ + for(Description d: children) + try { + if(reasoner.instanceCheck(d, ind)) + criticals.addAll(getCriticalDescriptions(ind, d)); + } catch (ReasoningMethodUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + else + criticals.add(desc); + return criticals; } + public Set<Individual> getIndividualsOfPropertyRange(ObjectQuantorRestriction objRestr){ + + + System.out.println(objRestr.getChild(0)); + + + Set<Individual> individuals = rs.retrieval(objRestr.getChild(0)); + System.out.println(objRestr.getRole()); + + System.out.println(individuals); + + return individuals; + } + + public Set<NamedClass> getpossibleMoveClasses(Individual ind){ + Set<NamedClass> classes = rs.getAtomicConcepts(); + for(NamedClass nc : classes) + if(rs.instanceCheck(nc, ind)) + classes.remove(nc); + + return classes; + } + + + public static void main(String[] args){ - ORE test = new ORE(); + final ORE test = new ORE(); - File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/father.owl"); + File owlFile = new File("src/dl-learner/org/dllearner/tools/ore/test.owl"); test.setKnowledgeSource(owlFile); test.detectReasoner(); ReasoningService rs = test.getReasoningService(); - System.err.println("Concepts :" + rs.getAtomicConcepts()); +// System.err.println("Concepts :" + rs.getAtomicConcepts()); - test.setConcept(new NamedClass("http://example.com/father#father")); - test.setPosNegExamples(); - System.out.println(test.posExamples); - System.out.println(test.negExamples); - test.start(); - test.la.start();//Bug? +// test.setConcept(new NamedClass("http://example.com/father#father")); +// test.setPosNegExamples(); +// System.out.println(test.posExamples); +// System.out.println(test.negExamples); +// test.start(); + Individual ind = new Individual("http://www.test.owl#lorenz"); + System.out.println(rs.getIndividuals()); + Description d = new Intersection(new NamedClass("http://www.test.owl#A"), new Negation(new Union(new NamedClass("http://www.test.owl#B"), + new Negation(new Intersection(new NamedClass("http://www.test.owl#C"),new Negation(new NamedClass("http://www.test.owl#D"))))))); + System.out.println(d); + System.out.println(test.getCriticalDescriptions(ind, d)); + + + + + + } + + + + +} -} + + + Modified: trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifierOWLAPI.java 2008-06-17 10:56:39 UTC (rev 964) @@ -1,13 +1,15 @@ package org.dllearner.tools.ore; import java.net.URI; -import java.net.URISyntaxException; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Set; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; import org.dllearner.reasoning.OWLAPIReasoner; import org.semanticweb.owl.apibinding.OWLManager; @@ -18,6 +20,10 @@ import org.semanticweb.owl.model.OWLDataFactory; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLInverseObjectPropertiesAxiom; +import org.semanticweb.owl.model.OWLObjectProperty; +import org.semanticweb.owl.model.OWLObjectPropertyAssertionAxiom; +import org.semanticweb.owl.model.OWLObjectPropertyExpression; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyManager; @@ -40,7 +46,8 @@ this.factory = manager.getOWLDataFactory(); this.ontology = reasoner.getOWLAPIOntologies().get(0); } - + + public void addAxiomToOWL(Description newDesc, Description oldDesc){ OWLDescription newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(newDesc); OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(oldDesc); @@ -61,6 +68,7 @@ e.printStackTrace(); } + } public void saveOntology(){ @@ -77,19 +85,14 @@ } } - + /** + * Deletes the complete individual from the ontology + * @param ind + */ public void deleteIndividual(Individual ind){ - OWLIndividual individualOWLAPI = null; + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); - try { - individualOWLAPI = factory.getOWLIndividual( new URI(ind.getName())); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - OWLEntityRemover remover = new OWLEntityRemover(manager, Collections.singleton(ontology)); individualOWLAPI.accept(remover); @@ -104,29 +107,50 @@ } - + /** + * Removes a classAssertion + * @param ind + * @param desc + */ public void removeClassAssertion(Individual ind, Description desc){ - OWLIndividual individualOWLAPI = null; + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); OWLDescription owlDesc = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); + OWLClassAssertionAxiom owlCl = factory.getOWLClassAssertionAxiom(individualOWLAPI, owlDesc); + + RemoveAxiom rm = new RemoveAxiom(ontology, owlCl); + try { - individualOWLAPI = factory.getOWLIndividual( new URI(ind.getName())); - } catch (URISyntaxException e) { + manager.applyChange(rm); + } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } + } + /** + * removes classAssertion between individual to a old class, and creates a new classAssertion + * @param ind individual which has to be moved + * @param oldClass class where individual is asserted before + * @param newClass class where individual is moved to + */ + public void moveIndividual(Individual ind, Description oldClass, Description newClass){ - OWLClassAssertionAxiom owlCl = factory.getOWLClassAssertionAxiom(individualOWLAPI, owlDesc); + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); + //Loeschen + removeClassAssertion(ind, oldClass); - RemoveAxiom rm = new RemoveAxiom(ontology, owlCl); + //Hinzufuegen + OWLDescription newClassOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(newClass); + + OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(individualOWLAPI, newClassOWLAPI); - + AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); try { - manager.applyChange(rm); + manager.applyChange(axiom); } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -134,38 +158,87 @@ } - public void moveIndividual(Individual ind, Description oldConcept, Description newConcept){ + public void deleteObjectProperty(Individual ind, ObjectSomeRestriction objSome){ - - OWLIndividual individualOWLAPI = null; + OWLIndividual individualOWLAPI = factory.getOWLIndividual( URI.create(ind.getName())); + OWLObjectProperty propertyOWLAPI = factory.getOWLObjectProperty(URI.create(objSome.getRole().getName())); + Set<OWLObjectPropertyAssertionAxiom> properties = ontology.getObjectPropertyAssertionAxioms(individualOWLAPI); + Set<OWLInverseObjectPropertiesAxiom> invProperties = ontology.getInverseObjectPropertyAxioms(propertyOWLAPI); + OWLObjectPropertyExpression invProperty = null; + + for(OWLInverseObjectPropertiesAxiom inv : invProperties) + if(propertyOWLAPI.equals(inv.getSecondProperty())) + invProperty = inv.getFirstProperty(); + else + invProperty = inv.getSecondProperty(); + + + List<RemoveAxiom> removeList = new LinkedList<RemoveAxiom>(); + + for(OWLObjectPropertyAssertionAxiom o :properties){ + if( (o.getProperty().equals(propertyOWLAPI)) && (o.getSubject().equals(individualOWLAPI))) + removeList.add(new RemoveAxiom(ontology, o)); + if(invProperty != null) + for(OWLObjectPropertyAssertionAxiom ob :ontology.getObjectPropertyAssertionAxioms(o.getObject())) + if(ob.getProperty().equals(invProperty) && ob.getObject().equals(individualOWLAPI)) + removeList.add(new RemoveAxiom(ontology, ob)); + + + } + try { - individualOWLAPI = factory.getOWLIndividual( new URI(ind.getName())); - } catch (URISyntaxException e) { + manager.applyChanges(removeList); + } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } - //Loeschen - removeClassAssertion(ind, oldConcept); + } + + + public void addObjectProperty(Individual subInd, ObjectSomeRestriction objSome, Individual objInd){ + OWLIndividual subIndividualOWLAPI = factory.getOWLIndividual( URI.create(subInd.getName())); + OWLIndividual objIndividualOWLAPI = factory.getOWLIndividual( URI.create(objInd.getName())); + OWLObjectProperty propertyOWLAPI = factory.getOWLObjectProperty(URI.create(objSome.getRole().getName())); - //Hinzufuegen + OWLObjectPropertyAssertionAxiom objAssertion = factory.getOWLObjectPropertyAssertionAxiom(subIndividualOWLAPI, propertyOWLAPI, objIndividualOWLAPI); - OWLDescription newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(newConcept); - - OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(individualOWLAPI, newConceptOWLAPI); - - AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); + AddAxiom axiom = new AddAxiom(ontology, objAssertion); try { manager.applyChange(axiom); } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } - } +// public OWLOntology copyOntology(){ +// try{ +// OWLOntology ontologyCopy = manager.createOntology(ontology.getURI()); +// +// +// Set<OWLAxiom> axioms = ontology.getAxioms(); +// List<AddAxiom> changes = new LinkedList<AddAxiom>(); +// for(OWLAxiom a : axioms) +// changes.add(new AddAxiom(ontologyCopy, a)); +// +// manager.applyChanges(changes); +// +// return ontologyCopy; +// +// }catch(OWLException e){ +// e.printStackTrace(); +// return null; +// } +// +// +// } + + + + } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/RepairPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/RepairPanelDescriptor.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/RepairPanelDescriptor.java 2008-06-17 10:56:39 UTC (rev 964) @@ -67,7 +67,9 @@ public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 2 && e.getSource() == panel4.getNegFailureList() ){ - new NegExampleRepairDialog((Individual)panel4.getNegFailureList().getSelectedValue(), getWizard().getDialog(), getWizardModel().getOre() ); + Individual ind = (Individual)panel4.getNegFailureList().getSelectedValue(); + new NegExampleRepairDialog(ind, getWizard().getDialog(), getWizardModel().getOre()); +// System.out.println(getWizardModel().getOre().getCriticalDescriptions(ind, getWizardModel().getOre().conceptToAdd )); } } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-06-17 10:53:42 UTC (rev 963) +++ trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-06-17 10:56:39 UTC (rev 964) @@ -76,7 +76,7 @@ if( nextPanelDescriptor.equals("REPAIR_PANEL")){ ((RepairPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getNegFailureModel().clear(); ((RepairPanelDescriptor)wizard.getModel().getPanelHashMap().get(nextPanelDescriptor)).panel4.getPosFailureModel().clear(); -// wizard.getModel().getOre().getModi().addAxiomToOWL(wizard.getModel().getOre().getConceptToAdd(), wizard.getModel().getOre().getConcept()); + wizard.getModel().getOre().getModi().addAxiomToOWL(wizard.getModel().getOre().getConceptToAdd(), wizard.getModel().getOre().getConcept()); new FailInstancesRetriever(nextPanelDescriptor).execute(); // for(Description desc : wizard.getModel().getOre().getConceptToAdd().getChildren()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |