package edu.ntnu.idi.goldfish.preprocessors;

import edu.ntnu.idi.goldfish.StopWatch;
import edu.ntnu.idi.goldfish.configurations.Config;
import edu.ntnu.idi.goldfish.mahout.DBModel;
import org.apache.mahout.cf.taste.model.DataModel;
import weka.classifiers.Classifier;
import weka.core.Instance;
import weka.core.Instances;

import java.util.List;
import java.util.stream.Collectors;

public abstract class PreprocessorClassifier extends Preprocessor {


    public DataModel classify(Config config, Classifier classifier, Instances dataset) throws Exception {
        DBModel model = config.get("model");

        StopWatch.start("classifier-build");
        classifier.buildClassifier(dataset);
        config.set("time:preprocess-build", StopWatch.get("classifier-build"));

        List<DBModel.DBRow> results = model.getFeedbackRows().stream().filter(row -> row.rating == 0).collect(Collectors.toList());
        for (DBModel.DBRow row : results) {
            Instance un = new Instance(1, new double[]{0, row.timeonpage, row.timeonmouse});
            un.setDataset(dataset);
            double rating = classifier.classifyInstance(un);
//            System.out.format("classify: u: %d  i: %6d  estimate: %.2f\n", row.userid, row.itemid, rating);
            model.setPreference(row.userid, row.itemid, (float) Math.round(rating));
            pseudoRatings.add(String.format("%d_%d", row.userid, row.itemid));
        }
        return model;
    }

    public abstract DataModel preprocess(Config config) throws Exception;

}
@@ -172,24 +172,89 @@
 ut.DBModel;%0A
+import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;%0A
 import org.a
@@ -380,24 +380,45 @@
 Instances;%0A%0A
+import java.io.File;%0A
 import java.
@@ -1508,24 +1508,26 @@
       %7D%0A
+%0A%0A
         
 return m
@@ -1522,20 +1522,227 @@
     
-return model
+String tempPath = String.format(%22/tmp/preprocessor-classifier-remove-invalid-%25s.csv%22, Thread.currentThread().hashCode());%0A        model.DBModelToCsv(model, tempPath);%0A        return new FileDataModel(new File(tempPath))
 ;%0A  

Return FileDataModel in PreprocessorClassifier