diff --git a/README.TXT b/README.TXT index 10d0f4c052d6c9f6de89192bcfe21d5cbddac501..2e8ad9c05285ed3e4dd49645d77f32cee6573693 100644 --- a/README.TXT +++ b/README.TXT @@ -1,6 +1,6 @@ ####################################################################### # Ontology alignment API and implementation # -# 29/02/2008, version 3.2+ # +# 29/02/2008, version 3.3 # ####################################################################### Copyright (C) 2003 The University of Manchester. @@ -106,17 +106,19 @@ build.xml the Ant build file for compiling and testing classes/ empty directory for compiling the sources distrib/ some files for generating new jarfiles dtd/ contains the ontoalign DTDs (and schemas) +examples/ examples of use of the API and server html/ contains some documentation in HTML format (includes relnotes.html) html/tutorial/ web based tutorial javadoc/ javadoc API documentation in HTML (not very useful) lib/ contains align.jar, alignwn.jar, procalign.jar, alignsvc.jar and other necessary jarfiles -examples/ examples of use of the API and server +plugins/neon/ Plug-in for the NeOn toolkit src/ Java sources of ontoalign org.semanticweb.owl.align: the API fr.inrialpes.exmo.align.impl: basic implementation fr.inrialpes.exmo.align.util: utility wrapper functions fr.inrialpes.exmo.align.ling: WordNet-based implementation fr.inrialpes.exmo.align.service: Alignment Service - + fr.inrialpes.exmo.align.onto: Abstract ontology layer +test/ Unit tests for testng diff --git a/build.xml b/build.xml index 8cbe8279291ec0f90ac983a7ef5868b9222157b4..95a9dff2d4397136b81b664538b251c19af4f9c5 100644 --- a/build.xml +++ b/build.xml @@ -192,8 +192,9 @@ <echo message="Cleaning tests..."/> <delete> <fileset dir="test/classes" includes="**/*.class"/> - <fileset dir="test/html" includes="**/*.html"/> + <fileset dir="test/html" includes="**/*.html,**/*.xml,**/*.css"/> </delete> + <delete file="test/html/Ant\ suite"/> </target> <!-- tested --> diff --git a/test/src/OWLAPIAlignmentTest.java b/test/src/OWLAPIAlignmentTest.java index 40880c72f649a73387ded41b5721139a40d25ab3..da64a83117201929972fe79f4806437917b8a012 100644 --- a/test/src/OWLAPIAlignmentTest.java +++ b/test/src/OWLAPIAlignmentTest.java @@ -23,19 +23,44 @@ 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; //import org.testng.annotations.*; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLEntity; + +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.Cell; + import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.OWLAPICell; +import fr.inrialpes.exmo.align.impl.rel.EquivRelation; import fr.inrialpes.exmo.align.impl.URIAlignment; +import fr.inrialpes.exmo.align.impl.Annotations; +import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; import fr.inrialpes.exmo.align.onto.OntologyCache; +import fr.inrialpes.exmo.align.onto.LoadedOntology; +import fr.inrialpes.exmo.align.onto.Ontology; import fr.inrialpes.exmo.align.parser.AlignmentParser; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.FileOutputStream; +import java.net.URI; +import java.util.Set; + public class OWLAPIAlignmentTest { + private String localURIPrefix = "file://" + System.getProperty("user.dir"); + private OWLAPIAlignment alignment = null; + private Ontology onto1 = null; + private Ontology onto2 = null; @BeforeClass(groups = { "fast" }) private void init(){ @@ -44,13 +69,11 @@ public class OWLAPIAlignmentTest { @Test(groups = { "fast" }) public void aFastTest() { - //System.out.println("Fast test"); assertNotNull( alignment, "Alignment was null" ); } @Test(groups = { "full" }) public void loadingAndConvertingTest() throws Exception { - //System.out.println("Fast test"); assertNotNull( alignment, "Alignment was null" ); AlignmentParser aparser = new AlignmentParser( 0 ); assertNotNull( aparser, "AlignmentParser was null" ); @@ -58,9 +81,88 @@ public class OWLAPIAlignmentTest { assertNotNull( result, "URIAlignment(result) was null" ); alignment = OWLAPIAlignment.toOWLAPIAlignment( result, (OntologyCache)null ); assertNotNull( alignment, "toOWLAPIAlignment(result) was null" ); + result = alignment.toURIAlignment(); + assertNotNull( result, "toURIAlignment() was null" ); + assertTrue( result instanceof URIAlignment ); + } + + @Test(groups = { "full" }, dependsOnMethods = {"loadingAndConvertingTest"}) + public void basicAttributeTest() throws Exception { assertEquals( alignment.getLevel(), "0" ); assertEquals( alignment.getType(), "**" ); + assertEquals( alignment.getExtension( Annotations.ALIGNNS, Annotations.METHOD), "fr.inrialpes.exmo.align.impl.method.StringDistAlignment" ); + assertEquals( alignment.getExtension( Annotations.ALIGNNS, Annotations.TIME), "7" ); + } + + @Test(groups = { "full" }, dependsOnMethods = {"loadingAndConvertingTest"}) + public void ontologyTest() throws Exception { + onto1 = alignment.getOntologyObject1(); + onto2 = alignment.getOntologyObject2(); + assertTrue( onto1 instanceof LoadedOntology ); + assertTrue( onto2 instanceof LoadedOntology ); + assertTrue( alignment.getOntology1() instanceof OWLOntology ); + assertTrue( alignment.getOntology2() instanceof OWLOntology ); + assertEquals( alignment.getOntology1URI().toString(), "http://www.example.org/ontology1" ); + assertEquals( alignment.getOntology2URI().toString(), "http://www.example.org/ontology2" ); + assertEquals( onto1.getURI().toString(), "http://www.example.org/ontology1" ); + assertEquals( onto2.getURI().toString(), "http://www.example.org/ontology2" ); + assertEquals( onto1.getFile().toString(), localURIPrefix+"/examples/rdf/onto1.owl" ); + assertEquals( onto2.getFile().toString(), localURIPrefix+"/examples/rdf/onto2.owl" ); + assertEquals( onto1.getFormalism(), "OWL1.0" ); + assertEquals( onto2.getFormalism(), "OWL1.0" ); + assertEquals( onto1.getFormURI().toString(), "http://www.w3.org/2002/07/owl#" ); + assertEquals( onto2.getFormURI().toString(), "http://www.w3.org/2002/07/owl#" ); + } + + @Test(groups = { "full" }, dependsOnMethods = {"ontologyTest"}) + public void basicCellTest() throws Exception { assertEquals( alignment.nbCells(), 2 ); + Object ob2 = ((LoadedOntology)onto2).getEntity( new URI("http://www.example.org/ontology2#journalarticle") ); + assertTrue( ob2 instanceof OWLEntity ); + Set<Cell> s2 = alignment.getAlignCells2( ob2 ); + assertEquals( s2.size(), 2 ); + for( Cell c2 : s2 ){ + assertTrue( c2 instanceof OWLAPICell ); + assertTrue( c2.getRelation() instanceof EquivRelation ); + assertTrue( c2.getObject1() instanceof OWLEntity ); + } + Object ob1 = ((LoadedOntology)onto1).getEntity( new URI("http://www.example.org/ontology1#journalarticle") ); + assertTrue( ob1 instanceof OWLEntity ); + Set<Cell> s1 = alignment.getAlignCells1( ob1 ); + assertEquals( s1.size(), 1 ); + for( Cell c1 : s1 ){ + assertTrue( c1 instanceof OWLAPICell ); + assertTrue( c1.getRelation() instanceof EquivRelation ); + assertEquals( c1.getStrength(), 1. ); + assertTrue( c1.getObject2() instanceof OWLEntity ); + assertEquals( ((LoadedOntology)onto2).getEntityURI( c1.getObject2() ).toString(), "http://www.example.org/ontology2#journalarticle" ); + } + ob1 = ((LoadedOntology)onto1).getEntity( new URI("http://www.example.org/ontology1#reviewedarticle") ); + assertTrue( ob1 instanceof OWLEntity ); + s1 = alignment.getAlignCells1( ob1 ); + assertEquals( s1.size(), 1 ); + for( Cell c1 : s1 ){ + assertTrue( c1 instanceof OWLAPICell ); + assertTrue( c1.getRelation() instanceof EquivRelation ); + assertEquals( c1.getStrength(), .4666666666666667 ); + assertTrue( c1.getObject2() instanceof OWLEntity ); + assertEquals( ((LoadedOntology)onto2).getEntityURI( c1.getObject2() ).toString(), "http://www.example.org/ontology2#journalarticle" ); + } + } + + @Test(groups = { "full" }, dependsOnMethods = {"loadingAndConvertingTest"}) + public void rendererTest() throws Exception { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + //FileOutputStream stream = new FileOutputStream("result.rdf"); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + alignment.render( renderer ); + writer.flush(); + writer.close(); + assertEquals( stream.toString().length(), 1740, "Rendered differently" ); } } diff --git a/test/src/READMETest.java b/test/src/READMETest.java index 796f3084f5f17e592f2bc717d2cec2b8714e2a87..3f61d2ffaf9f14c1997154cf28d7ee5dc46269fb 100644 --- a/test/src/READMETest.java +++ b/test/src/READMETest.java @@ -23,19 +23,32 @@ 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; //import org.testng.annotations.*; +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentProcess; +import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.Parameters; + +import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; import fr.inrialpes.exmo.align.impl.method.StringDistAlignment; import fr.inrialpes.exmo.align.impl.BasicParameters; import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.onto.OntologyCache; import fr.inrialpes.exmo.align.parser.AlignmentParser; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.FileOutputStream; +import java.net.URI; +import java.net.URISyntaxException; public class READMETest { @@ -49,97 +62,124 @@ public class READMETest { } @Test(groups = { "full", "routine" }) - public void routineTest2() { - alignment = new StringDistAlignment(); - assertEquals( alignment.nbCells(), 0 ); - assertNotNull( alignment, "ObjectAlignment should not be null" ); - //alignment.init( , ); - //alignment.align( (Alignment)null, ); - assertEquals( alignment.nbCells(), 0 ); + public void routineTest2() throws Exception { /* $ java -jar lib/procalign.jar file://$CWD/examples/rdf/onto1.owl file://$CWD/examples/rdf/onto2.owl - */ + Parameters params = new BasicParameters(); + alignment = new StringDistAlignment(); + assertNotNull( alignment, "ObjectAlignment should not be null" ); + assertEquals( alignment.nbCells(), 0 ); + alignment.init( new URI("file:examples/rdf/onto1.owl"), new URI("file:examples/rdf/onto2.owl")); + alignment.align( (Alignment)null, params ); + assertEquals( alignment.nbCells(), 1 ); } @Test(groups = { "full", "routine" }) - public void routineTest3() { + public void routineTest3() throws Exception { /* $ java -jar lib/procalign.jar file://$CWD/examples/rdf/onto1.owl file://$CWD/examples/rdf/onto2.owl -i fr.inrialpes.exmo.align.impl.method.StringDistAlignment -DstringFunction=levenshteinDistance -r fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor - */ - } - - @Test(groups = { "full", "routine" }) - public void routineTest4() { + Parameters params = new BasicParameters(); + params.setParameter( "stringFunction", "levenshteinDistance"); + alignment = new StringDistAlignment(); + assertNotNull( alignment, "ObjectAlignment should not be null" ); + assertEquals( alignment.nbCells(), 0 ); + alignment.init( new URI("file:examples/rdf/onto1.owl"), new URI("file:examples/rdf/onto2.owl")); + alignment.align( (Alignment)null, params ); + assertEquals( alignment.nbCells(), 3 ); + // Rendering + // Playing with threshold /* $ java -jar lib/procalign.jar file://$CWD/examples/rdf/onto1.owl file://$CWD/examples/rdf/onto2.owl -i fr.inrialpes.exmo.align.impl.method.StringDistAlignment -DstringFunction=levenshteinDistance -t 0.4 -o examples/rdf/sample.rdf - */ + alignment.cut( "hard", 0.4 ); + assertEquals( alignment.nbCells(), 2 ); } @Test(groups = { "full", "routine" }) - public void routineTest5() { + public void routineTest5() throws Exception { /* $ java -cp lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter examples/rdf/newsample.rdf - */ + AlignmentParser aparser = new AlignmentParser( 0 ); + assertNotNull( aparser, "AlignmentParser was null" ); + Alignment result = aparser.parse( "file:examples/rdf/newsample.rdf" ); + assertNotNull( result, "URIAlignment(result) was null" ); + assertTrue( result instanceof URIAlignment ); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + //FileOutputStream stream = new FileOutputStream("result.rdf"); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + result.render( renderer ); + writer.flush(); + writer.close(); + assertEquals( stream.toString().length(), 1740, "Rendered differently" ); } - @Test(groups = { "full", "routine" }) - public void routineTest6() { + @Test(groups = { "full", "routine" }, dependsOnMethods = {"routineTest3"}) + public void routineTest6() throws Exception { /* $ java -jar lib/procalign.jar file://$CWD/examples/rdf/onto1.owl file://$CWD/examples/rdf/onto2.owl -a examples/rdf/sample.rdf */ } - @Test(groups = { "full", "routine" }) - public void routineTest7() { + @Test(groups = { "full", "routine" }, dependsOnMethods = {"routineTest3"}) + public void routineTest7() throws Exception { /* $ java -jar lib/Procalign.jar file://$CWD/examples/rdf/edu.umbc.ebiquity.publication.owl file://$CWD/examples/rdf/edu.mit.visus.bibtex.owl - */ + Parameters params = new BasicParameters(); + alignment = new StringDistAlignment(); + assertNotNull( alignment, "ObjectAlignment should not be null" ); + assertEquals( alignment.nbCells(), 0 ); + 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 ); } - @Test(groups = { "full", "routine" }) - public void routineTest8() { + @Test(groups = { "full", "routine" }, dependsOnMethods = {"routineTest7"}) + public void routineTest8() throws Exception { /* $ java -jar lib/Procalign.jar file://$CWD/examples/rdf/edu.umbc.ebiquity.publication.owl file://$CWD/examples/rdf/edu.mit.visus.bibtex.owl -i fr.inrialpes.exmo.align.impl.method.StringDistAlignment -DstringFunction=levenshteinDistance -o examples/rdf/bibref.rdf - */ - } - - @Test(groups = { "full", "routine" }) - public void routineTest9() { + Parameters params = new BasicParameters(); + params.setParameter( "stringFunction", "levenshteinDistance"); + alignment = new StringDistAlignment(); + assertNotNull( alignment, "ObjectAlignment should not be null" ); + assertEquals( alignment.nbCells(), 0 ); + 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(), 43 ); /* $ java -jar lib/Procalign.jar file://$CWD/examples/rdf/edu.umbc.ebiquity.publication.owl file://$CWD/examples/rdf/edu.mit.visus.bibtex.owl -i fr.inrialpes.exmo.align.impl.method.StringDistAlignment -DstringFunction=subStringDistance -t .4 -o examples/rdf/bibref2.rdf - */ + alignment.cut( "hard", 0.4 ); + assertEquals( alignment.nbCells(), 35 ); /* Why does it get 36 ?? */ } @Test(groups = { "full", "routine" }) - public void routineEvalTest() { + public void routineEvalTest() throws Exception { /* $ java -cp lib/procalign.jar fr.inrialpes.exmo.align.util.EvalAlign -i fr.inrialpes.exmo.align.impl.eval.PRecEvaluator file://$CWD/examples/rdf/bibref2.rdf file://$CWD/examples/rdf/bibref.rdf - */ } @Test(groups = { "full", "routine" }) - public void routineMatrixTest() { + public void routineMatrixTest() throws Exception { /* $ java -jar lib/Procalign.jar file://$CWD/examples/rdf/edu.umbc.ebiquity.publication.owl file://$CWD/examples/rdf/edu.mit.visus.bibtex.owl -i fr.inrialpes.exmo.align.impl.method.StringDistAlignment -DstringFunction=levenshteinDistance -DprintMatrix=1 -o /dev/null > examples/rdf/matrix.tex -*/ + */ } - @Test(groups = { "full", "routine" }) - public void routineJWNLTest() { - /* For JWNL Readme - + @Test(groups = { "full", "routine" }, dependsOnMethods = {"routineTest3"}) + public void routineJWNLTest() throws Exception { + /* $ setenv WNDIR ../WordNet-2.0/dict $ java -jar lib/alignwn.jar -Dwndict=$WNDIR file://$CWD/examples/rdf/edu.umbc.ebiquity.publication.owl file://$CWD/examples/rdf/edu.mit.visus.bibtex.owl -i fr.inrialpes.exmo.align.ling.JWNLAlignment -o examples/rdf/JWNL.rdf - */ } }