diff --git a/html/relnotes.html b/html/relnotes.html index 30320c537501503b77fd1afc127793f8f09e9dd6..1bc67f810b9214de1daa8296be5984691aafa6f5 100644 --- a/html/relnotes.html +++ b/html/relnotes.html @@ -63,8 +63,9 @@ The development of 4 versions continues. <p><ul compact="1"> <li>Added <tt>WeightedPRecEvaluator</tt> weighting confidences (eval)</li> +<li>Added <tt>toURIAlignment</tt> and <tt>toEDOALAlignment</tt> for <tt>EDOALAlignment</tt> (edoal)</li> <li>Changed order of display to precision/F-measure/recall (util)</li> -<li>Suppressed incorrect computation of fallout (eval)</li> +<li><span style="color: red;">Suppressed</span> incorrect computation of fallout (eval)</li> <li>Minor display changes in HTML display (server)</li> </ul></p> diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java index 0ad09c35847b76e8b39e0c6dd37264e7934a413f..c6bc77b9158836c6fc56fee26ca218ea86c1e898 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2010 + * Copyright (C) INRIA, 2003-2011 * Copyright (C) CNR Pisa, 2005 * * This program is free software; you can redistribute it and/or modify @@ -626,6 +626,23 @@ public class BasicAlignment implements Alignment { return result; } + public Extensions convertExtension( String label, String method ) { + Extensions newext = (Extensions)extensions.clone(); + String oldid = extensions.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); + if ( oldid != null && !oldid.equals("") ) { + newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.DERIVEDFROM, oldid ); + newext.unsetExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); + } + String pretty = getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); + if ( pretty != null ){ + newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY, pretty+"/"+label ); + }; + newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.PROVENANCE, + extensions.getExtension( Namespace.ALIGNMENT.uri, Annotations.PROVENANCE )+"" ); + newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.METHOD, method ); + return newext; + } + /** * A new alignment is created such that for * any pair (o, o', n, r) in O the resulting alignment will contain: @@ -639,21 +656,7 @@ public class BasicAlignment implements Alignment { // We must inverse getType result.setType( getType() ); result.setLevel( getLevel() ); - // Must add an inverse to the method extension - Extensions newext = (Extensions)extensions.clone(); - String oldid = extensions.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); - if ( oldid != null && !oldid.equals("") ) { - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.DERIVEDFROM, oldid ); - newext.unsetExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); - } - String pretty = result.getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); - if ( pretty != null ){ - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY, pretty+"/inverted" ); - }; - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.PROVENANCE, - extensions.getExtension( Namespace.ALIGNMENT.uri, Annotations.PROVENANCE )+"" ); - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.METHOD, "http://exmo.inrialpes.fr/align/impl/BasicAlignment#inverse" ); - result.setExtensions( newext ); + result.setExtensions( convertExtension( "inverted", "http://exmo.inrialpes.fr/align/impl/BasicAlignment#inverse" ) ); for ( Enumeration e = namespaces.getNames() ; e.hasMoreElements(); ){ String label = (String)e.nextElement(); result.setXNamespace( label, getXNamespace( label ) ); @@ -693,14 +696,7 @@ public class BasicAlignment implements Alignment { align.setLevel( getLevel() ); align.setFile1( getFile1() ); align.setFile2( getFile2() ); - Extensions newext = (Extensions)extensions.clone(); - String oldid = align.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); - if ( oldid != null && !oldid.equals("") ) { - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.DERIVEDFROM, oldid ); - newext.unsetExtension( Namespace.ALIGNMENT.getUriPrefix(), Annotations.ID ); - } - newext.setExtension( Namespace.ALIGNMENT.uri, Annotations.METHOD, this.getClass().getName()+"#clone" ); - align.setExtensions( newext ); + align.setExtensions( convertExtension( "cloned", this.getClass().getName()+"#clone" ) ); for ( Enumeration e = namespaces.getNames() ; e.hasMoreElements(); ){ String label = (String)e.nextElement(); align.setXNamespace( label, getXNamespace( label ) ); diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java index 5b3fa4181d64905c5ead71d27f261f27a35a5749..4e2af6f1a59d4b7ff63a26d3f91a7ea660a5ad2f 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2003-2010 + * Copyright (C) INRIA, 2003-2011 * * 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 @@ -107,30 +107,34 @@ public class ObjectAlignment extends BasicAlignment { /** * This is a clone with the URI instead of Object objects - * */ public URIAlignment toURIAlignment() throws AlignmentException { + return toURIAlignment( false ); + } + + public URIAlignment toURIAlignment( boolean strict ) throws AlignmentException { URIAlignment align = new URIAlignment(); align.init( getOntology1URI(), getOntology2URI() ); align.setType( getType() ); align.setLevel( getLevel() ); align.setFile1( getFile1() ); align.setFile2( getFile2() ); - for ( String[] ext : extensions.getValues() ) { - align.setExtension( ext[0], ext[1], ext[2] ); - } + align.setExtensions( convertExtension( "EDOALURIConverted", this.getClass().getName()+"#toURI" ) ); for (Enumeration e = getElements(); e.hasMoreElements();) { Cell c = (Cell)e.nextElement(); try { align.addAlignCell( c.getId(), c.getObject1AsURI(this), c.getObject2AsURI(this), c.getRelation(), c.getStrength() ); } catch (AlignmentException aex) { - // Sometimes URIs are null, this is ignore + // Sometimes URIs are null, this is ignored + if ( strict ) { + throw new AlignmentException( "Cannot convert to URIAlignment" ); + } } }; return align; } - static public ObjectAlignment toObjectAlignment( URIAlignment al ) throws AlignmentException, SAXException { + public static ObjectAlignment toObjectAlignment( URIAlignment al ) throws AlignmentException, SAXException { ObjectAlignment alignment = new ObjectAlignment(); try { alignment.init( al.getFile1(), al.getFile2() ); @@ -143,9 +147,7 @@ public class ObjectAlignment extends BasicAlignment { } alignment.setType( al.getType() ); alignment.setLevel( al.getLevel() ); - for ( String[] ext : al.getExtensions() ) { - alignment.setExtension( ext[0], ext[1], ext[2] ); - } + alignment.setExtensions( al.convertExtension( "ObjectURIConverted", "fr.inrialpes.exmo.align.ObjectAlignment#toObject" ) ); LoadedOntology<Object> o1 = (LoadedOntology<Object>)alignment.getOntologyObject1(); // [W:unchecked] LoadedOntology<Object> o2 = (LoadedOntology<Object>)alignment.getOntologyObject2(); // [W:unchecked] try { diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java index aff7a0ea9edc006e1e07e558fe67ecc73b847cf1..6afe5f60a048c6dddd0a6bde631714c3cc2a975f 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java @@ -2,7 +2,7 @@ * $Id$ * * Sourceforge version 1.6 - 2008 - was OMWGAlignment - * Copyright (C) INRIA, 2007-2010 + * Copyright (C) INRIA, 2007-2011 * * 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 @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; +import java.util.Collection; import java.util.Set; import java.net.URI; @@ -34,9 +35,12 @@ import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.ontowrap.Ontology; +import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.align.impl.Annotations; import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.impl.Extensions; import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; @@ -203,11 +207,95 @@ public class EDOALAlignment extends BasicAlignment { }; }; + /** + * This is a clone with the URI instead of Object objects + * This conversion will drop any correspondences using something not identified by an URI + * For converting to ObjectAlignment, first convert to URIAlignment and load as an ObjectAlignment + * The same code as for ObjectAlignment works... + */ + public URIAlignment toURIAlignment() throws AlignmentException { + return toURIAlignment( false ); + } + public URIAlignment toURIAlignment( boolean strict ) throws AlignmentException { + URIAlignment align = new URIAlignment(); + align.init( getOntology1URI(), getOntology2URI() ); + align.setType( getType() ); + align.setLevel( getLevel() ); + align.setFile1( getFile1() ); + align.setFile2( getFile2() ); + align.setExtensions( convertExtension( "EDOALURIConverted", "http://exmo.inrialpes.fr/align/impl/edoal/EDOALAlignment#toURI" ) ); + for (Enumeration e = getElements(); e.hasMoreElements();) { + Cell c = (Cell)e.nextElement(); + try { + align.addAlignCell( c.getId(), c.getObject1AsURI(this), c.getObject2AsURI(this), c.getRelation(), c.getStrength() ); + } catch (AlignmentException aex) { + // Ignore every cell that does not work + if ( strict ) { + throw new AlignmentException( "Cannot convert to URIAlignment" ); + } + } + }; + return align; + } -/** - * Returns the mappings of the EDOALAlignment - * @return The set of rules contained by the EDOALAlignment - */ + /** + * convert an URI alignment into a corresponding EDOALAlignment + * The same could be implemented for ObjectAlignent if necessary + */ + public static EDOALAlignment toEDOALAlignment( URIAlignment al ) throws AlignmentException { + EDOALAlignment alignment = new EDOALAlignment(); + try { + alignment.init( al.getFile1(), al.getFile2() ); + } catch ( AlignmentException aex ) { + try { // Really a friendly fallback + alignment.init( al.getOntology1URI(), al.getOntology2URI() ); + } catch ( AlignmentException xx ) { + throw aex; + } + } + alignment.setType( al.getType() ); + //alignment.setLevel( al.getLevel() ); // Should n't it be EDOAL level? + alignment.setExtensions( al.convertExtension( "EDOALConverted", "fr.inrialpes.exmo.align.edoal.EDOALAlignment#toEDOAL" ) ); + LoadedOntology<Object> o1 = (LoadedOntology<Object>)alignment.getOntologyObject1(); // [W:unchecked] + LoadedOntology<Object> o2 = (LoadedOntology<Object>)alignment.getOntologyObject2(); // [W:unchecked] + try { + for ( Cell c : al ) { + // HERE THIS SHOULD BE CREATED AS THE CORRESPONDING ID DEPENDING ON THEIR TYPES... MAKE A FUNCTION + Cell newc = alignment.addAlignCell( c.getId(), + getEntity( o1, c.getObject1AsURI(alignment) ), + getEntity( o2, c.getObject2AsURI(alignment) ), + c.getRelation(), + c.getStrength() ); + Collection<String[]> exts = c.getExtensions(); + if ( exts != null ) { + for ( String[] ext : exts ){ + newc.setExtension( ext[0], ext[1], ext[2] ); + } + } + } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot dereference entity", owex ); + } + return alignment; + } + + static private Id getEntity( LoadedOntology<Object> o, URI u ) throws OntowrapException, AlignmentException { + Object e = o.getEntity( u ); + if ( o.isClass( e ) ) { + return new ClassId( u ); + } else if ( o.isDataProperty( e ) ) { + return new PropertyId( u ); + } else if ( o.isObjectProperty( e ) ) { + return new RelationId( u ); + } else if ( o.isIndividual( e ) ) { + return new InstanceId( u ); + } else throw new AlignmentException( "Cannot interpret URI" ); + } + + /** + * Returns the mappings of the EDOALAlignment + * @return The set of rules contained by the EDOALAlignment + */ /** * Generate a copy of this alignment object @@ -225,10 +313,7 @@ public class EDOALAlignment extends BasicAlignment { align.setLevel( getLevel() ); align.setFile1( getFile1() ); align.setFile2( getFile2() ); - for ( String[] ext: extensions.getValues() ){ - align.setExtension( ext[0], ext[1], ext[2] ); - } - align.setExtension( Namespace.ALIGNMENT.getUriPrefix(), "id", (String)null ); + align.setExtensions( convertExtension( "cloned", this.getClass().getName()+"#clone" ) ); try { align.ingest( this ); } catch (AlignmentException ex) { ex.printStackTrace(); } diff --git a/test/src/EDOALTest.java b/test/src/EDOALTest.java index 91114a132d680d7afd95c1306f41e0504b117fc8..39ae8f8783e5da63f0f69686a00eaf469e6fded3 100644 --- a/test/src/EDOALTest.java +++ b/test/src/EDOALTest.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2008-2010 + * Copyright (C) INRIA, 2008-2011 * * 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 @@ -31,6 +31,7 @@ import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Alignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; import fr.inrialpes.exmo.align.parser.AlignmentParser; @@ -133,4 +134,20 @@ java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine // This does not work because (at least) the order of correspondences is never the same... //assertEquals( wine2, stream.toString() ); } + + /* This is round triping wrt converting to URIALignment... */ + @Test(expectedExceptions = AlignmentException.class, groups = { "full", "omwg", "raw" }, dependsOnMethods = {"roundTripTest"}) + public void anotherRoundTripTest() throws Exception { + aparser1.initAlignment( null ); + EDOALAlignment eal = (EDOALAlignment)aparser1.parse( "file:test/output/wine2.xml" ); + assertNotNull( eal ); + assertEquals( eal.nbCells(), 5 ); + URIAlignment al = eal.toURIAlignment(); + assertNotNull( al ); + assertEquals( al.nbCells(), 3 ); + eal = EDOALAlignment.toEDOALAlignment( al ); // does not work because the ontology cannot be loaded! + assertNotNull( eal ); + assertEquals( eal.nbCells(), 3 ); + } + } diff --git a/test/src/READMETest.java b/test/src/READMETest.java index 5ee9a687a27708cc069f797e59dbe31f9be06ac7..abf066bdbc7718f4954ff549993dbe9c0dddd0be 100644 --- a/test/src/READMETest.java +++ b/test/src/READMETest.java @@ -41,6 +41,7 @@ import fr.inrialpes.exmo.align.impl.method.StringDistAlignment; import fr.inrialpes.exmo.align.impl.eval.PRecEvaluator; import fr.inrialpes.exmo.align.impl.eval.SemPRecEvaluator; import fr.inrialpes.exmo.align.impl.URIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.parser.AlignmentParser; import fr.inrialpes.exmo.align.util.NullStream; @@ -146,6 +147,12 @@ $ java -jar lib/Procalign.jar file://$CWD/examples/rdf/edu.umbc.ebiquity.publica alignment.init( new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl"), new URI("file:examples/rdf/edu.mit.visus.bibtex.owl")); alignment.align( (Alignment)null, params ); assertEquals( alignment.nbCells(), 10 ); + URIAlignment al = ((ObjectAlignment)alignment).toURIAlignment(); + assertNotNull( al, "URIAlignment should not be null" ); + assertEquals( al.nbCells(), 10 ); + ObjectAlignment al2 = ObjectAlignment.toObjectAlignment( al ); + assertNotNull( al2, "ObjectAlignment should not be null" ); + assertEquals( al2.nbCells(), 10 ); } @Test(groups = { "full", "impl", "raw" }, dependsOnMethods = {"routineTest7"})