package anotacja; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.List; import anotacja.WebCBIRwithPATSI.OrderedWithIndex; public class AnnotatorTest { public static void main(String[] args) throws Exception { if (args.length != 8) { System.out.println("Parameters:"); System.out.println("java -jar Annotest.jar [queries] [database] [annotations] [cluster number] [annotation number] [cluster type] [t/tarray] [k]"); System.out.println("For example:"); System.out.println("java - jar Annotest.jar"); System.out.println("/home/www/temp/workspace/visible/collections/zabytki-anot/files-out"); System.out.println("/home/www/temp/workspace/visible/collections/zabytki-anot"); System.out.println("/home/www/temp/workspace/visible/collections/zabytki-anot/files-annot"); System.out.println("50000 273 .rootsift256"); System.out.println("0.9 19"); System.exit(0); } File queryFolder = new File(args[0]); int Clusters = Integer.parseInt(args[3]); int Annotations = Integer.parseInt(args[4]); String Extension = args[5]; File TransferArray = new File(args[6]); double t; boolean LoadArray = false; if (!TransferArray.exists()) t = Double.parseDouble(args[6]); else { t = 0.0; LoadArray = true; } int k = Integer.parseInt(args[7]); String FullExtension = Extension + ".cluster_" + Clusters; int[] R = new int[Annotations]; int[] E = new int[Annotations]; int[] C = new int[Annotations]; WebCBIRwithPATSI Anot = new WebCBIRwithPATSI(args[1], "", args[2], new RankTransferFunction(), t, k); if (LoadArray) Anot.LoadTArray(args[6], Annotations); int N = 0; System.out.println("[?] Scanning folder..."); File tFile = new File("test.tmat"); if (!tFile.exists()) tFile.createNewFile(); BufferedWriter TMatFile = new BufferedWriter(new FileWriter(tFile.getAbsoluteFile())); Anot.BegginLogging(TMatFile); for (File f : queryFolder.listFiles()) { if (f.getName().endsWith(FullExtension)) { N++; System.out.println("\t[-] Current file: [" + N + "] - " + f.getName()); List fE = Anot.getAnnotationsForFile(f); //System.out.print("\tE:"); for (Integer a : fE) { E[a]++; //System.out.print(" " + a); } //System.out.println(); List> fR = Anot.annotateQuery(f.getAbsolutePath(), Anot.compareAllToQuery(f.getAbsolutePath(), Clusters)); //System.out.print("\tR:"); for (OrderedWithIndex b : fR) { R[b.getIndex()]++; //System.out.print(" " + b.getIndex()); } //System.out.println(); //System.out.print("\tC:"); for (OrderedWithIndex c : fR) { if (fE.contains(c.getIndex())) { C[c.getIndex()]++; //System.out.print(" " + c.getIndex()); } } //System.out.println(); } } Anot.StopLogging(); TMatFile.close(); System.out.println("[?] Finished processing " + N + " files..."); System.out.println("[?] Calculating results..."); int PrecisionN = 0; int RecallN = 0; double PrecisionAcc = 0.0; double RecallAcc = 0.0; int WordsOmmitedP = 0; int WordsOmmitedR = 0; File cFile = new File("test.cmat"); if (!cFile.exists()) cFile.createNewFile(); BufferedWriter CMatFile = new BufferedWriter(new FileWriter(cFile.getAbsoluteFile())); CMatFile.write("Annotation;E;R;C\n"); for (int i = 0; i < Annotations; i++) CMatFile.write(i + ";" + E[i] + ";" + R[i] + ";" + C[i] + "\n"); CMatFile.close(); for (int i = 0; i < Annotations; i++) { if (E[i] != 0) { RecallAcc += (double)C[i] / (double)E[i]; RecallN++; } else WordsOmmitedR++; if (R[i] != 0) { PrecisionAcc += (double)C[i] / (double)R[i]; PrecisionN++; } else WordsOmmitedP++; } double Precision = (PrecisionAcc / (double)PrecisionN); double Recall = (RecallAcc / (double)RecallN); double FScore = (2 * Precision * Recall) / (Precision + Recall); System.out.println("\tPrecision: " + Precision); System.out.println("\tRecall: " + Recall); System.out.println("\tF-Score: " + FScore); System.out.println("\tOmmited: " + WordsOmmitedP + "/" + WordsOmmitedR); } }