From: <lor...@us...> - 2012-04-19 13:39:37
|
Revision: 3642 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3642&view=rev Author: lorenz_b Date: 2012-04-19 13:39:25 +0000 (Thu, 19 Apr 2012) Log Message: ----------- Started Protege plugin refactoring to be able to work with latest DL-Learner architecture and Protege 4.1. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java trunk/protege/src/main/resources/META-INF/MANIFEST.MF trunk/protege/src/main/resources/lib/components-core-1.0-SNAPSHOT.jar Added Paths: ----------- trunk/protege/src/main/resources/lib/jamon-2.0.jar trunk/protege/src/main/resources/lib/json-20090211.jar trunk/protege/src/main/resources/lib/log4j-1.2.16.jar Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -778,251 +778,254 @@ return inds; } -@SuppressWarnings("unchecked") -public SortedSet<Individual> getIndividualsImplFast(Description description) - throws ReasoningMethodUnsupportedException { - // policy: returned sets are clones, i.e. can be modified - // (of course we only have to clone the leafs of a class description tree) - if (description instanceof NamedClass) { - return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); - } else if (description instanceof Negation) { - if(description.getChild(0) instanceof NamedClass) { - return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone(); - } - // implement retrieval as default negation - return Helper.difference((TreeSet<Individual>) individuals.clone(), getIndividualsImpl(description.getChild(0))); - } else if (description instanceof Thing) { - return (TreeSet<Individual>) individuals.clone(); - } else if (description instanceof Nothing) { - return new TreeSet<Individual>(); - } else if (description instanceof Union) { - // copy instances of first element and then subtract all others - SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); - int childNr = 0; - for(Description child : description.getChildren()) { - if(childNr != 0) { - ret.addAll(getIndividualsImpl(child)); + @SuppressWarnings("unchecked") + public SortedSet<Individual> getIndividualsImplFast(Description description) + throws ReasoningMethodUnsupportedException { + // policy: returned sets are clones, i.e. can be modified + // (of course we only have to clone the leafs of a class description tree) + if (description instanceof NamedClass) { + if(((NamedClass) description).getName().equals("http://www.w3.org/2002/07/owl#Nothing")){ + return new TreeSet<Individual>(); } - childNr++; - } - return ret; - } else if (description instanceof Intersection) { - // copy instances of first element and then subtract all others - SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); - int childNr = 0; - for(Description child : description.getChildren()) { - if(childNr != 0) { - ret.retainAll(getIndividualsImpl(child)); + return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); + } else if (description instanceof Negation) { + if(description.getChild(0) instanceof NamedClass) { + return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone(); } - childNr++; - } - return ret; - } else if (description instanceof ObjectSomeRestriction) { - SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Retrieval for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - - // each individual is connected to a set of individuals via the property; - // we loop through the complete mapping - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - SortedSet<Individual> inds = entry.getValue(); - for(Individual ind : inds) { - if(targetSet.contains(ind)) { - returnSet.add(entry.getKey()); - // once we found an individual, we do not need to check the others - continue; + // implement retrieval as default negation + return Helper.difference((TreeSet<Individual>) individuals.clone(), getIndividualsImpl(description.getChild(0))); + } else if (description instanceof Thing) { + return (TreeSet<Individual>) individuals.clone(); + } else if (description instanceof Nothing) { + return new TreeSet<Individual>(); + } else if (description instanceof Union) { + // copy instances of first element and then subtract all others + SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); + int childNr = 0; + for(Description child : description.getChildren()) { + if(childNr != 0) { + ret.addAll(getIndividualsImpl(child)); } + childNr++; } - } - return returnSet; - } else if (description instanceof ObjectAllRestriction) { - // \forall restrictions are difficult to handle; assume we want to check - // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons - // this is satisfied trivially (all of their non-existing children are male) -// if(!configurator.getForallRetrievalSemantics().equals("standard")) { -// throw new Error("Only forallExists semantics currently implemented."); -// } - - // problem: we need to make sure that \neg \exists r.\top \equiv \forall r.\bot - // can still be reached in an algorithm (\forall r.\bot \equiv \bot under forallExists - // semantics) - - SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); - - ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); -// SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet()); - SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - - // each individual is connected to a set of individuals via the property; - // we loop through the complete mapping - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - SortedSet<Individual> inds = entry.getValue(); - for(Individual ind : inds) { - if(!targetSet.contains(ind)) { - returnSet.remove(entry.getKey()); - continue; + return ret; + } else if (description instanceof Intersection) { + // copy instances of first element and then subtract all others + SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); + int childNr = 0; + for(Description child : description.getChildren()) { + if(childNr != 0) { + ret.retainAll(getIndividualsImpl(child)); } + childNr++; } - } - return returnSet; - } else if (description instanceof ObjectMinCardinalityRestriction) { - ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Description child = description.getChild(0); - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> targetSet = getIndividualsImpl(child); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - int number = ((ObjectCardinalityRestriction) description).getNumber(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - int nrOfFillers = 0; - int index = 0; - SortedSet<Individual> inds = entry.getValue(); + return ret; + } else if (description instanceof ObjectSomeRestriction) { + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - // we do not need to run tests if there are not sufficiently many fillers - if(inds.size() < number) { - continue; + ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Retrieval for description " + + description + " unsupported. Inverse object properties not supported."); } + ObjectProperty op = (ObjectProperty) ope; + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - for(Individual ind : inds) { - // stop inner loop when nr of fillers is reached - if(nrOfFillers >= number) { - returnSet.add(entry.getKey()); - break; - } - // early abort when too many instance checks failed - if (inds.size() - index < number) { - break; - } - if(targetSet.contains(ind)) { - nrOfFillers++; + // each individual is connected to a set of individuals via the property; + // we loop through the complete mapping + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + SortedSet<Individual> inds = entry.getValue(); + for(Individual ind : inds) { + if(targetSet.contains(ind)) { + returnSet.add(entry.getKey()); + // once we found an individual, we do not need to check the others + continue; + } } - index++; } - } - - return returnSet; - } else if (description instanceof ObjectMaxCardinalityRestriction) { - ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Description child = description.getChild(0); - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> targetSet = getIndividualsImpl(child); - // initially all individuals are in the return set and we then remove those - // with too many fillers - SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - - int number = ((ObjectCardinalityRestriction) description).getNumber(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - int nrOfFillers = 0; - int index = 0; - SortedSet<Individual> inds = entry.getValue(); + return returnSet; + } else if (description instanceof ObjectAllRestriction) { + // \forall restrictions are difficult to handle; assume we want to check + // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons + // this is satisfied trivially (all of their non-existing children are male) +// if(!configurator.getForallRetrievalSemantics().equals("standard")) { +// throw new Error("Only forallExists semantics currently implemented."); +// } - // we do not need to run tests if there are not sufficiently many fillers - if(number < inds.size()) { - returnSet.add(entry.getKey()); - continue; + // problem: we need to make sure that \neg \exists r.\top \equiv \forall r.\bot + // can still be reached in an algorithm (\forall r.\bot \equiv \bot under forallExists + // semantics) + + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + + ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); } + ObjectProperty op = (ObjectProperty) ope; + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); +// SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet()); + SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - for(Individual ind : inds) { - // stop inner loop when nr of fillers is reached - if(nrOfFillers >= number) { - break; - } - // early abort when too many instance are true already - if (inds.size() - index < number) { - returnSet.add(entry.getKey()); - break; - } - if(targetSet.contains(ind)) { - nrOfFillers++; + // each individual is connected to a set of individuals via the property; + // we loop through the complete mapping + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + SortedSet<Individual> inds = entry.getValue(); + for(Individual ind : inds) { + if(!targetSet.contains(ind)) { + returnSet.remove(entry.getKey()); + continue; + } } - index++; } - } - - return returnSet; - } else if (description instanceof ObjectValueRestriction) { - Individual i = ((ObjectValueRestriction)description).getIndividual(); - ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); - - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - if(entry.getValue().contains(i)) { - returnSet.add(entry.getKey()); + return returnSet; + } else if (description instanceof ObjectMinCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); } - } - return returnSet; - } else if (description instanceof BooleanValueRestriction) { - DatatypeProperty dp = ((BooleanValueRestriction) description) - .getRestrictedPropertyExpression(); - boolean value = ((BooleanValueRestriction) description).getBooleanValue(); + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(child); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - if (value) { - return (TreeSet<Individual>) bdPos.get(dp).clone(); - } else { - return (TreeSet<Individual>) bdNeg.get(dp).clone(); - } - } else if (description instanceof DatatypeSomeRestriction) { - DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; - DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); - DataRange dr = dsr.getDataRange(); + int number = ((ObjectCardinalityRestriction) description).getNumber(); - Map<Individual, SortedSet<Double>> mapping = dd.get(dp); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(inds.size() < number) { + continue; + } + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + returnSet.add(entry.getKey()); + break; + } + // early abort when too many instance checks failed + if (inds.size() - index < number) { + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectMaxCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); + } + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(child); + // initially all individuals are in the return set and we then remove those + // with too many fillers + SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - if (dr instanceof DoubleMaxValue) { - for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { - if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) { + int number = ((ObjectCardinalityRestriction) description).getNumber(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(number < inds.size()) { returnSet.add(entry.getKey()); + continue; } - } - } else if (dr instanceof DoubleMinValue) { - for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { - if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) { + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + break; + } + // early abort when too many instance are true already + if (inds.size() - index < number) { + returnSet.add(entry.getKey()); + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectValueRestriction) { + Individual i = ((ObjectValueRestriction)description).getIndividual(); + ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); + + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + if(entry.getValue().contains(i)) { returnSet.add(entry.getKey()); } } + return returnSet; + } else if (description instanceof BooleanValueRestriction) { + DatatypeProperty dp = ((BooleanValueRestriction) description) + .getRestrictedPropertyExpression(); + boolean value = ((BooleanValueRestriction) description).getBooleanValue(); + + if (value) { + return (TreeSet<Individual>) bdPos.get(dp).clone(); + } else { + return (TreeSet<Individual>) bdNeg.get(dp).clone(); + } + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DataRange dr = dsr.getDataRange(); + + Map<Individual, SortedSet<Double>> mapping = dd.get(dp); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + if (dr instanceof DoubleMaxValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } else if (dr instanceof DoubleMinValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } } + + throw new ReasoningMethodUnsupportedException("Retrieval for description " + + description + " unsupported."); + + // return rs.retrieval(concept); +// SortedSet<Individual> inds = new TreeSet<Individual>(); +// for (Individual i : individuals) { +// if (hasType(concept, i)) { +// inds.add(i); +// } +// } +// return inds; } - - throw new ReasoningMethodUnsupportedException("Retrieval for description " - + description + " unsupported."); - - // return rs.retrieval(concept); -// SortedSet<Individual> inds = new TreeSet<Individual>(); -// for (Individual i : individuals) { -// if (hasType(concept, i)) { -// inds.add(i); -// } -// } -// return inds; -} @Override public Set<NamedClass> getTypesImpl(Individual individual) { Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -99,6 +99,14 @@ // view.setLearningStarted(); // view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), // Manager.getInstance().getMaximumHorizontalExpansion()); +// try { +// Manager manager = Manager.getInstance(); +// manager.initLearningProblem(); +// manager.initLearningAlgorithm(); +// Manager.getInstance().startLearning(); +// } catch (Exception e) { +// e.printStackTrace(); +// } retriever = new SuggestionRetriever(); retriever.addPropertyChangeListener(view.getStatusBar()); @@ -181,30 +189,30 @@ manager.initLearningAlgorithm(); view.setBusyTaskEnded(); -// SwingUtilities.invokeLater(new Runnable() { -// @Override -// public void run() { -// view.setLearningStarted(); -// view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), -// Manager.getInstance().getMaximumHorizontalExpansion()); -// } -// }); -// -// timer = new Timer(); -// timer.schedule(new TimerTask(){ -// int progress = 0; -// List<? extends EvaluatedDescription> result; -// @Override -// public void run() { -// progress++; -// setProgress(progress); -// if(!isCancelled() && Manager.getInstance().isLearning()){ -// result = Manager.getInstance().getCurrentlyLearnedDescriptions(); -// publish(result); -// } -// } -// -// }, 1000, 500); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + view.setLearningStarted(); + view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), + Manager.getInstance().getMaximumHorizontalExpansion()); + } + }); + + timer = new Timer(); + timer.schedule(new TimerTask(){ + int progress = 0; + List<? extends EvaluatedDescription> result; + @Override + public void run() { + progress++; + setProgress(progress); + if(!isCancelled() && Manager.getInstance().isLearning()){ + result = Manager.getInstance().getCurrentlyLearnedDescriptions(); + publish(result); + } + } + + }, 1000, 500); Manager.getInstance().startLearning(); } catch (Exception e) { ErrorLogPanel.showErrorDialog(e); @@ -218,13 +226,13 @@ @Override public void done() { -// if(!isCancelled()){ -// timer.cancel(); -// List<? extends EvaluatedDescription> result = Manager.getInstance().getCurrentlyLearnedDescriptions(); -// updateList(result); -// setProgress(0); -// view.setLearningFinished(); -// } + if(!isCancelled()){ + timer.cancel(); + List<? extends EvaluatedDescription> result = Manager.getInstance().getCurrentlyLearnedDescriptions(); + updateList(result); + setProgress(0); + view.setLearningFinished(); + } ProtegeApplication.getBackgroundTaskManager().endTask(learningTask); } Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml 2012-04-19 13:39:25 UTC (rev 3642) @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <plugin> <extension id="org.dllearner.tools.protege.ProtegePlugin" - point="org.protege.editor.owl.ui_editor_description"> + point="org.protege.editor.core.application.ViewComponent"> <label value="DL-Learner"/> <class value="org.dllearner.tools.protege.ProtegePlugin"/> <index value="E"/> Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -6,11 +6,8 @@ import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -18,6 +15,7 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.EvaluatedDescriptionClass; import org.dllearner.reasoning.ProtegeReasoner; +import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.owl.OWLAPIConverter; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.protege.editor.core.Disposable; @@ -37,14 +35,6 @@ public class Manager implements OWLModelManagerListener, OWLSelectionModelListener, Disposable{ - private final String[] components = { "org.dllearner.kb.OWLFile", - "org.dllearner.reasoning.OWLAPIReasoner", - "org.dllearner.reasoning.FastInstanceChecker", - "org.dllearner.reasoning.ProtegeReasoner", - "org.dllearner.reasoning.FastRetrievalReasoner", - "org.dllearner.algorithms.celoe.CELOE", - "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.ClassLearningProblem"}; - private static Manager instance; private OWLEditorKit editorKit; @@ -52,11 +42,10 @@ private boolean reinitNecessary = true; - private ComponentManager cm; - private AbstractLearningProblem lp; - private AbstractCELA la; + private ClassLearningProblem lp; + private CELOE la; private ProtegeReasoner reasoner; - private AbstractKnowledgeSource ks; + private KnowledgeSource ks; private LearningType learningType; private int maxExecutionTimeInSeconds; @@ -85,8 +74,6 @@ private Manager(OWLEditorKit editorKit){ this.editorKit = editorKit; - ComponentManager.setComponentClasses(components); - cm = ComponentManager.getInstance(); } public void setOWLEditorKit(OWLEditorKit editorKit){ @@ -110,20 +97,25 @@ public void initLearningAlgorithm() throws Exception { System.out.print("Initializing learning algorithm..."); long startTime = System.currentTimeMillis(); - la = cm.learningAlgorithm(CELOE.class, lp, reasoner); - cm.applyConfigEntry(la, "useAllConstructor", useAllConstructor); - cm.applyConfigEntry(la, "useExistsConstructor", useExistsConstructor); - cm.applyConfigEntry(la, "useHasValueConstructor", - useHasValueConstructor); - cm.applyConfigEntry(la, "useNegation", useNegation); - cm.applyConfigEntry(la, "useCardinalityRestrictions", - useCardinalityRestrictions); - if (useCardinalityRestrictions) { - cm.applyConfigEntry(la, "cardinalityLimit", cardinalityLimit); + la = new CELOE(lp, reasoner); + + RhoDRDown op = new RhoDRDown(); + op.setReasoner(reasoner); + op.setUseNegation(useNegation); + op.setUseHasValueConstructor(useAllConstructor); + op.setUseCardinalityRestrictions(useCardinalityRestrictions); + if(useCardinalityRestrictions){ + op.setCardinalityLimit(cardinalityLimit); } - cm.applyConfigEntry(la, "noisePercentage", noisePercentage); - cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); + op.setUseExistsConstructor(useExistsConstructor); + op.setUseHasValueConstructor(useHasValueConstructor); + op.init(); + + la.setOperator(op); + + la.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + la.setNoisePercentage(noisePercentage); + la.setMaxNrOfResults(maxNrOfResults); la.init(); System.out.println("done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -133,16 +125,11 @@ public void initLearningProblem() throws Exception { System.out.print("Initializing learning problem..."); long startTime = System.currentTimeMillis(); - lp = cm.learningProblem(ClassLearningProblem.class, reasoner); - cm.applyConfigEntry(lp, "classToDescribe", editorKit.getOWLWorkspace() - .getOWLSelectionModel().getLastSelectedClass().getIRI().toURI() - .toURL()); - if (learningType == LearningType.EQUIVALENT) { - cm.applyConfigEntry(lp, "type", "equivalence"); - } else if (learningType == LearningType.SUPER) { - cm.applyConfigEntry(lp, "type", "superClass"); - } - cm.applyConfigEntry(lp, "checkConsistency", false); + lp = new ClassLearningProblem(reasoner); + lp.setClassToDescribe(new NamedClass(editorKit.getOWLWorkspace() + .getOWLSelectionModel().getLastSelectedClass().getIRI().toURI())); + lp.setEquivalence(learningType == LearningType.EQUIVALENT); + lp.setCheckConsistency(false); lp.init(); System.out.println("Done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -154,17 +141,16 @@ } public void initReasoner() throws Exception{ - System.out.print("Initializing reasoner..."); + System.out.print("Initializing DL-Learner internal reasoner..."); long startTime = System.currentTimeMillis(); - reasoner = cm.reasoner(ProtegeReasoner.class, ks); - reasoner.setOWLReasoner(editorKit.getOWLModelManager().getReasoner()); + reasoner = new ProtegeReasoner(Collections.singleton(ks), editorKit.getOWLModelManager().getReasoner()); reasoner.setProgressMonitor(progressMonitor); reasoner.init(); System.out.println("Done in " + (System.currentTimeMillis()-startTime) + "ms."); } public void initReasonerAsynchronously(){ - reasoner = cm.reasoner(ProtegeReasoner.class, ks); + reasoner = new ProtegeReasoner(Collections.singleton(ks), editorKit.getOWLModelManager().getReasoner()); reasoner.setOWLReasoner(editorKit.getOWLModelManager().getReasoner()); reasoner.setProgressMonitor(progressMonitor); @@ -372,7 +358,6 @@ @Override public void dispose() throws Exception { reasoner.releaseKB(); - cm.freeAllComponents(); editorKit.getOWLModelManager().removeListener(this); editorKit.getOWLWorkspace().getOWLSelectionModel().removeListener(this); Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -25,6 +25,10 @@ import javax.swing.JComponent; import org.protege.editor.core.ui.util.InputVerificationStatusChangedListener; +import org.protege.editor.owl.model.OWLModelManager; +import org.protege.editor.owl.model.event.EventType; +import org.protege.editor.owl.model.event.OWLModelManagerChangeEvent; +import org.protege.editor.owl.model.event.OWLModelManagerListener; import org.protege.editor.owl.model.inference.NoOpReasoner; import org.protege.editor.owl.ui.editor.AbstractOWLClassExpressionEditor; import org.semanticweb.owlapi.model.AxiomType; @@ -38,7 +42,7 @@ * @author Christian Koetteritzsch * */ -public class ProtegePlugin extends AbstractOWLClassExpressionEditor { +public class ProtegePlugin extends AbstractOWLClassExpressionEditor implements OWLModelManagerListener{ private static final long serialVersionUID = 728362819273927L; private DLLearnerView view; @@ -60,16 +64,22 @@ Manager.getInstance(getOWLEditorKit()).setLearningType(LearningType.SUPER); } view.reset(); + checkReasonerStatus(); + return true; + } + + private void checkReasonerStatus(){ OWLReasoner r = getOWLEditorKit().getModelManager().getReasoner(); if(r instanceof NoOpReasoner){ view.setHintMessage("<html><font size=\"3\" color=\"red\">You have to select a reasoner (click on menu \"Reasoner\"). We recommend to use Pellet. </font></html>"); view.setRunButtonEnabled(false); } else { + view.setHintMessage(""); + view.setRunButtonEnabled(true); if(!Manager.getInstance().isPreparing() && Manager.getInstance().isReinitNecessary()){ new ReadingOntologyThread(view).start(); } } - return true; } @Override @@ -105,6 +115,7 @@ } private void addListeners(){ + getOWLEditorKit().getOWLModelManager().addListener(this); getOWLEditorKit().getOWLModelManager().addListener(Manager.getInstance(getOWLEditorKit())); getOWLEditorKit().getOWLWorkspace().getOWLSelectionModel().addListener(Manager.getInstance(getOWLEditorKit())); } @@ -113,4 +124,11 @@ getOWLEditorKit().getOWLModelManager().removeListener(Manager.getInstance(getOWLEditorKit())); getOWLEditorKit().getOWLWorkspace().getOWLSelectionModel().removeListener(Manager.getInstance(getOWLEditorKit())); } + + @Override + public void handleChange(OWLModelManagerChangeEvent event) { + if(event.isType(EventType.REASONER_CHANGED) || event.isType(EventType.ACTIVE_ONTOLOGY_CHANGED)){ + checkReasonerStatus(); + } + } } Modified: trunk/protege/src/main/resources/META-INF/MANIFEST.MF =================================================================== --- trunk/protege/src/main/resources/META-INF/MANIFEST.MF 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/resources/META-INF/MANIFEST.MF 2012-04-19 13:39:25 UTC (rev 3642) @@ -11,6 +11,9 @@ lib/junit-4.4.jar, lib/jamon-2.7.jar, lib/swingx-1.6.jar, + lib/json-20090211.jar, + lib/log4j-1.2.16.jar, + lib/jamon-2.0.jar, lib/jena/json.jar, lib/jena/commons-logging-1.1.1.jar, lib/components-core-1.0-SNAPSHOT.jar Modified: trunk/protege/src/main/resources/lib/components-core-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Added: trunk/protege/src/main/resources/lib/jamon-2.0.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/jamon-2.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/protege/src/main/resources/lib/json-20090211.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/json-20090211.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/protege/src/main/resources/lib/log4j-1.2.16.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/log4j-1.2.16.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |