From: <lor...@us...> - 2009-05-07 08:42:34
|
Revision: 1744 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1744&view=rev Author: lorenz_b Date: 2009-05-07 08:42:31 +0000 (Thu, 07 May 2009) Log Message: ----------- some small changes axiom ranking class started to implement Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -0,0 +1,78 @@ +package org.dllearner.tools.ore.explanation; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import org.mindswap.pellet.owlapi.PelletReasonerFactory; +import org.mindswap.pellet.owlapi.Reasoner; +import org.mindswap.pellet.utils.SetUtils; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChangeException; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; +import org.semanticweb.owl.model.OWLSubClassAxiom; +import org.semanticweb.owl.model.RemoveAxiom; + +public class AxiomRanker { + + Map axiomSOSMap; + OWLOntology ontology; + Reasoner reasoner; + OWLDataFactory factory; + + public AxiomRanker(OWLOntology ont, Reasoner reasoner, OWLDataFactory fact){ + this.ontology = ont; + this.reasoner = reasoner; + this.factory = fact; + } + + private void computeImpactSOS(OWLAxiom ax) { + + + } + + + + public static void main(String[] args){ + + try { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory dFactory = manager.getOWLDataFactory(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(URI.create("file:examples/ore/koala.owl")); + PelletReasonerFactory factory = new PelletReasonerFactory(); + Reasoner reasoner = factory.createReasoner(manager); + reasoner.loadOntology(ontology); + reasoner.classify(); + + + OWLClass cl1 = dFactory.getOWLClass(URI.create("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#koala")); + OWLClass cl2 = dFactory.getOWLClass(URI.create("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#person")); + OWLAxiom ax = dFactory.getOWLSubClassAxiom(cl1, dFactory.getOWLObjectComplementOf(cl2)); + Set<OWLClass> before = null; + Set<OWLClass> after = null; + if(ax instanceof OWLSubClassAxiom){ + before = SetUtils.union(reasoner.getSuperClasses(cl1)); + manager.applyChange(new RemoveAxiom(ontology, ax)); + after = SetUtils.union(reasoner.getSuperClasses(cl1)); + System.out.println(SetUtils.difference(before, after)); + } + System.out.println(cl1.getSuperClasses(ontology)); + System.out.println(after); + + + + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java ___________________________________________________________________ Added: svn:executable + * Deleted: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java 2009-05-07 08:38:31 UTC (rev 1743) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -1,120 +0,0 @@ - - -package org.dllearner.tools.ore.explanation; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLDataFactory; -import org.semanticweb.owl.model.OWLDataRange; -import org.semanticweb.owl.model.OWLDataValueRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLObjectComplementOf; -import org.semanticweb.owl.model.OWLObjectExactCardinalityRestriction; -import org.semanticweb.owl.model.OWLObjectMaxCardinalityRestriction; -import org.semanticweb.owl.model.OWLObjectMinCardinalityRestriction; -import org.semanticweb.owl.model.OWLObjectPropertyExpression; -import org.semanticweb.owl.model.OWLObjectUnionOf; - - - -public class BetaGenerator extends BaseDescriptionGenerator -{ - - public BetaGenerator(OWLDataFactory factory) - { - super(factory); - } - - public Set<OWLDescription> visit(OWLClass desc) - { - Set<OWLDescription> descs = new HashSet<OWLDescription>(3); - descs.add(desc); - descs.add(getDataFactory().getOWLNothing()); - return descs; - } - - public Set<OWLDescription> visit(OWLObjectComplementOf desc) - { - Set<OWLDescription> descs = new HashSet<OWLDescription>(); - - for(OWLDescription d : computeTau(desc.getOperand())){ - descs.add(getDataFactory().getOWLObjectComplementOf(d)); - } - - return descs; - } - - protected Set<OWLDescription> compute(OWLDescription description) - { - return computeBeta(description); - } - - public Set<OWLDescription> visit(OWLObjectMaxCardinalityRestriction desc) - { - Set<OWLDescription> fillers = computeTau(desc.getFiller()); - Set<OWLDescription> result = new HashSet<OWLDescription>(); - for(int n = desc.getCardinality(); n > 0; n--) - { - for(OWLDescription filler : fillers){ - result.add(getDataFactory().getOWLObjectMinCardinalityRestriction((OWLObjectPropertyExpression)desc.getProperty(), n, filler)); - } - } - - result.add(getLimit()); - return result; - } - - @Override - public Set<OWLDescription> visit(OWLObjectExactCardinalityRestriction desc) - { - Set<OWLDescription> fillers = computeBeta((OWLDescription)desc.getFiller()); - Set<OWLDescription> result = new HashSet<OWLDescription>(); - - for(OWLDescription filler : fillers){ - result.add(getDataFactory().getOWLObjectExactCardinalityRestriction((OWLObjectPropertyExpression)desc.getProperty(), desc.getCardinality(), filler)); - } - result.add(getLimit()); - return result; - } - - @Override - public Set<OWLDescription> visit(OWLObjectUnionOf desc) - { - return super.visit(desc); - } - - public Set<OWLDescription> visit(OWLObjectMinCardinalityRestriction desc) - { - Set<OWLDescription> fillers = computeBeta((OWLDescription)desc.getFiller()); - Set<OWLDescription> result = new HashSet<OWLDescription>(); - - for(OWLDescription filler : fillers){ - result.add(getDataFactory().getOWLObjectMinCardinalityRestriction((OWLObjectPropertyExpression)desc.getProperty(), desc.getCardinality(), filler)); - } - result.add(getLimit()); - return result; - } - - @Override - protected OWLClass getLimit() - { - return getDataFactory().getOWLNothing(); - } - - @Override - protected OWLDataRange getDataLimit() - { - return getDataFactory().getOWLDataComplementOf(getDataFactory().getTopDataType()); - } - - @Override - public Set<OWLDescription> visit(OWLDataValueRestriction desc) - { - return Collections.singleton((OWLDescription)desc); - } - - -} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java 2009-05-07 08:38:31 UTC (rev 1743) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -119,14 +119,14 @@ System.out.println("\t ***** No change in ontology. Early termination."); break; } - +// man2.saveOntology(extendedOnt, URI.create("file:/home/lorenz/neu.owl")); axiomsInPreviousOntology.clear(); axiomsInPreviousOntology.addAll(extendedOnt.getLogicalAxioms()); Set<Set<OWLAxiom>> allPrevJustsCopy = new HashSet<Set<OWLAxiom>>(allPreviouslyFoundJustifications); - + Set<OWLOntology> ont2 = new HashSet<OWLOntology>(); - ont2.add(extendedOnt); + ont2.add(extendedOnt); PelletExplanation expGen = new PelletExplanation(man2, ont2); Set<Set<OWLAxiom>> currentJustifications = expGen.getEntailmentExplanations((OWLAxiom)entailment); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java 2009-05-07 08:38:31 UTC (rev 1743) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -8,6 +8,8 @@ import java.util.Set; import org.mindswap.pellet.owlapi.PelletReasonerFactory; +import org.mindswap.pellet.owlapi.Reasoner; +import org.mindswap.pellet.utils.progress.SwingProgressMonitor; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.inference.OWLReasonerException; @@ -22,6 +24,7 @@ import org.semanticweb.owl.model.OWLOntologyManager; import org.semanticweb.owl.model.OWLSubClassAxiom; +import com.clarkparsia.explanation.PelletExplanation; import com.clarkparsia.explanation.io.manchester.ManchesterSyntaxExplanationRenderer; public class LaconicTest { @@ -30,48 +33,105 @@ public static void main(String[] args) { - miniTest(); +// test(); +// miniTest(); miniEconomyTest(); - universityTest(); +// universityTest(); } + public static void test(){ + String file = "file:/home/lorenz/neu.owl"; + + + + try { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + PrintWriter pw = new PrintWriter(System.out); + renderer.startRendering(pw); + OWLDataFactory dataFactory = manager.getOWLDataFactory(); + PelletReasonerFactory resonerFact = new PelletReasonerFactory(); + + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(URI + .create(file)); + + Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); + Reasoner reasoner = resonerFact.createReasoner(manager); + reasoner.loadOntologies(Collections.singleton(ontology)); + System.out.println(reasoner.getInconsistentClasses()); + PelletExplanation exp = new PelletExplanation(manager, Collections.singleton(ontology)); + + System.out.println(exp.getUnsatisfiableExplanations(dataFactory.getOWLClass( + URI.create("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#KoalaWithPhD")))); + renderer.endRendering(); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public static void miniEconomyTest() { String file = "file:examples/ore/miniEconomy.owl"; try { - + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); PrintWriter pw = new PrintWriter(System.out); renderer.startRendering(pw); + + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(URI .create(file)); Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); ontologies.add(ontology); - OWLReasonerFactory resonerFact = new PelletReasonerFactory(); + PelletReasonerFactory resonerFact = new PelletReasonerFactory(); OWLDataFactory dataFactory = manager.getOWLDataFactory(); - - OWLReasoner reasoner = resonerFact.createReasoner(manager); + + ////////////////////HermiT test +// HermiTReasonerFactory f = new HermiTReasonerFactory(); +// HermitReasoner re = (HermitReasoner) f.createReasoner(manager); +// re.loadOntologies(ontologies); +// Timer t1 = new Timer("classifying"); +// t1.start(); +// re.classify(); +// t1.stop(); +// re.realise(); +// System.out.println("HermiT" + re.getInconsistentClasses()); + ////////////////////////////// + + Reasoner reasoner = resonerFact.createReasoner(manager); reasoner.loadOntologies(ontologies); + SwingProgressMonitor monitor = new SwingProgressMonitor(); + reasoner.getKB().getTaxonomyBuilder().setProgressMonitor(monitor); reasoner.classify(); - + System.out.println(reasoner.getInconsistentClasses()); + LaconicExplanationGenerator expGen = new LaconicExplanationGenerator( manager, resonerFact, ontologies); + + Set<OWLClass> unsatClasses = reasoner.getInconsistentClasses(); OWLSubClassAxiom unsatAxiom; - for (OWLClass unsat : unsatClasses) { - unsatAxiom = dataFactory.getOWLSubClassAxiom(unsat, dataFactory - .getOWLNothing()); - Set<Set<OWLAxiom>> preciseJusts = expGen - .getExplanations(unsatAxiom); - renderer.render(unsatAxiom, preciseJusts); - } - + unsatAxiom = dataFactory.getOWLSubClassAxiom(dataFactory.getOWLClass(URI.create("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#KoalaWithPhD")), + dataFactory.getOWLNothing()); +// for (OWLClass unsat : unsatClasses) { +// unsatAxiom = dataFactory.getOWLSubClassAxiom(unsat, dataFactory +// .getOWLNothing()); +// Set<Set<OWLAxiom>> preciseJusts = expGen +// .getExplanations(unsatAxiom); +// renderer.render(unsatAxiom, preciseJusts); +// } + Set<Set<OWLAxiom>> preciseJusts = expGen.getExplanations(unsatAxiom); + renderer.render(unsatAxiom, preciseJusts); renderer.endRendering(); } catch (OWLOntologyCreationException e) { Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java 2009-05-07 08:38:31 UTC (rev 1743) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -333,12 +333,10 @@ OWLReasonerFactory factory = new PelletReasonerFactory(); OWLReasoner reasoner = factory.createReasoner(manager); reasoner.loadOntologies(Collections.singleton(ontology)); - UnsatRootClassesFinder strReasoner = new UnsatRootClassesFinder(manager, reasoner, factory); - System.out.println(strReasoner.getRootUnsatisfiableClasses()); + RootFinder strReasoner = new RootFinder(manager, reasoner, factory); + System.out.println(strReasoner.getRootClasses()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); - } catch (ExplanationException e) { - e.printStackTrace(); } catch (OWLReasonerException e) { e.printStackTrace(); } Deleted: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java 2009-05-07 08:38:31 UTC (rev 1743) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java 2009-05-07 08:42:31 UTC (rev 1744) @@ -1,84 +0,0 @@ - -package org.dllearner.tools.ore.explanation; - -import java.util.HashSet; -import java.util.Set; - -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLDataFactory; -import org.semanticweb.owl.model.OWLDataRange; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLObjectComplementOf; -import org.semanticweb.owl.model.OWLObjectMaxCardinalityRestriction; -import org.semanticweb.owl.model.OWLObjectMinCardinalityRestriction; -import org.semanticweb.owl.model.OWLObjectPropertyExpression; - - -public class TauGenerator extends BaseDescriptionGenerator -{ - - public TauGenerator(OWLDataFactory factory) - { - super(factory); - } - - public Set<OWLDescription> visit(OWLClass desc) - { - Set<OWLDescription> descs = new HashSet<OWLDescription>(); - descs.add(desc); - descs.add(getDataFactory().getOWLThing()); - return descs; - } - - public Set<OWLDescription> visit(OWLObjectComplementOf desc) - { - Set<OWLDescription> descs = new HashSet<OWLDescription>(); - - for(OWLDescription d : computeBeta(desc.getOperand())){ - descs.add(getDataFactory().getOWLObjectComplementOf(d)); - } - return descs; - } - - public Set<OWLDescription> visit(OWLObjectMaxCardinalityRestriction desc) - { - Set<OWLDescription> descs = new HashSet<OWLDescription>(); - - for(OWLDescription filler : computeBeta(desc.getFiller())){ - descs.add(getDataFactory().getOWLObjectMaxCardinalityRestriction((OWLObjectPropertyExpression)desc.getProperty(), desc.getCardinality(), filler)); - } - descs.add(getLimit()); - return descs; - } - - public Set<OWLDescription> visit(OWLObjectMinCardinalityRestriction desc) - { - Set<OWLDescription> weakenedFillers = computeTau((OWLDescription)desc.getFiller()); - Set<OWLDescription> result = new HashSet<OWLDescription>(); - for(int n = desc.getCardinality(); n > 0; n--) - { - - for(OWLDescription filler : weakenedFillers ){ - result.add(getDataFactory().getOWLObjectMinCardinalityRestriction((OWLObjectPropertyExpression)desc.getProperty(), n, filler)); - } - - } - - result.add(getLimit()); - return result; - } - - @Override - protected OWLClass getLimit() - { - return getDataFactory().getOWLThing(); - } - - @Override - protected OWLDataRange getDataLimit() - { - return getDataFactory().getTopDataType(); - } - - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |