From bc952b77ce6999c4f90138a12fa4883959fdad9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Sat, 21 May 2011 16:54:24 +0000 Subject: [PATCH] - reengineered OntologyNetworkWeakener as an interface - added OntologyNetworkGenerator - added new weakeners --- html/credits.html | 1 + html/relnotes.html | 9 +- .../align/gen/NetworkAlignmentDropper.java | 76 +++++ .../align/gen/NetworkAlignmentWeakener.java | 92 ++++++ .../gen/NetworkCorrespondenceDropper.java | 114 ++++++++ .../exmo/align/gen/NetworkDeconnector.java | 57 ++++ .../align/gen/OntologyNetworkGenerator.java | 54 ++++ .../align/gen/OntologyNetworkWeakener.java | 104 +------ test/src/OntologyNetworkTest.java | 275 ++++++++++++++++-- 9 files changed, 665 insertions(+), 117 deletions(-) create mode 100644 src/fr/inrialpes/exmo/align/gen/NetworkAlignmentDropper.java create mode 100644 src/fr/inrialpes/exmo/align/gen/NetworkAlignmentWeakener.java create mode 100644 src/fr/inrialpes/exmo/align/gen/NetworkCorrespondenceDropper.java create mode 100644 src/fr/inrialpes/exmo/align/gen/NetworkDeconnector.java create mode 100644 src/fr/inrialpes/exmo/align/gen/OntologyNetworkGenerator.java diff --git a/html/credits.html b/html/credits.html index dc7214cc..bd3cb332 100644 --- a/html/credits.html +++ b/html/credits.html @@ -38,6 +38,7 @@ IDDN.FR. 001.050019 .000.S.P.2 011.000.2090 0 storage layer and the web service profile for the Alignment Server</dd> <dt><a href="http://www.eurecom.fr/~troncy/">Raphaël Troncy</a></dt><dd>fixed the basic implementation of BasicAlignment for n:m alignments.</dd> +<dt>Maria Rosoiu</dt><dd>developed the generator interface (gen).</dd> <dt>Arun Sharma</dt><dd>Developed the query interface</dd> <dt><a href="http://www.scharffe.fr/">François Scharffe</a></dt><dd>developed the initial version of EDOAL</dd> <dt><a href="http://web.comlab.ox.ac.uk/isg/people/giorgos.stoilos/">Giorgos diff --git a/html/relnotes.html b/html/relnotes.html index df285fe7..2f4d925f 100644 --- a/html/relnotes.html +++ b/html/relnotes.html @@ -52,26 +52,33 @@ The development of 4 versions continues. <li>Render alignments as module descriptions (impl)</li> <li>Implement extensive evaluation framework (impl)</li> <li>Implement debug options with log4j</li> +<li>Matcher plugin for OpenII? (util)</li> <li>Add more tests</li> </ul></p> <h2>Current SVN trunk version</h2> <!--h2>Version 4.3 (): xx/xx/xxxx - Zimt</h2--> -<!--h2>Version 4.2 (): xx/05/2011 - Tring</h2--> +<!--h2>Version 4.2 (16xx): 29/05/2011 - Tring</h2--> <p><ul compact="1"> +<li>Added minimal API implementation for embedded devices (android)</li> <li>Added type checking to EDOAL parser (parser)</li> <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>Added matching test generator facility (gen)</li> <li>Added autoselecting <tt>BasicOntology.load()</tt> (ontowrap)</li> +<li>Reengineered <tt>OntologyNetworkWeakener</tt> and added further weakening methods (gen)</li> +<!--li>Added <tt>SEALSAlignment</tt> for SEALS evaluation (impl)</li--> +<li>Added a few statistical primitives to BasicAlignment (impl)</li> <li>Suppressed <tt>EDOALRelation</tt>: EDOAL uses <tt>BasicRelation</tt> (edoal)</li> <li>EDOAL default printout now uses pretty relations, i.e., <, >, =, % (edoal)</li> +<li>Modified server answers so that namespaces are well placed in REST (server)</li> <li>Changed order of display to precision/F-measure/recall (util)</li> <li><span style="color: red;">Suppressed</span> incorrect computation of fallout (eval)</li> <li>Upgraded to <span style="color: green">OntoSim 2.1??</span> (lib)</li> <li>Minor display changes in HTML display (server)</li> +<li>Suppressed <tt>PreAlignment</tt> (impl)</li> </ul></p> <h2>Version 4.1 (1534): 13/10/2010 - Napjakmandu</h2> diff --git a/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentDropper.java b/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentDropper.java new file mode 100644 index 00000000..98437ff3 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentDropper.java @@ -0,0 +1,76 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2009-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 the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package fr.inrialpes.exmo.align.gen; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.OntologyNetwork; + +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; + +import java.net.URI; +import java.util.Properties; +import java.util.Set; +import java.util.Collections; +import java.util.ArrayList; + +/** + * NetworkAlignmentDropper + * + * randomly drops n% of all alignments + * n is a number between 0. and 1. + * Returns a brand new BasicOntologyNetwork (with the initial alignments) + */ +public class NetworkAlignmentDropper implements OntologyNetworkWeakener { + + public OntologyNetwork weaken( OntologyNetwork on, double n, Properties p ) throws AlignmentException { + //System.err.println( " >>>> "+n ); + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + if ( n < 0. || n > 1. ) + throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); + return weaken( on, (int)(n*(double)on.getAlignments().size()), p ); + } + + public OntologyNetwork weaken( OntologyNetwork on, int n, Properties p ) throws AlignmentException { + //System.err.println( " >>>> "+n ); + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + if ( n < 0 ) + throw new AlignmentException( "Argument must be a positive integer: "+n ); + OntologyNetwork newon = new BasicOntologyNetwork(); + for ( URI ontouri : on.getOntologies() ){ + newon.addOntology( ontouri ); + } + Set<Alignment> alignments = on.getAlignments(); + int size = alignments.size(); + if ( n > size ) return newon; + ArrayList<Alignment> array = new ArrayList<Alignment>( size ); + for ( Alignment al : alignments ){ + array.add( al ); + } + Collections.shuffle( array ); + for ( int i = size - n -1; i >= 0; i-- ) { + newon.addAlignment( array.get( i ) ); + } + return newon; + } +} diff --git a/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentWeakener.java b/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentWeakener.java new file mode 100644 index 00000000..b02ecade --- /dev/null +++ b/src/fr/inrialpes/exmo/align/gen/NetworkAlignmentWeakener.java @@ -0,0 +1,92 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2009-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 the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package fr.inrialpes.exmo.align.gen; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.OntologyNetwork; + +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Properties; +import java.net.URI; + +/** + * AlignmentWeakener + * + * suppress n% of the correspondences at random in each alignments + * n is a number between 0. and 1. + * Returns a brand new BasicOntologyNetwork (with new alignments and cells) + * the @threshold parameter tells if the corrrespondences are suppressed at random (false) of by suppressing the n% of lower confidence (true) + */ + +public class NetworkAlignmentWeakener implements OntologyNetworkWeakener { + + public OntologyNetwork weaken( OntologyNetwork on, int n, Properties p ) throws AlignmentException { + throw new AlignmentException( "Cannot weaken alignments by fixed number of correspondences" ); + } + + public OntologyNetwork weaken( OntologyNetwork on, double n, Properties p ) throws AlignmentException { + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + if ( n < 0. || n > 1. ) + throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); + boolean threshold = (p != null && p.getProperty("threshold") != null); + OntologyNetwork newon = new BasicOntologyNetwork(); + for ( URI ontouri : on.getOntologies() ){ + newon.addOntology( ontouri ); + } + for ( Alignment al : on.getAlignments() ){ + Alignment newal = (Alignment)al.clone(); + if ( threshold ) { + newal.cut( "perc", 1.-n ); + } else { + int size = newal.nbCells(); + // -------------------------------------------------------------------- + // JE: Here is a tricky one. + // Using collection schuffle randomly reorganises a list + // Then choosing the fist n% and destroying them in the Set is performed + // The complexity is O(copy=N)+O(shuffle=N)+n%*O(delete=N) + // That's not bad... (and also avoid checking if the same nb is drawn) + // But in practice other solutions may be better, like: + // Generating randomly n%*N numbers between 0 and N (util.Random) + // Ordering them + // Traversing the initial structure and deleting the choosen ones... + // This one (deleting when traversing) is tricky in Java. + // -------------------------------------------------------------------- + ArrayList<Cell> array = new ArrayList<Cell>( size ); + for ( Cell c : newal ) { + array.add( c ); + } + Collections.shuffle( array ); + for ( int i = (int)(n*size)-1; i >= 0; i-- ){ + newal.remCell( array.get( i ) ); + } + } + newon.addAlignment( newal ); + } + return newon; + } + +} diff --git a/src/fr/inrialpes/exmo/align/gen/NetworkCorrespondenceDropper.java b/src/fr/inrialpes/exmo/align/gen/NetworkCorrespondenceDropper.java new file mode 100644 index 00000000..2efb03f8 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/gen/NetworkCorrespondenceDropper.java @@ -0,0 +1,114 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2009-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 the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package fr.inrialpes.exmo.align.gen; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.OntologyNetwork; + +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; + +import java.net.URI; +import java.util.Collections; +import java.util.Collection; +import java.util.TreeSet; +import java.util.ArrayList; +import java.util.Properties; + +/** + * NetworkCorrespondenceDropper + * + * suppress n% of the correspondences at random in all alignments (globally) + * n is a number between 0. and 1. + * Returns a brand new BasicOntologyNetwork (with new alignments and cells) + * the @threshold parameter tells if the corrrespondences are suppressed at random (false) of by suppressing the n% of lower confidence (true) + */ + +public class NetworkCorrespondenceDropper implements OntologyNetworkWeakener { + + public OntologyNetwork weaken( OntologyNetwork on, int n, Properties p ) throws AlignmentException { + throw new AlignmentException( "Cannot weaken alignments by fixed number of correspondences" ); + } + + public OntologyNetwork weaken( OntologyNetwork on, double n, Properties p ) throws AlignmentException { + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + if ( n < 0. || n > 1. ) + throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); + boolean threshold = (p != null && p.getProperty("threshold") != null); + OntologyNetwork newon = new BasicOntologyNetwork(); + for ( URI ontouri : on.getOntologies() ){ + newon.addOntology( ontouri ); + } + // Put all the cell/alignment in a array + Collection<LCell> corresp = null; + if ( threshold ) { + corresp = new TreeSet<LCell>(); + } else { + corresp = new ArrayList<LCell>(); + } + for ( Alignment al : on.getAlignments() ) { + Alignment newal = (Alignment)al.clone(); + for ( Cell c : newal ) { + corresp.add( new LCell( c, newal ) ); + } + newon.addAlignment( newal ); + } + // Select these correspondences to delete: either shuffle or order + //System.err.println( n+" * "+corresp.size()+" = "+n*(double)(corresp.size()) ); + int q = (int)(n*(double)(corresp.size())); + if ( !threshold ) Collections.shuffle( (ArrayList)corresp ); + // Suppress the n*size() last ones or those which are under threshold + for ( LCell c : corresp ) { + if ( q == 0 ) break; + q--; + //System.err.println( "Cell ["+c.getCell().getStrength()+"] : "+c ); + c.getAlignment().remCell( c.getCell() ); + } + // Cut + return newon; + } +} + +class LCell implements Comparable<LCell> { + Alignment alignment = null; + Cell cell = null; + + LCell( Cell c, Alignment al ) { + alignment = al; + cell = c; + } + + /** + * This is not the standard required definition of compareTo + * But this is the one which works exactly here (we want the structure ordered, + * we do not want that two cells be equated (in case of 0) + */ + public int compareTo( LCell c ) { + if ( cell.getStrength() > c.getCell().getStrength() ) return 1; + else return -1;/*if ( cell.getStrength() < c.getCell().getStrength() ) return -1; + else return 0;*/ + } + + Alignment getAlignment() { return alignment; } + Cell getCell() { return cell; } +} diff --git a/src/fr/inrialpes/exmo/align/gen/NetworkDeconnector.java b/src/fr/inrialpes/exmo/align/gen/NetworkDeconnector.java new file mode 100644 index 00000000..b3f567f9 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/gen/NetworkDeconnector.java @@ -0,0 +1,57 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2009-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 the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package fr.inrialpes.exmo.align.gen; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.OntologyNetwork; + +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; + +import java.util.Properties; + +/** + * NetworkDeconnector + * + * suppress alignments in the ontology network so that it retain n-connectivity, + * i.e., any pairs of ontologies connected by less than n alignments + * are still connected through at most n alignments. + * JE: this is an interesting graph theoretic problem and I do not know where + * to find it. + * + * NOT IMPLEMENTED + */ + +public class NetworkDeconnector implements OntologyNetworkWeakener { + + public OntologyNetwork weaken( OntologyNetwork on, int n, Properties p ) throws AlignmentException { + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + return on; + } + public OntologyNetwork weaken( OntologyNetwork on, double n, Properties p ) throws AlignmentException { + if ( on == null ) throw new AlignmentException( "cannot weaken null ontology network" ); + if ( n < 0. || n > 1. ) + throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); + return on; + } +} diff --git a/src/fr/inrialpes/exmo/align/gen/OntologyNetworkGenerator.java b/src/fr/inrialpes/exmo/align/gen/OntologyNetworkGenerator.java new file mode 100644 index 00000000..65afafb8 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/gen/OntologyNetworkGenerator.java @@ -0,0 +1,54 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 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 the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package fr.inrialpes.exmo.align.gen; + +import org.semanticweb.owl.align.OntologyNetwork; + +import fr.inrialpes.exmo.ontowrap.Ontology; + +import java.util.Properties; + +/** + * OntologyNetworkGenerator + * + * An interface for generating an ontology network from an ontology or an ontology generator. + * + */ + +public interface OntologyNetworkGenerator { + + /** + * Returns an ontology network of size n (the number of ontologies) + * starting from an ontology o. + * Parameters may further specify the requirements. + */ + public OntologyNetwork generate( int n, Ontology o, Properties params ); + + /** + * Returns an ontology network of size n (the number of ontologies) + * with ontologies generated by the generator g. + * Parameters may further specify the requirements. + */ + //public OntologyNetwork generate( int n, OntologyGenerator o, Properties params ); + +} + diff --git a/src/fr/inrialpes/exmo/align/gen/OntologyNetworkWeakener.java b/src/fr/inrialpes/exmo/align/gen/OntologyNetworkWeakener.java index ca21f7d0..d044fac1 100644 --- a/src/fr/inrialpes/exmo/align/gen/OntologyNetworkWeakener.java +++ b/src/fr/inrialpes/exmo/align/gen/OntologyNetworkWeakener.java @@ -21,113 +21,29 @@ package fr.inrialpes.exmo.align.gen; -import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; -import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.OntologyNetwork; -import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; - -import java.net.URI; -import java.util.Set; -import java.util.Collections; -import java.util.ArrayList; +import java.util.Properties; /** * OntologyNetworkWeakener * - * A class which alters ontology networks, usually by altering alignments + * A interface which alters ontology networks. + * NOTE: These two primitives would benefit from the hability to declare static in ineterfaces... + * Now we have to create instances of the implementing classes. + * */ -public class OntologyNetworkWeakener { +public interface OntologyNetworkWeakener { /** - * suppress alignments in the ontology network so that it retain n-connectivity, - * i.e., any pairs of ontologies connected by less than n alignments - * are still connected through at most n alignments. - * JE: this is an interesting graph theoretic problem and I do not know where - * to find it. + * Weakens the ontology network of n units */ - public static OntologyNetwork unconnect( OntologyNetwork on, int n ){ - return on; - } + public OntologyNetwork weaken( OntologyNetwork on, int n, Properties p ) throws AlignmentException; /** - * suppress n% of the correspondences at random in all alignments - * n is a number between 0. and 1. - * Returns a brand new BasicOntologyNetwork (with new alignments and cells) - * the @threshold parameter tells if the corrrespondences are suppressed at random (false) of by suppressing the n% of lower confidence (true) + * Weakens the ontology network of n% */ - public static OntologyNetwork weakenAlignments( OntologyNetwork on, double n, boolean threshold ) throws AlignmentException { - if ( n < 0. || n > 1. ) - throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); - OntologyNetwork newon = new BasicOntologyNetwork(); - for ( URI ontouri : on.getOntologies() ){ - newon.addOntology( ontouri ); - } - for ( Alignment al : on.getAlignments() ){ - Alignment newal = (Alignment)al.clone(); - if ( threshold ) { - newal.cut( "perc", 1.-n ); - } else { - int size = newal.nbCells(); - // -------------------------------------------------------------------- - // JE: Here is a tricky one. - // Using collection schuffle randomly reorganises a list - // Then choosing the fist n% and destroying them in the Set is performed - // The complexity is O(copy=N)+O(shuffle=N)+n%*O(delete=N) - // That's not bad... (and also avoid checking if the same nb is drawn) - // But in practice other solutions may be better, like: - // Generating randomly n%*N numbers between 0 and N (util.Random) - // Ordering them - // Traversing the initial structure and deleting the choosen ones... - // This one (deleting when traversing) is tricky in Java. - // -------------------------------------------------------------------- - ArrayList<Cell> array = new ArrayList<Cell>( size ); - for ( Cell c : newal ) { - array.add( c ); - } - Collections.shuffle( array ); - for ( int i = (int)(n*size)-1; i >= 0; i-- ){ - newal.remCell( array.get( i ) ); - } - } - newon.addAlignment( newal ); - } - return newon; - } - - /** - * randomly drops n% of all alignments - * n is a number between 0. and 1. - * Returns a brand new BasicOntologyNetwork (with the initial alignments) - */ - public static OntologyNetwork dropAlignments( OntologyNetwork on, double n ) throws AlignmentException { - //System.err.println( " >>>> "+n ); - if ( n < 0. || n > 1. ) - throw new AlignmentException( "Argument must be between 0 and 1.: "+n ); - return dropAlignments( on, (int)(n*on.getAlignments().size()) ); - } - - public static OntologyNetwork dropAlignments( OntologyNetwork on, int n ) throws AlignmentException { - //System.err.println( " >>>> "+n ); - if ( n < 0 || n > on.getAlignments().size() ) - throw new AlignmentException( "Argument must be a positive integer: "+n ); - OntologyNetwork newon = new BasicOntologyNetwork(); - for ( URI ontouri : on.getOntologies() ){ - newon.addOntology( ontouri ); - } - Set<Alignment> alignments = on.getAlignments(); - int size = alignments.size(); - ArrayList<Alignment> array = new ArrayList<Alignment>( size ); - for ( Alignment al : alignments ){ - array.add( al ); - } - Collections.shuffle( array ); - for ( int i = size - (int)(n*size); i > 0; i-- ) { - newon.addAlignment( array.get( i ) ); - } - return newon; - } - + public OntologyNetwork weaken( OntologyNetwork on, double n, Properties p ) throws AlignmentException; } diff --git a/test/src/OntologyNetworkTest.java b/test/src/OntologyNetworkTest.java index ee414d7e..fda54b39 100644 --- a/test/src/OntologyNetworkTest.java +++ b/test/src/OntologyNetworkTest.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 @@ -18,11 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//package test.com.acme.dona.dep; - import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import org.testng.annotations.BeforeClass; import org.testng.annotations.Configuration; import org.testng.annotations.Test; @@ -31,13 +30,11 @@ import org.testng.annotations.Test; import java.net.URI; import java.net.URISyntaxException; import java.util.Set; +import java.util.Properties; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; -// JE: this one is too much -//import org.omwg.mediation.parser.rdf.RDFParserException; - import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.parser.AlignmentParser; @@ -47,7 +44,11 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.OntologyNetwork; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; -import fr.inrialpes.exmo.align.util.OntologyNetworkWeakener; +import fr.inrialpes.exmo.align.gen.OntologyNetworkWeakener; +import fr.inrialpes.exmo.align.gen.NetworkAlignmentDropper; +import fr.inrialpes.exmo.align.gen.NetworkCorrespondenceDropper; +import fr.inrialpes.exmo.align.gen.NetworkAlignmentWeakener; +import fr.inrialpes.exmo.align.gen.NetworkDeconnector; public class OntologyNetworkTest { private OntologyNetwork noo = null; @@ -127,33 +128,263 @@ public class OntologyNetworkTest { } @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"}) - public void weakenTest() throws URISyntaxException, AlignmentException { + public void expandTest() throws URISyntaxException, AlignmentException { + + assertEquals( noo.getOntologies().size(), 4); + assertEquals( noo.getAlignments().size(), 2); + + Alignment al2 = new URIAlignment(); + al2.init( new URI("http://www.example.org/ontology1"), new URI("file:examples/rdf/edu.mit.visus.bibtex.owl") ); + al2.addAlignCell( new URI("http://www.example.org/ontology1#reviewedarticle"), new URI("http://purl.org/net/nknouf/ns/bibtex#Article"), "<", 1.0 ); + al2.addAlignCell( new URI("http://www.example.org/ontology1#journalarticle"), new URI("http://purl.org/net/nknouf/ns/bibtex#Article"), "<", 1.0 ); + al2.addAlignCell( new URI("http://www.example.org/ontology1#journalarticle"), new URI("http://purl.org/net/nknouf/ns/bibtex#Article"), "=", .5 ); + assertEquals( al2.nbCells(), 3); + noo.addAlignment( al2 ); + + al2 = new URIAlignment(); + al2.init( new URI("http://www.example.org/ontology2"), new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl") ); + al2.addAlignCell( new URI("http://www.example.org/ontology2#journalarticle"), new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Article"), "<", .78 ); + al2.addAlignCell( new URI("http://www.example.org/ontology2#article"), new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Article"), "=", 1.0 ); + al2.addAlignCell( new URI("http://www.example.org/ontology2#reference"), new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Publication"), "=", .6 ); + assertEquals( al2.nbCells(), 3); + noo.addAlignment( al2 ); + + al2 = new URIAlignment(); + al2.init( new URI("file:examples/rdf/edu.mit.visus.bibtex.owl"), new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl") ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasPublisher"), new URI("http://www.example.org/ontology1#publisher"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasURL"), new URI("http://www.example.org/ontology1#softCopyURI"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Inproceedings"), new URI("http://www.example.org/ontology1#InProceedings"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasEditor"), new URI("http://www.example.org/ontology1#editor"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasNumber"), new URI("http://www.example.org/ontology1#number"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasNote"), new URI("http://www.example.org/ontology1#note"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasType"), new URI("http://www.example.org/ontology1#type"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasBooktitle"), new URI("http://www.example.org/ontology1#booktitle"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasJournal"), new URI("http://www.example.org/ontology1#journal"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasKeywords"), new URI("http://www.example.org/ontology1#keyword"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Article"), new URI("http://www.example.org/ontology1#Article"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasChapter"), new URI("http://www.example.org/ontology1#chapter"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Techreport"), new URI("http://www.example.org/ontology1#TechReport"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasSchool"), new URI("http://www.example.org/ontology1#school"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Misc"), new URI("http://www.example.org/ontology1#Misc"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasPages"), new URI("http://www.example.org/ontology1#pages"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Phdthesis"), new URI("http://www.example.org/ontology1#PhdThesis"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Mastersthesis"), new URI("http://www.example.org/ontology1#MastersThesis"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Incollection"), new URI("http://www.example.org/ontology1#InCollection"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasAbstract"), new URI("http://www.example.org/ontology1#abstract"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasAddress"), new URI("http://www.example.org/ontology1#address"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Book"), new URI("http://www.example.org/ontology1#Book"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasSeries"), new URI("http://www.example.org/ontology1#series"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasTitle"), new URI("http://www.example.org/ontology1#title"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Inbook"), new URI("http://www.example.org/ontology1#InBook"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasInstitution"), new URI("http://www.example.org/ontology1#institution"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasEdition"), new URI("http://www.example.org/ontology1#edition"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasVolume"), new URI("http://www.example.org/ontology1#volume"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#Proceedings"), new URI("http://www.example.org/ontology1#Proceedings"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasSize"), new URI("http://www.example.org/ontology1#softCopySize"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasAuthor"), new URI("http://www.example.org/ontology1#author"), "=", 1.0 ); + al2.addAlignCell( new URI("http://purl.org/net/nknouf/ns/bibtex#hasOrganization"), new URI("http://www.example.org/ontology1#organization"), "=", 1.0 ); + assertEquals( al2.nbCells(), 32); + noo.addAlignment( al2 ); + + al2 = new URIAlignment(); + al2.init( new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl"), new URI("file:examples/rdf/edu.mit.visus.bibtex.owl") ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Article"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Article"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#volume"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasVolume"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#note"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasNote"), "=", 0.73 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#type"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasType"), "=", 0.73 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#address"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasAddress"), "=", 0.82 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#TechReport"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Techreport"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#SoftCopy"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Conference"), "=", 0.22 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#InBook"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Inbook"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#chapter"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasChapter"), "=", 0.82 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#series"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasSeries"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#author"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasAuthor"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Misc"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Misc"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Book"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Book"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#publishedOn"), new URI( "http://purl.org/net/nknouf/ns/bibtex#howPublished"), "=", 0.78 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#firstAuthor"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasAuthor"), "=", 0.6 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#InCollection"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Incollection"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Resource"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Phdthesis"), "=", 0.23 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#publisher"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasPublisher"), "=", 0.86 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#school"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasSchool"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#softCopy"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasCopyright"), "=", 0.4 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#version"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasEdition"), "=", 0.35 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#softCopyURI"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasCopyright"), "=", 0.35 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#description"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasEdition"), "=", 0.38 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#MastersThesis"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Mastersthesis"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Proceedings"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Proceedings"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#PhdThesis"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Phdthesis"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#institution"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasInstitution"), "=", 0.88 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#number"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasNumber"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#keyword"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasKeywords"), "=", 0.78 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#softCopyFormat"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasCopyright"), "=", 0.31 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#title"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasTitle"), "=", 0.77 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#journal"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasJournal"), "=", 0.82 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/person.owl#Person"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Mastersthesis"), "=", 0.32 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#InProceedings"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Inproceedings"), "=", 1.0 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#edition"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasEdition"), "=", 0.82 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#abstract"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasAbstract"), "=", 0.84 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#editor"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasEditor"), "=", 0.8 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#counter"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasChapter"), "=", 0.35 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#softCopySize"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasSize"), "=", 0.42 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#organization"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasOrganization"), "=", 0.89 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#pages"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasPages"), "=", 0.77 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#booktitle"), new URI( "http://purl.org/net/nknouf/ns/bibtex#hasBooktitle"), "=", 0.86 ); + al2.addAlignCell( new URI("http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#Publication"), new URI( "http://purl.org/net/nknouf/ns/bibtex#Unpublished"), "=", 0.45 ); + assertEquals( al2.nbCells(), 43); + noo.addAlignment( al2 ); + + assertEquals( noo.getOntologies().size(), 4); + assertEquals( noo.getAlignments().size(), 6); + + URI u = new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl"); + assertEquals( noo.getTargetingAlignments(u).size(), 2 ); + assertEquals( noo.getSourceAlignments(u).size(), 1 ); + u = new URI("file:examples/rdf/edu.mit.visus.bibtex.owl"); + assertEquals( noo.getTargetingAlignments(u).size(), 2 ); + assertEquals( noo.getSourceAlignments(u).size(), 1 ); + u = new URI("http://www.example.org/ontology1"); + assertEquals( noo.getTargetingAlignments(u).size(), 0 ); + assertEquals( noo.getSourceAlignments(u).size(), 3 ); + u = new URI("http://www.example.org/ontology2"); + assertEquals( noo.getTargetingAlignments(u).size(), 2 ); + assertEquals( noo.getSourceAlignments(u).size(), 1 ); + } + + // Then I would apply the weakening + @Test(groups = { "full", "raw" }, dependsOnMethods = {"expandTest"}) + public void weakenAlignmentDropper() throws URISyntaxException, AlignmentException { OntologyNetwork noon = null; - noon = OntologyNetworkWeakener.weakenAlignments( noo, 1., true ); + OntologyNetworkWeakener weakener = new NetworkAlignmentDropper(); + Properties propThres = new Properties(); + noon = weakener.weaken( noo, 1., propThres ); Set<Alignment> s = noon.getTargetingAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")); + assertEquals( noon.getAlignments().size(), 0); + noon = weakener.weaken( noo, .5, propThres ); + assertEquals( noon.getAlignments().size(), 3); + noon = weakener.weaken( noo, 0., propThres ); + assertEquals( noon.getAlignments().size(), 6); + noon = weakener.weaken( noo, 1., (Properties)null ); + assertEquals( noon.getAlignments().size(), 0); + noon = weakener.weaken( noo, .5, (Properties)null ); + assertEquals( noon.getAlignments().size(), 3); + noon = weakener.weaken( noo, 0., (Properties)null ); + assertEquals( noon.getAlignments().size(), 6); + } + //@Test(groups = { "full", "raw" }, dependsOnMethods = {"expandTest"}) + // public void weakenNetworkDeconnector() throws URISyntaxException, AlignmentException { + //} - noon = OntologyNetworkWeakener.weakenAlignments( noo, .5, true ); - noon = OntologyNetworkWeakener.weakenAlignments( noo, 0., true ); - noon = OntologyNetworkWeakener.weakenAlignments( noo, 0., false ); - noon = OntologyNetworkWeakener.weakenAlignments( noo, .5, false ); - noon = OntologyNetworkWeakener.weakenAlignments( noo, 1., false ); + @Test(groups = { "full", "raw" }, dependsOnMethods = {"expandTest"}) + public void weakenCorrespondenceDropper() throws URISyntaxException, AlignmentException { + OntologyNetwork noon = null; + OntologyNetworkWeakener weakener = new NetworkCorrespondenceDropper(); + Properties propThres = new Properties(); + propThres.setProperty( "threshold", "true" ); + + int init = 0; + for ( Alignment al : noo.getAlignments() ) { init += al.nbCells(); } + + int size = 0; + noon = weakener.weaken( noo, 1., propThres ); + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertEquals( size, 0); + noon = weakener.weaken( noo, .5, propThres ); + size = 0; + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertTrue( init/2 <= size && size <= init/2 + 1, "Expected "+init/2+" but got "+size ); + noon = weakener.weaken( noo, 0., propThres ); + size = 0; + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertEquals( size, init); + noon = weakener.weaken( noo, 1., (Properties)null ); + size = 0; + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertEquals( size, 0); + noon = weakener.weaken( noo, .5, (Properties)null ); + size = 0; + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertTrue( init/2 <= size && size <= init/2 + 1, "Expected "+init/2+" but got "+size ); + noon = weakener.weaken( noo, 0., (Properties)null ); + size = 0; + for ( Alignment al : noon.getAlignments() ) { size += al.nbCells(); } + assertEquals( size, init); + } + + @Test(groups = { "full", "raw" }, dependsOnMethods = {"expandTest"}) + public void weakenAlignmentWeakener() throws URISyntaxException, AlignmentException { + OntologyNetwork noon = null; + OntologyNetworkWeakener weakener = new NetworkAlignmentWeakener(); + Properties propThres = new Properties(); + int init = noo.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(); + + propThres.setProperty( "threshold", "true" ); + noon = weakener.weaken( noo, 1., propThres ); + assertEquals( noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(), 0); + noon = weakener.weaken( noo, .5, propThres ); + int val = noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(); + assertTrue( init/2 <= val && val <= init/2+1, "Expected "+init/2+" but got "+val ); + noon = weakener.weaken( noo, 0., propThres ); + assertEquals( noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(), init); + noon = weakener.weaken( noo, 1., (Properties)null ); + assertEquals( noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(), 0); + noon = weakener.weaken( noo, .5, (Properties)null ); + val = noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(); + assertTrue( init/2 <= val && val <= init/2+1, "Expected "+init/2+" but got "+val ); + noon = weakener.weaken( noo, 0., (Properties)null ); + assertEquals( noon.getSourceAlignments(new URI("file:examples/rdf/edu.umbc.ebiquity.publication.owl")).iterator().next().nbCells(), init); + } + + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNADExceptionTest10() throws URISyntaxException, AlignmentException { + new NetworkAlignmentDropper().weaken( (OntologyNetwork)null, .5, (Properties)null ); + } + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNADExceptionTest11() throws URISyntaxException, AlignmentException { + new NetworkAlignmentDropper().weaken( noo, 1.2, (Properties)null ); + } + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNADExceptionTest12() throws URISyntaxException, AlignmentException { + new NetworkAlignmentDropper().weaken( noo, -.2, (Properties)null ); } @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) - public void weakenExceptionTest1() throws URISyntaxException, AlignmentException { - OntologyNetworkWeakener.weakenAlignments( noo, 1.2, true ); + public void weakenNCDExceptionTest10() throws URISyntaxException, AlignmentException { + new NetworkCorrespondenceDropper().weaken( (OntologyNetwork)null, .5, (Properties)null ); + } + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNCDExceptionTest11() throws URISyntaxException, AlignmentException { + new NetworkCorrespondenceDropper().weaken( noo, 1.2, (Properties)null ); } @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) - public void weakenExceptionTest2() throws URISyntaxException, AlignmentException { - OntologyNetworkWeakener.weakenAlignments( noo, -.2, true ); + public void weakenNCDExceptionTest12() throws URISyntaxException, AlignmentException { + new NetworkCorrespondenceDropper().weaken( noo, -.2, (Properties)null ); + } + + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNAWExceptionTest10() throws URISyntaxException, AlignmentException { + new NetworkAlignmentWeakener().weaken( (OntologyNetwork)null, .5, (Properties)null ); + } + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNAWExceptionTest11() throws URISyntaxException, AlignmentException { + new NetworkAlignmentWeakener().weaken( noo, 1.2, (Properties)null ); + } + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNAWExceptionTest12() throws URISyntaxException, AlignmentException { + new NetworkAlignmentWeakener().weaken( noo, -.2, (Properties)null ); + } + + @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) + public void weakenNDExceptionTest10() throws URISyntaxException, AlignmentException { + new NetworkDeconnector().weaken( (OntologyNetwork)null, .5, (Properties)null ); } @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) - public void weakenExceptionTest3() throws URISyntaxException, AlignmentException { - OntologyNetworkWeakener.weakenAlignments( noo, 1.2, false ); + public void weakenNDExceptionTest11() throws URISyntaxException, AlignmentException { + new NetworkDeconnector().weaken( noo, 1.2, (Properties)null ); } @Test(groups = { "full", "raw" }, dependsOnMethods = {"lambdaTest"},expectedExceptions = AlignmentException.class) - public void weakenExceptionTest4() throws URISyntaxException, AlignmentException { - OntologyNetworkWeakener.weakenAlignments( noo, -.2, false ); + public void weakenNDExceptionTest12() throws URISyntaxException, AlignmentException { + new NetworkDeconnector().weaken( noo, -.2, (Properties)null ); } } -- GitLab