From d3e1cbfb128f82a695090110bda1d005a56bd249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Thu, 22 Oct 2015 12:55:05 +0000 Subject: [PATCH] - Improved algebras of relations declaration - added support for non integral algebras - added createRelation from BaseRelations - added isIdRelation(), getIdRelation(), getEmptyRelation(), getNoInfoRelation() --- .../align/impl/rel/A16AlgebraRelation.java | 97 +++++++++++-------- .../align/impl/rel/A2AlgebraRelation.java | 60 +++++++----- .../align/impl/rel/A5AlgebraRelation.java | 60 +++++++----- 3 files changed, 131 insertions(+), 86 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/impl/rel/A16AlgebraRelation.java b/src/fr/inrialpes/exmo/align/impl/rel/A16AlgebraRelation.java index e6ea99bb..c7608270 100644 --- a/src/fr/inrialpes/exmo/align/impl/rel/A16AlgebraRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/rel/A16AlgebraRelation.java @@ -44,46 +44,30 @@ import org.slf4j.LoggerFactory; public class A16AlgebraRelation extends BitSetAlgebraRelation<A16BaseRelation> { final static Logger logger = LoggerFactory.getLogger( A16AlgebraRelation.class ); - /** Creation **/ - private A16AlgebraRelation(){}; - - public A16AlgebraRelation( String rels ) throws AlignmentException { - if ( size == -1 ) init(); - relset = instance0.read( rels ); - } - - public static A16AlgebraRelation createRelation( String rels ) throws AlignmentException { - return new A16AlgebraRelation( rels ); - } - - /** - * This is private because it refers to the implementation as BitSet - */ - private A16AlgebraRelation( BitSet rels ) { - super( rels ); - } - protected static void init() { protoinit(); - declareRelation( A16BaseRelation.EQ_N, A16BaseRelation.EQ_N ); - declareRelation( A16BaseRelation.SUBSUME, A16BaseRelation.SUBSUMED ); - declareRelation( A16BaseRelation.SUBSUMED, A16BaseRelation.SUBSUME ); - declareRelation( A16BaseRelation.OVERLAP, A16BaseRelation.OVERLAP ); - declareRelation( A16BaseRelation.DISJOINT, A16BaseRelation.DISJOINT ); - declareRelation( A16BaseRelation.HAS, A16BaseRelation.ISA ); - declareRelation( A16BaseRelation.HASNOT, A16BaseRelation.ISNOT ); - declareRelation( A16BaseRelation.ISA, A16BaseRelation.HAS ); - declareRelation( A16BaseRelation.ISNOT, A16BaseRelation.HASNOT ); - declareRelation( A16BaseRelation.EQ_I, A16BaseRelation.EQ_I ); - declareRelation( A16BaseRelation.NOTEQ_I, A16BaseRelation.NOTEQ_I ); - declareRelation( A16BaseRelation.NE, A16BaseRelation.EN ); - declareRelation( A16BaseRelation.IE, A16BaseRelation.EI ); - declareRelation( A16BaseRelation.EQ_E, A16BaseRelation.EQ_E ); - declareRelation( A16BaseRelation.EN, A16BaseRelation.NE ); - declareRelation( A16BaseRelation.EI, A16BaseRelation.IE ); - - initStructures(); - + // Declare relations + declareRelation( A16BaseRelation.EQ_N, A16BaseRelation.EQ_N ); // Equals non empty classes + declareRelation( A16BaseRelation.SUBSUME, A16BaseRelation.SUBSUMED ); // Subsumes a non empty classe + declareRelation( A16BaseRelation.SUBSUMED, A16BaseRelation.SUBSUME ); // Is subsumed and non empty + declareRelation( A16BaseRelation.OVERLAP, A16BaseRelation.OVERLAP ); // Overlaping classes + declareRelation( A16BaseRelation.DISJOINT, A16BaseRelation.DISJOINT );// Disjoint + declareRelation( A16BaseRelation.HAS, A16BaseRelation.ISA ); // Instance belong to class + declareRelation( A16BaseRelation.HASNOT, A16BaseRelation.ISNOT ); // Instance does not belong to class + declareRelation( A16BaseRelation.ISA, A16BaseRelation.HAS ); // Class has instance + declareRelation( A16BaseRelation.ISNOT, A16BaseRelation.HASNOT ); // Class has no instance + declareRelation( A16BaseRelation.EQ_I, A16BaseRelation.EQ_I ); // Equal instances + declareRelation( A16BaseRelation.NOTEQ_I, A16BaseRelation.NOTEQ_I ); // Different instance + declareRelation( A16BaseRelation.NE, A16BaseRelation.EN ); // Is subsumed by and empty + declareRelation( A16BaseRelation.IE, A16BaseRelation.EI ); // Individual not belonging to empty class + declareRelation( A16BaseRelation.EQ_E, A16BaseRelation.EQ_E ); // Equal empty classes + declareRelation( A16BaseRelation.EN, A16BaseRelation.NE ); // Subsumes an empty classe + declareRelation( A16BaseRelation.EI, A16BaseRelation.IE ); // Empty class not containing individual + + // Declare id relation + initStructures( A16BaseRelation.EQ_N, A16BaseRelation.EQ_E, A16BaseRelation.EQ_I ); + + // Declare composition table // ---- EQ_N o( A16BaseRelation.EQ_N, A16BaseRelation.EQ_N, A16BaseRelation.EQ_N ); @@ -220,8 +204,6 @@ public class A16AlgebraRelation extends BitSetAlgebraRelation<A16BaseRelation> { A16BaseRelation.EI ); o( A16BaseRelation.EN, A16BaseRelation.NE, A16BaseRelation.EQ_E ); - - // ---- EQ_I o( A16BaseRelation.EQ_I, A16BaseRelation.EQ_I, A16BaseRelation.EQ_I ); @@ -306,6 +288,32 @@ public class A16AlgebraRelation extends BitSetAlgebraRelation<A16BaseRelation> { * Unfortunately, this MUST be copied in all class. **********************************************************************/ + /** Creation **/ + private A16AlgebraRelation(){}; + + public A16AlgebraRelation( String rels ) throws AlignmentException { + if ( size == -1 ) init(); + relset = instance0.read( rels ); + } + + public static A16AlgebraRelation createRelation( String rels ) throws AlignmentException { + return new A16AlgebraRelation( rels ); + } + + public static A16AlgebraRelation createRelation( A16BaseRelation... rels ) throws AlignmentException { + if ( size == -1 ) init(); + A16AlgebraRelation newrel = new A16AlgebraRelation(); + for ( A16BaseRelation r: rels ) newrel.relset.set( r.index ); + return newrel; + } + + /** + * This is private because it refers to the implementation as BitSet + */ + private A16AlgebraRelation( BitSet rels ) { + super( rels ); + } + protected static HashMap<String,A16BaseRelation> relations = null; protected static Vector<A16BaseRelation> positions; @@ -329,13 +337,15 @@ public class A16AlgebraRelation extends BitSetAlgebraRelation<A16BaseRelation> { positions = new Vector<A16BaseRelation>(); } - protected static void initStructures() { + protected static void initStructures( A16BaseRelation... idrels ) { compositionTable = new BitSet[size][size]; for( int i=0; i < size; i++ ) for( int j=0; j < size; j++ ) compositionTable[i][j] = new BitSet( size ); BitSet bs = new BitSet( size ); - bs.set( 0 ); + for( A16BaseRelation rel : idrels ) { + bs.set( rel.index ); + } instance0 = new A16AlgebraRelation( bs ); bs = new BitSet( size ); emptySet = new A16AlgebraRelation( bs ); @@ -428,5 +438,8 @@ public class A16AlgebraRelation extends BitSetAlgebraRelation<A16BaseRelation> { return instance0; } + public boolean isIdRelation() { + return instance0.entails( this ); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/rel/A2AlgebraRelation.java b/src/fr/inrialpes/exmo/align/impl/rel/A2AlgebraRelation.java index c0a5337b..9717328e 100644 --- a/src/fr/inrialpes/exmo/align/impl/rel/A2AlgebraRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/rel/A2AlgebraRelation.java @@ -46,30 +46,14 @@ import org.slf4j.LoggerFactory; public class A2AlgebraRelation extends BitSetAlgebraRelation<A2BaseRelation> { final static Logger logger = LoggerFactory.getLogger( A2AlgebraRelation.class ); - /** Creation **/ - private A2AlgebraRelation(){}; - - public A2AlgebraRelation( String rels ) throws AlignmentException { - if ( size == -1 ) init(); - relset = instance0.read( rels ); - } - - public static A2AlgebraRelation createRelation( String rels ) throws AlignmentException { - return new A2AlgebraRelation( rels ); - } - - /** - * This is private because it refers to the implementation as BitSet - */ - private A2AlgebraRelation( BitSet rels ) { - super( rels ); - } - protected static void init() { protoinit(); + // Declare relations declareRelation( A2BaseRelation.EQUIV, A2BaseRelation.EQUIV ); declareRelation( A2BaseRelation.DIFF, A2BaseRelation.DIFF ); - initStructures(); + // Declare id relation + initStructures( A2BaseRelation.EQUIV ); + // Declare composition table: here through compatible triples /* o( A2BaseRelation.EQUIV, A2BaseRelation.EQUIV, A2BaseRelation.EQUIV ); o( A2BaseRelation.EQUIV, A2BaseRelation.DIFF, A2BaseRelation.DIFF ); @@ -87,6 +71,32 @@ public class A2AlgebraRelation extends BitSetAlgebraRelation<A2BaseRelation> { * Unfortunately, this MUST be copied in all class. **********************************************************************/ + /** Creation **/ + private A2AlgebraRelation(){}; + + public A2AlgebraRelation( String rels ) throws AlignmentException { + if ( size == -1 ) init(); + relset = instance0.read( rels ); + } + + public static A2AlgebraRelation createRelation( String rels ) throws AlignmentException { + return new A2AlgebraRelation( rels ); + } + + public static A2AlgebraRelation createRelation( A2BaseRelation... rels ) throws AlignmentException { + if ( size == -1 ) init(); + A2AlgebraRelation newrel = new A2AlgebraRelation(); + for ( A2BaseRelation r: rels ) newrel.relset.set( r.index ); + return newrel; + } + + /** + * This is private because it refers to the implementation as BitSet + */ + private A2AlgebraRelation( BitSet rels ) { + super( rels ); + } + protected static HashMap<String,A2BaseRelation> relations = null; protected static Vector<A2BaseRelation> positions; @@ -110,13 +120,15 @@ public class A2AlgebraRelation extends BitSetAlgebraRelation<A2BaseRelation> { positions = new Vector<A2BaseRelation>(); } - protected static void initStructures() { + protected static void initStructures( A2BaseRelation... idrels ) { compositionTable = new BitSet[size][size]; for( int i=0; i < size; i++ ) for( int j=0; j < size; j++ ) compositionTable[i][j] = new BitSet( size ); BitSet bs = new BitSet( size ); - bs.set( 0 ); + for( A2BaseRelation rel : idrels ) { + bs.set( rel.index ); + } instance0 = new A2AlgebraRelation( bs ); bs = new BitSet( size ); emptySet = new A2AlgebraRelation( bs ); @@ -209,5 +221,9 @@ public class A2AlgebraRelation extends BitSetAlgebraRelation<A2BaseRelation> { if ( size == -1 ) init(); return instance0; } + + public boolean isIdRelation() { + return instance0.entails( this ); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/rel/A5AlgebraRelation.java b/src/fr/inrialpes/exmo/align/impl/rel/A5AlgebraRelation.java index 2c7cf0e5..8fed7c12 100644 --- a/src/fr/inrialpes/exmo/align/impl/rel/A5AlgebraRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/rel/A5AlgebraRelation.java @@ -46,33 +46,17 @@ import org.slf4j.LoggerFactory; public class A5AlgebraRelation extends BitSetAlgebraRelation<A5BaseRelation> { final static Logger logger = LoggerFactory.getLogger( A5AlgebraRelation.class ); - /** Creation **/ - private A5AlgebraRelation(){}; - - public A5AlgebraRelation( String rels ) throws AlignmentException { - if ( size == -1 ) init(); - relset = instance0.read( rels ); - } - - public static A5AlgebraRelation createRelation( String rels ) throws AlignmentException { - return new A5AlgebraRelation( rels ); - } - - /** - * This is private because it refers to the implementation as BitSet - */ - private A5AlgebraRelation( BitSet rels ) { - super( rels ); - } - protected static void init() { protoinit(); + // Declare relations declareRelation( A5BaseRelation.EQUIV, A5BaseRelation.EQUIV ); declareRelation( A5BaseRelation.SUBSUME, A5BaseRelation.SUBSUMED ); declareRelation( A5BaseRelation.SUBSUMED, A5BaseRelation.SUBSUME ); declareRelation( A5BaseRelation.OVERLAP, A5BaseRelation.OVERLAP ); declareRelation( A5BaseRelation.DISJOINT, A5BaseRelation.DISJOINT ); - initStructures(); + // Declare id relation + initStructures( A5BaseRelation.EQUIV ); + // Declare composition table // ---- EQUIV o( A5BaseRelation.EQUIV, A5BaseRelation.EQUIV, A5BaseRelation.EQUIV ); @@ -136,6 +120,32 @@ public class A5AlgebraRelation extends BitSetAlgebraRelation<A5BaseRelation> { * Unfortunately, this MUST be copied in all class. **********************************************************************/ + /** Creation **/ + private A5AlgebraRelation(){}; + + public A5AlgebraRelation( String rels ) throws AlignmentException { + if ( size == -1 ) init(); + relset = instance0.read( rels ); + } + + public static A5AlgebraRelation createRelation( String rels ) throws AlignmentException { + return new A5AlgebraRelation( rels ); + } + + public static A5AlgebraRelation createRelation( A5BaseRelation... rels ) throws AlignmentException { + if ( size == -1 ) init(); + A5AlgebraRelation newrel = new A5AlgebraRelation(); + for ( A5BaseRelation r: rels ) newrel.relset.set( r.index ); + return newrel; + } + + /** + * This is private because it refers to the implementation as BitSet + */ + private A5AlgebraRelation( BitSet rels ) { + super( rels ); + } + protected static HashMap<String,A5BaseRelation> relations = null; protected static Vector<A5BaseRelation> positions; @@ -159,13 +169,15 @@ public class A5AlgebraRelation extends BitSetAlgebraRelation<A5BaseRelation> { positions = new Vector<A5BaseRelation>(); } - protected static void initStructures() { + protected static void initStructures( A5BaseRelation... idrels ) { compositionTable = new BitSet[size][size]; for( int i=0; i < size; i++ ) for( int j=0; j < size; j++ ) compositionTable[i][j] = new BitSet( size ); BitSet bs = new BitSet( size ); - bs.set( 0 ); + for( A5BaseRelation rel : idrels ) { + bs.set( rel.index ); + } instance0 = new A5AlgebraRelation( bs ); bs = new BitSet( size ); emptySet = new A5AlgebraRelation( bs ); @@ -258,5 +270,9 @@ public class A5AlgebraRelation extends BitSetAlgebraRelation<A5BaseRelation> { if ( size == -1 ) init(); return instance0; } + + public boolean isIdRelation() { + return instance0.entails( this ); + } } -- GitLab