From: <jen...@us...> - 2008-01-06 10:58:28
|
Revision: 341 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=341&view=rev Author: jenslehmann Date: 2008-01-06 02:57:59 -0800 (Sun, 06 Jan 2008) Log Message: ----------- started mapping to OWL API reasoner interface (not working yet) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2008-01-06 10:56:17 UTC (rev 340) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2008-01-06 10:57:59 UTC (rev 341) @@ -196,7 +196,8 @@ } if (format.equals("KB")) { try{ - kb=KBParser.parseKBFile(new StringReader(ont)); + // kb=KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); } catch(Exception e) {e.printStackTrace();} } }catch(IOException e) { Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2008-01-06 10:56:17 UTC (rev 340) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2008-01-06 10:57:59 UTC (rev 341) @@ -359,7 +359,8 @@ } if (format.equals("KB")) { try { - kb = KBParser.parseKBFile(new StringReader(ont)); + //kb = KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); } catch (Exception e) { e.printStackTrace(); } Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-01-06 10:56:17 UTC (rev 340) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-01-06 10:57:59 UTC (rev 341) @@ -32,11 +32,6 @@ KBParser parser = new KBParser(new FileInputStream(file)); return parser.KB(); } - - public static KB parseKBFile(StringReader read) throws ParseException{ - KBParser parser = new KBParser(read); - return parser.KB(); - } final public KB KB() throws ParseException { ConceptAssertion conceptAssertion; Added: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-06 10:57:59 UTC (rev 341) @@ -0,0 +1,212 @@ +/** + * Copyright (C) 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.reasoning; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +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.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; +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.model.OWLClass; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLNamedObject; +import org.semanticweb.owl.model.OWLObjectProperty; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; + +/** + * Mapping to OWL API reasoner interface. The OWL API currently + * supports two reasoners: FaCT++ and Pellet. FaCT++ is connected + * using JNI and native libraries, while Pellet is a pure Java + * library. + * + * @author Jens Lehmann + * + */ +public class OWLAPIReasoner extends ReasonerComponent { + + private String reasonerType = "FaCT++"; + + private Set<KnowledgeSource> sources; + private OWLReasoner reasoner; + + private ConceptComparator conceptComparator = new ConceptComparator(); + private RoleComparator roleComparator = new RoleComparator(); + private SubsumptionHierarchy subsumptionHierarchy; + private RoleHierarchy roleHierarchy; + + public OWLAPIReasoner(Set<KnowledgeSource> sources) { + this.sources = sources; + } + + public static String getName() { + return "FaCT++ reasoner"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + StringConfigOption type = new StringConfigOption("reasonerType", "FaCT++ or Pellet", "FaCT++"); + type.setAllowedValues(new String[] {"FaCT++", "Pellet"}); + options.add(type); + return options; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.config.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + if(name.equals("reasonerType")) + reasonerType = (String) entry.getValue(); + } + + @Override + public void init() { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // it is a bit cumbersome to obtain all classes, because there + // are no reasoner queries to obtain them => hence we query them + // for each ontology and add them to a set; a comparator avoids + // duplicates by checking URIs + Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { + public int compare(OWLNamedObject o1, OWLNamedObject o2) { + return o1.getURI().compareTo(o2.getURI()); + } + }; + Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); + Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLIndividual> individuals = new TreeSet<OWLIndividual>(namedObjectComparator); + + for(KnowledgeSource source : sources) { + if(!(source instanceof OWLFile)) { + System.out.println("Currently, only OWL files are supported. Ignoring knowledge source " + source + "."); + } else { + URL url = ((OWLFile)source).getURL(); + try { + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); + classes.addAll(ontology.getReferencedClasses()); + properties.addAll(ontology.getReferencedObjectProperties()); + individuals.addAll(ontology.getReferencedIndividuals()); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + } + + // create actual reasoner + if(reasonerType.equals("FaCT++")) { + try { + reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + // .. insert Pellet code here + } + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicConcepts() + */ + public Set<AtomicConcept> getAtomicConcepts() { + // reasoner + + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicRoles() + */ + public Set<AtomicRole> getAtomicRoles() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getIndividuals() + */ + public SortedSet<Individual> getIndividuals() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getReasonerType() + */ + public ReasonerType getReasonerType() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) + */ + public void prepareSubsumptionHierarchy(Set<AtomicConcept> allowedConcepts) { + // TODO Auto-generated method stub + + } + + /** + * Test + * + * @param args + */ + public static void main(String[] args) { + // System.out.println(System.getProperty("java.library.path")); + + String uri = "http://www.co-ode.org/ontologies/pizza/2007/02/12/pizza.owl"; + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + try { + manager.loadOntologyFromPhysicalURI(URI.create(uri)); + new org.mindswap.pellet.owlapi.Reasoner(manager); + System.out.println("Reasoner loaded succesfully."); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |