Mentions légales du service

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

- Added GroupAggreg command line class

- cleaned up some command lines
parent 518f9519
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ the <tt>fr.inrialpes.exmo.align.cli</tt> package:
reference alignment.</dd>
<dt>TestGen</dt><dd>Generates tests for evaluating matchers.</dd>
<dt>GroupAlign</dt><dd>Runs a matcher against several different test cases.</dd>
<dt>GroupAggreg</dt><dd>Aggregates several matcher results in several different test cases.</dd>
<dt>GroupEval</dt><dd>Evaluates several matcher results in several different test cases.</dd>
<dt>ExtGroupEval</dt><dd>Same as above with extended evaluators</dd>
<dt>WGroupEval</dt><dd>Same as above with weighted evaluators.</dd>
......@@ -193,7 +194,58 @@ $ java -cp $CWD/../lib/procalign.jar fr.inrialpes.exmo.align.cli@.GroupAlign -o
This will compare each onto.rdf file in each of the subdirectory to the <tt>file://$CWD/101/onto.rdf</tt> with the <tt>EditDistNameAlignment</tt> method and output the result in a <tt>edna.rdf</tt> file in each directory.
</p>
<p>
The output is ready to be evaluated by <tt>GroupEval</tt>.
The output is ready to be evaluated by <tt>GroupEval</tt> and <tt>GroupAggreg</tt>.
</p>
<h3>Aggregation of multiple alignments</h3>
<p><tt>GroupAggreg</tt> aggregates alignments provided by different
matchers. It starts with a
directory (specified with <tt>-w</tt>, default current directort) containing a set of
subdirectories (one per test).
Each subdirectory contains a set of alignments
(called <tt>xxx.rdf</tt> where <tt>xxx</tt> is a string passed
to <tt>-l</tt>).
The alignments considered in the <tt>-l</tt> parameters are
aggregated with the method specified with the <tt>-m</tt> parameter
(default "min").
The results may be further trimmed with the usual <tt>-t</tt>
and <tt>-T</tt> parameters.
Finally, one alignment per directory is output to the directory
specified by <tt>-o</tt>.
</p>
<div class="terminal">
$ java -cp /Java/alignapi/lib/procalign.jar fr.inrialpes.exmo.align.cli.GroupAggreg --help
usage: java fr.inrialpes.exmo.align.cli.GroupAggreg [options]
Evaluates in parallel several matching results on several tests in
subdirectories
Options:
-D &lt;NAME=VALUE> Use value for given property
-d,--debug &lt;LEVEL> debug argument is deprecated, use logging instead
See http://alignapi.gforge.inria.fr/logging.html
-h,--help Print this page
-l,--list &lt;FILE> List of FILEs to be included in the results
(required)
-m,--aggmethod &lt;METHOD> Method to use for aggregating (min|max|avg|pool)
-o,--outputDir &lt;DIR> The DIRectory where to output results
-P,--params &lt;FILE> Read parameters from FILE
-T,--cutmethod &lt;METHOD> Method to use for triming (hard|perc|prop|best|span)
-t,--threshold &lt;DOUBLE> Trim the alignment with regard to threshold
-w,--workDir &lt;DIR> The DIRectory containing the data to evaluate
Alignment API implementation 4.6 (1975M)
</div>
<p>Invoking <tt>GroupAggreg</tt> as below:
<div class="terminal">
$ java -cp /Java/alignapi/lib/procalign.jar fr.inrialpes.exmo.align.cli.GroupAggreg -o /tmp/agg -T prop -t .7 -m avg -l "edna,AML,YAM++,StringsAuto"
</div>
will aggregate in the current directory (no <tt>-w</tt>), the
alignments in subdirectories identified by edna,AML,YAM++,StringsAuto,
with the aggregation method (<tt>-m avg</tt> for
average); it will trim the result with the trimming method (<tt>-T prop -t .7</tt> for the 70% best
correspondences) and output it in the /tmp/agg directory.
</p>
<h2>Generating tests</h2>
......
/*
* $Id$
*
* Copyright (C) 2003-2014, INRIA
*
* 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.
*/
/* This program evaluates the results of several ontology aligners in a row.
*/
package fr.inrialpes.exmo.align.cli;
import org.semanticweb.owl.align.Alignment;
import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owl.align.Evaluator;
import org.semanticweb.owl.align.AlignmentVisitor;
import fr.inrialpes.exmo.align.parser.AlignmentParser;
import fr.inrialpes.exmo.align.impl.BasicAlignment;
import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor;
import fr.inrialpes.exmo.ontowrap.OntologyFactory;
import fr.inrialpes.exmo.ontowrap.OntowrapException;
import java.io.File;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.lang.Integer;
import java.lang.reflect.Constructor;
import java.util.Set;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Properties;
import org.xml.sax.SAXException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.ParseException;
/**
* A basic class for aggregating a set of alignments provided by different algorithms.
* The output is an alignment per pair of ontologies obtained by aggregation with the
* given method.
*
* <pre>
* java -cp procalign.jar fr.inrialpes.exmo.align.util.GroupAggreg [options]
* </pre>
*
* where the options are:
* <pre>
* -l,--list &lt;FILE> List of FILEs to be included in the results
* (required)
* -m,--aggmethod &lt;METHOD> Method to use for aggregating (min|max|avg|pool)
* -P,--params &lt;FILE> Read parameters from FILE
* -T,--cutmethod &lt;METHOD> Method to use for triming (hard|perc|prop|best|span)
* -t,--threshold &lt;DOUBLE> Trim the alignment with regard to threshold
* -w,--workDir &lt;DIR> The DIRectory containing the data to evaluate
* </pre>
*
* The input is taken in the current directory in a set of subdirectories (one per
* test which will be rendered by a line) each directory contains a number of
* alignment files (one per algorithms which will be renderer as a column).
*
* If output is requested (<CODE>-o</CODE> flags), then output will be written to
* <CODE>output</CODE> if present, stdout by default.
*
* <pre>
* $Id$
* </pre>
*
*/
public class GroupAggreg extends CommonCLI {
final static Logger logger = LoggerFactory.getLogger( GroupAggreg.class );
String[] listAlgo = null;
int size = 0;
String srcDir = null;
String dirName = null;
double threshold = 0;
String cutMethod = "hard";
String aggMethod = "min";
/* OPTIONS */
public GroupAggreg() {
super();
options.addOption( OptionBuilder.withLongOpt( "list" ).hasArgs().withValueSeparator(',').withDescription( "List of FILEs to be included in the results (required)" ).withArgName("FILE").create( 'l' ) );
options.addOption( OptionBuilder.withLongOpt( "workDir" ).hasOptionalArg().withDescription( "The DIRectory containing the data to evaluate" ).withArgName("DIR").create( 'w' ) );
options.addOption( OptionBuilder.withLongOpt( "aggmethod" ).hasArg().withDescription( "Method to use for aggregating (min|max|avg|pool)" ).withArgName("METHOD").create( 'm' ) );
options.addOption( OptionBuilder.withLongOpt( "threshold" ).hasArg().withDescription( "Trim the alignment with regard to threshold" ).withArgName("DOUBLE").create( 't' ) );
options.addOption( OptionBuilder.withLongOpt( "cutmethod" ).hasArg().withDescription( "Method to use for triming (hard|perc|prop|best|span)" ).withArgName("METHOD").create( 'T' ) );
options.addOption( OptionBuilder.withLongOpt( "outputDir" ).hasArg().withDescription( "The DIRectory where to output results" ).withArgName("DIR").create( 'o' ) );
// .setRequired( true )
Option opt = options.getOption( "list" );
if ( opt != null ) opt.setRequired( true );
}
public static void main(String[] args) {
try { new GroupAggreg().run( args ); }
catch (Exception ex) { ex.printStackTrace(); };
}
public void run(String[] args) throws Exception {
try {
CommandLine line = parseCommandLine( args );
if ( line == null ) return; // --help
// Here deal with command specific arguments
if ( line.hasOption( 't' ) ) threshold = Double.parseDouble(line.getOptionValue( 't' ));
if ( line.hasOption( 'T' ) ) cutMethod = line.getOptionValue( 'T' );
if ( line.hasOption( 'm' ) ) aggMethod = line.getOptionValue( 'm' );
if ( line.hasOption( 'l' ) ) {
listAlgo = line.getOptionValues( 'l' );
size = listAlgo.length;
}
if ( line.hasOption( 'w' ) ) srcDir = line.getOptionValue( 'w' );
if ( line.hasOption( 'o' ) ) dirName = line.getOptionValue( 'o' );
} catch( ParseException exp ) {
logger.error( exp.getMessage() );
usage();
System.exit( -1 );
}
iterateDirectories();
}
/**
* Each directory contains various alignments between the same ontologies
*/
public void iterateDirectories (){
File [] subdir = null;
try {
if (srcDir == null) {
subdir = ( new File(System.getProperty("user.dir") ) ).listFiles();
} else {
subdir = ( new File(srcDir) ).listFiles();
}
} catch ( Exception e ) {
logger.error( "Cannot stat dir ", e );
usage();
}
int size = subdir.length;
Arrays.sort(subdir);
int i = 0;
for ( int j=0 ; j < size; j++ ) {
if ( subdir[j].isDirectory() ) iterateAlignments( subdir[j] );
}
}
public void iterateAlignments ( File dir ) {
String prefix = dir.toURI().toString()+File.separator;
Set<BasicAlignment> listal = new HashSet<BasicAlignment>();
// for all alignments there,
for ( String m: listAlgo ) {
BasicAlignment al = loadAlignment( prefix+m+".rdf" );
if ( al != null ) listal.add( al );
}
Alignment result = null;
try {
// Depends on the method
result = BasicAlignment.aggregate( aggMethod, listal );
} catch ( AlignmentException alex ) {
logger.debug( "IGNORED: cannot aggregate for {}", prefix, alex );
return;
}
// Thresholding
try {
if (threshold != 0) result.cut( cutMethod, threshold );
} catch ( AlignmentException alex ) {
logger.debug( "IGNORED: Cannot trim alignment {} {}", cutMethod, threshold, alex );
}
// This should be printed now
print( result, dir.getName()+".rdf" );
}
public BasicAlignment loadAlignment( String alignName ) {
try {
// Load alignments
AlignmentParser aparser = new AlignmentParser();
return (BasicAlignment)aparser.parse( alignName );
} catch (Exception ex) {
logger.debug( "IGNORED Exception", ex );
};
return null;
}
/**
* This does not only print the results but compute the average as well
*/
public void print( Alignment al, String outputfilename ) {
PrintWriter writer = null;
try {
writer = new PrintWriter (
new BufferedWriter(
new OutputStreamWriter( new FileOutputStream( dirName+File.separator+outputfilename ), "UTF-8" )), true);
// Create renderer
AlignmentVisitor renderer = new RDFRendererVisitor( writer );
renderer.init( parameters );
// Render the alignment
al.render( renderer );
} catch ( Exception aex ) {
logger.error( "Cannot print into file {}", outputfilename );
} finally {
writer.flush();
writer.close();
}
}
public void usage() {
usage( "java "+this.getClass().getName()+" [options]\nEvaluates in parallel several matching results on several tests in subdirectories" );
}
}
......@@ -220,7 +220,7 @@ public class GroupAlign extends CommonCLI {
long time = System.currentTimeMillis();
result.align( init, parameters );
long newTime = System.currentTimeMillis();
result.setExtension( Namespace.ALIGNMENT.uri, Annotations.TIME, Long.toString(newTime - time) );
result.setExtension( Namespace.EXT.uri, Annotations.TIME, Long.toString(newTime - time) );
logger.debug(" Alignment performed");
......
......@@ -59,37 +59,49 @@ import org.apache.commons.cli.ParseException;
import fr.inrialpes.exmo.align.parser.AlignmentParser;
/** A basic class for synthesizing the results of a set of alignments provided by
different algorithms. The output is a table showing various classical measures
for each test and for each algorithm. Average is also computed as Harmonic means.
<pre>
java -cp procalign.jar fr.inrialpes.exmo.align.util.GroupEval [options]
</pre>
where the options are:
<pre>
-o filename --output=filename
-e classname --evaluator=classname
-f format = prfot (precision/recall/f-measure/overall/time) --format=prfot
-r filename --reference=filename
-s algo/measure
-l list of compared algorithms
-t output --type=output: xml/tex/html/ascii
</pre>
The input is taken in the current directory in a set of subdirectories (one per
test which will be rendered by a line) each directory contains a number of
alignment files (one per algorithms which will be renderer as a column).
If output is requested (<CODE>-o</CODE> flags), then output will be written to
<CODE>output</CODE> if present, stdout by default.
<pre>
$Id$
</pre>
*/
/**
* A basic class for synthesizing the results of a set of alignments provided by
* different algorithms. The output is a table showing various classical measures
* for each test and for each algorithm. Average is also computed as Harmonic means.
*
* <pre>
* java -cp procalign.jar fr.inrialpes.exmo.align.util.GroupEval [options]
* </pre>
*
* where the options are:
* <pre>
* -c,--color &lt;COLOR> Color even lines of the output in COLOR (default:
* lightblue)
* -D &lt;NAME=VALUE> Use value for given property
* -d,--debug &lt;LEVEL> debug argument is deprecated, use logging instead
* See http://alignapi.gforge.inria.fr/logging.html
* -e,--evaluator &lt;CLASS> Use CLASS as evaluation plotter
* -f,--format &lt;MEAS> Used MEASures and order
* (precision/recall/f-measure/overall/time) (default:
* pr)
* -h,--help Print this page
* -l,--list &lt;FILE> List of FILEs to be included in the results (required)
* -o,--output &lt;FILE> Send output to FILE
* -P,--params &lt;FILE> Read parameters from FILE
* -r,--reference &lt;FILE> Name of the reference alignment FILE (default:
* refalign.rdf)
* -t,--type &lt;TYPE> Output TYPE (html|xml|tex|ascii|triangle; default:
* html)
* -w,--directory &lt;DIR> The DIRectory containing the data to evaluate
* </pre>
*
* The input is taken in the current directory in a set of subdirectories (one per
* test which will be rendered by a line) each directory contains a number of
* alignment files (one per algorithms which will be renderer as a column).
*
* If output is requested (<CODE>-o</CODE> flags), then output will be written to
* <CODE>output</CODE> if present, stdout by default.
*
* <pre>
* $Id$
* </pre>
*
*/
public class GroupEval extends CommonCLI {
final static Logger logger = LoggerFactory.getLogger( GroupEval.class );
......
......@@ -47,33 +47,33 @@ import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor;
import fr.inrialpes.exmo.align.parser.AlignmentParser;
/** A really simple utility that loads and alignment and prints it.
A basic class for ontology alignment processing.
Command synopsis is as follows:
<pre>
java fr.inrialpes.exmo.align.util.ParserPrinter [options] input [output]
</pre>
where the options are:
<pre>
--renderer=className -r className Use the given class for output.
--parser=className -p className Use the given class for input.
--inverse -i Inverse first and second ontology
--threshold=threshold -t threshold Trim the alugnment with regard to threshold
--cutmethod=hard|perc|prop|best|span -T hard|perc|prop|best|span Method to use for triming
--output=filename -o filename Output the alignment in filename
--help -h Print this message
</pre>
The <CODE>input</CODE> is a filename. If output is
requested (<CODE>-o</CODE> flags), then output will be written to
<CODE>output</CODE> if present, stdout by default.
<pre>
$Id$
</pre>
*/
* A basic class for ontology alignment processing.
* Command synopsis is as follows:
*
* <pre>
* java fr.inrialpes.exmo.align.util.ParserPrinter [options] input [output]
* </pre>
*
* where the options are:
* <pre>
* --renderer=className -r className Use the given class for output.
* --parser=className -p className Use the given class for input.
* --inverse -i Inverse first and second ontology
* --threshold=threshold -t threshold Trim the alugnment with regard to threshold
* --cutmethod=hard|perc|prop|best|span -T hard|perc|prop|best|span Method to use for triming
* --output=filename -o filename Output the alignment in filename
* --help -h Print this message
* </pre>
*
* The <CODE>input</CODE> is a filename. If output is
* requested (<CODE>-o</CODE> flags), then output will be written to
* <CODE>output</CODE> if present, stdout by default.
*
* <pre>
* $Id$
* </pre>
*
*/
public class ParserPrinter extends CommonCLI {
final static Logger logger = LoggerFactory.getLogger( ParserPrinter.class );
......
......@@ -182,7 +182,7 @@ public class Procalign extends CommonCLI {
long time = System.currentTimeMillis();
result.align( init, parameters ); // add opts
long newTime = System.currentTimeMillis();
result.setExtension( Namespace.ALIGNMENT.uri, Annotations.TIME, Long.toString(newTime - time) );
result.setExtension( Namespace.EXT.uri, Annotations.TIME, Long.toString(newTime - time) );
// Thresholding
if (threshold != 0) result.cut( cutMethod, threshold );
......
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