Ignore:
Timestamp:
2016-09-24T15:17:55+02:00 (8 years ago)
Author:
donvip
Message:

refactor duplicated code

Location:
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/core/TrainWorker.java

    r32404 r33013  
    44import static java.util.concurrent.TimeUnit.NANOSECONDS;
    55
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    8 import java.io.BufferedWriter;
    96import java.io.File;
    107import java.io.FileInputStream;
    118import java.io.FileNotFoundException;
    12 import java.io.FileOutputStream;
    139import java.io.IOException;
    1410import java.io.InputStream;
    1511import java.io.OutputStream;
    16 import java.io.OutputStreamWriter;
    1712import java.io.PrintStream;
    18 import java.io.UnsupportedEncodingException;
    1913import java.util.ArrayList;
    2014import java.util.Arrays;
     
    2620import java.util.logging.Logger;
    2721
    28 import javax.swing.SwingWorker;
    29 
    30 import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;
    3122import org.openstreetmap.josm.plugins.osmrec.container.OSMWay;
    32 import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;
    3323import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector;
    3424import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures;
     
    4030import org.openstreetmap.josm.plugins.osmrec.parsers.OSMParser;
    4131import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology;
    42 import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;
    4332
    4433import de.bwaldvogel.liblinear.FeatureNode;
     
    5443 * @author imis-nkarag
    5544 */
    56 public class TrainWorker extends SwingWorker<Void, Void> implements ActionListener {
    57 
    58     private final String inputFilePath;
    59     private static Map<String, String> mappings;
    60     private static Map<String, Integer> mapperWithIDs;
    61 
    62     private static List<OSMWay> wayList;
    63     private static List<OSMRelation> relationList;
    64 
    65     private static Map<String, List<String>> indirectClasses;
    66     private static Map<String, Integer> indirectClassesWithIDs;
    67     private static List<String> namesList;
    68     private int numberOfTrainingInstances;
    69     private final String modelDirectoryPath;
    70     private final File modelDirectory;
    71     private static double score1 = 0;
    72     private static double score5 = 0;
    73     private static double score10 = 0;
    74     private static double foldScore1 = 0;
    75     private static double foldScore5 = 0;
    76     private static double foldScore10 = 0;
    77     private static double bestScore = 0;
     45public class TrainWorker extends AbstractTrainWorker {
     46
    7847    private int trainProgress = 0;
    79     private final boolean validateFlag;
    80     private final double cParameterFromUser;
    81     private double bestConfParam;
    82     private final int topK;
    83     private final int frequency;
    84     private final boolean topKIsSelected;
    85     private String textualListFilePath;
    86 
    87     private static final boolean USE_CLASS_FEATURES = false;
    88     private static final boolean USE_RELATION_FEATURES = false;
    89     private static final boolean USE_TEXTUAL_FEATURES = true;
    90     private static int numberOfFeatures;
    91     private static LanguageDetector languageDetector;
    92     private final String inputFileName;
    9348
    9449    public TrainWorker(String inputFilePath, boolean validateFlag, double cParameterFromUser,
    9550            int topK, int frequency, boolean topKIsSelected, LanguageDetector languageDetector) {
    96         TrainWorker.languageDetector = languageDetector;
    97         this.inputFilePath = inputFilePath;
    98         this.validateFlag = validateFlag;
    99         this.cParameterFromUser = cParameterFromUser;
    100         this.topK = topK;
    101         this.frequency = frequency;
    102         this.topKIsSelected = topKIsSelected;
    103         if (System.getProperty("os.name").contains("ux")) {
    104             inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("/"));
    105         } else {
    106             inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("\\"));
    107         }
    108         System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
    109         modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
    110 
    111         modelDirectory = new File(modelDirectoryPath);
    112 
    113         if (!modelDirectory.exists()) {
    114             modelDirectory.mkdir();
    115             System.out.println("model directory created!");
    116         } else {
    117             System.out.println("directory already exists!");
    118         }
     51        super(inputFilePath, validateFlag, cParameterFromUser, topK, frequency, topKIsSelected, languageDetector);
    11952    }
    12053
     
    14073    }
    14174
    142     private void extractTextualList() {
    143         System.out.println("Running analysis..");
    144         //provide top-K
    145         //Keep the top-K most frequent terms
    146         //Keep terms with frequency higher than N
    147         //Use the remaining terms as training features
    148 
    149         Analyzer anal = new Analyzer(inputFilePath, languageDetector);
    150         anal.runAnalysis();
    151 
    152         textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt";
    153         File textualFile = new File(textualListFilePath); //decide path of models
    154         if (textualFile.exists()) {
    155             textualFile.delete();
    156         }
    157         try {
    158             textualFile.createNewFile();
    159         } catch (IOException ex) {
    160             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    161         }
    162 
    163         List<Map.Entry<String, Integer>> textualList;
    164         if (topKIsSelected) {
    165             textualList = anal.getTopKMostFrequent(topK);
    166         } else {
    167             textualList = anal.getWithFrequency(frequency);
    168         }
    169 
    170         writeTextualListToFile(textualListFilePath, textualList);
    171         System.out.println("textual list saved at location:\n" + textualListFilePath);
    172         //write list to file and let parser do the loading from the names file
    173 
    174         //method read default list
    175         //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called
    176         if (USE_CLASS_FEATURES) {
    177             numberOfFeatures = 1422 + 105 + textualList.size(); //105 is number of geometry features
    178         } else {
    179             numberOfFeatures = 105 + textualList.size();
    180         }
    181     }
    182 
    18375    private void parseFiles() {
    184         InputStream tagsToClassesMapping = TrainWorker.class.getResourceAsStream("/resources/files/Map");
     76        InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map");
    18577
    18678        Mapper mapper = new Mapper();
     
    19385        mapperWithIDs = mapper.getMappingsWithIDs();
    19486
    195         InputStream ontologyStream = TrainWorker.class.getResourceAsStream("/resources/files/owl.xml");
     87        InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml");
    19688        Ontology ontology = new Ontology(ontologyStream);
    19789
     
    20597            textualFileStream = new FileInputStream(new File(textualListFilePath));
    20698        } catch (FileNotFoundException ex) {
    207             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     99            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    208100        }
    209101
     
    211103
    212104        OSMParser osmParser = new OSMParser(inputFilePath);
    213 
    214105        osmParser.parseDocument();
    215106        relationList = osmParser.getRelationList();
     
    218109        System.out.println("number of instances: " + numberOfTrainingInstances);
    219110        System.out.println("end of parsing files.");
    220 
    221111    }
    222112
    223113    public void validateLoop() {
    224         Double[] confParams = new Double[] {Math.pow(2, -3), Math.pow(2, 1),
    225                 Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3)};
     114        Double[] confParams = new Double[] {
     115                Math.pow(2, -3), Math.pow(2, 1), Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3)};
    226116
    227117        double bestC = Math.pow(2, -10);
     
    259149            clearDataset();
    260150            System.out.println("fold4");
    261             //crossValidateFold(0, 5, 1, 2, true, param);
    262151            crossValidateFold(0, 5, 2, 3, true, param);
    263152            setProgress(4*((5*(trainProgress++))/confParams.length));
    264             //System.out.println((5*trainProgress)/confParams.length);
    265153
    266154            foldScore1 = foldScore1 + score1;
     
    377265        problem.x = trainingSetWithUnknown2; // feature nodes
    378266        problem.y = GROUPS_ARRAY2; // target values
    379         //SolverType solver = SolverType.MCSVM_CS; //Cramer and Singer for multiclass classification - equivalent of SVMlight
    380267        SolverType solver2 = SolverType.getById(2); //2 -- L2-regularized L2-loss support vector classification (primal)
    381268
     
    414301            System.out.println("model saved at: " + modelFile);
    415302        } catch (IOException ex) {
    416             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     303            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    417304        }
    418305
     
    432319            model = Model.load(modelFile);
    433320        } catch (IOException ex) {
    434             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     321            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    435322        }
    436323        int modelLabelSize = model.getLabels().length;
     
    554441        int wayListSizeWithoutUnclassified = wayList.size();
    555442        System.out.println("trainList size: " + wayListSizeWithoutUnclassified);
    556 
    557443        //set classes for each osm instance
    558444        int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
     
    657543        File customModelFile;
    658544        if (topKIsSelected) {
    659             customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_topK" + topK + ".0");
     545            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
     546                    inputFileName + "_model_c" + param + "_topK" + topK + ".0");
    660547        } else {
    661             customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + ".0");
     548            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
     549                    inputFileName + "_model_c" + param + "_maxF" + frequency + ".0");
    662550        }
    663551
     
    671559
    672560        try {
    673             //System.out.println("file created");
    674561            model.save(modelFile);
    675562            model.save(customModelFile);
     
    677564            System.out.println("custom model saved at: " + customModelFile);
    678565        } catch (IOException ex) {
    679             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     566            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    680567        }
    681568    }
     
    782669        File customModelFile;
    783670        if (topKIsSelected) {
    784             customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model" + "_c" + param + "_topK" + topK + ".1");
     671            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
     672                    inputFileName + "_model" + "_c" + param + "_topK" + topK + ".1");
    785673        } else {
    786             customModelFile = new File(modelDirectory.getAbsolutePath()+"/" + inputFileName + "_model_c" + param + "_maxF" + frequency + ".1");
     674            customModelFile = new File(modelDirectory.getAbsolutePath()+"/" +
     675                    inputFileName + "_model_c" + param + "_maxF" + frequency + ".1");
    787676        }
    788677
     
    799688            model.save(customModelFile);
    800689            System.out.println("model with classes saved at: " + modelFile);
    801             System.out.println("custom model with classes saved at: " + modelFile);
     690            System.out.println("custom model with classes saved at: " + customModelFile);
    802691        } catch (IOException ex) {
    803             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    804         }
    805     }
    806 
    807     private static void clearDataset() {
    808         for (OSMWay way : wayList) {
    809             way.getFeatureNodeList().clear();
    810         }
    811     }
    812 
    813     private void readTextualFromDefaultList(InputStream textualFileStream) {
    814 
    815         TextualStatistics textualStatistics = new TextualStatistics();
    816         textualStatistics.parseTextualList(textualFileStream);
    817         namesList = textualStatistics.getTextualList();
     692            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
     693        }
    818694    }
    819695
     
    827703        }
    828704    }
    829 
    830     @Override
    831     public void actionPerformed(ActionEvent ae) {
    832         //cancel button, end process after clearing Dataset
    833     }
    834 
    835     private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) {
    836         try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"))) {
    837             for (Map.Entry<String, Integer> entry : textualList) {
    838                 writer.write(entry.getKey());
    839                 writer.newLine();
    840             }
    841         } catch (UnsupportedEncodingException ex) {
    842             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    843         } catch (FileNotFoundException ex) {
    844             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    845         } catch (IOException ex) {
    846             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    847         }
    848     }
    849705}
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java

    r32404 r33013  
    44import static java.util.concurrent.TimeUnit.NANOSECONDS;
    55
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    8 import java.io.BufferedWriter;
    96import java.io.File;
    107import java.io.FileInputStream;
    118import java.io.FileNotFoundException;
    12 import java.io.FileOutputStream;
    139import java.io.IOException;
    1410import java.io.InputStream;
    1511import java.io.OutputStream;
    16 import java.io.OutputStreamWriter;
    1712import java.io.PrintStream;
    18 import java.io.UnsupportedEncodingException;
    1913import java.util.ArrayList;
    2014import java.util.Arrays;
     
    2620import java.util.logging.Logger;
    2721
    28 import javax.swing.SwingWorker;
    29 
    30 import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;
    3122import org.openstreetmap.josm.plugins.osmrec.container.OSMWay;
    32 import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;
     23import org.openstreetmap.josm.plugins.osmrec.core.AbstractTrainWorker;
    3324import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector;
    3425import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures;
     
    3930import org.openstreetmap.josm.plugins.osmrec.parsers.Mapper;
    4031import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology;
    41 import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;
    4232
    4333import de.bwaldvogel.liblinear.FeatureNode;
     
    5343 *  @author imis-nkarag
    5444 */
    55 public class TrainByUser extends SwingWorker<Void, Void> implements ActionListener {
    56 
    57     private final String inputFilePath;
    58     private static Map<String, String> mappings;
    59     private static Map<String, Integer> mapperWithIDs;
    60     private static List<OSMWay> wayList;
    61     private static List<OSMRelation> relationList;
    62 
    63     private static Map<String, List<String>> indirectClasses;
    64     private static Map<String, Integer> indirectClassesWithIDs;
    65     private static List<String> namesList;
    66     private int numberOfTrainingInstances;
    67     private final String modelDirectoryPath;
    68     private final File modelDirectory;
    69     private static double score1 = 0;
    70     private static double score5 = 0;
    71     private static double score10 = 0;
    72     private static double foldScore1 = 0;
    73     private static double foldScore5 = 0;
    74     private static double foldScore10 = 0;
    75     private static double bestScore = 0;
    76     private final boolean validateFlag;
    77     private final double cParameterFromUser;
    78     private double bestConfParam;
    79     private final int topK;
    80     private final int frequency;
    81     private final boolean topKIsSelected;
    82     private String textualListFilePath;
    83     private static final boolean USE_CLASS_FEATURES = false;
    84     private static final boolean USE_RELATION_FEATURES = false;
    85     private static final boolean USE_TEXTUAL_FEATURES = true;
    86     private static int numberOfFeatures;
    87     private static LanguageDetector languageDetector;
     45public class TrainByUser extends AbstractTrainWorker {
     46
    8847    private final String username;
    89     private final String inputFileName;
    9048
    9149    public TrainByUser(String inputFilePath, String username, boolean validateFlag, double cParameterFromUser,
    9250            int topK, int frequency, boolean topKIsSelected, LanguageDetector languageDetector, List<OSMWay> wayList) {
    93         TrainByUser.languageDetector = languageDetector;
    94         this.inputFilePath = inputFilePath;
     51        super(inputFilePath, validateFlag, cParameterFromUser, topK, frequency, topKIsSelected, languageDetector);
    9552        this.username = username;
    96         this.validateFlag = validateFlag;
    97         this.cParameterFromUser = cParameterFromUser;
    98         this.topK = topK;
    99         this.frequency = frequency;
    100         this.topKIsSelected = topKIsSelected;
    101         System.out.println("find parent directory, create osmrec dir for models: " + new File(inputFilePath).getParentFile());
    102 
    103         if (System.getProperty("os.name").contains("ux")) {
    104             inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("/"));
    105         } else {
    106             inputFileName = inputFilePath.substring(inputFilePath.lastIndexOf("\\"));
    107         }
    108 
    109         modelDirectoryPath = new File(inputFilePath).getParentFile() + "/OSMRec_models";
    110 
    111         modelDirectory = new File(modelDirectoryPath);
    112 
    113         if (!modelDirectory.exists()) {
    114             modelDirectory.mkdir();
    115             System.out.println("model directory created!");
    116         } else {
    117             System.out.println("directory already exists!");
    118         }
    119         TrainByUser.wayList = wayList;
     53        AbstractTrainWorker.wayList = wayList;
    12054    }
    12155
     
    15387    }
    15488
    155     private void extractTextualList() {
    156         System.out.println("Running analysis..");
    157         //provide top-K
    158         //Keep the top-K most frequent terms
    159         //Keep terms with frequency higher than N
    160         //Use the remaining terms as training features
    161 
    162         Analyzer anal = new Analyzer(inputFilePath, languageDetector);
    163         anal.runAnalysis();
    164 
    165         textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt";
    166         File textualFile = new File(textualListFilePath); //decide path of models
    167         if (textualFile.exists()) {
    168             textualFile.delete();
    169         }
    170         try {
    171             textualFile.createNewFile();
    172         } catch (IOException ex) {
    173             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
    174         }
    175 
    176         //writeTextualListToFile(textualFilePath, anal.getTopKMostFrequent(15));
    177         List<Map.Entry<String, Integer>> textualList;
    178         if (topKIsSelected) {
    179             textualList = anal.getTopKMostFrequent(topK);
    180             System.out.println(textualList);
    181         } else {
    182             textualList = anal.getWithFrequency(frequency);
    183             System.out.println(textualList);
    184         }
    185 
    186         writeTextualListToFile(textualListFilePath, textualList);
    187         System.out.println("textual list saved at location:\n" + textualListFilePath);
    188         //write list to file and let parser do the loading from the names file
    189 
    190         //method read default list
    191         //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called
    192         if (USE_CLASS_FEATURES) {
    193             numberOfFeatures = 1422 + 105 + textualList.size();
    194         } else {
    195             numberOfFeatures = 105 + textualList.size();
    196         }
    197     }
    198 
    19989    private void parseFiles() {
    200         InputStream tagsToClassesMapping = TrainByUser.class.getResourceAsStream("/resources/files/Map");
     90        InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map");
    20191
    20292        Mapper mapper = new Mapper();
     
    20999        mapperWithIDs = mapper.getMappingsWithIDs();
    210100
    211         InputStream ontologyStream = TrainByUser.class.getResourceAsStream("/resources/files/owl.xml");
     101        InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml");
    212102        Ontology ontology = new Ontology(ontologyStream);
    213103
     
    217107        indirectClassesWithIDs = ontology.getIndirectClassesIDs();
    218108
    219         //InputStream textualFileStream = TrainWorker.class.getResourceAsStream("/resources/files/names");
    220109        InputStream textualFileStream = null;
    221110        try {
    222111            textualFileStream = new FileInputStream(new File(textualListFilePath));
    223112        } catch (FileNotFoundException ex) {
    224             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
     113            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    225114        }
    226115
    227116        readTextualFromDefaultList(textualFileStream);
    228117
    229         //osmParser.parseDocument();
    230         //relationList = osmParser.getRelationList();
    231         //wayList = osmParser.getWayList();
    232118        numberOfTrainingInstances = wayList.size();
    233119        System.out.println("number of instances: " + numberOfTrainingInstances);
     
    238124    }
    239125
    240     private void validateLoop() {
     126    public void validateLoop() {
    241127        Double[] confParams = new Double[] {
    242128                Math.pow(2, -10), Math.pow(2, -10), Math.pow(2, -5), Math.pow(2, -3), Math.pow(2, -1), Math.pow(2, 0)};
     
    295181    }
    296182
    297     private void crossValidateFold(int a, int b, int c, int d, boolean skip, double param) {
     183    public void crossValidateFold(int a, int b, int c, int d, boolean skip, double param) {
    298184        System.out.println("Starting cross validation");
    299185        int testSize = wayList.size()/5;
     
    418304        }
    419305        try {
    420             //System.out.println("file created");
    421306            model.save(modelFile);
    422             //System.out.println("saved");
     307            System.out.println("model saved at: " + modelFile);
    423308        } catch (IOException ex) {
    424             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
    425         }
     309            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
     310        }
     311
     312        //end of evaluation training
    426313
    427314        //test set
     
    438325            model = Model.load(modelFile);
    439326        } catch (IOException ex) {
    440             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
     327            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    441328        }
    442329        int modelLabelSize = model.getLabels().length;
     
    511398
    512399            Arrays.sort(scores);
    513             //System.out.println("max value: " + scores[scores.length-1] + " second max: " + scores[scores.length-2]);
    514             //System.out.println("ask this index from labels: " + scoresValues.get(scores[scores.length-1]));
    515             //System.out.println("got from labels: " +  labels[scoresValues.get(scores[scores.length-1])]);
    516             //System.out.println("next prediction: " +  labels[scoresValues.get(scores[scores.length-2])]);
    517             //System.out.println("way labels: " + way.getClassIDs());
    518             //System.out.println("test prediction: " + prediction);
    519400            if (way.getClassIDs().contains(labels[scoresValues.get(scores[scores.length-1])])) {
    520401                succededInstances++;
     
    573454        //set classes for each osm instance
    574455        int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
    575 
    576456        for (OSMWay way : wayList) {
    577457            OSMClassification classifyInstances = new OSMClassification();
     
    584464            }
    585465        }
    586         //System.out.println("end classify instances");
    587466        double C = param;
    588467        double eps = 0.001;
     
    687566            model.save(modelFile);
    688567            model.save(customModelFile);
    689             System.out.println("model saved at: " + modelFile);
     568            System.out.println("best model saved at: " + modelFile);
    690569            System.out.println("custom model saved at: " + customModelFile);
    691570        } catch (IOException ex) {
    692             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
     571            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    693572        }
    694573    }
     
    815694            System.out.println("custom model with classes saved at: " + customModelFile);
    816695        } catch (IOException ex) {
    817             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
    818         }
    819     }
    820 
    821     private static void clearDataset() {
    822         for (OSMWay way : wayList) {
    823             way.getFeatureNodeList().clear();
    824         }
    825     }
    826 
    827     private void readTextualFromDefaultList(InputStream textualFileStream) {
    828 
    829         TextualStatistics textualStatistics = new TextualStatistics();
    830         textualStatistics.parseTextualList(textualFileStream);
    831         namesList = textualStatistics.getTextualList();
    832 
    833     }
    834 
    835     private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) {
    836         try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"))) {
    837             for (Map.Entry<String, Integer> entry : textualList) {
    838                 writer.write(entry.getKey());
    839                 writer.newLine();
    840                 System.out.println(entry.getKey());
    841             }
    842         } catch (UnsupportedEncodingException ex) {
    843             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
    844         } catch (FileNotFoundException ex) {
    845             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
    846         } catch (IOException ex) {
    847             Logger.getLogger(TrainByUser.class.getName()).log(Level.SEVERE, null, ex);
     696            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    848697        }
    849698    }
     
    859708        }
    860709    }
    861 
    862     @Override
    863     public void actionPerformed(ActionEvent ae) {
    864         //cancel button, end process after clearing Dataset
    865     }
    866710}
Note: See TracChangeset for help on using the changeset viewer.