Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bed26c32 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- updated equal implementation (suppressed in most cases)

- added getObjectAsURI returning URIs in EDOALCell
parent c46a23ad
No related branches found
No related tags found
No related merge requests found
......@@ -64,12 +64,14 @@ public class BasicCell implements Cell, Comparable<Cell> {
};
// the strength must be compared with regard to abstract types
public boolean equals( Cell c ) {
if ( c instanceof BasicCell ){
return ( object1 == c.getObject1() && object2 == c.getObject2() && strength == c.getStrength() && (relation.equals( c.getRelation() )) );
} else {
return false;
}
public boolean equals( Object c ) {
if ( c != null && c instanceof Cell ) return equals( (Cell)c );
else return false;
}
public boolean equals ( Cell c ) {
if ( c == null ) return false;
else return ( object1.equals(((BasicCell)c).getObject1()) && object2.equals(((BasicCell)c).getObject2()) && strength == ((BasicCell)c).getStrength() && (relation.equals( ((BasicCell)c).getRelation() )) );
}
public int hashCode() {
......
......@@ -56,21 +56,6 @@ public class ObjectCell extends BasicCell {
super( id, ob1, ob2, rel, m );
};
// the strength must be compared with regard to abstract types
public boolean equals( Cell c ) {
if ( c instanceof ObjectCell ){
return ( object1 == c.getObject1() && object2 == c.getObject2() && strength == c.getStrength() && (relation.equals( c.getRelation() )) );
} else {
return false;
}
}
public int hashCode() {
return 31 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.);
}
/**
* Used to order the cells in an alignment:
* -- this > c iff this.getStrength() < c.getStrength() --
......
......@@ -67,19 +67,6 @@ public class URICell extends BasicCell {
// super( ob1, ob2, rel, m );
//};
// the strength must be compared with regard to abstract types
public boolean equals( Cell c ) {
if ( c instanceof URICell ){
return ( object1.equals(c.getObject1()) && object2.equals(c.getObject2()) && strength == c.getStrength() && (relation.equals( c.getRelation() )) );
} else {
return false;
}
}
public int hashCode() {
return 23 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.);
}
public URI getObject1AsURI( Alignment al ) throws AlignmentException {
return (URI)object1;
};
......
......@@ -78,25 +78,14 @@ public class EDOALCell extends BasicCell {
super( id, (Object)ob1, (Object)ob2, rel, m );
};
public boolean equals( Cell c ) {
if ( c instanceof EDOALCell ){
return ( object1.equals(c.getObject1()) && object2.equals(c.getObject2()) && strength == c.getStrength() && (relation.equals( c.getRelation() )) );
} else {
return false;
}
}
public int hashCode() {
return 11 + 7*object1.hashCode() + 11*object2.hashCode() + relation.hashCode() + (int)(strength*150.);
}
// JE// Maybe do it in case Expressions have URI
public URI getObject1AsURI( Alignment al ) throws AlignmentException {
return null;
if ( object1 instanceof Id ) return ((Id)object1).getURI();
else return null;
//throw new AlignmentException( "Cannot convert to URI "+object1 );
}
public URI getObject2AsURI( Alignment al ) throws AlignmentException {
return null;
if ( object2 instanceof Id ) return ((Id)object2).getURI();
else return null;
//throw new AlignmentException( "Cannot convert to URI "+object2 );
}
......
......@@ -37,6 +37,7 @@ import fr.inrialpes.exmo.align.impl.BasicAlignment;
import fr.inrialpes.exmo.align.impl.BasicCell;
import fr.inrialpes.exmo.align.impl.BasicRelation;
import fr.inrialpes.exmo.align.impl.URIAlignment;
import fr.inrialpes.exmo.align.impl.URICell;
import fr.inrialpes.exmo.align.parser.AlignmentParser;
import org.semanticweb.owl.align.Alignment;
......@@ -71,7 +72,8 @@ public class BasicAlignmentTest {
assertEquals( result.nbCells(), 1, "Alignment should contain 1 cell" );
}
private static Cell cell1, cell2, cell3, cell4, cell5;
private static Cell cell1, cell2, cell3, cell4, cell5, cell6;
private static Cell ucell1, ucell2, ucell3, ucell4, ucell5, ucell6;
/**
* @throws java.lang.Exception
......@@ -81,6 +83,7 @@ public class BasicAlignmentTest {
URI cls1 = URI.create( "http://example.org/test#cls1" );
URI cls2 = URI.create( "http://example.org/test#cls2" );
URI cls3 = URI.create( "http://example.org/test#cls3" );
URI cls4 = URI.create( "http://example.org/test#cls3" );
Relation rel1 = new BasicRelation( "=" );
Relation rel2 = new BasicRelation( "<" );
cell1 = new BasicCell( "1", cls1, cls2, rel1, 0);
......@@ -88,16 +91,17 @@ public class BasicAlignmentTest {
cell3 = new BasicCell( "3", cls1, cls3, rel1, 0);
cell4 = new BasicCell( "4", cls1, cls2, rel2, 0);
cell5 = new BasicCell( "5", cls1, cls2, rel1, .5);
cell6 = new BasicCell( "6", cls1, cls4, rel1, 0);
ucell1 = new URICell( "1", cls1, cls2, rel1, 0);
ucell2 = new URICell( "2", cls1, cls2, rel1, 0);
ucell3 = new URICell( "3", cls1, cls3, rel1, 0);
ucell4 = new URICell( "4", cls1, cls2, rel2, 0);
ucell5 = new URICell( "5", cls1, cls2, rel1, .5);
ucell6 = new URICell( "6", cls1, cls4, rel1, 0);
assertTrue( cls3.equals( cls4 ) ); // Check that URIs are correct!
assertTrue( cls3.hashCode() == cls4.hashCode() );
}
/**
* @throws java.lang.Exception
*/
@AfterClass(groups = { "raw", "full" }, alwaysRun = true )
public static void tearDownAfterClass() throws Exception {
cell1 = cell2 = cell3 = cell4 = cell5 = null;
}
@Test(groups = { "full", "raw" })
public void testEquals() {
assertTrue( cell1.equals( cell1 ) ); // 1 == 1
......@@ -107,6 +111,7 @@ public class BasicAlignmentTest {
assertTrue( !cell1.equals( cell3 ) ); // 1 != 3
assertTrue( !cell1.equals( cell4 ) ); // 1 != 4
assertTrue( !cell1.equals( cell5 ) ); // 1 != 5
assertTrue( cell6.equals( cell3 ) ); // 6 == 3
}
@Test(groups = { "full", "raw" })
......@@ -118,6 +123,32 @@ public class BasicAlignmentTest {
assertTrue( !cell1.equals( (Object) cell3 ) ); // 1 != 3
assertTrue( !cell1.equals( (Object) cell4 ) ); // 1 != 4
assertTrue( !cell1.equals( (Object) cell5 ) ); // 1 != 5
assertTrue( cell6.equals( (Object)cell3 ) ); // 6 == 3
}
// These have been added because equals is not redefined in URICell anymore
@Test(groups = { "full", "raw" })
public void testUEquals() {
assertTrue( ucell1.equals( ucell1 ) ); // 1 == 1
assertTrue( ucell1.equals( ucell2 ) ); // 1 == 2
assertTrue( ucell2.equals( ucell1 ) ); // 2 == 1
assertTrue( !ucell1.equals( null ) ); // 1 != null
assertTrue( !ucell1.equals( ucell3 ) ); // 1 != 3
assertTrue( !ucell1.equals( ucell4 ) ); // 1 != 4
assertTrue( !ucell1.equals( ucell5 ) ); // 1 != 5
assertTrue( cell6.equals( cell3 ) ); // 6 == 3
}
@Test(groups = { "full", "raw" })
public void testUEqualsObject() {
assertTrue( ucell1.equals( (Object) ucell1 ) ); // 1 == 1
assertTrue( ucell1.equals( (Object) ucell2 ) ); // 1 == 2
assertTrue( ucell2.equals( (Object) ucell1 ) ); // 2 == 1
assertTrue( !ucell1.equals( (Object) null ) ); // 1 != null
assertTrue( !ucell1.equals( (Object) ucell3 ) ); // 1 != 3
assertTrue( !ucell1.equals( (Object) ucell4 ) ); // 1 != 4
assertTrue( !ucell1.equals( (Object) ucell5 ) ); // 1 != 5
assertTrue( ucell6.equals( (Object)ucell3 ) ); // 6 == 3
}
@Test(groups = { "full", "raw" })
......@@ -125,6 +156,15 @@ public class BasicAlignmentTest {
assertTrue( cell1.equals( cell2 ) && cell1.hashCode() == cell2.hashCode() );
assertTrue( cell1.equals( cell1 ) && cell1.hashCode() == cell1.hashCode() );
assertTrue( cell2.equals( cell1 ) && cell2.hashCode() == cell1.hashCode() );
assertTrue( cell3.equals( cell6 ) && cell3.hashCode() == cell6.hashCode() );
}
/**
* @throws java.lang.Exception
*/
@AfterClass(groups = { "raw", "full" }, alwaysRun = true )
public static void tearDownAfterClass() throws Exception {
cell1 = cell2 = cell3 = cell4 = cell5 = cell6 = null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment