From 1c371b38e5015503e7963cf3294f7030e9fcf50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Wed, 25 Jun 2008 14:27:23 +0000 Subject: [PATCH] - Modified Cell interface so that object URIs can be found in a generic way -> solves a database storage bug - Modified inverse() so that it works when no extensions are there --- .../inrialpes/exmo/align/impl/BasicCell.java | 9 +++++- .../inrialpes/exmo/align/impl/OWLAPICell.java | 5 ++-- .../inrialpes/exmo/align/impl/ObjectCell.java | 30 ++++++++++++++----- src/fr/inrialpes/exmo/align/impl/URICell.java | 11 +++++-- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/impl/BasicCell.java b/src/fr/inrialpes/exmo/align/impl/BasicCell.java index c8b2952d..ee7a727d 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicCell.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicCell.java @@ -26,6 +26,7 @@ import java.util.Enumeration; import org.xml.sax.ContentHandler; +import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Cell; @@ -100,6 +101,9 @@ public class BasicCell implements Cell, Comparable<Cell> { * Use <tt>Ontology.getEntityURI( this )</tt> instead. */ public URI getObject1AsURI() throws AlignmentException { + return getObject1AsURI( null ); + } + public URI getObject1AsURI( Alignment al ) throws AlignmentException { if ( object1 instanceof URI ) { return (URI)object1; } else { @@ -114,6 +118,9 @@ public class BasicCell implements Cell, Comparable<Cell> { * Use <tt>Ontology.getEntityURI( this )</tt> instead. */ public URI getObject2AsURI() throws AlignmentException { + return getObject2AsURI( null ); + } + public URI getObject2AsURI( Alignment al ) throws AlignmentException { if ( object2 instanceof URI ) { return (URI)object2; } else { @@ -157,8 +164,8 @@ public class BasicCell implements Cell, Comparable<Cell> { for ( Object ext : ((BasicParameters)extensions).getValues() ){ result.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); } + result.getExtensions().unsetParameter( Annotations.ALIGNNS+Annotations.ID ); } - result.getExtensions().unsetParameter( Annotations.ALIGNNS+Annotations.ID ); // The sae should be done for the measure return result; } diff --git a/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java b/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java index 15997729..a01e9e28 100644 --- a/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java +++ b/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java @@ -33,6 +33,7 @@ import org.xml.sax.SAXException; import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.model.OWLException; +import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Cell; @@ -71,7 +72,7 @@ public class OWLAPICell extends ObjectCell { } // Only OWL - public URI getObject1AsURI() throws AlignmentException { + public URI getObject1AsURI( Alignment al ) throws AlignmentException { try { return ((OWLEntity)object1).getURI(); } catch (OWLException e) { @@ -80,7 +81,7 @@ public class OWLAPICell extends ObjectCell { } // Only OWL - public URI getObject2AsURI() throws AlignmentException { + public URI getObject2AsURI( Alignment al ) throws AlignmentException { try { return ((OWLEntity)object2).getURI(); } catch (OWLException e) { diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java index a4033d51..22dd5e89 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java @@ -26,12 +26,16 @@ import java.util.Enumeration; import org.xml.sax.ContentHandler; +import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; import org.semanticweb.owl.align.Parameters; +import fr.inrialpes.exmo.align.onto.LoadedOntology; +import fr.inrialpes.exmo.align.impl.BasicAlignment; + /** * Represents an ontology alignment correspondence. * @@ -72,20 +76,30 @@ public class ObjectCell extends BasicCell { } */ - public URI getObject1AsURI() throws AlignmentException { + public URI getObject1AsURI( Alignment al ) throws AlignmentException { + if ( al instanceof BasicAlignment ) { + Object ontology = ((BasicAlignment)al).getOntologyObject1(); + if ( ontology instanceof LoadedOntology ) { + return ((LoadedOntology)ontology).getEntityURI( object1 ); + } + }; if ( object1 instanceof URI ) { return (URI)object1; } else { - // TO BE DONE - return null; + throw new AlignmentException( "Cannot find URI for "+object1 ); } } - public URI getObject2AsURI() throws AlignmentException { - if ( object2 instanceof URI ) { + public URI getObject2AsURI( Alignment al ) throws AlignmentException { + if ( al instanceof BasicAlignment ) { + Object ontology = ((BasicAlignment)al).getOntologyObject2(); + if ( ontology instanceof LoadedOntology ) { + return ((LoadedOntology)ontology).getEntityURI( object2 ); + } + }; + if ( object2 instanceof URI ) { return (URI)object2; } else { - // TO BE DONE - return null; + throw new AlignmentException( "Cannot find URI for "+object2 ); } } public Cell inverse() throws AlignmentException { @@ -94,8 +108,8 @@ public class ObjectCell extends BasicCell { for ( Object ext : ((BasicParameters)extensions).getValues() ){ result.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); } + result.getExtensions().unsetParameter( Annotations.ALIGNNS+Annotations.ID ); } - result.getExtensions().unsetParameter( Annotations.ALIGNNS+Annotations.ID ); // The sae should be done for the measure return result; } diff --git a/src/fr/inrialpes/exmo/align/impl/URICell.java b/src/fr/inrialpes/exmo/align/impl/URICell.java index 482c51c9..550193b1 100644 --- a/src/fr/inrialpes/exmo/align/impl/URICell.java +++ b/src/fr/inrialpes/exmo/align/impl/URICell.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2007-2008 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -30,6 +30,7 @@ import java.net.URI; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; +import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Cell; @@ -75,8 +76,12 @@ public class URICell extends BasicCell { } } - public URI getObject1AsURI() throws AlignmentException { return (URI)object1; }; - public URI getObject2AsURI() throws AlignmentException { return (URI)object2; }; + public URI getObject1AsURI( Alignment al ) throws AlignmentException { + return (URI)object1; + }; + public URI getObject2AsURI( Alignment al ) throws AlignmentException { + return (URI)object2; + }; //public Object getObject1(){ return object1; }; //public Object getObject2(){ return object2; }; // We could check that the given values are URIs -- GitLab