String dataFileName = args[ai];
String modelFileName =
dataFileName.substring(0,dataFileName.lastIndexOf('.'))
+ "Model.txt";
File outputFile = new File(modelFileName);
AbstractModelWriter writer = null;
try {
FileReader datafr = new FileReader(new File(dataFileName));
EventStream es;
if (!real) {
es = new BasicEventStream(new PlainTextByLineDataStream(datafr));
}
else {
es = new RealBasicEventStream(new PlainTextByLineDataStream(datafr));
}
GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;
AbstractModel model;
if (type.equals("maxent")) {
if (!real) {
model = GIS.trainModel(es,USE_SMOOTHING);
}
else {
model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
}
writer = new SuffixSensitiveGISModelWriter(model, outputFile);
}
else if (type.equals("perceptron")){
System.err.println("Perceptron training");
model = new PerceptronTrainer().trainModel(10, new OnePassDataIndexer(es,0),0);
writer = new SuffixSensitivePerceptronModelWriter(model, outputFile);
}
else {
System.err.println("Unknown model type: "+type);
model = null;
}
writer.persist();
} catch (Exception e) {
System.out.print("Unable to create model due to exception: ");
System.out.println(e);
e.printStackTrace();
}