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 SilesiaAnnotationBuilder { public static void main(String[] args) { String SavePath = "C:\\NEKST\\album-anotacja\\"; String FileName; String DictionaryPath = "C:\\NEKST\\album-anotacja\\annotation.list"; String CSVPath = "C:\\NEKST\\anotacje_poprawki_I_ETAP_dolny_slask.csv"; 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, ";"); String Anotations = null; FileName = Tokens.nextToken() + ".png.annot"; PrintWriter AnotationWrite = new PrintWriter(new FileWriter(SavePath + FileName)); System.out.println("Constructing: " + FileName); while (Tokens.hasMoreTokens()) Anotations = Tokens.nextToken(); System.out.println("Anotation variable: " + Anotations); StringTokenizer AnotationTokens = new StringTokenizer(Anotations, "_"); while (AnotationTokens.hasMoreTokens()) { String CurrentAnotation = AnotationTokens.nextToken(); 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); } } }