Changeset 33013 in osm for applications/editors/josm/plugins/OSMRecPlugin/src/org
- Timestamp:
- 2016-09-24T15:17:55+02:00 (8 years ago)
- 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 4 4 import static java.util.concurrent.TimeUnit.NANOSECONDS; 5 5 6 import java.awt.event.ActionEvent;7 import java.awt.event.ActionListener;8 import java.io.BufferedWriter;9 6 import java.io.File; 10 7 import java.io.FileInputStream; 11 8 import java.io.FileNotFoundException; 12 import java.io.FileOutputStream;13 9 import java.io.IOException; 14 10 import java.io.InputStream; 15 11 import java.io.OutputStream; 16 import java.io.OutputStreamWriter;17 12 import java.io.PrintStream; 18 import java.io.UnsupportedEncodingException;19 13 import java.util.ArrayList; 20 14 import java.util.Arrays; … … 26 20 import java.util.logging.Logger; 27 21 28 import javax.swing.SwingWorker;29 30 import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;31 22 import org.openstreetmap.josm.plugins.osmrec.container.OSMWay; 32 import org.openstreetmap.josm.plugins.osmrec.extractor.Analyzer;33 23 import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector; 34 24 import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures; … … 40 30 import org.openstreetmap.josm.plugins.osmrec.parsers.OSMParser; 41 31 import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology; 42 import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;43 32 44 33 import de.bwaldvogel.liblinear.FeatureNode; … … 54 43 * @author imis-nkarag 55 44 */ 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; 45 public class TrainWorker extends AbstractTrainWorker { 46 78 47 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;93 48 94 49 public TrainWorker(String inputFilePath, boolean validateFlag, double cParameterFromUser, 95 50 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); 119 52 } 120 53 … … 140 73 } 141 74 142 private void extractTextualList() {143 System.out.println("Running analysis..");144 //provide top-K145 //Keep the top-K most frequent terms146 //Keep terms with frequency higher than N147 //Use the remaining terms as training features148 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 models154 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 file173 174 //method read default list175 //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called176 if (USE_CLASS_FEATURES) {177 numberOfFeatures = 1422 + 105 + textualList.size(); //105 is number of geometry features178 } else {179 numberOfFeatures = 105 + textualList.size();180 }181 }182 183 75 private void parseFiles() { 184 InputStream tagsToClassesMapping = TrainWorker.class.getResourceAsStream("/resources/files/Map");76 InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map"); 185 77 186 78 Mapper mapper = new Mapper(); … … 193 85 mapperWithIDs = mapper.getMappingsWithIDs(); 194 86 195 InputStream ontologyStream = TrainWorker.class.getResourceAsStream("/resources/files/owl.xml");87 InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml"); 196 88 Ontology ontology = new Ontology(ontologyStream); 197 89 … … 205 97 textualFileStream = new FileInputStream(new File(textualListFilePath)); 206 98 } catch (FileNotFoundException ex) { 207 Logger.getLogger( TrainWorker.class.getName()).log(Level.SEVERE, null, ex);99 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 208 100 } 209 101 … … 211 103 212 104 OSMParser osmParser = new OSMParser(inputFilePath); 213 214 105 osmParser.parseDocument(); 215 106 relationList = osmParser.getRelationList(); … … 218 109 System.out.println("number of instances: " + numberOfTrainingInstances); 219 110 System.out.println("end of parsing files."); 220 221 111 } 222 112 223 113 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)}; 226 116 227 117 double bestC = Math.pow(2, -10); … … 259 149 clearDataset(); 260 150 System.out.println("fold4"); 261 //crossValidateFold(0, 5, 1, 2, true, param);262 151 crossValidateFold(0, 5, 2, 3, true, param); 263 152 setProgress(4*((5*(trainProgress++))/confParams.length)); 264 //System.out.println((5*trainProgress)/confParams.length);265 153 266 154 foldScore1 = foldScore1 + score1; … … 377 265 problem.x = trainingSetWithUnknown2; // feature nodes 378 266 problem.y = GROUPS_ARRAY2; // target values 379 //SolverType solver = SolverType.MCSVM_CS; //Cramer and Singer for multiclass classification - equivalent of SVMlight380 267 SolverType solver2 = SolverType.getById(2); //2 -- L2-regularized L2-loss support vector classification (primal) 381 268 … … 414 301 System.out.println("model saved at: " + modelFile); 415 302 } catch (IOException ex) { 416 Logger.getLogger( TrainWorker.class.getName()).log(Level.SEVERE, null, ex);303 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 417 304 } 418 305 … … 432 319 model = Model.load(modelFile); 433 320 } catch (IOException ex) { 434 Logger.getLogger( TrainWorker.class.getName()).log(Level.SEVERE, null, ex);321 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 435 322 } 436 323 int modelLabelSize = model.getLabels().length; … … 554 441 int wayListSizeWithoutUnclassified = wayList.size(); 555 442 System.out.println("trainList size: " + wayListSizeWithoutUnclassified); 556 557 443 //set classes for each osm instance 558 444 int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size … … 657 543 File customModelFile; 658 544 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"); 660 547 } 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"); 662 550 } 663 551 … … 671 559 672 560 try { 673 //System.out.println("file created");674 561 model.save(modelFile); 675 562 model.save(customModelFile); … … 677 564 System.out.println("custom model saved at: " + customModelFile); 678 565 } catch (IOException ex) { 679 Logger.getLogger( TrainWorker.class.getName()).log(Level.SEVERE, null, ex);566 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 680 567 } 681 568 } … … 782 669 File customModelFile; 783 670 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"); 785 673 } 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"); 787 676 } 788 677 … … 799 688 model.save(customModelFile); 800 689 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); 802 691 } 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 } 818 694 } 819 695 … … 827 703 } 828 704 } 829 830 @Override831 public void actionPerformed(ActionEvent ae) {832 //cancel button, end process after clearing Dataset833 }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 }849 705 } -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java
r32404 r33013 4 4 import static java.util.concurrent.TimeUnit.NANOSECONDS; 5 5 6 import java.awt.event.ActionEvent;7 import java.awt.event.ActionListener;8 import java.io.BufferedWriter;9 6 import java.io.File; 10 7 import java.io.FileInputStream; 11 8 import java.io.FileNotFoundException; 12 import java.io.FileOutputStream;13 9 import java.io.IOException; 14 10 import java.io.InputStream; 15 11 import java.io.OutputStream; 16 import java.io.OutputStreamWriter;17 12 import java.io.PrintStream; 18 import java.io.UnsupportedEncodingException;19 13 import java.util.ArrayList; 20 14 import java.util.Arrays; … … 26 20 import java.util.logging.Logger; 27 21 28 import javax.swing.SwingWorker;29 30 import org.openstreetmap.josm.plugins.osmrec.container.OSMRelation;31 22 import org.openstreetmap.josm.plugins.osmrec.container.OSMWay; 32 import org.openstreetmap.josm.plugins.osmrec. extractor.Analyzer;23 import org.openstreetmap.josm.plugins.osmrec.core.AbstractTrainWorker; 33 24 import org.openstreetmap.josm.plugins.osmrec.extractor.LanguageDetector; 34 25 import org.openstreetmap.josm.plugins.osmrec.features.ClassFeatures; … … 39 30 import org.openstreetmap.josm.plugins.osmrec.parsers.Mapper; 40 31 import org.openstreetmap.josm.plugins.osmrec.parsers.Ontology; 41 import org.openstreetmap.josm.plugins.osmrec.parsers.TextualStatistics;42 32 43 33 import de.bwaldvogel.liblinear.FeatureNode; … … 53 43 * @author imis-nkarag 54 44 */ 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; 45 public class TrainByUser extends AbstractTrainWorker { 46 88 47 private final String username; 89 private final String inputFileName;90 48 91 49 public TrainByUser(String inputFilePath, String username, boolean validateFlag, double cParameterFromUser, 92 50 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); 95 52 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; 120 54 } 121 55 … … 153 87 } 154 88 155 private void extractTextualList() {156 System.out.println("Running analysis..");157 //provide top-K158 //Keep the top-K most frequent terms159 //Keep terms with frequency higher than N160 //Use the remaining terms as training features161 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 models167 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 file189 190 //method read default list191 //method extract textual list - > the list will be already in memory, so the names parser doesn t have to be called192 if (USE_CLASS_FEATURES) {193 numberOfFeatures = 1422 + 105 + textualList.size();194 } else {195 numberOfFeatures = 105 + textualList.size();196 }197 }198 199 89 private void parseFiles() { 200 InputStream tagsToClassesMapping = TrainByUser.class.getResourceAsStream("/resources/files/Map");90 InputStream tagsToClassesMapping = getClass().getResourceAsStream("/resources/files/Map"); 201 91 202 92 Mapper mapper = new Mapper(); … … 209 99 mapperWithIDs = mapper.getMappingsWithIDs(); 210 100 211 InputStream ontologyStream = TrainByUser.class.getResourceAsStream("/resources/files/owl.xml");101 InputStream ontologyStream = getClass().getResourceAsStream("/resources/files/owl.xml"); 212 102 Ontology ontology = new Ontology(ontologyStream); 213 103 … … 217 107 indirectClassesWithIDs = ontology.getIndirectClassesIDs(); 218 108 219 //InputStream textualFileStream = TrainWorker.class.getResourceAsStream("/resources/files/names");220 109 InputStream textualFileStream = null; 221 110 try { 222 111 textualFileStream = new FileInputStream(new File(textualListFilePath)); 223 112 } catch (FileNotFoundException ex) { 224 Logger.getLogger( TrainByUser.class.getName()).log(Level.SEVERE, null, ex);113 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 225 114 } 226 115 227 116 readTextualFromDefaultList(textualFileStream); 228 117 229 //osmParser.parseDocument();230 //relationList = osmParser.getRelationList();231 //wayList = osmParser.getWayList();232 118 numberOfTrainingInstances = wayList.size(); 233 119 System.out.println("number of instances: " + numberOfTrainingInstances); … … 238 124 } 239 125 240 p rivatevoid validateLoop() {126 public void validateLoop() { 241 127 Double[] confParams = new Double[] { 242 128 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 181 } 296 182 297 p rivatevoid 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) { 298 184 System.out.println("Starting cross validation"); 299 185 int testSize = wayList.size()/5; … … 418 304 } 419 305 try { 420 //System.out.println("file created");421 306 model.save(modelFile); 422 //System.out.println("saved");307 System.out.println("model saved at: " + modelFile); 423 308 } 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 426 313 427 314 //test set … … 438 325 model = Model.load(modelFile); 439 326 } catch (IOException ex) { 440 Logger.getLogger( TrainByUser.class.getName()).log(Level.SEVERE, null, ex);327 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 441 328 } 442 329 int modelLabelSize = model.getLabels().length; … … 511 398 512 399 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);519 400 if (way.getClassIDs().contains(labels[scoresValues.get(scores[scores.length-1])])) { 520 401 succededInstances++; … … 573 454 //set classes for each osm instance 574 455 int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size 575 576 456 for (OSMWay way : wayList) { 577 457 OSMClassification classifyInstances = new OSMClassification(); … … 584 464 } 585 465 } 586 //System.out.println("end classify instances");587 466 double C = param; 588 467 double eps = 0.001; … … 687 566 model.save(modelFile); 688 567 model.save(customModelFile); 689 System.out.println(" model saved at: " + modelFile);568 System.out.println("best model saved at: " + modelFile); 690 569 System.out.println("custom model saved at: " + customModelFile); 691 570 } catch (IOException ex) { 692 Logger.getLogger( TrainByUser.class.getName()).log(Level.SEVERE, null, ex);571 Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 693 572 } 694 573 } … … 815 694 System.out.println("custom model with classes saved at: " + customModelFile); 816 695 } 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); 848 697 } 849 698 } … … 859 708 } 860 709 } 861 862 @Override863 public void actionPerformed(ActionEvent ae) {864 //cancel button, end process after clearing Dataset865 }866 710 }
Note:
See TracChangeset
for help on using the changeset viewer.