Index: /applications/editors/josm/plugins/OSMRecPlugin/nbproject/private/private.xml
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/nbproject/private/private.xml	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/nbproject/private/private.xml	(revision 31554)
@@ -4,10 +4,11 @@
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
-            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java</file>
+            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java</file>
             <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java</file>
-            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java</file>
             <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java</file>
-            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/Analyzer.java</file>
+            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java</file>
+            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java</file>
             <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java</file>
+            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java</file>
         </group>
     </open-files>
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java	(revision 31554)
@@ -91,4 +91,5 @@
     private static int numberOfFeatures;
     private static LanguageDetector languageDetector;
+    private final String inputFileName;
     
     
@@ -104,4 +105,6 @@
         this.frequency = frequency;
         this.topKIsSelected = topKIsSelected;
+        
+        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";
@@ -744,11 +747,27 @@
         
         File modelFile = new File(modelDirectory.getAbsolutePath()+"/best_model"); //decide path of models
+        
+        File customModelFile;
+        if(topKIsSelected){
+            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");
+        }
+        
+        
         if(modelFile.exists()){
             modelFile.delete();
-        }        
+        }       
+        if(customModelFile.exists()){
+            customModelFile.delete();
+        }         
+        
         try {
             //System.out.println("file created");
             model.save(modelFile);
+            model.save(customModelFile);
             System.out.println("best model saved at: " + modelFile); 
+            System.out.println("custom model saved at: " + customModelFile);
         } catch (IOException ex) {
             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
@@ -873,11 +892,28 @@
         
         File modelFile = new File(modelDirectory.getAbsolutePath()+"/model_with_classes"); 
+        
+                
+        File customModelFile;
+        if(topKIsSelected){
+            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");
+        }               
+              
+        if(customModelFile.exists()){
+            customModelFile.delete();
+        }                 
+                
         if(modelFile.exists()){
             modelFile.delete();
-        }        
+        } 
+   
         try {
             //System.out.println("file created");
             model.save(modelFile);
+            model.save(customModelFile);
             System.out.println("model with classes saved at: " + modelFile); 
+            System.out.println("custom model with classes saved at: " + modelFile);
         } catch (IOException ex) {
             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java	(revision 31554)
@@ -29,4 +29,8 @@
         //File modelFile = new File(bestModelPath);
         File targetFile = new File(modelPath);
+        
+        if(targetFile.exists()){
+            return;
+        }
         try {
             targetFile.createNewFile();
@@ -38,21 +42,5 @@
         System.out.println("trying to get stream.. for " + "/resources/files/" + modelName);
         svmModelStream = SampleModelsExtractor.class.getResourceAsStream("/resources/files/" + modelName);
-        
-        
-        //Scanner input = new Scanner(svmModelStream);
-        //svmModelStream.
-        
-        
-//            while (input.hasNext()) {
-//                String nextLine = input.nextLine();
-//
-//                //outputStream.write(nextLine.getBytes(Charset.forName("UTF-8")));
-//                System.out.println(nextLine);
-//                //outputStream.write(nextLine);
-//                //textualList.add(nextLine);
-//
-//            }       
-//            System.out.println("GER RESOURCE SUCCESS");
-            
+           
         try {
             outputStream = new FileOutputStream(targetFile);
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java	(revision 31554)
@@ -6,5 +6,5 @@
 import org.openstreetmap.josm.plugins.Plugin;
 import org.openstreetmap.josm.plugins.PluginInformation;
-import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
+//import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
 
 /** 
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java	(revision 31554)
@@ -37,8 +37,13 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.io.EOFException;
 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.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
@@ -53,4 +58,5 @@
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Scanner;
 import java.util.concurrent.CancellationException;
@@ -74,4 +80,5 @@
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JList;
@@ -164,4 +171,6 @@
     private boolean useCustomSVMModel = false;
     private String customSVMModelPath;
+    private final String combinedModelClasses;
+    private final String combinedModel;
        
     // Selection that we are editing by using both dialogs
@@ -205,12 +214,15 @@
         MODEL_PATH = new File(MAIN_PATH).getParentFile() + "/OSMRec_models";
         TEXTUAL_LIST_PATH = MODEL_PATH + "/textualList.txt";
+        combinedModelClasses = MODEL_PATH + "/combinedModel.1";
+        combinedModel = MODEL_PATH + "/combinedModel.0";
         bestModelPath = MODEL_PATH + "/best_model";
+        customSVMModelPath = bestModelPath;
         modelWithClassesPath = MODEL_PATH + "/model_with_classes";
         languageDetector = LanguageDetector.getInstance(MODEL_PATH + "/profiles");
 
-        SampleModelsExtractor sa = new SampleModelsExtractor();
-        
-        sa.extractSampleSVMmodel("best_model", bestModelPath);
-        sa.extractSampleSVMmodel("model_with_classes", modelWithClassesPath);
+        SampleModelsExtractor sampleModelsExtractor = new SampleModelsExtractor();
+                
+        sampleModelsExtractor.extractSampleSVMmodel("best_model", bestModelPath);
+        sampleModelsExtractor.extractSampleSVMmodel("model_with_classes", modelWithClassesPath);
         
     }
@@ -1199,6 +1211,7 @@
         private final JButton chooseModelButton;
         private final JTextField chooseModelTextField;
-        private final JList<String> modelCombinationList;
+        
         private final DefaultListModel<String> combinationDefaultListModel = new DefaultListModel<>();
+        private final JList<String> modelCombinationList = new javax.swing.JList<>(combinationDefaultListModel);
         private final JPanel modelCombinationPanel;
         //private final JTextField weightTextField;
@@ -1210,15 +1223,35 @@
         private final JButton resetWeightsButton;
         private final JButton removeSelectedModelButton;
-        private final Map<JTextField, String> weightFieldsAndPaths = new HashMap<>();
+        private Map<JTextField, String> weightFieldsAndPaths = new HashMap<>();
         private final Map<String, Double> normalizedPathsAndWeights = new HashMap<>();
+        private final JOptionPane pane;
+        private final JDialog dlg;
+        private final JPanel mainPanel;
+        private final JPanel singleSelectionPanel;
+        private final JPanel setResetWeightsPanel;
+        private final JScrollPane combinationScrollPane;
+        private final JScrollPane singleSelectionScrollPane;
+        private final TitledBorder modelTitle;
+        private final TitledBorder weightTitle;
+        private final TitledBorder combineTitle;
+        //private final BorderLayout mainBorderLayout;
+        //private final BorderLayout mainBorderLayoutDefault;
+        //private final Dimension combinationPanelDimension;
+        private final Dimension singleSelectionDimension;
+        private final Dimension modelCombinationDimension;
+        private final Dimension mainPanelDimension;
         
-        public ModelSettingsDialog(Collection<OsmPrimitive> sel, AddTagsDialog addDialog){  
-            //checkbox: use combined models
-            //button: remove selected model
+        
+        public ModelSettingsDialog(Collection<OsmPrimitive> sel1, final AddTagsDialog addDialog){ 
+            
+            loadPreviousCombinedSVMModel();
+            singleSelectionDimension = new Dimension(470,70);
+            modelCombinationDimension = new Dimension(450,250);
+            mainPanelDimension = new Dimension(600,350);
             
             //------- <NORTH of main> ---------//
-            JPanel mainPanel = new JPanel(new BorderLayout(10,10));
-            JPanel singleSelectionPanel = new JPanel(new BorderLayout(10,10));
-            JPanel setResetWeightsPanel = new JPanel();
+            mainPanel = new JPanel(new BorderLayout(10,10));
+            singleSelectionPanel = new JPanel(new BorderLayout(10,10));
+            setResetWeightsPanel = new JPanel();
             
             chooseModelLabel = new javax.swing.JLabel("Choose a Model:");
@@ -1230,11 +1263,16 @@
             singleSelectionPanel.add(chooseModelTextField, BorderLayout.WEST);
             singleSelectionPanel.add(chooseModelButton, BorderLayout.EAST); 
+            
+            singleSelectionScrollPane = new JScrollPane(singleSelectionPanel);
+            singleSelectionScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+            singleSelectionScrollPane.setPreferredSize(singleSelectionDimension);
+            
             //------- </NORTH of main> ---------//
 
             //------- <WEST of main> ---------//
-            modelCombinationList = new javax.swing.JList<>(combinationDefaultListModel);
+            //modelCombinationList = new javax.swing.JList<>(combinationDefaultListModel);
             modelCombinationList.setFixedCellHeight(20);  
             modelCombinationList.setEnabled(false);
-            modelCombinationPanel = new JPanel(new BorderLayout()); 
+            modelCombinationPanel = new JPanel(new BorderLayout(10,10)); //new BorderLayout() 
 
             weightsPanel = new JPanel();
@@ -1257,11 +1295,11 @@
             modelCombinationPanel.add(setResetWeightsPanel, BorderLayout.SOUTH); 
 
-            JScrollPane combinationScrollPane = new JScrollPane(modelCombinationPanel);
+            combinationScrollPane = new JScrollPane(modelCombinationPanel);
             
             combinationScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
-            combinationScrollPane.setPreferredSize(new Dimension(450,250));    // w/h        
+            combinationScrollPane.setPreferredSize(modelCombinationDimension);   //new Dimension(450,250) // w/h  
+
             //------- </WEST of main> ---------//
 
-            
             //------- <SOUTH of main> ---------//
             useModelCombinationCheckbox = new JCheckBox("Combine different models?");
@@ -1270,9 +1308,21 @@
             
             //------- <Borders> ---------//
-            TitledBorder modelTitle = BorderFactory.createTitledBorder("Models");
-            TitledBorder weightTitle = BorderFactory.createTitledBorder("W");
-            TitledBorder combineTitle = BorderFactory.createTitledBorder("Combine Models");
+            modelTitle = BorderFactory.createTitledBorder("Models");
+            weightTitle = BorderFactory.createTitledBorder("W");
+            combineTitle = BorderFactory.createTitledBorder("Combine Models");
             modelCombinationList.setBorder(modelTitle);
             weightsPanel.setBorder(weightTitle);
+            
+            for(Entry<JTextField, String> entry : weightFieldsAndPaths.entrySet()){
+                //modelCombinationList.add(entry.getValue());
+                combinationDefaultListModel.addElement(entry.getValue());
+                
+                JTextField weightTextField = new javax.swing.JTextField("0.00");                   
+                weightTextField.setMaximumSize(new Dimension(80,20));
+                weightsPanel.add(entry.getKey());               
+
+                //entry.getKey().setText("0.00");
+            }            
+            
             //modelCombinationPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE));
             modelCombinationPanel.setBorder(combineTitle);
@@ -1314,37 +1364,121 @@
                 }
             });            
-            mainPanel.add(singleSelectionPanel, BorderLayout.NORTH);
-            mainPanel.add(combinationScrollPane, BorderLayout.CENTER);
+            mainPanel.add(singleSelectionScrollPane, BorderLayout.NORTH);
+            mainPanel.add(combinationScrollPane, BorderLayout.CENTER);  
             mainPanel.add(useModelCombinationCheckbox,BorderLayout.SOUTH);
 
+            mainPanel.setPreferredSize(mainPanelDimension);
+            
             this.add(mainPanel);
-            
-            JOptionPane pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
-            JDialog dlg = pane.createDialog(Main.parent, tr("Model Settings"));            
-            dlg.setVisible(true);
-            //JButton ok = dlg.getRootPane().getDefaultButton();
-            
+            //pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
+            
+            //final JFrame frame = new JFrame();
+            pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
+                @Override
+                public void setValue(Object newValue) {
+                    super.setValue(newValue);
+                    if(newValue instanceof Integer && (int) newValue == 0 && useModelCombinationCheckbox.isSelected()){
+                        System.out.println("model settings button value: " + newValue);
+                        System.out.println("\nUSE COMBINED MODEL\n");
+                        useCombinedModel = true;
+                        useCustomSVMModel = false;
+                        
+                        addDialog.loadSVMmodel(); 
+                        addDialog.createOSMObject(sel);                              
+                        saveCombinedModel();
+                        dlg.setVisible(false);
+                        //this.setVisible(false);
+                    }
+                    else if(newValue instanceof Integer && (int) newValue == -1 && useModelCombinationCheckbox.isSelected()){
+                        System.out.println("model settings button value: " + newValue);
+                        useCombinedModel = false;
+                        useCustomSVMModel = false;
+                        System.out.println("Use combined model");
+
+                        addDialog.loadSVMmodel();
+                        addDialog.createOSMObject(sel);
+                        dlg.setVisible(false);
+                    } 
+                    else if(newValue instanceof Integer && (int) newValue == 0 && !useModelCombinationCheckbox.isSelected() ){
+                        System.out.println("model settings button value: " + newValue);
+                        System.out.println("Don t use combined model, use custom model");
+                        useCombinedModel = false;
+                        useCustomSVMModel = true;
+                        addDialog.loadSVMmodel();
+                        addDialog.createOSMObject(sel);
+                        dlg.setVisible(false);
+                    } 
+                    else if(newValue instanceof Integer && (int) newValue == -1 && !useModelCombinationCheckbox.isSelected() ){
+                        System.out.println("model settings button value: " + newValue);
+                        System.out.println("Don t use combined model, use custom model");
+                        useCombinedModel = false;
+                        useCustomSVMModel = false;
+                        addDialog.loadSVMmodel();
+                        addDialog.createOSMObject(sel);
+                        dlg.setVisible(false);
+                    }      
+                    else if(newValue == null || newValue.equals("uninitializedValue")){
+                        System.out.println("uninitializedValue, do nothing");
+                    }
+                    //JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue);
+                }
+            };            
+            
+            
+            //pane.showConfirmDialog();
+            //pane.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY);
+            
+            
+             //JButton ok = dlg.getRootPane().getDefaultButton();
+            dlg = pane.createDialog(Main.parent, tr("Model Settings"));
+            dlg.setVisible(true);  
+            
+            /*
             //returned value of pane.getValue indicates the key pressed by the user. "0" is for the OK button
             int buttonValue = -1;
             if(pane.getValue() != null){
+                //System.out.println("type? " + pane.getValue());
                 buttonValue = (int) pane.getValue();
             }
-            
-            System.out.println("value of model sel button: " + pane.getValue());
-            if(buttonValue == 0 && useCombinedModel && useModelCombinationCheckbox.isSelected()){
-                System.out.println("\n\nUSE COMBINED MODEL\n\n");
+
+            System.out.println("value of model sel button: " + pane.getValue());           
+           
+            if(buttonValue == 0 && useModelCombinationCheckbox.isSelected()){
+                useCombinedModel = true;
+                System.out.println("\nold - USE COMBINED MODEL\n");
                 //recompute predictions with combination
-                modelWithClasses = false;
+                
+                //modelWithClasses = false;
                 addDialog.loadSVMmodel(); 
-                addDialog.createOSMObject(sel);
-            }
-            else {
-                useCombinedModel = false;
+                addDialog.createOSMObject(sel);                               
+                saveCombinedModel();
+                dlg.setVisible(false);
+                //this.setVisible(false);
+            }
+            else if(useModelCombinationCheckbox.isSelected()){
+                useCombinedModel = true;
+                System.out.println("old - use combined model");
+                
                 addDialog.loadSVMmodel();
                 addDialog.createOSMObject(sel);
-            }            
+                dlg.setVisible(false);
+            } 
+            else{
+                System.out.println("old - don t use combined model, use custom model");
+                useCombinedModel = false;
+                useCustomSVMModel = true;
+                addDialog.loadSVMmodel();
+                addDialog.createOSMObject(sel);
+                dlg.setVisible(false);
+            }
+            */
         }
         
-        private void modelChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {     
+        public void makeVisible(boolean visible){ 
+            dlg.setVisible(true);
+        }
+        
+        private void modelChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {   
+            
             try {
                 final File file = new File(chooseModelTextField.getText());
@@ -1384,5 +1518,8 @@
         
         private void userCombinationCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
+
             if(useModelCombinationCheckbox.isSelected()){
+                useCombinedModel = true;
+                useCustomSVMModel = false; //reseting the selected custom SVM model only here
                 removeSelectedModelButton.setEnabled(true);
                 acceptWeightsButton.setEnabled(true);
@@ -1396,7 +1533,9 @@
                     weightPanelComponent.setEnabled(true);
                 }
-                useCustomSVMModel = false; //reseting the selected custom SVM model only here
+                
             }
             else{
+                useCombinedModel = false;
+                useCustomSVMModel = true;
                 removeSelectedModelButton.setEnabled(false);
                 acceptWeightsButton.setEnabled(false);
@@ -1414,7 +1553,12 @@
         
         private void acceptWeightsButtonActionPerformed(ActionEvent evt) {
+            int weightsCount = 0;
             removeSelectedModelButton.setEnabled(false);
             double weightSum = 0;            
             for(JTextField weightField : weightFieldsAndPaths.keySet()){
+                if(weightField.getText().equals("")){
+                    weightField.setText("0.00");
+                }
+                
                 try{
                     Double weightValue = Double.parseDouble(weightField.getText());
@@ -1426,4 +1570,5 @@
                     Main.warn(ex);
                 }
+                weightsCount++;
             }  
             
@@ -1437,4 +1582,10 @@
 
                     weightValue = Math.abs(weightValue)/weightSum; //normalize
+                    
+                    if(weightSum == 0){
+                        //System.out.println("Zero weights");
+                        weightValue = 1.0/weightsCount;
+                    }                    
+                    
                     weightField.setText(new DecimalFormat("#.##").format(weightValue));
                     normalizedPathsAndWeights.put(weightFieldsAndPaths.get(weightField), weightValue);                   
@@ -1450,4 +1601,6 @@
 
             useCombinedModel = true;
+            useCustomSVMModel = false;
+            
             //filesAndWeights.putAll(normalizedPathsAndWeights);
         }
@@ -1462,8 +1615,61 @@
         private void removeSelectedModelButtonActionPerformed(ActionEvent evt) {
             int index  = modelCombinationList.getSelectedIndex();
-            combinationDefaultListModel.remove(index);
+            String modelToBeRemoved = combinationDefaultListModel.get(index);
+            combinationDefaultListModel.remove(index); 
+            System.out.println("model to be removed: " + modelToBeRemoved);
+
+            Iterator<Entry<JTextField, String>> it = weightFieldsAndPaths.entrySet().iterator();               
+            while (it.hasNext()) {
+                Entry<JTextField, String> en = it.next();
+                if(en.getValue().equals(modelToBeRemoved)){
+                    it.remove();
+                }
+            }
+            System.out.println("model to be removed: " + modelToBeRemoved);
+
             weightsPanel.remove(index); 
             weightsPanel.revalidate();
             weightsPanel.repaint();
+        }
+
+        @SuppressWarnings("unchecked")
+        private void loadPreviousCombinedSVMModel() {
+            File combinedModelClassesFile = new File(combinedModelClasses);
+
+            if (combinedModelClassesFile.exists()) {
+                FileInputStream fileIn = null;
+                ObjectInputStream in = null;
+                try {
+                    fileIn = new FileInputStream(combinedModelClassesFile);
+                    in = new ObjectInputStream(fileIn);
+                    weightFieldsAndPaths = (Map<JTextField, String>) in.readObject();
+                } catch (FileNotFoundException ex) {
+                    Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex);
+                } catch (IOException | ClassNotFoundException ex) {
+                    Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex);
+                } finally {
+                    try {
+                        in.close();
+                        fileIn.close();
+                    } catch (IOException ex) {
+                        Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                }
+            } else {
+                try {
+                    combinedModelClassesFile.createNewFile();
+                } catch (IOException ex) {
+                    Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+        }
+
+        private void saveCombinedModel() {
+            try (FileOutputStream fileOut = new FileOutputStream(combinedModelClasses);
+                ObjectOutputStream out = new ObjectOutputStream(fileOut)) {
+                out.writeObject(weightFieldsAndPaths);
+            } catch (IOException e) {
+                System.out.println("serialize error" + e);
+            }
         }
     }
@@ -1484,7 +1690,10 @@
         private Map<String, String> mappings;
         private Map<String, Integer> mapperWithIDs;
+        private Map<Integer, String> idsWithMappings;
         private List<String> textualList = new ArrayList<>();
         //private boolean useClassFeatures = false;
-        private final JCheckBox useTagsCheckBox;       
+        private final JCheckBox useTagsCheckBox;  
+        private ModelSettingsDialog modelSettingsDialog;
+        private static final int RECOMMENDATIONS_SIZE = 10;
 
         public AddTagsDialog() {
@@ -1493,5 +1702,5 @@
             setCancelButton(2);
             configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */);
-            final AddTagsDialog lala = this;
+            final AddTagsDialog addTagsDialog = this;
             
             loadOntology();
@@ -1567,8 +1776,18 @@
                 @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt) {
-
-                    ModelSettingsDialog modelSettingsDialog = new ModelSettingsDialog(sel, lala);  
-                }
-            });            
+                    if(modelSettingsDialog == null){
+                        System.out.println("new modelSettingsDialog");
+                        modelSettingsDialog = new ModelSettingsDialog(sel, addTagsDialog);  
+                        
+                        //modelSettingsDialog.makeVisible(true);
+                        //modelSettingsDialog.setVisible(true);
+                    }
+                    else{
+                        System.out.println("set modelSettingsDialog visible");
+                        modelSettingsDialog.makeVisible(true);
+                        //modelSettingsDialog.setVisible(true);
+                    } 
+                }
+            });         
 
             useTagsCheckBox.addActionListener(new java.awt.event.ActionListener() {                
@@ -1938,13 +2157,131 @@
 
         private void loadSVMmodel() {
+            File modelDirectory = new File(MODEL_PATH);
+            File modelFile = null;
+            if(useCombinedModel){
+                if(filesAndWeights.isEmpty()){
+                    System.out.println("No models selected! Loading defaults..");
+                    if(modelWithClasses){
+                        System.out.println("Using default/last model with classes: " + modelDirectory.getAbsolutePath() + "/model_with_classes");
+                        modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes");
+                    }
+                    else{
+                        System.out.println("Using default/last model without classes: " + modelDirectory.getAbsolutePath() + "/best_model");
+                        modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model");
+                    } 
+                }               
+                if(modelWithClasses){ //check filenames to define if model with classes is selected
+                    System.out.println("Using combined model with classes");
+                    useCombinedSVMmodels(sel, true);
+                }
+                else{
+                    System.out.println("Using combined model without classes");
+                    useCombinedSVMmodels(sel, false);
+                }               
+                                
+            }
+            else if(useCustomSVMModel){
+                System.out.println("custom path: " + customSVMModelPath);
+                File checkExistance = new File(customSVMModelPath);             
+                if(checkExistance.exists() && checkExistance.isFile()){
+                    if (modelWithClasses) {
+                        System.out.println("Using custom model with classes: ");
+                        if (customSVMModelPath.endsWith(".0")) {
+                            //String customSVMModelPathWithClasses = customSVMModelPath.replace(".0", ".1");
+                            String customSVMModelPathWithClasses = customSVMModelPath.substring(0, customSVMModelPath.length() - 2) + ".1";
+
+                            modelFile = new File(customSVMModelPathWithClasses);
+                            System.out.println(customSVMModelPathWithClasses);
+                        } 
+                        else {
+                            modelFile = new File(customSVMModelPath);
+                        }
+                    } else {
+                        System.out.println("Using custom model without classes");
+                        if (customSVMModelPath.endsWith(".1")) {
+                            String customSVMModelPathWithoutClasses = customSVMModelPath.substring(0, customSVMModelPath.length() - 2) + ".0";
+                            modelFile = new File(customSVMModelPathWithoutClasses);
+                            System.out.println(customSVMModelPathWithoutClasses);
+                        } else {
+                            modelFile = new File(customSVMModelPath);
+                        }
+                    }
+                    try {
+                        System.out.println("try to load model: " + modelFile.getAbsolutePath());
+                        modelSVM = Model.load(modelFile);
+                        System.out.println("model loaded!");
+
+                    } catch (IOException ex) {
+                        Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                    modelSVMLabelSize = modelSVM.getLabels().length;
+                    modelSVMLabels = modelSVM.getLabels();                    
+
+                } 
+                else {
+                    //user chose to use a custom model, but did not provide a path to a model:
+                    if(modelWithClasses){
+                        System.out.println("Using default/last model with classes");
+                        modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes");
+                    }
+                    else{
+                        System.out.println("Using default/last model without classes");
+                        modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model");
+                    }
+
+                    try {
+                        System.out.println("try to load model: " + modelFile.getAbsolutePath());
+                        modelSVM = Model.load(modelFile);
+                        System.out.println("model loaded!");
+
+                    } catch (IOException ex) {
+                        Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+                    }
+                    modelSVMLabelSize = modelSVM.getLabels().length;
+                    modelSVMLabels = modelSVM.getLabels();                    
+                    
+                }
+            } 
+            else {
+                if(modelWithClasses){
+                    System.out.println("Using default/last model with classes");
+                    modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes");
+                }
+                else{
+                    System.out.println("Using default/last model without classes");
+                    modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model");
+                }  
+                
+                try {
+                    System.out.println("try to load model: " + modelFile.getAbsolutePath());
+                    modelSVM = Model.load(modelFile);
+                    System.out.println("model loaded!");
+
+                } catch (IOException ex) {
+                    Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
+                }
+                modelSVMLabelSize = modelSVM.getLabels().length;
+                modelSVMLabels = modelSVM.getLabels();                
+            }
+            
+
+            
+            //try to use last SVM model
+            /*
             if(useCombinedModel){
                 System.out.println("Using combined model.");
-                useCombinedSVMmodels(sel, false);
+                if(modelWithClasses){ //check filenames to define if model with classes is selected
+                    useCombinedSVMmodels(sel, true);
+                }
+                else{
+                    useCombinedSVMmodels(sel, false);
+                }
+                
                 return;        
             }
             //String modelDirectoryPath = new File(MAIN_PATH).getParentFile() + "/OSMRec_models";
-            File modelDirectory = new File(MODEL_PATH);
-            
-            File modelFile;
+            //File modelDirectory = new File(MODEL_PATH);
+            
+            //File modelFile;
             if(useCustomSVMModel){
                 System.out.println("using custom model: " + customSVMModelPath);
@@ -1971,4 +2308,5 @@
             modelSVMLabels = modelSVM.getLabels();
             //System.out.println("is model path same as this? " + MODEL_PATH + "\n" + modelDirectoryPath);
+            */        
         }
         
@@ -2054,7 +2392,4 @@
             if(selectedInstance != null){
                 int id;
-                if(mappings == null){
-                   System.out.println("null mappings ERROR");
-                }
                 
                 OSMClassification classifier = new OSMClassification();
@@ -2099,11 +2434,13 @@
                 
                 Map<String, Double> scoreMap = new HashMap<>();
-                
-                for(File modelFile : filesAndWeights.keySet()){
-                    //filessAndweights
+
+                Map<File, Double> alignedFilesAndWeights = getAlignedModels(filesAndWeights);
+                
+                for(File modelFile : alignedFilesAndWeights.keySet()){
+                    
 
                     try {
                         modelSVM = Model.load(modelFile);
-                        System.out.println("model loaded: " + modelFile.getAbsolutePath());
+                        //System.out.println("model loaded: " + modelFile.getAbsolutePath());
                     } catch (IOException ex) {
                         Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
@@ -2196,9 +2533,9 @@
                         }
                     }
-                    System.out.println("predicted classes: " + Arrays.toString(predictedTags));
+                    System.out.println("combined, predicted classes: " + Arrays.toString(predictedTags));
                     
                     for(int r = 0; r<ranks.length; r++){
                         String predictedTag = predictedTags[r];
-                        Double currentWeight = filesAndWeights.get(modelFile);
+                        Double currentWeight = alignedFilesAndWeights.get(modelFile);
                         double finalRank = ranks[r]*currentWeight;
                         //String roundedWeight = new DecimalFormat("##.###").format(finalRank);
@@ -2391,5 +2728,19 @@
 
                 Arrays.sort(scores);
-                    
+                
+                int[] preds = new int[RECOMMENDATIONS_SIZE];
+                for(int p=0; p < RECOMMENDATIONS_SIZE; p++){
+                    preds[p] = modelSVMLabels[scoresValues.get(scores[scores.length-(p+1)])];
+                }
+                String[] predictedTags2 = new String[RECOMMENDATIONS_SIZE];
+                
+                for(int p=0; p<RECOMMENDATIONS_SIZE; p++){
+                    if(idsWithMappings.containsKey(preds[p])){
+                        predictedTags2[p] = idsWithMappings.get(preds[p]);
+                    }
+
+                }                
+                
+                /*
                 int predicted1 = modelSVMLabels[scoresValues.get(scores[scores.length-1])];  
                 int predicted2 = modelSVMLabels[scoresValues.get(scores[scores.length-2])];
@@ -2448,4 +2799,5 @@
                     }                     
                 }
+                */
                 //clearing model, to add the new computed classes in jlist
                 model.clear();
@@ -2453,11 +2805,12 @@
                     
                     for(int k=0; k<10; k++){
-                        if(tag.getValue().equals(predictedTags[k])){
-                            predictedTags[k] = tag.getKey();
+                        if(tag.getValue().equals(predictedTags2[k])){
+                            predictedTags2[k] = tag.getKey();
                             model.addElement(tag.getKey());
                         }
                     }
                 }
-                System.out.println("predicted classes: " + Arrays.toString(predictedTags));
+                //System.out.println("createdOSM object, predicted classes: " + Arrays.toString(predictedTags));
+                System.out.println("Optimized - create OSMObject, predicted classes: " + Arrays.toString(predictedTags2));
             }
         }
@@ -2475,4 +2828,5 @@
             mappings = mapper.getMappings();
             mapperWithIDs = mapper.getMappingsWithIDs(); 
+            idsWithMappings = mapper.getIDsWithMappings();
             //System.out.println("mappings " + mappings);
             //System.out.println("mapperWithIDs " + mapperWithIDs);
@@ -2511,4 +2865,39 @@
             indirectClassesWithIDs = ontology.getIndirectClassesIDs();
         }
+
+        private Map<File, Double> getAlignedModels(Map<File, Double> filesAndWeights) {
+            Map<File, Double> alignedFilesAndWeights = new HashMap<>();
+            if(modelWithClasses){
+                for(Entry<File, Double> entry : filesAndWeights.entrySet()){
+                    String absolutePath = entry.getKey().getAbsolutePath();
+                    if(absolutePath.endsWith(".0")){
+                        String newPath = absolutePath.substring(0, absolutePath.length()-2) + ".1";
+                        File alignedFile = new File(newPath);
+                        if(alignedFile.exists()){
+                            alignedFilesAndWeights.put(alignedFile, entry.getValue());
+                        }                        
+                    }                    
+                    else{
+                        alignedFilesAndWeights.put(entry.getKey(), entry.getValue());
+                    }                    
+                }
+            }
+            else{
+                for(Entry<File, Double> entry : filesAndWeights.entrySet()){
+                    String absolutePath = entry.getKey().getAbsolutePath();
+                    if(absolutePath.endsWith(".1")){
+                        String newPath = absolutePath.substring(0, absolutePath.length()-2) + ".0";
+                        File alignedFile = new File(newPath);
+                        if(alignedFile.exists()){
+                            alignedFilesAndWeights.put(alignedFile, entry.getValue());
+                        }                       
+                    }
+                    else{
+                        alignedFilesAndWeights.put(entry.getKey(), entry.getValue());
+                    }                    
+                }                
+            }
+            return alignedFilesAndWeights;
+        }
     }
 }
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 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java	(revision 31554)
@@ -85,4 +85,5 @@
     private static LanguageDetector languageDetector;
     private final String username;
+    private final String inputFileName;
         
     public TrainByUser(String inputFilePath, String username, boolean validateFlag, double cParameterFromUser, 
@@ -98,4 +99,6 @@
         this.topKIsSelected = topKIsSelected;
         System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
+        
+        inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("/"));
         modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
         //textualDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models/textualList.txt";
@@ -243,5 +246,7 @@
         System.out.println("number of instances: " + numberOfTrainingInstances);   
         System.out.println("end of parsing files."); 
-        
+        if(numberOfTrainingInstances == 0){
+            System.out.println("This user has not edited the loaded area. Cannot train a model!");            
+        }        
     }
 
@@ -450,5 +455,5 @@
         }
         else{
-            modelFile = new File(modelDirectory.getAbsolutePath()+"/user__" + username + "_model_geometries_textual_c=" + param);
+            modelFile = new File(modelDirectory.getAbsolutePath()+"/user_" + username + "_model_geometries_textual_c=" + param);
         }
   
@@ -624,4 +629,8 @@
         int u = 0;
         System.out.println("trainList size: " + wayListSizeWithoutUnclassified);
+        if(wayListSizeWithoutUnclassified == 0){
+            System.out.println("aborting training process..");
+            return;
+        }
         //set classes for each osm instance
         int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size 
@@ -735,11 +744,25 @@
         
         File modelFile = new File(modelDirectory.getAbsolutePath()+"/best_model"); //decide path of models
+        
+        File customModelFile;
+        if(topKIsSelected){
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_topK" + topK + "user" + username + ".0");
+        }
+        else{
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + "user" + username + ".0");
+        }
+        
         if(modelFile.exists()){
             modelFile.delete();
-        }        
+        }  
+        if(customModelFile.exists()){
+            customModelFile.delete();
+        }         
         try {
             //System.out.println("file created");
             model.save(modelFile);
-            //System.out.println("saved"); 
+            model.save(customModelFile);
+            System.out.println("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);
@@ -753,4 +776,8 @@
         System.out.println("trainList size: " + wayListSizeWithoutUnclassified);
         
+        if(wayListSizeWithoutUnclassified == 0){
+            System.out.println("aborting training process with classes..");
+            return;
+        }
         //set classes for each osm instance
         int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size 
@@ -864,4 +891,15 @@
         
         File modelFile = new File(modelDirectory.getAbsolutePath()+"/model_with_classes"); 
+        File customModelFile;
+        if(topKIsSelected){
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_topK" + topK + "user" + username + ".1");
+        }
+        else{
+            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + "user" + username + ".1");
+        }
+
+        if(customModelFile.exists()){
+            customModelFile.delete();
+        }        
         if(modelFile.exists()){
             modelFile.delete();
@@ -870,5 +908,7 @@
             //System.out.println("file created");
             model.save(modelFile);
-            //System.out.println("saved"); 
+            model.save(customModelFile);
+            System.out.println("model with classes saved at: " + modelFile); 
+            System.out.println("custom model with classes saved at: " + customModelFile);
         } catch (IOException ex) {
             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java	(revision 31553)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java	(revision 31554)
@@ -22,4 +22,5 @@
     private final HashMap<String, String> mappings;
     private final HashMap<String, Integer> mappingsWithIDs;
+    private final Map<Integer, String> idsWithMappings;
     
     public Mapper(){    
@@ -27,4 +28,5 @@
        mappings = new LinkedHashMap<>();
        mappingsWithIDs = new HashMap<>();
+       idsWithMappings = new HashMap<>();
     
     }
@@ -47,4 +49,5 @@
         }
         constructMappingsWithIDs();
+        constructIDsWithMappings();
         System.out.println("Mappings file parsed successfully!");
         //LOG.info("Mappings file parsed successfully!");     
@@ -65,4 +68,17 @@
     public Map<String,String> getMappings(){
         return Collections.unmodifiableMap(mappings);
-    }        
+    }   
+    
+    private void constructIDsWithMappings(){
+        int i = 1; //starting ID is 1: SVM multiclass does not accept 0 as a class ID
+ 
+        for (String ontologyClass : mappings.values()){  
+            idsWithMappings.put(i, ontologyClass);
+            i++;
+        }
+    }  
+    
+    public Map<Integer, String> getIDsWithMappings(){
+        return Collections.unmodifiableMap(idsWithMappings);
+    }    
 }
