package smieci; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.HashMap; import java.util.StringTokenizer; public class ICPRAnotationBuilder { public static void main(String[] args) { String SavePath = "C:\\NEKST\\icpr-anotacja\\"; String FileName; String DictionaryPath = "C:\\NEKST\\icpr-anotacja\\annotation.list"; String CSVPath = "C:\\NEKST\\OverworkedAnno(1).txt"; HashMap AnotationMap = new HashMap(); int NewAnotation = 0; Integer AnotationIndex; String Line; try { BufferedReader CSVRead = new BufferedReader(new FileReader(new File(CSVPath))); PrintWriter ListWrite = new PrintWriter(new FileWriter(DictionaryPath)); boolean FirstDone = false; while ((Line = CSVRead.readLine()) != null) { StringTokenizer Tokens = new StringTokenizer(Line, " "); FileName = Tokens.nextToken().replace('/', '-') + ".png.annot"; PrintWriter AnotationWrite = new PrintWriter(new FileWriter(SavePath + FileName)); System.out.println("Constructing: " + FileName); System.out.println("Line: " + Line); while (Tokens.hasMoreTokens()) { String CurrentAnotation = Tokens.nextToken().toLowerCase().trim(); AnotationIndex = AnotationMap.get(CurrentAnotation); if (AnotationIndex == null) { AnotationIndex = NewAnotation; AnotationMap.put(CurrentAnotation, NewAnotation); if (FirstDone) ListWrite.println(); FirstDone = true; ListWrite.print(NewAnotation + ";" + CurrentAnotation); AnotationWrite.print(NewAnotation + " "); System.out.println(CurrentAnotation + " (" + NewAnotation + ") NEW!"); NewAnotation++; } else { AnotationWrite.print(AnotationIndex + " "); System.out.println(CurrentAnotation + " (" + AnotationIndex + ")"); } } AnotationWrite.close(); } CSVRead.close(); ListWrite.close(); } catch (Exception Ex) { System.out.println("ERROR:"); Ex.printStackTrace(); } finally { System.exit(0); } } }