From 29657bb048d94965df3ec1ceffc0dbc5cb96aa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Sun, 16 Aug 2009 21:18:45 +0000 Subject: [PATCH] - improved the primitives for accessing various names of entities --- .../exmo/align/onto/LoadedOntology.java | 32 ++++++++++++----- .../exmo/align/onto/jena25/JENAOntology.java | 17 ++++++---- .../align/onto/owlapi2/OWLAPI2Ontology.java | 34 ++++++++++++------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java b/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java index 12fbe5ae..506d82bb 100644 --- a/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rh�ne-Alpes, 2008 + * Copyright (C) INRIA, 2008-2009 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -32,7 +32,11 @@ public interface LoadedOntology<O> extends Ontology<O> { public URI getEntityURI( Object o ) throws AlignmentException; /** - * return one of the "rdfs:label" property values for a given entity. + * returns the default name of an entity if specified. + * otherwise, returns one of its names (e.g., "rdfs:label" property values) + * In case no such official name is given to the entity it is possible to + * use the entity URI to return its fragment identifier (after the '#') or + * last fragment (after the last "/" or just before) in this order. * @param o the entity * @return a label * @throws AlignmentException @@ -40,15 +44,27 @@ public interface LoadedOntology<O> extends Ontology<O> { public String getEntityName( Object o ) throws AlignmentException; /** - * Returns the values of the "rdfs:label" property for a given entity and for a given natural language (attribute xml:lang). + * returns the default name of an entity in a language (attribute xml:lang) + * if specified. + * otherwise, returns one of its names (e.g., "rdfs:label" property values) + * otherwise returns the default name (getEntityName) + * @param o the entity + * @return a label + * @throws AlignmentException + */ + public String getEntityName( Object o, String lang ) throws AlignmentException; + + /** + * returns all the names of an entity in a language if specified. + * otherwise, returns null * @param o the entity * @param lang the code of the language ("en", "fr", "es", etc.) - * @return the set of labels + * @return the default name * @throws AlignmentException */ - public Set<String> getEntityNames( Object o , String lang ) throws AlignmentException; + public Set<String> getEntityNames( Object o, String lang ) throws AlignmentException; /** - * Returns all the values of the "rdfs:label" property for a given entity. + * Returns all the names a given entity (e.g., rdfs:labels in OWL/RDFS). * @param o the entity * @return the set of labels * @throws AlignmentException @@ -56,7 +72,7 @@ public interface LoadedOntology<O> extends Ontology<O> { public Set<String> getEntityNames( Object o ) throws AlignmentException; /** - * Returns the values of the "rdfs:comment" property for a given entity and for a given natural language (attribute xml:lang). + * Returns the values ofof textual properties (e.g., "rdfs:comment", rdfs:label in RDFS/OWL) for a given entity and for a given natural language (attribute xml:lang). * @param o the entity * @param lang the code of the language ("en", "fr", "es", etc.) * @return the set of comments @@ -65,7 +81,7 @@ public interface LoadedOntology<O> extends Ontology<O> { public Set<String> getEntityComments( Object o , String lang ) throws AlignmentException; /** - * Returns all the values of the "rdfs:comment" property for a given entity + * Returns all the values of textual properties (e.g., "rdfs:comment", rdfs:label in RDFS/OWL) for a given entity * @param o the entity * @return the set of comments * @throws AlignmentException diff --git a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java index 35480769..946e8ede 100644 --- a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2008 + * Copyright (C) INRIA, 2003-2009 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -92,17 +92,20 @@ public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntol } - public String getEntityName(Object o) throws AlignmentException { + public String getEntityName( Object o ) throws AlignmentException { try { - // Try to get labels first... (done in the OWLAPI way) - URI u = new URI(((OntResource) o).getURI()); - if ( u != null ) return u.getFragment(); - else return ""; - } catch (Exception oex) { + // Should try to get labels first... (done in the OWLAPI way) + return getFragmentAsLabel( new URI( ((OntResource) o).getURI() ) ); + } catch ( Exception oex ) { return null; } } + public String getEntityName( Object o, String lang ) throws AlignmentException { + // Should first get the label in the language + return getEntityName( o ); + } + public Set<String> getEntityNames(Object o, String lang) throws AlignmentException { Set<String> labels = new HashSet<String>(); OntResource or = (OntResource) o; diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi2/OWLAPI2Ontology.java b/src/fr/inrialpes/exmo/align/onto/owlapi2/OWLAPI2Ontology.java index 1cfef92d..6b38556e 100644 --- a/src/fr/inrialpes/exmo/align/onto/owlapi2/OWLAPI2Ontology.java +++ b/src/fr/inrialpes/exmo/align/onto/owlapi2/OWLAPI2Ontology.java @@ -108,24 +108,32 @@ public class OWLAPI2Ontology extends BasicOntology<OWLOntology> implements public String getEntityName(Object o) throws AlignmentException { try { - return ((OWLEntity) o).getURI().getFragment(); - } catch (NullPointerException e) { - return null; + // Should try to get the label first + return getFragmentAsLabel( ((OWLEntity) o).getURI() ); } catch (ClassCastException e) { - throw new AlignmentException(o + " is not an entity for " - + onto.getURI()); + throw new AlignmentException(o+" is not an entity for "+ onto.getURI()); } } - public Set<String> getEntityNames(Object o, String lang) - throws AlignmentException { - return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), - lang); + public String getEntityName( Object o, String lang ) throws AlignmentException { + // Should first get the label in the language + return getEntityName( o ); + } + + public Set<String> getEntityNames(Object o, String lang) throws AlignmentException { + return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), lang); } public Set<String> getEntityNames(Object o) throws AlignmentException { - return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), - null); + Set<String> result = getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), null); + if ( result == null ) { + String label = getEntityName( o ); + if ( label != null ) { + result = new HashSet(); + result.add( label ); + } + } + return result; } public URI getEntityURI(Object o) throws AlignmentException { @@ -382,8 +390,8 @@ public class OWLAPI2Ontology extends BasicOntology<OWLOntology> implements list.add( (Object)rest.getProperty() ); } public void getProperties( OWLNaryBooleanDescription d, Set<Object> list, Set<Object> visited ) throws OWLException { - for ( Iterator it = d.getOperands().iterator(); it.hasNext() ;){ - getProperties( (OWLDescription)it.next(), list, visited ); + for ( OWLDescription desc : d.getOperands() ){ + getProperties( desc, list, visited ); } } public void getProperties( OWLClass cl, Set<Object> list, Set<Object> visited ) throws OWLException { -- GitLab