System.out
.println("usage: VOCExample trainfile.voc trainfile.fvec testfile.voc testfile.fvec");
return;
}
FvecImporter fvecimp = new FvecImporter();
// read train features
List<double[]> feat = null;
try {
feat = fvecimp.readFile(args[1]);
} catch (IOException e1) {
System.out.println("Unable to read train features: " + args[1]);
return;
}
// read voc train file
List<TrainingSample<double[]>> train = new ArrayList<TrainingSample<double[]>>();
try {
LineNumberReader lin = new LineNumberReader(new FileReader(args[0]));
String line;
int i = 0;
while ((line = lin.readLine()) != null) {
// get label from second field. ex: "000012 -1"
int label = Integer.parseInt(line.split("[ ]+")[1]);
train.add(new TrainingSample<double[]>(feat.get(i), label));
i++;
}
lin.close();
} catch (FileNotFoundException e) {
System.out
.println("trainfile.voc : " + args[0] + " was not found.");
return;
} catch (IOException e) {
System.out
.println("Error while parsing trainfile.voc : " + args[0]);
return;
}
System.out.println("Train features loaded.");
// load test features
try {
feat = fvecimp.readFile(args[3]);
} catch (IOException e1) {
System.out.println("Unable to read test features: " + args[3]);
return;
}