diff --git a/README.TXT b/README.TXT index 2e8ad9c05285ed3e4dd49645d77f32cee6573693..5d96760ef5a582eec7b3a638ff047d1e466dafde 100644 --- a/README.TXT +++ b/README.TXT @@ -38,6 +38,12 @@ Building: --------- $ ant jar +(or ant compileall; ant jar) + +Testing +------- + +$ ant test Running: -------- diff --git a/test/src/JWNLTest.java b/test/src/JWNLTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e85c010f5d79dbe3de695b026b93318ffcb3f5d8 --- /dev/null +++ b/test/src/JWNLTest.java @@ -0,0 +1,85 @@ +/* + * $Id$ + * + * Copyright (C) INRIA Rhône-Alpes, 2008 + * + * 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 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; +//import org.testng.annotations.*; + +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentProcess; +import org.semanticweb.owl.align.Parameters; + +import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; +import fr.inrialpes.exmo.align.impl.BasicParameters; +import fr.inrialpes.exmo.align.ling.JWNLAlignment; + +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * These tests corresponds to the JWNL test of the README file in the main directory + */ + +public class JWNLTest { + + private AlignmentProcess alignment = null; + + @Test(groups = { "full", "ling" }) + public void routineJWNLTest() throws Exception { + /* +$ setenv WNDIR +$ java -jar lib/alignwn.jar -D=$WNDIR file://$CWD/examples/rdf/ file://$CWD/examples/rdf/ -i fr.inrialpes.exmo.align.ling.JWNLAlignment -o examples/rdf/JWNL.rdf + */ + Parameters params = new BasicParameters(); + //System.getenv("WNDIR"); + params.setParameter( "wndict", "../WordNet-2.0/dict" ); + alignment = new JWNLAlignment(); + 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 ); + 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(), 14037, "Rendered differently" ); + alignment.cut( "hard", 0.4 ); + assertEquals( alignment.nbCells(), 35 ); + } +} diff --git a/test/src/OMWGTest.java b/test/src/OMWGTest.java new file mode 100644 index 0000000000000000000000000000000000000000..383e00a67bf7f0621c35d191ac970fcc58a9ff93 --- /dev/null +++ b/test/src/OMWGTest.java @@ -0,0 +1,118 @@ +/* + * $Id$ + * + * Copyright (C) INRIA Rhône-Alpes, 2008 + * + * 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 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; +//import org.testng.annotations.*; + +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.Alignment; + +import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; +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; + +/** + * These tests corresponds to the tests presented in the examples/omwg directory + */ + +public class OMWGTest { + + private Alignment alignment = null; + private AlignmentParser aparser1 = null; + + @Test(groups = { "full", "omwg" }) + public void loadPrintTest() throws Exception { + /* +java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine.xml > wine2.xml + */ + aparser1 = new AlignmentParser( 0 ); + assertNotNull( aparser1 ); + alignment = aparser1.parse( "examples/omwg/wine.xml" ); + assertNotNull( alignment ); + //assertTrue( alignment instanceof OMWGAlignment ); + FileOutputStream stream = new FileOutputStream("examples/omwg/wine2.xml"); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + alignment.render( renderer ); + writer.flush(); + writer.close(); + } + + @Test(groups = { "full", "omwg" }, dependsOnMethods = {"loadPrintTest"}) + public void roundTripTest() throws Exception { + /* +java -cp ../../lib/procalign.jar fr.inrialpes.exmo.align.util.ParserPrinter wine2.xml > wine3.xml + */ + alignment = aparser1.parse( "examples/omwg/wine2.xml" ); + assertNotNull( alignment ); + FileOutputStream stream = new FileOutputStream("examples/omwg/wine3.xml"); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + alignment.render( renderer ); + writer.flush(); + writer.close(); + } + + @Test(groups = { "full", "omwg" }, dependsOnMethods = {"roundTripTest"}) + public void diffTest() throws Exception { + /* +diff wine2.xml wine3.xml + */ + Alignment oldal = aparser1.parse( "examples/omwg/wine2.xml" ); + alignment = aparser1.parse( "examples/omwg/wine3.xml" ); + assertNotNull( alignment ); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + AlignmentVisitor renderer = new RDFRendererVisitor( writer ); + oldal.render( renderer ); + writer.flush(); + writer.close(); + String wine2 = stream.toString(); + stream = new ByteArrayOutputStream(); + writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + renderer = new RDFRendererVisitor( writer ); + alignment.render( renderer ); + writer.flush(); + writer.close(); + assertEquals( wine2, stream.toString() ); + } +} diff --git a/test/src/READMETest.java b/test/src/READMETest.java index 7edcf815623c8226799842ab682de4db8d5cbcdd..f96e2b78101d3c64d3f991c7ad0df4e697646bcf 100644 --- a/test/src/READMETest.java +++ b/test/src/READMETest.java @@ -43,15 +43,21 @@ 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 fr.inrialpes.exmo.align.util.NullStream; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.FileOutputStream; +import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; +/** + * These tests corresponds to the README file in the main directory + */ + public class READMETest { private AlignmentProcess alignment = null; @@ -194,33 +200,24 @@ $ java -cp lib/procalign.jar fr.inrialpes.exmo.align.util.EvalAlign -i fr.inrial assertNotNull( align2 ); Parameters params = new BasicParameters(); assertNotNull( params ); - Evaluator eval = new PRecEvaluator( align1, align2 ); + PRecEvaluator eval = new PRecEvaluator( align1, align2 ); assertNotNull( eval ); eval.eval( params ) ; - /* - stream = new FileOutputStream(filename); - } - writer = new PrintWriter ( - new BufferedWriter( - new OutputStreamWriter( stream, "UTF-8" )), true); - eval.write( writer ); - writer.flush(); - */ - /* -<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' - xmlns:map='http://www.atl.external.lmco.com/projects/ontology/ResultsOntology.n3#'> - <map:output rdf:about=''> - <map:input1 rdf:resource="http://ebiquity.umbc.edu/v2.1/ontology/publication.owl#publication"/> - <map:input2 rdf:resource="file:examples/rdf/edu.mit.visus.bibtex.owl"/> - <map:precision>0.8372093023255814</map:precision> - <map:recall>1.0</map:recall> - <fallout>0.16279069767441862</fallout> - <map:fMeasure>0.9113924050632911</map:fMeasure> - <map:oMeasure>0.8055555555555556</map:oMeasure> - <result>1.1944444444444444</result> - </map:output> -</rdf:RDF> - */ + + // This only output the result to check that this is possible + OutputStream stream = new NullStream(); + PrintWriter writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( stream, "UTF-8" )), true); + eval.write( writer ); + writer.flush(); + writer.close(); + assertEquals( eval.getPrecision(), 0.7441860465116279 ); + assertEquals( eval.getRecall(), 1.0 ); + assertEquals( eval.getFallout(), 0.2558139534883721 ); + assertEquals( eval.getFmeasure(), 0.8533333333333333 ); + assertEquals( eval.getOverall(), 0.65625 ); + //assertEquals( eval.getResult(), 1.34375 ); } @Test(groups = { "full", "impl" })