Mentions légales du service

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

- implemented -o option

- implemented -t tex plot option (generate the result of gnuplot)
parent 902a7bb8
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,10 @@ import fr.inrialpes.exmo.align.impl.eval.PRGraphEvaluator; ...@@ -46,6 +46,10 @@ import fr.inrialpes.exmo.align.impl.eval.PRGraphEvaluator;
import java.io.File; import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.net.URI; import java.net.URI;
import java.lang.Double; import java.lang.Double;
import java.lang.Integer; import java.lang.Integer;
...@@ -87,13 +91,12 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; ...@@ -87,13 +91,12 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser;
* *
* If output is * If output is
* requested (<CODE>-o</CODE> flags), then output will be written to * requested (<CODE>-o</CODE> flags), then output will be written to
* <CODE>output</CODE> if present, stdout by default. * <CODE>output</CODE> if present, stdout by default. In case of the Latex output, there are numerous files generated (regardless the <CODE>-o</CODE> flag).
* *
* <pre> * <pre>
* $Id$ * $Id$
* </pre> * </pre>
* *
* @author Sean K. Bechhofer
* @author Jrme Euzenat * @author Jrme Euzenat
*/ */
...@@ -103,10 +106,11 @@ public class GenPlot { ...@@ -103,10 +106,11 @@ public class GenPlot {
static Parameters params = null; static Parameters params = null;
static Vector listAlgo; static Vector listAlgo;
static String fileNames = ""; static String fileNames = "";
static String outFile = null; // This is unused for the moment static String outFile = null;
static String type = "html"; static String type = "tsv";
static int debug = 0; static int debug = 0;
static Hashtable loaded = null; static Hashtable loaded = null;
static PrintWriter output = null;
public static void main(String[] args) { public static void main(String[] args) {
try { run( args ); } try { run( args ); }
...@@ -137,7 +141,7 @@ public class GenPlot { ...@@ -137,7 +141,7 @@ public class GenPlot {
outFile = g.getOptarg(); outFile = g.getOptarg();
break; break;
case 't' : case 't' :
/* Type of output (tex/html/xml/ascii) */ /* Type of output (tex/tsv(/html/xml/ascii)) */
type = g.getOptarg(); type = g.getOptarg();
break; break;
case 'l' : case 'l' :
...@@ -165,7 +169,23 @@ public class GenPlot { ...@@ -165,7 +169,23 @@ public class GenPlot {
params.setParameter("step", new Integer(STEP)); params.setParameter("step", new Integer(STEP));
print( iterateDirectories() ); // Set output file
OutputStream stream;
if (outFile == null) {
stream = System.out;
} else {
stream = new FileOutputStream(outFile);
}
output = new PrintWriter (
new BufferedWriter(
new OutputStreamWriter( stream, "UTF-8" )), true);
// type
if ( type.equals("tsv") ){
printTSV( iterateDirectories() );
} else if ( type.equals("tex") ) {
printPGFTex( iterateDirectories() );
} else System.err.println("Flag -t "+type+" : not implemented yet");
} }
/** /**
...@@ -270,28 +290,87 @@ public class GenPlot { ...@@ -270,28 +290,87 @@ public class GenPlot {
/** /**
* This does average plus plot * This does average plus plot
*
*/ */
public static void print( double[][] result ) { public static void printPGFTex( double[][] result ){
int i = 0;
output.println("\\documentclass[11pt]{book}");
output.println();
output.println("\\usepackage{pgf}");
output.println("\\usepackage{tikz}");
output.println();
output.println("\\begin{document}");
output.println("\\date{today}");
output.println("\n%% Plot generated by GenPlot of alignapi");
output.println("\\begin{tikzpicture}[cap=round]");
output.println("% Draw grid");
output.println("\\draw[step="+(STEP/10)+"cm,very thin,color=gray] (-0.2,-0.2) grid ("+STEP+","+STEP+");");
output.println("\\draw[->] (-0.2,0) -- (10.2,0) node[below] {$precision$}; ");
output.println("\\draw[->] (0,-0.2) -- (0,10.2) node[above] {$recall$}; ");
output.println("% Plots");
// Should be improved by changing the symbol
for ( Enumeration e = listAlgo.elements() ; e.hasMoreElements() ; i++) {
output.println("\\draw plot[mark=+,smooth] file {"+(String)e.nextElement()+".table};");
}
// And a legend
output.println("% Legend");
output.println("\\end{tikzpicture}");
output.println();
output.println("\\end{document}");
i = 0;
for ( Enumeration e = listAlgo.elements() ; e.hasMoreElements() ; i++) {
String algo = (String)e.nextElement();
// Open one file
PrintWriter writer;
try {
writer = new PrintWriter (
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(algo+".table"), "UTF-8" )), true);
// Print header
writer.println("#Curve 0, "+(STEP+1)+" points");
writer.println("#x y type");
writer.println("%% Plot generated by GenPlot of alignapi");
writer.println("%% Include in PGF tex by:\n");
writer.println("%% \\begin{tikzpicture}[cap=round]");
writer.println("%% \\draw[step="+(STEP/10)+"cm,very thin,color=gray] (-0.2,-0.2) grid ("+STEP+","+STEP+");");
writer.println("%% \\draw[->] (-0.2,0) -- (10.2,0) node[right] {$precision$}; ");
writer.println("%% \\draw[->] (0,-0.2) -- (0,10.2) node[above] {$recall$}; ");
writer.println("%% \\draw plot[mark=+,smooth] file {"+algo+".table};");
writer.println("%% \\end{tikzpicture}");
writer.println();
for( int j = 0; j <= STEP; j++ ){
writer.print((double)j*10/STEP);
writer.println(" "+result[i][j]*10);
}
writer.close();
} catch (Exception ex) { ex.printStackTrace(); }
// UnsupportedEncodingException + FileNotFoundException
}
}
public static void printTSV( double[][] result ) {
// Print first line // Print first line
for ( Enumeration e = listAlgo.elements() ; e.hasMoreElements() ; ) { for ( Enumeration e = listAlgo.elements() ; e.hasMoreElements() ; ) {
System.out.print("\t"+(String)e.nextElement() ); output.print("\t"+(String)e.nextElement() );
} }
System.out.println(); output.println();
// Print others // Print others
for( int j = 0; j <= STEP; j++ ){ for( int j = 0; j <= STEP; j++ ){
System.out.print((double)j/STEP); output.print((double)j/STEP);
for( int i = 0; i < listAlgo.size(); i++ ){ for( int i = 0; i < listAlgo.size(); i++ ){
System.out.print("\t"+result[i][j]); output.print("\t"+result[i][j]);
} }
System.out.println(); output.println();
} }
} }
public static void usage() { public static void usage() {
System.out.println("usage: GenPlot [options]"); System.out.println("usage: GenPlot [options]");
System.out.println("options are:"); System.out.println("options are:");
System.out.println("\t--type=html|xml|tex|ascii -t html|xml|tex|ascii\tSpecifies the output format"); System.out.println("\t--type=tsv|tex|(html|xml) -t tsv|tex|(html|xml)\tSpecifies the output format");
System.out.println("\t--list=algo1,...,algon -l algo1,...,algon\tSequence of the filenames to consider"); System.out.println("\t--list=algo1,...,algon -l algo1,...,algon\tSequence of the filenames to consider");
System.out.println("\t--debug[=n] -d [n]\t\tReport debug info at level n"); System.out.println("\t--debug[=n] -d [n]\t\tReport debug info at level n");
System.out.println("\t--help -h\t\t\tPrint this message"); System.out.println("\t--help -h\t\t\tPrint this message");
......
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