@@ -0,0 +1,2276 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage de.hsbo.fbg.sm4c.classify;%0A%0Aimport de.hsbo.fbg.common.config.Configuration;%0Aimport de.hsbo.fbg.sm4c.classify.train.Dataset;%0Aimport de.hsbo.fbg.sm4c.common.model.Collection;%0Aimport de.hsbo.fbg.sm4c.common.model.Model;%0Aimport java.io.File;%0Aimport weka.classifiers.Classifier;%0Aimport weka.core.Instances;%0Aimport weka.core.SerializationHelper;%0Aimport weka.core.converters.ArffSaver;%0Aimport weka.core.converters.ConverterUtils.DataSource;%0A%0A/**%0A *%0A * @author Sebastian Drost%0A */%0Apublic class ModelManager %7B%0A%0A    private static final String WEKA_PATH_KEY = %22weka_path%22;%0A%0A    public String%5B%5D serializeModel(AbstractClassifier classifier, Collection collection) throws Exception %7B%0A        String%5B%5D paths = new String%5B2%5D;%0A        String userHome = System.getProperty(%22user.home%22);%0A        String wekaPath = Configuration.getConfig().getPropertyValue(WEKA_PATH_KEY);%0A        StringBuilder builder = new StringBuilder();%0A        builder.append(userHome).append(wekaPath).append(collection.getName());%0A        String classifierFileName = builder.toString() + %22.model%22;%0A        SerializationHelper.write(classifierFileName, classifier.getClassifier());%0A%0A        String datasetFilename = builder.toString() + %22.arff%22;%0A        ArffSaver saver = new ArffSaver();%0A        saver.setInstances(classifier.getTrainingData().getModelDataset());%0A        saver.setFile(new File(datasetFilename));%0A        saver.writeBatch();%0A%0A        paths%5B0%5D = classifierFileName.replace(%22%5C%5C%22, %22/%22);%0A        paths%5B1%5D = datasetFilename.replace(%22%5C%5C%22, %22/%22);%0A        return paths;%0A    %7D%0A%0A    public AbstractClassifier deserializeModel(Model model) throws Exception %7B%0A        Classifier cls = (Classifier) SerializationHelper.read(model.getClassifierPath());%0A        ClassifierFactory factory = new ClassifierFactory();%0A        AbstractClassifier result = factory.createClassifier(model.getClassifier().getName(), cls);%0A%0A        DataSource source = new DataSource(model.getInputDataPath());%0A        Instances data = source.getDataSet();%0A        result.setFormat(new Dataset(source.getDataSet()));%0A        return result;%0A    %7D%0A%0A%7D%0A

introduce manager for serializing classifier