From: <jen...@us...> - 2008-10-24 07:26:53
|
Revision: 1422 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1422&view=rev Author: jenslehmann Date: 2008-10-24 07:26:43 +0000 (Fri, 24 Oct 2008) Log Message: ----------- - annotation support in core OWL library - added method to get rdfs:label from entities Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/Individual.java trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java trunk/src/dl-learner/org/dllearner/core/owl/Property.java trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java trunk/src/dl-learner/org/dllearner/core/owl/Entity.java trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -26,7 +26,6 @@ import java.util.Map; import java.util.NavigableSet; import java.util.Set; -import java.util.Stack; import java.util.TreeSet; import org.dllearner.core.ReasoningService; Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -28,6 +28,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -83,6 +84,11 @@ public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + // annotations (not strictly reasoning methods) + // [OWL API supports only annotations specified in a given ontology, which + // is uncomfortable to handle when several ontologies are loaded] + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException; + // some convenience methods public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -31,6 +31,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -112,6 +113,11 @@ throw new ReasoningMethodUnsupportedException(); } + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -33,6 +33,7 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -475,6 +476,16 @@ } } + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + try { + return reasoner.getLabel(entity); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { reasoningStartTimeTmp = System.nanoTime(); Map<Individual, SortedSet<Individual>> result; Added: trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,87 @@ +/** + * 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.net.URI; +import java.util.Map; + +/** + * An annotation, e.g. rdfs:label "foo". + * + * @author Jens Lehmann + * + */ +public class Annotation implements KBElement { + + protected URI annotationURI; + protected KBElement annotationValue; + + public Annotation(URI annotationURI, KBElement annotationValue) { + this.annotationURI = annotationURI; + this.annotationValue = annotationValue; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) + */ + @Override + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + @Override + public int getLength() { + return 1 + annotationValue.getLength(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toKBSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { + return annotationURI + annotationValue.toKBSyntaxString(baseURI, prefixes); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + @Override + public String toString(String baseURI, Map<String, String> prefixes) { + return annotationURI + annotationValue.toString(baseURI, prefixes); + } + + /** + * @return the annotationURI + */ + public URI getAnnotationURI() { + return annotationURI; + } + + /** + * @return the annotationValue + */ + public KBElement getAnnotationValue() { + return annotationValue; + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,39 @@ +/** + * 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.net.URI; + +/** + * @author Jens Lehmann + * + */ +public class ConstantAnnotation extends Annotation { + + public ConstantAnnotation(URI annotationURI, Constant annotationValue) { + super(annotationURI, annotationValue); + } + + @Override + public Constant getAnnotationValue() { + return (Constant) annotationValue; + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/Entity.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Entity.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Entity.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,30 @@ +/** + * 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; + +/** + * Marker interface for classes, properties, individuals. + * + * @author Jens Lehmann + * + */ +public interface Entity extends NamedKBElement { + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/Individual.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Individual.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/Individual.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -29,7 +29,7 @@ * @author Jens Lehmann * */ -public class Individual implements NamedKBElement, Comparable<Individual> { +public class Individual implements Entity, NamedKBElement, Comparable<Individual> { private String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -43,4 +43,6 @@ void visit(UntypedConstant untypedConstant); + void visit(Annotation annotation); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,34 @@ +/** + * 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.net.URI; + +/** + * @author Jens Lehmann + * + */ +public class LabelAnnotation extends ConstantAnnotation { + + public LabelAnnotation(URI annotationURI, Constant annotationValue) { + super(annotationURI, annotationValue); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -30,7 +30,7 @@ * @author Jens Lehmann * */ -public class NamedClass extends Description implements NamedKBElement, Comparable<NamedClass> { +public class NamedClass extends Description implements Entity, NamedKBElement, Comparable<NamedClass> { String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/Property.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -23,6 +23,6 @@ * @author Jens Lehmann * */ -public interface Property extends PropertyExpression, NamedKBElement { +public interface Property extends Entity, PropertyExpression, NamedKBElement { } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -1,16 +1,12 @@ package org.dllearner.kb.sparql; -import java.util.HashMap; import java.util.SortedSet; -import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.ADC; import org.dllearner.core.ComponentManager; -import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; import org.dllearner.core.owl.DatatypeMinCardinalityRestriction; -import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.DatatypeValueRestriction; import org.dllearner.core.owl.Description; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -51,6 +51,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DoubleMaxValue; import org.dllearner.core.owl.DoubleMinValue; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -677,6 +678,11 @@ return rc.getRelatedValues(individual, datatypeProperty); } + @Override + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + return rc.getLabel(entity); + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -50,6 +50,7 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.KB; import org.dllearner.core.owl.NamedClass; @@ -68,6 +69,7 @@ import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.model.OWLAnnotation; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLConstant; import org.semanticweb.owl.model.OWLDataFactory; @@ -75,7 +77,9 @@ import org.semanticweb.owl.model.OWLDataRange; import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLLabelAnnotation; import org.semanticweb.owl.model.OWLNamedObject; import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLOntology; @@ -733,25 +737,7 @@ } catch (OWLReasonerException e) { e.printStackTrace(); } - // convert data back to DL-Learner structures - SortedSet<Constant> is = new TreeSet<Constant>(); - for(OWLConstant oi : constants) { - // for typed constants we have to figure out the correct - // data type and value - if(oi instanceof OWLTypedConstant) { - Datatype dt = convertDatatype(((OWLTypedConstant)oi).getDataType()); - is.add(new TypedConstant(oi.getLiteral(),dt)); - // for untyped constants we have to figure out the value - // and language tag (if any) - } else { - OWLUntypedConstant ouc = (OWLUntypedConstant) oi; - if(ouc.hasLang()) - is.add(new UntypedConstant(ouc.getLiteral(), ouc.getLang())); - else - is.add(new UntypedConstant(ouc.getLiteral())); - } - } - return is; + return convertConstants(constants); } public Map<Individual, SortedSet<Double>> getDoubleValues(DatatypeProperty datatypeProperty) { @@ -907,6 +893,33 @@ } } + public static Set<Constant> convertConstants(Set<OWLConstant> constants) { + SortedSet<Constant> is = new TreeSet<Constant>(); + for(OWLConstant oi : constants) { + is.add(convertConstant(oi)); + } + return is; + } + + public static Constant convertConstant(OWLConstant constant) { + Constant c; + // for typed constants we have to figure out the correct + // data type and value + if(constant instanceof OWLTypedConstant) { + Datatype dt = convertDatatype(((OWLTypedConstant)constant).getDataType()); + c = new TypedConstant(constant.getLiteral(),dt); + // for untyped constants we have to figure out the value + // and language tag (if any) + } else { + OWLUntypedConstant ouc = (OWLUntypedConstant) constant; + if(ouc.hasLang()) + c = new UntypedConstant(ouc.getLiteral(), ouc.getLang()); + else + c = new UntypedConstant(ouc.getLiteral()); + } + return c; + } + public static Datatype convertDatatype(OWLDataType dataType) { URI uri = dataType.getURI(); if(uri.equals(Datatype.BOOLEAN.getURI())) @@ -927,6 +940,19 @@ return staticFactory.getOWLDataProperty(URI.create(datatypeProperty.getName())); } + private static OWLEntity getOWLAPIEntity(Entity entity) { + if(entity instanceof ObjectProperty) { + return staticFactory.getOWLObjectProperty(URI.create(entity.getName())); + } else if(entity instanceof DatatypeProperty) { + return staticFactory.getOWLDataProperty(URI.create(entity.getName())); + } else if(entity instanceof NamedClass) { + return staticFactory.getOWLClass(URI.create(entity.getName())); + } else if(entity instanceof OWLIndividual) { + return staticFactory.getOWLIndividual(URI.create(entity.getName())); + } + throw new Error("OWL API entity conversion for " + entity + " not supported."); + } + /** * Test * @@ -1037,5 +1063,18 @@ } - + @Override + @SuppressWarnings("all") + public Set<Constant> getLabel(Entity entity) { + OWLEntity owlEntity = getOWLAPIEntity(entity); + Set<OWLAnnotation> labelAnnotations = owlEntity.getAnnotations(owlAPIOntologies.get(0), URI.create("http://www.w3.org/2000/01/rdf-schema#label")); + Set<Constant> annotations = new HashSet<Constant>(); + for(OWLAnnotation label : labelAnnotations) { + OWLConstant c = ((OWLLabelAnnotation)label).getAnnotationValue(); + annotations.add(convertConstant(c)); + } + return annotations; + } + + } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -102,6 +102,7 @@ final Component dialogd = this.getParent(); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent we) { if(allChanges.size() > 0){ if (JOptionPane.showConfirmDialog(dialogd, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |