From: <jen...@us...> - 2007-08-27 13:41:54
|
Revision: 55 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=55&view=rev Author: jenslehmann Date: 2007-08-25 01:43:30 -0700 (Sat, 25 Aug 2007) Log Message: ----------- add obtaining the role hierarchy to reasoner tasks (first step to role hierarchy support in refinement based learner) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-08-24 14:35:02 UTC (rev 54) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-08-25 08:43:30 UTC (rev 55) @@ -90,6 +90,10 @@ throw new ReasoningMethodUnsupportedException(); } + public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public Set<AtomicConcept> getConcepts(Individual i) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java 2007-08-24 14:35:02 UTC (rev 54) +++ trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java 2007-08-25 08:43:30 UTC (rev 55) @@ -40,6 +40,8 @@ public SubsumptionHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException; + public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> retrieval(Concept concept) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) throws ReasoningMethodUnsupportedException; Added: trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-08-25 08:43:30 UTC (rev 55) @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2007, 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.reasoning; + +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.dl.AtomicConcept; +import org.dllearner.dl.AtomicRole; +import org.dllearner.dl.Concept; +import org.dllearner.utilities.RoleComparator; + +/** + * Represents a hierarchy of roles. + * + * @author Jens Lehmann + * + */ +public class RoleHierarchy { + + RoleComparator rc = new RoleComparator(); + + public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { + + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-27 17:20:03
|
Revision: 71 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=71&view=rev Author: jenslehmann Date: 2007-08-27 10:20:01 -0700 (Mon, 27 Aug 2007) Log Message: ----------- added support for querying the most general and most specific roles Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java 2007-08-27 16:42:51 UTC (rev 70) +++ trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java 2007-08-27 17:20:01 UTC (rev 71) @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.OntologyFileFormat; import org.dllearner.dl.AtomicConcept; @@ -291,6 +292,7 @@ /** * Returns more general concepts in the subsumption hierarchy. * + * @see RoleHierarchy#getMoreGeneralRoles(AtomicRole) * @param role Atomic concept, top, or bottom. * @return A set of more general concepts. */ @@ -301,6 +303,7 @@ /** * Returns more special concepts in the subsumption hierarchy. * + * @see RoleHierarchy#getMoreSpecialRoles(AtomicRole) * @param role Atomic concept, top, or bottom. * @return A set of more special concepts. */ @@ -308,6 +311,22 @@ return getRoleHierarchy().getMoreSpecialRoles(role); } + /** + * @see RoleHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<AtomicRole> getMostGeneralRoles() { + return getRoleHierarchy().getMostGeneralRoles(); + } + + /** + * @see RoleHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<AtomicRole> getMostSpecialRoles() { + return getRoleHierarchy().getMostSpecialRoles(); + } + public SubsumptionHierarchy getSubsumptionHierarchy() { try { nrOfSubsumptionHierarchyQueries++; Modified: trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-08-27 16:42:51 UTC (rev 70) +++ trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-08-27 17:20:01 UTC (rev 71) @@ -69,6 +69,8 @@ return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); } + + @Override public String toString() { String str = ""; @@ -89,5 +91,20 @@ str += toString(hierarchy, c, depth+1); } return str; - } + } + + /** + * @return The most general roles. + */ + public TreeSet<AtomicRole> getMostGeneralRoles() { + return mostGeneralRoles; + } + + /** + * @return The most special roles. + */ + public TreeSet<AtomicRole> getMostSpecialRoles() { + return mostSpecialRoles; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-06 15:14:36
|
Revision: 344 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=344&view=rev Author: jenslehmann Date: 2008-01-06 07:14:35 -0800 (Sun, 06 Jan 2008) Log Message: ----------- continued OWL API reasoner Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/ReasonerType.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-06 11:54:42 UTC (rev 343) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-06 15:14:35 UTC (rev 344) @@ -26,8 +26,10 @@ import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; +import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import org.dllearner.core.KnowledgeSource; @@ -48,8 +50,12 @@ import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.core.dl.Top; import org.dllearner.kb.OWLFile; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.RoleComparator; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.inference.OWLReasonerException; @@ -81,17 +87,23 @@ // the data factory is used to generate OWL API objects private OWLDataFactory factory; - // private ConceptComparator conceptComparator = new ConceptComparator(); - // private RoleComparator roleComparator = new RoleComparator(); - // private SubsumptionHierarchy subsumptionHierarchy; - // private RoleHierarchy roleHierarchy; + private ConceptComparator conceptComparator = new ConceptComparator(); + private RoleComparator roleComparator = new RoleComparator(); + private SubsumptionHierarchy subsumptionHierarchy; + private RoleHierarchy roleHierarchy; + private Set<Concept> allowedConceptsInSubsumptionHierarchy; + // primitives + Set<AtomicConcept> atomicConcepts; + Set<AtomicRole> atomicRoles; + SortedSet<Individual> individuals; + public OWLAPIReasoner(Set<KnowledgeSource> sources) { this.sources = sources; } public static String getName() { - return "FaCT++ reasoner"; + return "OWL API reasoner"; } public static Collection<ConfigOption<?>> createConfigOptions() { @@ -127,7 +139,7 @@ }; Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); - Set<OWLIndividual> individuals = new TreeSet<OWLIndividual>(namedObjectComparator); + Set<OWLIndividual> owlIndividuals = new TreeSet<OWLIndividual>(namedObjectComparator); for(KnowledgeSource source : sources) { if(!(source instanceof OWLFile)) { @@ -138,7 +150,7 @@ OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); classes.addAll(ontology.getReferencedClasses()); properties.addAll(ontology.getReferencedObjectProperties()); - individuals.addAll(ontology.getReferencedIndividuals()); + owlIndividuals.addAll(ontology.getReferencedIndividuals()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (URISyntaxException e) { @@ -158,64 +170,225 @@ // instantiate Pellet reasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); } + factory = manager.getOWLDataFactory(); - factory = manager.getOWLDataFactory(); + // read in primitives + atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); + for(OWLClass owlClass : classes) + atomicConcepts.add(new AtomicConcept(owlClass.getURI().toString())); + atomicRoles = new TreeSet<AtomicRole>(roleComparator); + for(OWLObjectProperty owlProperty : properties) + atomicRoles.add(new AtomicRole(owlProperty.getURI().toString())); + individuals = new TreeSet<Individual>(); + for(OWLIndividual owlIndividual : owlIndividuals) + individuals.add(new Individual(owlIndividual.getURI().toString())); + } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getAtomicConcepts() */ public Set<AtomicConcept> getAtomicConcepts() { - // reasoner. - - // TODO Auto-generated method stub - return null; + return atomicConcepts; } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getAtomicRoles() */ public Set<AtomicRole> getAtomicRoles() { - // TODO Auto-generated method stub - return null; + return atomicRoles; } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ public SortedSet<Individual> getIndividuals() { - // TODO Auto-generated method stub - return null; + return individuals; } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getReasonerType() */ public ReasonerType getReasonerType() { - // TODO Auto-generated method stub - return null; + if(reasonerType.equals("FaCT++")) + return ReasonerType.FACT; + else + return ReasonerType.PELLET; } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) */ public void prepareSubsumptionHierarchy(Set<AtomicConcept> allowedConcepts) { - // TODO Auto-generated method stub + + // implementation almost identical to DIG reasoner + // except function calls + + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); + allowedConceptsInSubsumptionHierarchy.add(new Top()); + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + TreeMap<Concept, TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept, TreeSet<Concept>>( + conceptComparator); + + // refinements of top + TreeSet<Concept> tmp = getMoreSpecialConcepts(new Top()); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyDown.put(new Top(), tmp); + + // refinements of bottom + tmp = getMoreGeneralConcepts(new Bottom()); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyUp.put(new Bottom(), tmp); + + // refinements of atomic concepts + for (AtomicConcept atom : atomicConcepts) { + tmp = getMoreSpecialConcepts(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyDown.put(atom, tmp); + + tmp = getMoreGeneralConcepts(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyUp.put(atom, tmp); + } + + // create subsumption hierarchy + subsumptionHierarchy = new SubsumptionHierarchy(allowedConcepts, + subsumptionHierarchyUp, subsumptionHierarchyDown); } @Override + public SubsumptionHierarchy getSubsumptionHierarchy() { + return subsumptionHierarchy; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) + */ + @Override + public void prepareRoleHierarchy(Set<AtomicRole> allowedRoles) { + // code copied from DIG reasoner + + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + TreeMap<AtomicRole, TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole, TreeSet<AtomicRole>>( + roleComparator); + + // refinement of atomic concepts + for (AtomicRole role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRoles(role)); + roleHierarchyUp.put(role, getMoreGeneralRoles(role)); + } + + roleHierarchy = new RoleHierarchy(allowedRoles, roleHierarchyUp, + roleHierarchyDown); + } + + @Override + public RoleHierarchy getRoleHierarchy() { + return roleHierarchy; + } + + @Override public boolean subsumes(Concept superConcept, Concept subConcept) { try { - OWLDescription d1 = factory.getOWLClass(URI.create("a")); - OWLDescription d2 = factory.getOWLClass(URI.create("b")); - reasoner.isSubClassOf(d1, d2); + return reasoner.isSubClassOf(getOWLAPIDescription(subConcept), getOWLAPIDescription(superConcept)); } catch (OWLReasonerException e) { e.printStackTrace(); + throw new Error("Subsumption Error in OWL API."); } - return false; } + private TreeSet<Concept> getMoreGeneralConcepts(Concept concept) { + return null; + } + + private TreeSet<Concept> getMoreSpecialConcepts(Concept concept) { + return null; + } + + private TreeSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { + return null; + } + + private TreeSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { + return null; + } + + @Override + public boolean instanceCheck(Concept concept, Individual individual) { + OWLDescription d = getOWLAPIDescription(concept); + OWLIndividual i = factory.getOWLIndividual(URI.create(individual.getName())); + try { + return reasoner.hasType(i,d,false); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("Instance check error in OWL API."); + } + } + + @Override + public SortedSet<Individual> retrieval(Concept concept) { + OWLDescription d = getOWLAPIDescription(concept); + try { + reasoner.getIndividuals(d, false); + } catch (OWLReasonerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override + public Set<AtomicConcept> getConcepts(Individual individual) { + Set<Set<OWLClass>> result = null; + try { + result = reasoner.getTypes(factory.getOWLIndividual(URI.create(individual.getName())),false); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("GetConcepts() reasoning error in OWL API."); + } + // the OWL API returns a set of sets; each inner set consists of + // atomic classes + Set<AtomicConcept> concepts = new HashSet<AtomicConcept>(); + for(Set<OWLClass> classes : result) { + // take one element from the set and ignore the rest + // (TODO: we need to make sure we always ignore the same concepts) + OWLClass concept = classes.iterator().next(); + concepts.add(new AtomicConcept(concept.getURI().toString())); + } + return concepts; + } + + @Override + public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { + return null; + } + + @Override + public boolean isSatisfiable() { + try { + return reasoner.isSatisfiable(factory.getOWLThing()); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("Satisfiability check error in OWL API."); + } + } + + private Set<Concept> owlClassesToAtomicConcepts(Set<OWLClass> owlClasses) { + Set<Concept> concepts = new HashSet<Concept>(); + for(OWLClass owlClass : owlClasses) + concepts.add(owlClassToAtomicConcept(owlClass)); + return concepts; + } + + private Concept owlClassToAtomicConcept(OWLClass owlClass) { + return new AtomicConcept(owlClass.getURI().toString()); + } + public OWLDescription getOWLAPIDescription(Concept concept) { if (concept instanceof AtomicConcept) { return factory.getOWLClass(URI.create(((AtomicConcept)concept).getName())); Modified: trunk/src/dl-learner/org/dllearner/reasoning/ReasonerType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/ReasonerType.java 2008-01-06 11:54:42 UTC (rev 343) +++ trunk/src/dl-learner/org/dllearner/reasoning/ReasonerType.java 2008-01-06 15:14:35 UTC (rev 344) @@ -4,5 +4,5 @@ package org.dllearner.reasoning; public enum ReasonerType { - KAON2, DIG, FAST_RETRIEVAL + KAON2, DIG, FAST_RETRIEVAL, FACT, PELLET } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-04-14 22:45:20
|
Revision: 787 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=787&view=rev Author: kurzum Date: 2008-04-14 15:45:16 -0700 (Mon, 14 Apr 2008) Log Message: ----------- added config option reasonertype for fastinstancechecker to be able to use it with fact Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-04-14 14:45:06 UTC (rev 786) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-04-14 22:45:16 UTC (rev 787) @@ -20,6 +20,8 @@ package org.dllearner.reasoning; import java.io.File; +import java.util.Collection; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,7 +37,9 @@ import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; @@ -86,6 +90,8 @@ private boolean defaultNegation = true; + private String reasonerType = "pellet"; + private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; private SortedSet<DatatypeProperty> datatypeProperties; @@ -119,6 +125,17 @@ this.sources = sources; } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + StringConfigOption type = new StringConfigOption("reasonerType", "FaCT++ or Pellet to dematerialize", "pellet"); + type.setAllowedValues(new String[] {"fact", "pellet"}); + // closure option? see: + // http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup + options.add(type); + return options; + } + /* * (non-Javadoc) * @@ -126,7 +143,9 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - + String name = entry.getOptionName(); + if(name.equals("reasonerType")) + reasonerType = (String) entry.getValue(); } public static String getName() { @@ -142,6 +161,8 @@ @Override public void init() throws ComponentInitException { rc = new OWLAPIReasoner(sources); + //TODO make it nice + rc.setReasonerType(reasonerType); rc.init(); try { @@ -598,4 +619,8 @@ rc.releaseKB(); } + public void setReasonerType(String type){ + reasonerType=type; + } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-04-14 14:45:06 UTC (rev 786) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-04-14 22:45:16 UTC (rev 787) @@ -892,5 +892,9 @@ public List<OWLOntology> getOWLAPIOntologies() { return owlAPIOntologies; } + + public void setReasonerType(String type){ + reasonerType=type; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |