From: <jen...@us...> - 2008-02-23 21:13:15
|
Revision: 632 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=632&view=rev Author: jenslehmann Date: 2008-02-23 13:13:06 -0800 (Sat, 23 Feb 2008) Log Message: ----------- - added support for two axiom types: different individuals and disjoint classes - detected bug in OWL API different individuals export Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -35,4 +35,6 @@ public void visit(BooleanDatatypePropertyAssertion axiom); + public void visit(DifferentIndividualsAxiom axiom); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.util.Map; +import java.util.Set; + +/** + * @author Jens Lehmann + * + */ +public class DifferentIndividualsAxiom extends AssertionalAxiom { + + private Set<Individual> individuals; + + public DifferentIndividualsAxiom(Set<Individual> individuals) { + this.individuals = individuals; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + return individuals.size() + 1; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + // TODO Auto-generated method stub + return null; + } + + public Set<Individual> getIndividuals() { + return individuals; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.util.Map; +import java.util.Set; + +/** + * @author Jens Lehmann + * + */ +public class DisjointClassesAxiom extends TerminologicalAxiom { + + private Set<Description> descriptions; + + public DisjointClassesAxiom(Set<Description> descriptions) { + this.descriptions = descriptions; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + int length = 1; + for(Description d : descriptions) + length += d.getLength(); + return length; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /** + * @return the descriptions + */ + public Set<Description> getDescriptions() { + return descriptions; + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -29,4 +29,5 @@ public void visit(SubClassAxiom axiom); + public void visit(DisjointClassesAxiom axiom); } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-23 21:13:06 UTC (rev 632) @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -33,6 +34,9 @@ import java.util.TreeSet; import org.dllearner.core.owl.BooleanDatatypePropertyAssertion; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DifferentIndividualsAxiom; +import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ClassAssertionAxiom; @@ -96,10 +100,14 @@ private static int bondNr = 0; private static int structureNr = 0; + // list of all individuals in the knowlege base +// private static Set<String> individuals = new TreeSet<String>(); // list of all compounds private static Set<String> compounds = new TreeSet<String>(); // compounds with positive ames test private static Set<String> compoundsAmes = new TreeSet<String>(); + // list of all bonds + private static Set<String> bonds = new TreeSet<String>(); // list of all "hasProperty" test private static Set<String> tests = new TreeSet<String>(); @@ -187,9 +195,17 @@ } } - // TODO: disjoint classes axioms - // TODO: all different axiom (UNA) + // disjoint classes axioms + DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); + kb.addAxiom(disjointAtomTypes); + // all different axiom (UNA) + // exporting differentIndividuals axioms is broken in OWL API +// individuals.addAll(compounds); +// individuals.addAll(bonds); +// DifferentIndividualsAxiom una = getDifferentIndividualsAxiom(individuals); +// kb.addAxiom(una); + duration = System.nanoTime() - startTime; time = Helper.prettyPrintNanoSeconds(duration, false, false); System.out.println("OK (" + time + ")."); @@ -294,6 +310,7 @@ String bondType = head.getArgument(3).toPLString(); String bondClass = "Bond-" + bondType; String bondInstance = "bond" + bondNr; + bonds.add(bondInstance); ObjectPropertyAssertion op = getRoleAssertion("hasBond", compoundName, "bond" + bondNr); axioms.add(op); // make Bond-X subclass of Bond if that hasn't been done already @@ -426,6 +443,21 @@ return new DoubleDatatypePropertyAssertion(dp, ind, value); } + private static DisjointClassesAxiom getDisjointClassesAxiom(Set<String> classes) { + Set<Description> descriptions = new HashSet<Description>(); + for(String namedClass : classes) + descriptions.add(new NamedClass(namedClass)); + return new DisjointClassesAxiom(descriptions); + } + + @SuppressWarnings({"unused"}) + private static DifferentIndividualsAxiom getDifferentIndividualsAxiom(Set<String> individuals) { + Set<Individual> inds = new HashSet<Individual>(); + for(String i : individuals) + inds.add(new Individual(i)); + return new DifferentIndividualsAxiom(inds); + } + private static Individual getIndividual(String name) { return new Individual(ontologyURI + "#" + name); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -31,9 +31,13 @@ import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.DatatypePropertyRangeAxiom; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DifferentIndividualsAxiom; +import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.DoubleDatatypePropertyAssertion; import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.InverseObjectPropertyAxiom; import org.dllearner.core.owl.KB; import org.dllearner.core.owl.ObjectPropertyAssertion; @@ -294,4 +298,28 @@ addAxiom(axiomOWLAPI); } + /* (non-Javadoc) + * @see org.dllearner.core.owl.AssertionalAxiomVisitor#visit(org.dllearner.core.owl.DifferentIndividualsAxiom) + */ + public void visit(DifferentIndividualsAxiom axiom) { + Set<Individual> individuals = axiom.getIndividuals(); + Set<OWLIndividual> owlAPIIndividuals = new HashSet<OWLIndividual>(); + for(Individual individual : individuals) + owlAPIIndividuals.add(factory.getOWLIndividual(URI.create(individual.getName()))); + OWLAxiom axiomOWLAPI = factory.getOWLDifferentIndividualsAxiom(owlAPIIndividuals); + addAxiom(axiomOWLAPI); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.TerminologicalAxiomVisitor#visit(org.dllearner.core.owl.DisjointClassesAxiom) + */ + public void visit(DisjointClassesAxiom axiom) { + Set<Description> descriptions = axiom.getDescriptions(); + Set<OWLDescription> owlAPIDescriptions = new HashSet<OWLDescription>(); + for(Description description : descriptions) + owlAPIDescriptions.add(getOWLDescription(description)); + OWLAxiom axiomOWLAPI = factory.getOWLDisjointClassesAxiom(owlAPIDescriptions); + addAxiom(axiomOWLAPI); + } + } Added: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,42 @@ +package org.dllearner.test; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.util.SimpleURIMapper; + +import java.io.File; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +public class OWLAPIBugDemo { + + public static void main(String[] args) { + try { + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + URI ontologyURI = URI.create("http://www.examples.com/test"); + File f = new File("test.owl"); + URI physicalURI = f.toURI(); + SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); + manager.addURIMapper(mapper); + + OWLOntology ontology = manager.createOntology(ontologyURI); + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLIndividual a = factory.getOWLIndividual(URI.create(ontologyURI + "#a")); + OWLIndividual b = factory.getOWLIndividual(URI.create(ontologyURI + "#b")); + Set<OWLIndividual> inds = new HashSet<OWLIndividual>(); + inds.add(a); + inds.add(b); + + OWLAxiom axiom = factory.getOWLDifferentIndividualsAxiom(inds); + AddAxiom addAxiom = new AddAxiom(ontology, axiom); + manager.applyChange(addAxiom); + manager.saveOntology(ontology); + } + catch (OWLException e) { + e.printStackTrace(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |