public void predict(String testFile, String outputFile, String modelFile, byte vectorType) throws Exception
{
BufferedReader fin = UTInput.createBufferedFileReader(testFile);
PrintStream fout = UTOutput.createPrintBufferedFileStream(outputFile);
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(modelFile)));
SparseModel pModel = null;
StringModel sModel = null;
switch (vectorType)
{
case AbstractTrainSpace.VECTOR_SPARSE:
pModel = (SparseModel)in.readObject(); break;
case AbstractTrainSpace.VECTOR_STRING:
sModel = (StringModel)in.readObject(); break;
}
in.close();
boolean hasWeight = AbstractTrainSpace.hasWeight(vectorType, testFile);
int correct = 0, total = 0;
StringPrediction r = null;
String line, label = null;
System.out.print("Predicting");
while ((line = fin.readLine()) != null)
{
if (vectorType == AbstractTrainSpace.VECTOR_SPARSE)
{
Pair<String,SparseFeatureVector> sp = SparseTrainSpace.toInstance(line, hasWeight);
r = pModel.predictBest(sp.o2);
label = sp.o1;
}
else
{
StringInstance ss = StringTrainSpace.toInstance(line, hasWeight);