Index: applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/AbstractTrainWorker.java
===================================================================
--- applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/AbstractTrainWorker.java	(revision 33013)
+++ applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/AbstractTrainWorker.java	(revision 33013)
@@ -0,0 +1,158 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.osmrec.core;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.swing.SwingWorker;
+
+import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;
+import org.openstreetmap.josm.plugins.osmrec.container.OSMWay;
+import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;
+import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector;
+import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;
+
+public abstract class AbstractTrainWorker extends SwingWorker<Void, Void> implements ActionListener {
+
+    protected final String inputFilePath;
+    protected static Map<String, String> mappings;
+    protected static Map<String, Integer> mapperWithIDs;
+
+    protected static List<OSMWay> wayList;
+    protected static List<OSMRelation> relationList;
+
+    protected static Map<String, List<String>> indirectClasses;
+    protected static Map<String, Integer> indirectClassesWithIDs;
+    protected static List<String> namesList;
+    protected int numberOfTrainingInstances;
+    protected final String modelDirectoryPath;
+    protected final File modelDirectory;
+    protected static double score1;
+    protected static double score5;
+    protected static double score10;
+    protected static double foldScore1;
+    protected static double foldScore5;
+    protected static double foldScore10;
+    protected static double bestScore;
+    protected final boolean validateFlag;
+    protected final double cParameterFromUser;
+    protected double bestConfParam;
+    protected final int topK;
+    protected final int frequency;
+    protected final boolean topKIsSelected;
+    protected String textualListFilePath;
+
+    protected static final boolean USE_CLASS_FEATURES = false;
+    protected static final boolean USE_RELATION_FEATURES = false;
+    protected static final boolean USE_TEXTUAL_FEATURES = true;
+    protected static int numberOfFeatures;
+    protected static LanguageDetector languageDetector;
+    protected final String inputFileName;
+
+    protected AbstractTrainWorker(String inputFilePath, boolean validateFlag, double cParameterFromUser,
+            int topK, int frequency, boolean topKIsSelected, LanguageDetector languageDetector) {
+        AbstractTrainWorker.languageDetector = languageDetector;
+        this.inputFilePath = inputFilePath;
+        this.validateFlag = validateFlag;
+        this.cParameterFromUser = cParameterFromUser;
+        this.topK = topK;
+        this.frequency = frequency;
+        this.topKIsSelected = topKIsSelected;
+        System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
+
+        if (System.getProperty("os.name").contains("ux")) {
+            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf('/'));
+        } else {
+            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf('\\'));
+        }
+
+        modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
+
+        modelDirectory = new File(modelDirectoryPath);
+
+        if (!modelDirectory.exists()) {
+            modelDirectory.mkdir();
+        }
+    }
+
+    protected void extractTextualList() {
+        System.out.println("Running analysis..");
+        //provide top-K
+        //Keep the top-K most frequent terms
+        //Keep terms with frequency higher than N
+        //Use the remaining terms as training features
+
+        Analyzer anal = new Analyzer(inputFilePath, languageDetector);
+        anal.runAnalysis();
+
+        textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt";
+        File textualFile = new File(textualListFilePath); //decide path of models
+        if (textualFile.exists()) {
+            textualFile.delete();
+        }
+        try {
+            textualFile.createNewFile();
+        } catch (IOException ex) {
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
+        }
+
+        List<Map.Entry<String, Integer>> textualList;
+        if (topKIsSelected) {
+            textualList = anal.getTopKMostFrequent(topK);
+        } else {
+            textualList = anal.getWithFrequency(frequency);
+        }
+
+        writeTextualListToFile(textualListFilePath, textualList);
+        System.out.println("textual list saved at location:\n" + textualListFilePath);
+        //write list to file and let parser do the loading from the names file
+
+        //method read default list
+        //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called
+        if (USE_CLASS_FEATURES) {
+            numberOfFeatures = 1422 + 105 + textualList.size(); //105 is number of geometry features
+        } else {
+            numberOfFeatures = 105 + textualList.size();
+        }
+    }
+
+    protected static void clearDataset() {
+        for (OSMWay way : wayList) {
+            way.getFeatureNodeList().clear();
+        }
+    }
+
+    protected void readTextualFromDefaultList(InputStream textualFileStream) {
+        TextualStatistics textualStatistics = new TextualStatistics();
+        textualStatistics.parseTextualList(textualFileStream);
+        namesList = textualStatistics.getTextualList();
+    }
+
+    protected void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) {
+        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
+            for (Map.Entry<String, Integer> entry : textualList) {
+                writer.write(entry.getKey());
+                writer.newLine();
+            }
+        } catch (IOException ex) {
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        // cancel button, end process after clearing Dataset
+    }
+}
Index: applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/TrainWorker.java
===================================================================
--- applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/TrainWorker.java	(revision 32404)
+++ applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/TrainWorker.java	(revision 33013)
@@ -4,17 +4,11 @@
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -26,9 +20,5 @@
 import java.util.logging.Logger;
 
-import javax.swing.SwingWorker;
-
-import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;
 import org.openstreetmap.josm.plugins.osmrec.container.OSMWay;
-import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;
 import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector;
 import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures;
@@ -40,5 +30,4 @@
 import org.openstreetmap.josm.plugins.osmrec.parsers.OSMParser;
 import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology;
-import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;
 
 import de.bwaldvogel.liblinear.FeatureNode;
@@ -54,67 +43,11 @@
  * @author imis-nkarag
  */
-public class TrainWorker extends SwingWorker<Void, Void> implements ActionListener {
-
-    private final String inputFilePath;
-    private static Map<String, String> mappings;
-    private static Map<String, Integer> mapperWithIDs;
-
-    private static List<OSMWay> wayList;
-    private static List<OSMRelation> relationList;
-
-    private static Map<String, List<String>> indirectClasses;
-    private static Map<String, Integer> indirectClassesWithIDs;
-    private static List<String> namesList;
-    private int numberOfTrainingInstances;
-    private final String modelDirectoryPath;
-    private final File modelDirectory;
-    private static double score1 = 0;
-    private static double score5 = 0;
-    private static double score10 = 0;
-    private static double foldScore1 = 0;
-    private static double foldScore5 = 0;
-    private static double foldScore10 = 0;
-    private static double bestScore = 0;
+public class TrainWorker extends AbstractTrainWorker {
+
     private int trainProgress = 0;
-    private final boolean validateFlag;
-    private final double cParameterFromUser;
-    private double bestConfParam;
-    private final int topK;
-    private final int frequency;
-    private final boolean topKIsSelected;
-    private String textualListFilePath;
-
-    private static final boolean USE_CLASS_FEATURES = false;
-    private static final boolean USE_RELATION_FEATURES = false;
-    private static final boolean USE_TEXTUAL_FEATURES = true;
-    private static int numberOfFeatures;
-    private static LanguageDetector languageDetector;
-    private final String inputFileName;
 
     public TrainWorker(String inputFilePath, boolean validateFlag, double cParameterFromUser,
             int topK, int frequency, boolean topKIsSelected, LanguageDetector languageDetector) {
-        TrainWorker.languageDetector = languageDetector;
-        this.inputFilePath = inputFilePath;
-        this.validateFlag = validateFlag;
-        this.cParameterFromUser = cParameterFromUser;
-        this.topK = topK;
-        this.frequency = frequency;
-        this.topKIsSelected = topKIsSelected;
-        if (System.getProperty("os.name").contains("ux")) {
-            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("/"));
-        } else {
-            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("\\"));
-        }
-        System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
-        modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
-
-        modelDirectory = new File(modelDirectoryPath);
-
-        if (!modelDirectory.exists()) {
-            modelDirectory.mkdir();
-            System.out.println("model directory created!");
-        } else {
-            System.out.println("directory already exists!");
-        }
+        super(inputFilePath, validateFlag, cParameterFromUser, topK, frequency, topKIsSelected, languageDetector);
     }
 
@@ -140,47 +73,6 @@
     }
 
-    private void extractTextualList() {
-        System.out.println("Running analysis..");
-        //provide top-K
-        //Keep the top-K most frequent terms
-        //Keep terms with frequency higher than N
-        //Use the remaining terms as training features
-
-        Analyzer anal = new Analyzer(inputFilePath, languageDetector);
-        anal.runAnalysis();
-
-        textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt";
-        File textualFile = new File(textualListFilePath); //decide path of models
-        if (textualFile.exists()) {
-            textualFile.delete();
-        }
-        try {
-            textualFile.createNewFile();
-        } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
-        }
-
-        List<Map.Entry<String, Integer>> textualList;
-        if (topKIsSelected) {
-            textualList = anal.getTopKMostFrequent(topK);
-        } else {
-            textualList = anal.getWithFrequency(frequency);
-        }
-
-        writeTextualListToFile(textualListFilePath, textualList);
-        System.out.println("textual list saved at location:\n" + textualListFilePath);
-        //write list to file and let parser do the loading from the names file
-
-        //method read default list
-        //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called
-        if (USE_CLASS_FEATURES) {
-            numberOfFeatures = 1422 + 105 + textualList.size(); //105 is number of geometry features
-        } else {
-            numberOfFeatures = 105 + textualList.size();
-        }
-    }
-
     private void parseFiles() {
-        InputStream tagsToClassesMapping = TrainWorker.class.getResourceAsStream("/resources/files/Map");
+        InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map");
 
         Mapper mapper = new Mapper();
@@ -193,5 +85,5 @@
         mapperWithIDs = mapper.getMappingsWithIDs();
 
-        InputStream ontologyStream = TrainWorker.class.getResourceAsStream("/resources/files/owl.xml");
+        InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml");
         Ontology ontology = new Ontology(ontologyStream);
 
@@ -205,5 +97,5 @@
             textualFileStream = new FileInputStream(new File(textualListFilePath));
         } catch (FileNotFoundException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
 
@@ -211,5 +103,4 @@
 
         OSMParser osmParser = new OSMParser(inputFilePath);
-
         osmParser.parseDocument();
         relationList = osmParser.getRelationList();
@@ -218,10 +109,9 @@
         System.out.println("number of instances: " + numberOfTrainingInstances);
         System.out.println("end of parsing files.");
-
     }
 
     public void validateLoop() {
-        Double[] confParams = new Double[] {Math.pow(2, -3), Math.pow(2, 1),
-                Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3)};
+        Double[] confParams = new Double[] {
+                Math.pow(2, -3), Math.pow(2, 1), Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3)};
 
         double bestC = Math.pow(2, -10);
@@ -259,8 +149,6 @@
             clearDataset();
             System.out.println("fold4");
-            //crossValidateFold(0, 5, 1, 2, true, param);
             crossValidateFold(0, 5, 2, 3, true, param);
             setProgress(4*((5*(trainProgress++))/confParams.length));
-            //System.out.println((5*trainProgress)/confParams.length);
 
             foldScore1 = foldScore1 + score1;
@@ -377,5 +265,4 @@
         problem.x = trainingSetWithUnknown2; // feature nodes
         problem.y = GROUPS_ARRAY2; // target values
-        //SolverType solver = SolverType.MCSVM_CS; //Cramer and Singer for multiclass classification - equivalent of SVMlight
         SolverType solver2 = SolverType.getById(2); //2 -- L2-regularized L2-loss support vector classification (primal)
 
@@ -414,5 +301,5 @@
             System.out.println("model saved at: " + modelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
 
@@ -432,5 +319,5 @@
             model = Model.load(modelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
         int modelLabelSize = model.getLabels().length;
@@ -554,5 +441,4 @@
         int wayListSizeWithoutUnclassified = wayList.size();
         System.out.println("trainList size: " + wayListSizeWithoutUnclassified);
-
         //set classes for each osm instance
         int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
@@ -657,7 +543,9 @@
         File customModelFile;
         if (topKIsSelected) {
-            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_topK" + topK + ".0");
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
+                    inputFileName + "_model_c" + param + "_topK" + topK + ".0");
         } else {
-            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + ".0");
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
+                    inputFileName + "_model_c" + param + "_maxF" + frequency + ".0");
         }
 
@@ -671,5 +559,4 @@
 
         try {
-            //System.out.println("file created");
             model.save(modelFile);
             model.save(customModelFile);
@@ -677,5 +564,5 @@
             System.out.println("custom model saved at: " + customModelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
     }
@@ -782,7 +669,9 @@
         File customModelFile;
         if (topKIsSelected) {
-            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model" + "_c" + param + "_topK" + topK + ".1");
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
+                    inputFileName + "_model" + "_c" + param + "_topK" + topK + ".1");
         } else {
-            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + ".1");
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
+                    inputFileName + "_model_c" + param + "_maxF" + frequency + ".1");
         }
 
@@ -799,21 +688,8 @@
             model.save(customModelFile);
             System.out.println("model with classes saved at: " + modelFile);
-            System.out.println("custom model with classes saved at: " + modelFile);
+            System.out.println("custom model with classes saved at: " + customModelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
-        }
-    }
-
-    private static void clearDataset() {
-        for (OSMWay way : wayList) {
-            way.getFeatureNodeList().clear();
-        }
-    }
-
-    private void readTextualFromDefaultList(InputStream textualFileStream) {
-
-        TextualStatistics textualStatistics = new TextualStatistics();
-        textualStatistics.parseTextualList(textualFileStream);
-        namesList = textualStatistics.getTextualList();
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
+        }
     }
 
@@ -827,23 +703,3 @@
         }
     }
-
-    @Override
-    public void actionPerformed(ActionEvent ae) {
-        //cancel button, end process after clearing Dataset
-    }
-
-    private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) {
-        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"))) {
-            for (Map.Entry<String, Integer> entry : textualList) {
-                writer.write(entry.getKey());
-                writer.newLine();
-            }
-        } catch (UnsupportedEncodingException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (FileNotFoundException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (IOException ex) {
-            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
-        }
-    }
 }
Index: applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java
===================================================================
--- applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java	(revision 32404)
+++ applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java	(revision 33013)
@@ -4,17 +4,11 @@
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -26,9 +20,6 @@
 import java.util.logging.Logger;
 
-import javax.swing.SwingWorker;
-
-import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;
 import org.openstreetmap.josm.plugins.osmrec.container.OSMWay;
-import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;
+import org.openstreetmap.josm.plugins.osmrec.core.AbstractTrainWorker;
 import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector;
 import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures;
@@ -39,5 +30,4 @@
 import org.openstreetmap.josm.plugins.osmrec.parsers.Mapper;
 import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology;
-import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;
 
 import de.bwaldvogel.liblinear.FeatureNode;
@@ -53,69 +43,13 @@
  *  @author imis-nkarag
  */
-public class TrainByUser extends SwingWorker<Void, Void> implements ActionListener {
-
-    private final String inputFilePath;
-    private static Map<String, String> mappings;
-    private static Map<String, Integer> mapperWithIDs;
-    private static List<OSMWay> wayList;
-    private static List<OSMRelation> relationList;
-
-    private static Map<String, List<String>> indirectClasses;
-    private static Map<String, Integer> indirectClassesWithIDs;
-    private static List<String> namesList;
-    private int numberOfTrainingInstances;
-    private final String modelDirectoryPath;
-    private final File modelDirectory;
-    private static double score1 = 0;
-    private static double score5 = 0;
-    private static double score10 = 0;
-    private static double foldScore1 = 0;
-    private static double foldScore5 = 0;
-    private static double foldScore10 = 0;
-    private static double bestScore = 0;
-    private final boolean validateFlag;
-    private final double cParameterFromUser;
-    private double bestConfParam;
-    private final int topK;
-    private final int frequency;
-    private final boolean topKIsSelected;
-    private String textualListFilePath;
-    private static final boolean USE_CLASS_FEATURES = false;
-    private static final boolean USE_RELATION_FEATURES = false;
-    private static final boolean USE_TEXTUAL_FEATURES = true;
-    private static int numberOfFeatures;
-    private static LanguageDetector languageDetector;
+public class TrainByUser extends AbstractTrainWorker {
+
     private final String username;
-    private final String inputFileName;
 
     public TrainByUser(String inputFilePath, String username, boolean validateFlag, double cParameterFromUser,
             int topK, int frequency, boolean topKIsSelected, LanguageDetector languageDetector, List<OSMWay> wayList) {
-        TrainByUser.languageDetector = languageDetector;
-        this.inputFilePath = inputFilePath;
+        super(inputFilePath, validateFlag, cParameterFromUser, topK, frequency, topKIsSelected, languageDetector);
         this.username = username;
-        this.validateFlag = validateFlag;
-        this.cParameterFromUser = cParameterFromUser;
-        this.topK = topK;
-        this.frequency = frequency;
-        this.topKIsSelected = topKIsSelected;
-        System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
-
-        if (System.getProperty("os.name").contains("ux")) {
-            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("/"));
-        } else {
-            inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("\\"));
-        }
-
-        modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
-
-        modelDirectory = new File(modelDirectoryPath);
-
-        if (!modelDirectory.exists()) {
-            modelDirectory.mkdir();
-            System.out.println("model directory created!");
-        } else {
-            System.out.println("directory already exists!");
-        }
-        TrainByUser.wayList = wayList;
+        AbstractTrainWorker.wayList = wayList;
     }
 
@@ -153,50 +87,6 @@
     }
 
-    private void extractTextualList() {
-        System.out.println("Running analysis..");
-        //provide top-K
-        //Keep the top-K most frequent terms
-        //Keep terms with frequency higher than N
-        //Use the remaining terms as training features
-
-        Analyzer anal = new Analyzer(inputFilePath, languageDetector);
-        anal.runAnalysis();
-
-        textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt";
-        File textualFile = new File(textualListFilePath); //decide path of models
-        if (textualFile.exists()) {
-            textualFile.delete();
-        }
-        try {
-            textualFile.createNewFile();
-        } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
-        }
-
-        //writeTextualListToFile(textualFilePath, anal.getTopKMostFrequent(15));
-        List<Map.Entry<String, Integer>> textualList;
-        if (topKIsSelected) {
-            textualList = anal.getTopKMostFrequent(topK);
-            System.out.println(textualList);
-        } else {
-            textualList = anal.getWithFrequency(frequency);
-            System.out.println(textualList);
-        }
-
-        writeTextualListToFile(textualListFilePath, textualList);
-        System.out.println("textual list saved at location:\n" + textualListFilePath);
-        //write list to file and let parser do the loading from the names file
-
-        //method read default list
-        //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called
-        if (USE_CLASS_FEATURES) {
-            numberOfFeatures = 1422 + 105 + textualList.size();
-        } else {
-            numberOfFeatures = 105 + textualList.size();
-        }
-    }
-
     private void parseFiles() {
-        InputStream tagsToClassesMapping = TrainByUser.class.getResourceAsStream("/resources/files/Map");
+        InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map");
 
         Mapper mapper = new Mapper();
@@ -209,5 +99,5 @@
         mapperWithIDs = mapper.getMappingsWithIDs();
 
-        InputStream ontologyStream = TrainByUser.class.getResourceAsStream("/resources/files/owl.xml");
+        InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml");
         Ontology ontology = new Ontology(ontologyStream);
 
@@ -217,17 +107,13 @@
         indirectClassesWithIDs = ontology.getIndirectClassesIDs();
 
-        //InputStream textualFileStream = TrainWorker.class.getResourceAsStream("/resources/files/names");
         InputStream textualFileStream = null;
         try {
             textualFileStream = new FileInputStream(new File(textualListFilePath));
         } catch (FileNotFoundException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
 
         readTextualFromDefaultList(textualFileStream);
 
-        //osmParser.parseDocument();
-        //relationList = osmParser.getRelationList();
-        //wayList = osmParser.getWayList();
         numberOfTrainingInstances = wayList.size();
         System.out.println("number of instances: " + numberOfTrainingInstances);
@@ -238,5 +124,5 @@
     }
 
-    private void validateLoop() {
+    public void validateLoop() {
         Double[] confParams = new Double[] {
                 Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3), Math.pow(2, -1), Math.pow(2, 0)};
@@ -295,5 +181,5 @@
     }
 
-    private void crossValidateFold(int a, int b, int c, int d, boolean skip, double param) {
+    public void crossValidateFold(int a, int b, int c, int d, boolean skip, double param) {
         System.out.println("Starting cross validation");
         int testSize = wayList.size()/5;
@@ -418,10 +304,11 @@
         }
         try {
-            //System.out.println("file created");
             model.save(modelFile);
-            //System.out.println("saved");
+            System.out.println("model saved at: " + modelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
-        }
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
+        }
+
+        //end of evaluation training
 
         //test set
@@ -438,5 +325,5 @@
             model = Model.load(modelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
         int modelLabelSize = model.getLabels().length;
@@ -511,10 +398,4 @@
 
             Arrays.sort(scores);
-            //System.out.println("max value: " + scores[scores.length-1] + " second max: " + scores[scores.length-2]);
-            //System.out.println("ask this index from labels: " + scoresValues.get(scores[scores.length-1]));
-            //System.out.println("got from labels: " +  labels[scoresValues.get(scores[scores.length-1])]);
-            //System.out.println("next prediction: " +  labels[scoresValues.get(scores[scores.length-2])]);
-            //System.out.println("way labels: " + way.getClassIDs());
-            //System.out.println("test prediction: " + prediction);
             if (way.getClassIDs().contains(labels[scoresValues.get(scores[scores.length-1])])) {
                 succededInstances++;
@@ -573,5 +454,4 @@
         //set classes for each osm instance
         int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
-
         for (OSMWay way : wayList) {
             OSMClassification classifyInstances = new OSMClassification();
@@ -584,5 +464,4 @@
             }
         }
-        //System.out.println("end classify instances");
         double C = param;
         double eps = 0.001;
@@ -687,8 +566,8 @@
             model.save(modelFile);
             model.save(customModelFile);
-            System.out.println("model saved at: " + modelFile);
+            System.out.println("best model saved at: " + modelFile);
             System.out.println("custom model saved at: " + customModelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
     }
@@ -815,35 +694,5 @@
             System.out.println("custom model with classes saved at: " + customModelFile);
         } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
-        }
-    }
-
-    private static void clearDataset() {
-        for (OSMWay way : wayList) {
-            way.getFeatureNodeList().clear();
-        }
-    }
-
-    private void readTextualFromDefaultList(InputStream textualFileStream) {
-
-        TextualStatistics textualStatistics = new TextualStatistics();
-        textualStatistics.parseTextualList(textualFileStream);
-        namesList = textualStatistics.getTextualList();
-
-    }
-
-    private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) {
-        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"))) {
-            for (Map.Entry<String, Integer> entry : textualList) {
-                writer.write(entry.getKey());
-                writer.newLine();
-                System.out.println(entry.getKey());
-            }
-        } catch (UnsupportedEncodingException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (FileNotFoundException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (IOException ex) {
-            Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
         }
     }
@@ -859,8 +708,3 @@
         }
     }
-
-    @Override
-    public void actionPerformed(ActionEvent ae) {
-        //cancel button, end process after clearing Dataset
-    }
 }
