From: <lor...@us...> - 2009-04-09 16:36:51
|
Revision: 1694 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1694&view=rev Author: lorenz_b Date: 2009-04-09 16:36:41 +0000 (Thu, 09 Apr 2009) Log Message: ----------- renamed Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java Copied: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java (from rev 1680, trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BetaGenerator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Beta.java 2009-04-09 16:36:41 UTC (rev 1694) @@ -0,0 +1,115 @@ + + +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 Beta extends BaseDescriptionGenerator +{ + + public Beta(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; + } + + 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; + } + + 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; + } + + protected OWLClass getLimit() + { + return getDataFactory().getOWLNothing(); + } + + protected OWLDataRange getDataLimit() + { + return getDataFactory().getOWLDataComplementOf(getDataFactory().getTopDataType()); + } + + public Set<OWLDescription> visit(OWLDataValueRestriction desc) + { + return Collections.singleton((OWLDescription)desc); + } + + +} Copied: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java (from rev 1680, trunk/src/dl-learner/org/dllearner/tools/ore/explanation/TauGenerator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/Tau.java 2009-04-09 16:36:41 UTC (rev 1694) @@ -0,0 +1,82 @@ + +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 Tau extends BaseDescriptionGenerator +{ + + public Tau(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; + } + + protected OWLClass getLimit() + { + return getDataFactory().getOWLThing(); + } + + protected OWLDataRange getDataLimit() + { + return getDataFactory().getTopDataType(); + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2009-04-15 07:27:04
|
Revision: 1701 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1701&view=rev Author: lorenz_b Date: 2009-04-15 07:26:58 +0000 (Wed, 15 Apr 2009) Log Message: ----------- added generator for laconic/precise explanations and some test cases Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BaseDescriptionGenerator.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/OPlus.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/ExplanationException.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BaseDescriptionGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BaseDescriptionGenerator.java 2009-04-14 17:58:43 UTC (rev 1700) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/BaseDescriptionGenerator.java 2009-04-15 07:26:58 UTC (rev 1701) @@ -61,20 +61,20 @@ public Set<OWLDescription> computeTau(OWLDescription desc) { - TauGenerator gen = new TauGenerator(factory); + Tau gen = new Tau(factory); return desc.accept(gen); } public Set<OWLDescription> computeBeta(OWLDescription desc) { - BetaGenerator gen = new BetaGenerator(factory); + Beta gen = new Beta(factory); return (Set<OWLDescription>)desc.accept(gen); } private Set<Set<OWLDescription>> computeReplacements(Set<OWLDescription> operands) - {System.out.println("Eingabe : " + operands); + { Set<List<OWLDescription>> ps = new HashSet<List<OWLDescription>>(); - ps.add(new ArrayList()); + ps.add(new ArrayList<OWLDescription>()); for(OWLDescription op : operands) { @@ -95,7 +95,7 @@ for(List<OWLDescription> desc : ps ){ result.add(new HashSet<OWLDescription>(desc)); - }System.out.println("Ergebnis : " + result); + } return result; } Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/ExplanationException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/ExplanationException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/ExplanationException.java 2009-04-15 07:26:58 UTC (rev 1701) @@ -0,0 +1,29 @@ + + +package org.dllearner.tools.ore.explanation; + +import org.semanticweb.owl.model.OWLException; + +public class ExplanationException extends OWLException +{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ExplanationException(Throwable cause) + { + super(cause); + } + + public ExplanationException(String message) + { + super(message); + } + + public ExplanationException(String message, Throwable cause) + { + super(message, cause); + } +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicExplanationGenerator.java 2009-04-15 07:26:58 UTC (rev 1701) @@ -0,0 +1,308 @@ + +package org.dllearner.tools.ore.explanation; +import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasonerFactory; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLException; +import org.semanticweb.owl.model.OWLLogicalAxiom; +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 com.clarkparsia.explanation.PelletExplanation; + +public class LaconicExplanationGenerator +{ + + private PelletExplanation pelletExplanation; + private OWLOntologyManager manager; + private OWLOntology ontology; + private Set<Set<OWLAxiom>> lastRegularJusts; + private Set<Set<OWLAxiom>> allPreviouslyFoundJustifications; + private OPlus oPlus; + + public LaconicExplanationGenerator(OWLOntologyManager manager, + OWLReasonerFactory reasonerFactory, Set<OWLOntology> ontologies) { + + this.manager = manager; + + try { + ontology = manager.createOntology(URI.create(new StringBuilder().append( + "http://laconic").append(System.nanoTime()).toString()), + ontologies, true); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (OWLOntologyChangeException e) { + e.printStackTrace(); + } + + pelletExplanation = new PelletExplanation(manager, ontologies); + lastRegularJusts = new HashSet<Set<OWLAxiom>>(); + } + + /** + * Computes a more fine grained representation for a set of axioms, which means to split them + * e.g. for A \sqsubseteq B \sqcap C returning A \sqsubseteq B and A \sqsubseteq C + * @param axioms to split + * @return splitted axioms + */ + public Set<OWLAxiom> computeOPlus(Set<OWLAxiom> axioms) { + oPlus = new OPlus(manager.getOWLDataFactory()); + Set<OWLAxiom> oPlusAxioms = new HashSet<OWLAxiom>(); + + for(OWLAxiom ax : axioms){ + Set<OWLAxiom> weakenedAxioms = ax.accept(oPlus); + oPlusAxioms.addAll(weakenedAxioms); + } + return oPlusAxioms; + } + + + public Set<Set<OWLAxiom>> getLastRegularJustifications() { + return lastRegularJusts; + } + + /** + * Computes the precise explanations + * @param entailment + * @param limit + * @return + * @throws OWLException + */ + public Set<Set<OWLAxiom>> computePreciseJusts(OWLAxiom entailment, int limit) throws OWLException { + + Set<Set<OWLAxiom>> regularJusts = pelletExplanation.getEntailmentExplanations((OWLAxiom)entailment); + + System.out.println(new StringBuilder().append + ("Got regular justifications: ").append + (regularJusts.size()).toString()); + lastRegularJusts.clear(); + lastRegularJusts.addAll(regularJusts); + allPreviouslyFoundJustifications = new HashSet<Set<OWLAxiom>>(); + allPreviouslyFoundJustifications.addAll(regularJusts); + Set<Set<OWLAxiom>> nonLaconicJusts = new HashSet<Set<OWLAxiom>>(); + Set<Set<OWLAxiom>> laconicJusts = new HashSet<Set<OWLAxiom>>(); + Set<OWLAxiom> axiomsInPreviousOntology = new HashSet<OWLAxiom>(); + long counter = 0L; + for (;;) { + counter++; + System.out.println(new StringBuilder().append("Count ").append + (counter).toString()); + Set<OWLAxiom> unionOfAllJustifications = new HashSet<OWLAxiom>(); + for(Set<OWLAxiom> just : allPreviouslyFoundJustifications){ + unionOfAllJustifications.addAll(just); + } + + +// Set<OWLAxiom> lastOPlus = new HashSet<OWLAxiom>(computeOPlus(unionOfAllJustifications)); + Set<OWLAxiom> oPlus = computeOPlus(unionOfAllJustifications); + OWLOntologyManager man2 = OWLManager.createOWLOntologyManager(); + OWLOntology extendedOnt = man2.createOntology(oPlus); + for(OWLLogicalAxiom logAx : ontology.getLogicalAxioms()){ + if (!unionOfAllJustifications.contains(logAx) || oPlus.contains(logAx)){ + man2.addAxiom(extendedOnt, logAx); + } + } + + if (extendedOnt.getLogicalAxioms().equals(axiomsInPreviousOntology)) { + System.out.println("\t ***** No change in ontology. Early termination."); + break; + } + + axiomsInPreviousOntology.clear(); + axiomsInPreviousOntology.addAll(extendedOnt.getLogicalAxioms()); + Set<Set<OWLAxiom>> allPrevJustsCopy = new HashSet<Set<OWLAxiom>>(allPreviouslyFoundJustifications); + + + Set<OWLOntology> ont2 = new HashSet<OWLOntology>(); + ont2.add(extendedOnt); + PelletExplanation expGen = new PelletExplanation(man2, ont2); + Set<Set<OWLAxiom>> currentJustifications = expGen.getEntailmentExplanations((OWLAxiom)entailment); + + + allPreviouslyFoundJustifications.addAll(currentJustifications); + if (allPreviouslyFoundJustifications.equals(allPrevJustsCopy)){ + break; + } + for(Set<OWLAxiom> currentJust : currentJustifications){ + if(!laconicJusts.contains(currentJust) && !nonLaconicJusts.contains(currentJust)){ + if(isLaconic(currentJust, entailment)){ + laconicJusts.add(currentJust); + } else{ + nonLaconicJusts.add(currentJust); + } + if(laconicJusts.size() == limit){ + return retrieveAxioms(laconicJusts); + } + } + } + + } + Set<Set<OWLAxiom>> laconicJustifications = new HashSet<Set<OWLAxiom>>(); + for(Set<OWLAxiom> just : allPreviouslyFoundJustifications){ + if(!nonLaconicJusts.contains(just)){ + if(laconicJusts.contains(just)){ + laconicJustifications.add(just); + } else if(isLaconic(just, entailment)){ + laconicJustifications.add(just); + } + } + } + + + return retrieveAxioms(laconicJustifications); + } + + public boolean isLaconic(Set<OWLAxiom> justification, OWLAxiom entailment) + throws ExplanationException { + boolean laconic; + try { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + Set<OWLAxiom> justificationSigmaClosure = computeOPlus(justification); + + OWLOntology justificationSigmaClosureOnt = manager + .createOntology(justificationSigmaClosure); + + PelletExplanation expGen2 = new PelletExplanation(manager, + Collections.singleton(justificationSigmaClosureOnt)); + Set<Set<OWLAxiom>> exps = expGen2.getEntailmentExplanations( + entailment, Integer.MAX_VALUE); + + laconic = Collections.singleton(justification).equals(exps); + + } catch (OWLOntologyCreationException e) { + throw new ExplanationException(e); + } catch (OWLOntologyChangeException e) { + throw new ExplanationException(e); + } + return laconic; + } + + private Set<Set<OWLAxiom>> retrieveAxioms(Set<Set<OWLAxiom>> explanations) { + + Map<OWLAxiom, Set<OWLAxiom>> sourceAxioms2OPlus = new HashMap<OWLAxiom, Set<OWLAxiom>>(); + + for (Set<OWLAxiom> just : allPreviouslyFoundJustifications) { + for (OWLAxiom ax : just) { + if (ontology.containsAxiom(ax)) { + sourceAxioms2OPlus.put(ax, computeOPlus(Collections.singleton(ax))); + } + } + } + Set<Set<OWLAxiom>> reconstituedExplanations = new HashSet<Set<OWLAxiom>>(); + + for (Set<OWLAxiom> expl : explanations) { + Map<OWLClass, Map<OWLAxiom, Set<OWLSubClassAxiom>>> lhs2SubClassAxiom = new HashMap<OWLClass, Map<OWLAxiom, Set<OWLSubClassAxiom>>>(); + Set<OWLAxiom> reconstituedAxioms = new HashSet<OWLAxiom>(); + for (OWLAxiom laconicAx : expl) { + if (laconicAx instanceof OWLSubClassAxiom) { + OWLSubClassAxiom subAx = (OWLSubClassAxiom) laconicAx; + if (subAx.getSubClass().isAnonymous()) { + reconstituedAxioms.add(subAx); + } else { + Map<OWLAxiom, Set<OWLSubClassAxiom>> source2AxiomMap = lhs2SubClassAxiom.get(subAx.getSubClass().asOWLClass()); + if (source2AxiomMap == null) { + source2AxiomMap = new HashMap<OWLAxiom, Set<OWLSubClassAxiom>>(); + lhs2SubClassAxiom.put(subAx.getSubClass().asOWLClass(), source2AxiomMap); + } + + for (OWLAxiom sourceAxiom : sourceAxioms2OPlus.keySet()) { + if ((sourceAxioms2OPlus.get(sourceAxiom)).contains(subAx)) { + Set<OWLSubClassAxiom> subClassAxioms = source2AxiomMap.get(sourceAxiom); + if (subClassAxioms == null) { + subClassAxioms = new HashSet<OWLSubClassAxiom>(); + source2AxiomMap.put(sourceAxiom, subClassAxioms); + } + subClassAxioms.add(subAx); + } + } + } + } else { + reconstituedAxioms.add(laconicAx); + } + } + Set<OWLAxiom> consumedAxioms = new HashSet<OWLAxiom>(); + for (OWLClass lhs : (Set<OWLClass>) lhs2SubClassAxiom.keySet()) { + Map<OWLAxiom, Set<OWLSubClassAxiom>> source2SubClassAxiom = lhs2SubClassAxiom.get(lhs); + for (OWLAxiom source : source2SubClassAxiom.keySet()) { + Set<OWLDescription> rightHandSides = new HashSet<OWLDescription>(); + for (OWLSubClassAxiom sub : source2SubClassAxiom.get(source)) { + if (!consumedAxioms.contains(sub)) { + rightHandSides.add(sub.getSuperClass()); + consumedAxioms.add(sub); + } + } + + if (rightHandSides.size() == 1) + reconstituedAxioms.add(manager.getOWLDataFactory().getOWLSubClassAxiom((OWLDescription) lhs,((OWLDescription) rightHandSides.iterator().next()))); + else if (rightHandSides.size() > 1) { + org.semanticweb.owl.model.OWLObjectIntersectionOf conjunction = manager.getOWLDataFactory().getOWLObjectIntersectionOf(rightHandSides); + reconstituedAxioms.add(manager.getOWLDataFactory().getOWLSubClassAxiom((OWLDescription) lhs,conjunction)); + } + } + } + + reconstituedExplanations.add(reconstituedAxioms); + + } + + return reconstituedExplanations; + } + + + + public Set<Set<OWLAxiom>> getExplanations(OWLAxiom entailment) throws ExplanationException { + Set<Set<OWLAxiom>> set; + try { + set = computePreciseJusts(entailment, 2147483647); + } catch (OWLException e) { + throw new ExplanationException(e); + } + return set; + } + + public Set<Set<OWLAxiom>> getExplanations(OWLAxiom entailment, int limit) + throws ExplanationException { + Set<Set<OWLAxiom>> set; + try { + set = computePreciseJusts(entailment, limit); + } catch (OWLException e) { + throw new ExplanationException(e); + } + return set; + } + + public Set<Set<OWLAxiom>> getRegularExplanations(OWLAxiom entailment) throws ExplanationException { + Set<Set<OWLAxiom>> regularJusts; + + regularJusts = pelletExplanation.getEntailmentExplanations((OWLAxiom)entailment); + lastRegularJusts.addAll(regularJusts); + return regularJusts; + } + + public void returnSourceAxioms(Set<Set<OWLAxiom>> explanations){ + Map<OWLAxiom, Set<OWLAxiom>> sourceMap = oPlus.getAxiomsMap(); + System.out.println(sourceMap); + for(Set<OWLAxiom> explanation: explanations){ + for(OWLAxiom ax : explanation){ + System.out.println(ax + " gehört zu " + sourceMap.get(ax)); + + } + } + } + + + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/LaconicTest.java 2009-04-15 07:26:58 UTC (rev 1701) @@ -0,0 +1,197 @@ +package org.dllearner.tools.ore.explanation; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.mindswap.pellet.owlapi.PelletReasonerFactory; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.inference.OWLReasonerFactory; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLException; +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 com.clarkparsia.explanation.io.manchester.ManchesterSyntaxExplanationRenderer; + +public class LaconicTest { + + + + public static void main(String[] args) { + + miniTest(); + miniEconomyTest(); + universityTest(); + } + + 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(); + OWLDataFactory dataFactory = manager.getOWLDataFactory(); + + OWLReasoner reasoner = resonerFact.createReasoner(manager); + reasoner.loadOntologies(ontologies); + reasoner.classify(); + + + 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); + } + + renderer.endRendering(); + + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (UnsupportedOperationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void miniTest(){ + try { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + PrintWriter pw = new PrintWriter(System.out); + renderer.startRendering(pw); + OWLClass c = factory.getOWLClass(URI.create("c")); + OWLClass d = factory.getOWLClass(URI.create("d")); + OWLClass e = factory.getOWLClass(URI.create("e")); + OWLAxiom axiom = factory.getOWLSubClassAxiom(c, + factory.getOWLObjectIntersectionOf(d, factory.getOWLObjectComplementOf(d), e)); + OWLOntology ontology = manager.createOntology(Collections.singleton(axiom)); + OWLReasonerFactory resonerFact = new PelletReasonerFactory(); + OWLReasoner reasoner = resonerFact.createReasoner(manager); + reasoner.loadOntologies(Collections.singleton(ontology)); + + OWLSubClassAxiom unsatAxiom = factory.getOWLSubClassAxiom(c, factory.getOWLNothing()); + + LaconicExplanationGenerator expGen = new LaconicExplanationGenerator(manager, resonerFact, Collections.singleton(ontology)); + Set<Set<OWLAxiom>> preciseJusts = expGen.getExplanations(unsatAxiom); + renderer.render(unsatAxiom, preciseJusts); + renderer.endRendering(); + + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLReasonerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExplanationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public static void universityTest(){ + String file = "file:examples/ore/university.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)); + + OWLReasonerFactory resonerFact = new PelletReasonerFactory(); + OWLDataFactory dataFactory = manager.getOWLDataFactory(); + + OWLReasoner reasoner = resonerFact.createReasoner(manager); + reasoner.loadOntologies(Collections.singleton(ontology)); + + OWLSubClassAxiom axiom = dataFactory + .getOWLSubClassAxiom( + dataFactory + .getOWLClass(URI + .create("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Employee")), + dataFactory + .getOWLClass(URI + .create("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Person"))); + LaconicExplanationGenerator expGen = new LaconicExplanationGenerator( + manager, resonerFact, Collections.singleton(ontology)); + + + + Set<Set<OWLAxiom>> regularJusts = expGen.getRegularExplanations(axiom); + System.out.println("Regular explanations:"); + renderer.render(axiom, regularJusts); + + Set<Set<OWLAxiom>> preciseJusts = expGen.getExplanations(axiom); + System.out.println("Precise explanations:"); + renderer.render(axiom, preciseJusts); + + + renderer.endRendering(); + + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (UnsupportedOperationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/OPlus.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/OPlus.java 2009-04-14 17:58:43 UTC (rev 1700) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/OPlus.java 2009-04-15 07:26:58 UTC (rev 1701) @@ -329,7 +329,7 @@ } @Override - public Set<OWLAxiom> visit(OWLObjectSubPropertyAxiom axiom) {System.out.println("jo" + axiom); + public Set<OWLAxiom> visit(OWLObjectSubPropertyAxiom axiom) { return archive(axiom); } @@ -435,7 +435,7 @@ @Override public Set<OWLAxiom> visit(OWLInverseObjectPropertiesAxiom axiom) { - Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();System.out.println(axiom); + Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); axioms.add(dataFactory.getOWLSubObjectPropertyAxiom(axiom.getFirstProperty(), dataFactory.getOWLObjectPropertyInverse(axiom.getSecondProperty()))); axioms.add(dataFactory.getOWLSubObjectPropertyAxiom(axiom.getSecondProperty(), dataFactory.getOWLObjectPropertyInverse(axiom.getFirstProperty()))); return archive(axiom, axioms); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <lor...@us...> - 2009-06-15 08:31:33
|
Revision: 1798 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1798&view=rev Author: lorenz_b Date: 2009-06-15 08:31:17 +0000 (Mon, 15 Jun 2009) Log Message: ----------- started syntactic relevance based explanation generator Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java 2009-06-15 06:14:21 UTC (rev 1797) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomRanker.java 2009-06-15 08:31:17 UTC (rev 1798) @@ -29,6 +29,8 @@ import org.semanticweb.owl.model.RemoveAxiom; import com.clarkparsia.modularity.IncrementalClassifier; +import com.clarkparsia.modularity.ModuleExtractor; +import com.clarkparsia.modularity.ModuleExtractorFactory; public class AxiomRanker { @@ -38,6 +40,7 @@ private Reasoner reasoner; private OWLOntologyManager manager; private OWLDataFactory factory; + private IncrementalClassifier classifier; boolean enableImpactUnsat; @@ -46,15 +49,17 @@ this.reasoner = reasoner; this.manager = mng; this.factory = manager.getOWLDataFactory(); + ModuleExtractor extractor = ModuleExtractorFactory.createModuleExtractor(); + classifier = new IncrementalClassifier(manager, reasoner, extractor); } public Set<OWLAxiom> computeImpactOnRemoval(OWLAxiom ax){ Set<OWLAxiom> impact = new HashSet<OWLAxiom>(); try { - IncrementalClassifier classifier = new IncrementalClassifier(manager); - classifier.loadOntology(ontology); - classifier.classify(); +// IncrementalClassifier classifier = new IncrementalClassifier(manager); +// classifier.loadOntology(ontology); +// classifier.classify(); Set<OWLClass> inc = classifier.getInconsistentClasses(); for(OWLDescription cl : ontology.getClassesInSignature()){ if(!inc.contains(cl)){ @@ -170,7 +175,7 @@ } } - return result; +// return result; } } else if (axiom instanceof OWLObjectPropertyDomainAxiom) { @@ -239,12 +244,12 @@ 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); Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java 2009-06-15 08:31:17 UTC (rev 1798) @@ -0,0 +1,258 @@ +package org.dllearner.tools.ore.explanation; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.mindswap.pellet.owlapi.PelletReasonerFactory; +import org.mindswap.pellet.owlapi.Reasoner; +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.OWLIndividual; +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.OWLOntologyStorageException; +import org.semanticweb.owl.model.RemoveAxiom; +import org.semanticweb.owl.model.UnknownOWLOntologyException; + +import com.clarkparsia.explanation.PelletExplanation; + +public class SyntacticRelevanceBasedExplanationGenerator { + + private Reasoner reasoner; + private OWLOntologyManager manager; + private OWLOntology ontology; + + private static Logger logger = Logger.getRootLogger(); + + public SyntacticRelevanceBasedExplanationGenerator(Reasoner reasoner, OWLOntologyManager manager){ + this.reasoner = reasoner; + this.manager = manager; + this.ontology = reasoner.getLoadedOntologies().iterator().next(); + + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender( layout ); + logger.addAppender( consoleAppender ); + logger.setLevel(Level.DEBUG); + + } + + public Set<Set<OWLAxiom>> getExplanations(OWLClass unsat){ + return computeRelevantJustifications(unsat); + } + + private Set<Set<OWLAxiom>> computeRelevantJustifications(OWLClass unsat){ + + OWLOntology ont = null; + Set<Set<OWLAxiom>> justifications = new HashSet<Set<OWLAxiom>>(); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + Reasoner reasoner = new PelletReasonerFactory().createReasoner(man); + int k = 1; + try { + ont = man.createOntology(URI.create("file:/home/lorenz/test.owl")); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reasoner.loadOntology(ont); + + Set<OWLAxiom> relevant = getSyntacticRelevantAxioms(unsat, k); + logger.debug("step " + k + ": selected axioms: " + relevant); + Set<OWLAxiom> hittingSets = new HashSet<OWLAxiom>(); + Set<Set<OWLAxiom>> hittingSetLocal = new HashSet<Set<OWLAxiom>>(); + try { + man.addAxioms(ont, relevant); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + + while(!relevant.isEmpty()){ + try { + man.addAxioms(ont, relevant); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reasoner.refresh(); + if(!hittingSetLocal.isEmpty()){ + + } else if(!reasoner.isSatisfiable(unsat)){ + System.out.println(reasoner.getLoadedOntologies() + "" + reasoner.isSatisfiable(unsat)); + List<Set<Set<OWLAxiom>>> result = computeJustifications(unsat, ont); + justifications.addAll(result.get(0)); + hittingSetLocal.addAll(result.get(1)); + } + k++; + relevant = getSyntacticRelevantAxioms(unsat, k); + } + return justifications; + } + + private List<Set<Set<OWLAxiom>>> computeJustifications(OWLClass unsat, OWLOntology ont){ + Set<Set<OWLAxiom>> justifications = new HashSet<Set<OWLAxiom>>(); + PelletExplanation expGen = new PelletExplanation(manager, Collections.singleton(ont)); + Set<Set<OWLAxiom>> hittingSets = new HashSet<Set<OWLAxiom>>(); + Set<Set<OWLAxiom>> hittingSets1 = new HashSet<Set<OWLAxiom>>(); + + Set<OWLAxiom> justification = expGen.getUnsatisfiableExplanation(unsat); + System.out.println(justification); + justifications.add(justification); + for(OWLAxiom ax : justification){ + hittingSets1.add(Collections.singleton(ax)); + } + + while(true){ + Set<Set<OWLAxiom>> hittingSets2 = new HashSet<Set<OWLAxiom>>(); + for(Set<OWLAxiom> axioms : hittingSets1){ + try { + for(OWLAxiom ax : axioms){ + manager.applyChange(new RemoveAxiom(ont, ax)); + } + + if(reasoner.isSatisfiable(unsat)){ + hittingSets.add(axioms); + } else { + hittingSets2.add(axioms); + } + manager.addAxioms(ont, axioms); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if(hittingSets1.isEmpty() || hittingSets2.isEmpty()){ + List<Set<Set<OWLAxiom>>> result = new ArrayList<Set<Set<OWLAxiom>>>(); + result.add(justifications); + result.add(hittingSets); + return result; + } + hittingSets1.clear(); + for(Set<OWLAxiom> axioms : hittingSets2){ + try { + for(OWLAxiom ax : axioms){ + manager.applyChange(new RemoveAxiom(ont, ax)); + } + expGen = new PelletExplanation(manager, Collections.singleton(ont)); + Set<OWLAxiom> just = expGen.getUnsatisfiableExplanation(unsat); + justifications.add(just); + for(OWLAxiom a : just){ + Set<OWLAxiom> temp = new HashSet<OWLAxiom>(axioms); + temp.add(a); + hittingSets1.add(temp); + } + manager.addAxioms(ont, axioms); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + } + + + + public Set<OWLAxiom> getSyntacticRelevantAxioms(OWLClass cl, int k){ + + Set<OWLAxiom> relevantAxioms = new HashSet<OWLAxiom>(); + + if(k == 1){ + for(OWLAxiom ax : ontology.getLogicalAxioms()){ + if(ax.getSignature().contains(cl)){ + relevantAxioms.add(ax); + } + } + + } else { + Set<OWLAxiom> axioms = getSyntacticRelevantAxioms(cl, k - 1); + + for(OWLAxiom ax1 : axioms){ + + for(OWLAxiom ax2 : ontology.getLogicalAxioms()){ + + if(areSyntacticRelevant(ax1, ax2)){ + + relevantAxioms.add(ax2); + } + } + } + for(int i = k - 1; i>= 1 ;i--){ + relevantAxioms.removeAll(getSyntacticRelevantAxioms(cl,i)); + } + + + } + + return relevantAxioms; + } + + private boolean areSyntacticRelevant(OWLAxiom ax1, OWLAxiom ax2){ + return org.mindswap.pellet.utils.SetUtils.intersects(ax1.getSignature(), ax2.getSignature()); + } + + public static void main(String[] args){ + URI file = URI.create("file:examples/ore/koala.owl"); + String base = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl"; + URI classURI = URI.create(base + "#Koala"); + + try { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLClass cl = factory.getOWLClass(classURI); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(file); + + OWLClass cl1 = factory.getOWLClass(URI.create("Manager")); + OWLClass cl2 = factory.getOWLClass(URI.create("Employee")); + OWLClass cl3 = factory.getOWLClass(URI.create("JobPosition")); + OWLClass cl4 = factory.getOWLClass(URI.create("Leader")); + OWLClass cl5 = factory.getOWLClass(URI.create("Situation")); + OWLClass cl6 = factory.getOWLClass(URI.create("Happening")); + OWLClass cl7 = factory.getOWLClass(URI.create("Patent")); + OWLIndividual ind = factory.getOWLIndividual(URI.create("lectureship")); + Set<OWLAxiom> examples = new HashSet<OWLAxiom>(); + examples.add(factory.getOWLSubClassAxiom(cl1, cl2)); + examples.add(factory.getOWLSubClassAxiom(cl2, cl3)); + examples.add(factory.getOWLSubClassAxiom(cl4, cl3)); + examples.add(factory.getOWLSubClassAxiom(cl3, cl5)); + examples.add(factory.getOWLSubClassAxiom(cl5, cl6)); + examples.add(factory.getOWLSubClassAxiom(cl4, factory.getOWLObjectComplementOf(cl7))); + examples.add(factory.getOWLSubClassAxiom(cl6, factory.getOWLObjectComplementOf(cl1))); + examples.add(factory.getOWLSubClassAxiom(cl3, factory.getOWLObjectComplementOf(cl2))); + examples.add(factory.getOWLClassAssertionAxiom(ind, cl3)); + + OWLOntology example = manager.createOntology(examples); + + + Reasoner reasoner = new PelletReasonerFactory().createReasoner(manager); + reasoner.loadOntologies(Collections.singleton(ontology)); + SyntacticRelevanceBasedExplanationGenerator expGen = + new SyntacticRelevanceBasedExplanationGenerator(reasoner, manager); + + System.out.println(expGen.getExplanations(cl)); + + + + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2009-06-15 13:22:33
|
Revision: 1799 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1799&view=rev Author: lorenz_b Date: 2009-06-15 13:22:29 +0000 (Mon, 15 Jun 2009) Log Message: ----------- continued new explanation generator Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java 2009-06-15 13:22:29 UTC (rev 1799) @@ -0,0 +1,17 @@ +package org.dllearner.tools.ore.explanation; + +import java.util.HashSet; +import java.util.Set; + +import org.semanticweb.owl.model.OWLAxiom; + +public class HittingSet extends HashSet<OWLAxiom> { + + public HittingSet(Set<OWLAxiom> axioms){ + addAll(axioms); + } + + public HittingSet(OWLAxiom axiom){ + add(axiom); + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java 2009-06-15 08:31:17 UTC (rev 1798) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java 2009-06-15 13:22:29 UTC (rev 1799) @@ -22,18 +22,25 @@ import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyCreationException; import org.semanticweb.owl.model.OWLOntologyManager; -import org.semanticweb.owl.model.OWLOntologyStorageException; import org.semanticweb.owl.model.RemoveAxiom; -import org.semanticweb.owl.model.UnknownOWLOntologyException; +import uk.ac.manchester.cs.owl.dlsyntax.DLSyntaxObjectRenderer; + import com.clarkparsia.explanation.PelletExplanation; public class SyntacticRelevanceBasedExplanationGenerator { private Reasoner reasoner; + private Reasoner localReasoner; private OWLOntologyManager manager; private OWLOntology ontology; + public static enum Strategie{ + All_Just_Relevance, + CM_Just_Relevance; + } + private Strategie strategie; + private static Logger logger = Logger.getRootLogger(); public SyntacticRelevanceBasedExplanationGenerator(Reasoner reasoner, OWLOntologyManager manager){ @@ -48,7 +55,8 @@ } - public Set<Set<OWLAxiom>> getExplanations(OWLClass unsat){ + public Set<Set<OWLAxiom>> getExplanations(OWLClass unsat, Strategie strategie){ + this.strategie = strategie; return computeRelevantJustifications(unsat); } @@ -57,7 +65,7 @@ OWLOntology ont = null; Set<Set<OWLAxiom>> justifications = new HashSet<Set<OWLAxiom>>(); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); - Reasoner reasoner = new PelletReasonerFactory().createReasoner(man); + localReasoner = new PelletReasonerFactory().createReasoner(man); int k = 1; try { ont = man.createOntology(URI.create("file:/home/lorenz/test.owl")); @@ -65,12 +73,12 @@ // TODO Auto-generated catch block e.printStackTrace(); } - reasoner.loadOntology(ont); + localReasoner.loadOntology(ont); Set<OWLAxiom> relevant = getSyntacticRelevantAxioms(unsat, k); - logger.debug("step " + k + ": selected axioms: " + relevant); - Set<OWLAxiom> hittingSets = new HashSet<OWLAxiom>(); - Set<Set<OWLAxiom>> hittingSetLocal = new HashSet<Set<OWLAxiom>>(); + + Set<HittingSet> hittingSets = new HashSet<HittingSet>(); + Set<HittingSet> hittingSetLocal = new HashSet<HittingSet>(); try { man.addAxioms(ont, relevant); } catch (OWLOntologyChangeException e) { @@ -82,6 +90,7 @@ while(!relevant.isEmpty()){ + logger.debug("step " + k + ": selected axioms: " + relevant); try { man.addAxioms(ont, relevant); } catch (OWLOntologyChangeException e) { @@ -90,12 +99,57 @@ } reasoner.refresh(); if(!hittingSetLocal.isEmpty()){ + for(HittingSet hit : hittingSetLocal){ + try { + for(OWLAxiom ax : hit){ + manager.applyChange(new RemoveAxiom(ontology, ax)); + } + reasoner.refresh(); + + if(reasoner.isSatisfiable(unsat)){ + hittingSets.add(hit); + } + manager.addAxioms(ontology, hit); + reasoner.refresh(); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + hittingSetLocal.removeAll(hittingSets); + if( (!strategie.equals(Strategie.All_Just_Relevance) && !hittingSets.isEmpty()) || (hittingSetLocal.isEmpty()) ){ + logger.debug("early termination"); + return justifications; + } + Set<HittingSet> temp = new HashSet<HittingSet>(hittingSetLocal); + for(HittingSet hit : temp){ + try { + for(OWLAxiom ax : hit){ + man.applyChange(new RemoveAxiom(ont, ax)); + } + List<Set<? extends Set<OWLAxiom>>> result = computeJustifications(unsat, ont); + justifications.addAll(result.get(0)); + Set<HittingSet> localTemp = (Set<HittingSet>)result.get(1); + for(HittingSet h : localTemp){ + h.addAll(hit); + hittingSetLocal.add(h); + } + hittingSetLocal.remove(hit); + man.addAxioms(ont, hit); + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } - } else if(!reasoner.isSatisfiable(unsat)){ - System.out.println(reasoner.getLoadedOntologies() + "" + reasoner.isSatisfiable(unsat)); - List<Set<Set<OWLAxiom>>> result = computeJustifications(unsat, ont); + } else if(!localReasoner.isSatisfiable(unsat)){ + + List<Set<? extends Set<OWLAxiom>>> result = computeJustifications(unsat, ont); + logger.debug("step " + k + ": justifications computed : " + result.get(0)); justifications.addAll(result.get(0)); - hittingSetLocal.addAll(result.get(1)); + hittingSetLocal.addAll((Set<HittingSet>)result.get(1)); } k++; relevant = getSyntacticRelevantAxioms(unsat, k); @@ -103,40 +157,43 @@ return justifications; } - private List<Set<Set<OWLAxiom>>> computeJustifications(OWLClass unsat, OWLOntology ont){ + private List<Set<? extends Set<OWLAxiom>>> computeJustifications(OWLClass unsat, OWLOntology ont){ Set<Set<OWLAxiom>> justifications = new HashSet<Set<OWLAxiom>>(); PelletExplanation expGen = new PelletExplanation(manager, Collections.singleton(ont)); - Set<Set<OWLAxiom>> hittingSets = new HashSet<Set<OWLAxiom>>(); - Set<Set<OWLAxiom>> hittingSets1 = new HashSet<Set<OWLAxiom>>(); + Set<HittingSet> hittingSets = new HashSet<HittingSet>(); + Set<HittingSet> hittingSets1 = new HashSet<HittingSet>(); Set<OWLAxiom> justification = expGen.getUnsatisfiableExplanation(unsat); - System.out.println(justification); + justifications.add(justification); for(OWLAxiom ax : justification){ - hittingSets1.add(Collections.singleton(ax)); + hittingSets1.add(new HittingSet(ax)); } while(true){ - Set<Set<OWLAxiom>> hittingSets2 = new HashSet<Set<OWLAxiom>>(); - for(Set<OWLAxiom> axioms : hittingSets1){ + Set<HittingSet> hittingSets2 = new HashSet<HittingSet>(); + for(HittingSet hit : hittingSets1){ try { - for(OWLAxiom ax : axioms){ + for(OWLAxiom ax : hit){ manager.applyChange(new RemoveAxiom(ont, ax)); } + localReasoner.refresh(); - if(reasoner.isSatisfiable(unsat)){ - hittingSets.add(axioms); + if(localReasoner.isSatisfiable(unsat)){ + hittingSets.add(hit); + logger.debug("found local hitting set: " + hit); } else { - hittingSets2.add(axioms); + hittingSets2.add(hit); } - manager.addAxioms(ont, axioms); + manager.addAxioms(ont, hit); + localReasoner.refresh(); } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } } - if(hittingSets1.isEmpty() || hittingSets2.isEmpty()){ - List<Set<Set<OWLAxiom>>> result = new ArrayList<Set<Set<OWLAxiom>>>(); + if( (!strategie.equals(Strategie.All_Just_Relevance) && !hittingSets.isEmpty() ) || hittingSets1.isEmpty() || hittingSets2.isEmpty()){ + List<Set<? extends Set<OWLAxiom>>> result = new ArrayList<Set<? extends Set<OWLAxiom>>>(); result.add(justifications); result.add(hittingSets); return result; @@ -151,7 +208,7 @@ Set<OWLAxiom> just = expGen.getUnsatisfiableExplanation(unsat); justifications.add(just); for(OWLAxiom a : just){ - Set<OWLAxiom> temp = new HashSet<OWLAxiom>(axioms); + HittingSet temp = new HittingSet(axioms); temp.add(a); hittingSets1.add(temp); } @@ -167,37 +224,36 @@ - public Set<OWLAxiom> getSyntacticRelevantAxioms(OWLClass cl, int k){ - - Set<OWLAxiom> relevantAxioms = new HashSet<OWLAxiom>(); - - if(k == 1){ - for(OWLAxiom ax : ontology.getLogicalAxioms()){ - if(ax.getSignature().contains(cl)){ + public Set<OWLAxiom> getSyntacticRelevantAxioms(OWLClass cl, int k) { + + Set<OWLAxiom> relevantAxioms = new HashSet<OWLAxiom>(); + + if (k == 1) { + for (OWLAxiom ax : ontology.getLogicalAxioms()) { + if (ax.getSignature().contains(cl)) { relevantAxioms.add(ax); } } - + } else { Set<OWLAxiom> axioms = getSyntacticRelevantAxioms(cl, k - 1); - - for(OWLAxiom ax1 : axioms){ - - for(OWLAxiom ax2 : ontology.getLogicalAxioms()){ - - if(areSyntacticRelevant(ax1, ax2)){ - + + for (OWLAxiom ax1 : axioms) { + + for (OWLAxiom ax2 : ontology.getLogicalAxioms()) { + + if (areSyntacticRelevant(ax1, ax2)) { + relevantAxioms.add(ax2); } } } - for(int i = k - 1; i>= 1 ;i--){ - relevantAxioms.removeAll(getSyntacticRelevantAxioms(cl,i)); + for (int i = k - 1; i >= 1; i--) { + relevantAxioms.removeAll(getSyntacticRelevantAxioms(cl, i)); } - - + } - + return relevantAxioms; } @@ -208,7 +264,7 @@ public static void main(String[] args){ URI file = URI.create("file:examples/ore/koala.owl"); String base = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl"; - URI classURI = URI.create(base + "#Koala"); + URI classURI = URI.create(base + "#KoalaWithPhD"); try { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); @@ -216,37 +272,73 @@ OWLClass cl = factory.getOWLClass(classURI); OWLOntology ontology = manager.loadOntologyFromPhysicalURI(file); - OWLClass cl1 = factory.getOWLClass(URI.create("Manager")); - OWLClass cl2 = factory.getOWLClass(URI.create("Employee")); - OWLClass cl3 = factory.getOWLClass(URI.create("JobPosition")); - OWLClass cl4 = factory.getOWLClass(URI.create("Leader")); - OWLClass cl5 = factory.getOWLClass(URI.create("Situation")); - OWLClass cl6 = factory.getOWLClass(URI.create("Happening")); - OWLClass cl7 = factory.getOWLClass(URI.create("Patent")); - OWLIndividual ind = factory.getOWLIndividual(URI.create("lectureship")); +// OWLClass cl1 = factory.getOWLClass(URI.create("Manager")); +// OWLClass cl2 = factory.getOWLClass(URI.create("Employee")); +// OWLClass cl3 = factory.getOWLClass(URI.create("JobPosition")); +// OWLClass cl4 = factory.getOWLClass(URI.create("Leader")); +// OWLClass cl5 = factory.getOWLClass(URI.create("Situation")); +// OWLClass cl6 = factory.getOWLClass(URI.create("Happening")); +// OWLClass cl7 = factory.getOWLClass(URI.create("Patent")); +// OWLIndividual ind = factory.getOWLIndividual(URI.create("lectureship")); +// Set<OWLAxiom> examples = new HashSet<OWLAxiom>(); +// examples.add(factory.getOWLSubClassAxiom(cl1, cl2)); +// examples.add(factory.getOWLSubClassAxiom(cl2, cl3)); +// examples.add(factory.getOWLSubClassAxiom(cl4, cl3)); +// examples.add(factory.getOWLSubClassAxiom(cl3, cl5)); +// examples.add(factory.getOWLSubClassAxiom(cl5, cl6)); +// examples.add(factory.getOWLSubClassAxiom(cl4, factory.getOWLObjectComplementOf(cl7))); +// examples.add(factory.getOWLSubClassAxiom(cl6, factory.getOWLObjectComplementOf(cl1))); +// examples.add(factory.getOWLSubClassAxiom(cl3, factory.getOWLObjectComplementOf(cl2))); +// examples.add(factory.getOWLClassAssertionAxiom(ind, cl3)); +// OWLOntology example = manager.createOntology(examples); + + OWLClass u = factory.getOWLClass(URI.create("U")); + OWLClass a = factory.getOWLClass(URI.create("A")); + OWLClass b = factory.getOWLClass(URI.create("B")); + OWLClass c = factory.getOWLClass(URI.create("C")); + OWLClass d = factory.getOWLClass(URI.create("D")); + OWLClass e = factory.getOWLClass(URI.create("E")); + OWLClass f = factory.getOWLClass(URI.create("F")); + OWLClass g = factory.getOWLClass(URI.create("G")); + OWLClass h = factory.getOWLClass(URI.create("H")); + OWLClass k = factory.getOWLClass(URI.create("K")); Set<OWLAxiom> examples = new HashSet<OWLAxiom>(); - examples.add(factory.getOWLSubClassAxiom(cl1, cl2)); - examples.add(factory.getOWLSubClassAxiom(cl2, cl3)); - examples.add(factory.getOWLSubClassAxiom(cl4, cl3)); - examples.add(factory.getOWLSubClassAxiom(cl3, cl5)); - examples.add(factory.getOWLSubClassAxiom(cl5, cl6)); - examples.add(factory.getOWLSubClassAxiom(cl4, factory.getOWLObjectComplementOf(cl7))); - examples.add(factory.getOWLSubClassAxiom(cl6, factory.getOWLObjectComplementOf(cl1))); - examples.add(factory.getOWLSubClassAxiom(cl3, factory.getOWLObjectComplementOf(cl2))); - examples.add(factory.getOWLClassAssertionAxiom(ind, cl3)); - + examples.add( factory.getOWLSubClassAxiom(u, a)); + examples.add( factory.getOWLSubClassAxiom(u, factory.getOWLObjectComplementOf(a))); + examples.add( factory.getOWLSubClassAxiom(u, c)); + examples.add( factory.getOWLSubClassAxiom(c, factory.getOWLObjectComplementOf(b))); + examples.add( factory.getOWLSubClassAxiom(a, b)); + examples.add( factory.getOWLSubClassAxiom(u, g)); + examples.add( factory.getOWLSubClassAxiom(g, e)); + examples.add( factory.getOWLSubClassAxiom(u, f)); + examples.add( factory.getOWLSubClassAxiom(f, factory.getOWLObjectComplementOf(e))); + examples.add( factory.getOWLSubClassAxiom(u, d)); + examples.add( factory.getOWLSubClassAxiom(d, e)); + examples.add( factory.getOWLSubClassAxiom(c, k)); + examples.add( factory.getOWLSubClassAxiom(k, factory.getOWLObjectComplementOf(h))); + examples.add( factory.getOWLSubClassAxiom(b, h)); OWLOntology example = manager.createOntology(examples); + + Reasoner reasoner = new PelletReasonerFactory().createReasoner(manager); - reasoner.loadOntologies(Collections.singleton(ontology)); + reasoner.loadOntologies(Collections.singleton(example)); SyntacticRelevanceBasedExplanationGenerator expGen = new SyntacticRelevanceBasedExplanationGenerator(reasoner, manager); + DLSyntaxObjectRenderer renderer = new DLSyntaxObjectRenderer(); + int i = 1; + for(Set<OWLAxiom> explanation : expGen.getExplanations(u, Strategie.CM_Just_Relevance)){ + System.out.println("Explanation " + i); + i++; + for(OWLAxiom ax : explanation){ + System.out.println(renderer.render(ax)); + } + } + - System.out.println(expGen.getExplanations(cl)); - } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2009-06-18 07:54:00
|
Revision: 1804 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1804&view=rev Author: lorenz_b Date: 2009-06-18 07:53:24 +0000 (Thu, 18 Jun 2009) Log Message: ----------- swapped out axiom selection Function to static class Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomSelector.java Added: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomSelector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomSelector.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/AxiomSelector.java 2009-06-18 07:53:24 UTC (rev 1804) @@ -0,0 +1,52 @@ +package org.dllearner.tools.ore.explanation; + +import java.util.HashSet; +import java.util.Set; + +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLOntology; + +public class AxiomSelector { + + public static Set<OWLAxiom> getSyntacticRelevantAxioms( + OWLOntology ontology, OWLClass cl) { + + Set<OWLAxiom> relevantAxioms = new HashSet<OWLAxiom>(); + + for (OWLAxiom ax : ontology.getLogicalAxioms()) { + if (isSyntacticRelevant(ax,cl)) { + relevantAxioms.add(ax); + } + } + + return relevantAxioms; + } + + public static Set<OWLAxiom> getSyntacticRelevantAxioms( + OWLOntology ontology, Set<OWLAxiom> axioms) { + + Set<OWLAxiom> relevantAxioms = new HashSet<OWLAxiom>(); + + for (OWLAxiom ax : ontology.getLogicalAxioms()) { + for (OWLAxiom ax2 : axioms) { + if (isSyntacticRelevant(ax, ax2)) { + relevantAxioms.add(ax); + } + } + + } + + return relevantAxioms; + } + + private static boolean isSyntacticRelevant(OWLAxiom ax1, OWLAxiom ax2) { + return org.mindswap.pellet.utils.SetUtils.intersects( + ax1.getSignature(), ax2.getSignature()); + } + + private static boolean isSyntacticRelevant(OWLAxiom ax, OWLClass cl) { + return org.mindswap.pellet.utils.SetUtils.intersects(ax.getSignature(), + cl.getSignature()); + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java 2009-06-18 07:37:37 UTC (rev 1803) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/HittingSet.java 2009-06-18 07:53:24 UTC (rev 1804) @@ -7,6 +7,11 @@ public class HittingSet extends HashSet<OWLAxiom> { + /** + * + */ + private static final long serialVersionUID = 7704909550386943944L; + public HittingSet(Set<OWLAxiom> axioms){ addAll(axioms); } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java 2009-06-18 07:37:37 UTC (rev 1803) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/RootFinder.java 2009-06-18 07:53:24 UTC (rev 1804) @@ -15,7 +15,6 @@ import org.semanticweb.owl.inference.OWLReasonerException; import org.semanticweb.owl.inference.OWLReasonerFactory; import org.semanticweb.owl.model.AxiomType; -import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataAllRestriction; import org.semanticweb.owl.model.OWLDataExactCardinalityRestriction; Modified: trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java 2009-06-18 07:37:37 UTC (rev 1803) +++ trunk/src/dl-learner/org/dllearner/tools/ore/explanation/SyntacticRelevanceBasedExplanationGenerator.java 2009-06-18 07:53:24 UTC (rev 1804) @@ -77,7 +77,7 @@ } localReasoner.loadOntology(ont); - Set<OWLAxiom> relevant = getSyntacticRelevantAxioms(unsat, k); + Set<OWLAxiom> relevant = AxiomSelector.getSyntacticRelevantAxioms(ontology, unsat);//getSyntacticRelevantAxioms(unsat, k); Set<HittingSet> hittingSets = new HashSet<HittingSet>(); Set<HittingSet> hittingSetLocal = new HashSet<HittingSet>(); @@ -155,7 +155,7 @@ hittingSetLocal.addAll((Set<HittingSet>)result.get(1)); } k++; - relevant = getSyntacticRelevantAxioms(unsat, k); + relevant = AxiomSelector.getSyntacticRelevantAxioms(ontology, relevant);//getSyntacticRelevantAxioms(unsat, k); } return justifications; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |