Changeset 31461 in osm for applications/editors
- Timestamp:
- 2015-08-07T13:53:35+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/OSMRecPlugin
- Files:
-
- 3 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/OSMRecPlugin/nbproject/private/private.xml
r31441 r31461 4 4 <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> 5 5 <group> 6 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java</file>7 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/build.xml</file>8 6 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java</file> 9 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java</file>10 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Ontology.java</file>11 7 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java</file> 12 8 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java</file> 13 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/MenuExportAction.java</file>14 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/resources/log4j.properties</file>15 9 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java</file> 16 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/ osmrec/personalization/TrainByUser.java</file>10 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/Analyzer.java</file> 17 11 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java</file> 18 <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java</file>19 12 </group> 20 13 </open-files> -
applications/editors/josm/plugins/OSMRecPlugin/nbproject/project.xml
r31441 r31461 81 81 <compilation-unit> 82 82 <package-root>src</package-root> 83 <classpath mode="compile">../../core/dist/josm-custom.jar:lib/l iblinear-java-1.95.jar:lib/jena-core-2.12.0.jar:lib/gt-api-9.3.jar:lib/gt-referencing-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-metadata-9.3.jar:lib/slf4j-api-1.7.6.jar:lib/xercesImpl-2.11.0.jar:lib/commons-lang3-3.3.2.jar:lib/commons-pool-1.5.4.jar:lib/gt-api-9.3.jar:lib/gt-metadata-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-referencing-9.3.jar:lib/jai_core-1.1.3.jar:lib/jena-core-2.12.0.jar:lib/jena-iri-1.1.0.jar:lib/jgridshift-1.0.jar:lib/jsonic-1.2.7.jar:lib/jsr-275-1.0-beta-2.jar:lib/langdetect-1.1-20120112.jar:lib/liblinear-1.95.jar:lib/liblinear-java-1.95.jar:lib/lucene-analyzers-3.6.0.jar:lib/lucene-core-3.6.0.jar:lib/slf4j-api-1.7.6.jar:lib/slf4j-log4j12-1.7.6.jar:lib/vecmath-1.3.2.jar:lib/xercesImpl-2.11.0.jar:lib/xml-apis-1.4.01.jar:lib/jts-1.13.jar:lib/log4j-1.2.17.jar</classpath>83 <classpath mode="compile">../../core/dist/josm-custom.jar:lib/log4j-1.2.17.jar:lib/liblinear-java-1.95.jar:lib/jena-core-2.12.0.jar:lib/jts-1.13.jar:lib/gt-api-9.3.jar:lib/gt-referencing-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-metadata-9.3.jar:lib/slf4j-api-1.7.6.jar:lib/xercesImpl-2.11.0.jar:lib/commons-lang3-3.3.2.jar:lib/commons-pool-1.5.4.jar:lib/gt-api-9.3.jar:lib/gt-metadata-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-referencing-9.3.jar:lib/jai_core-1.1.3.jar:lib/jena-core-2.12.0.jar:lib/jena-iri-1.1.0.jar:lib/jgridshift-1.0.jar:lib/jsonic-1.2.7.jar:lib/jsr-275-1.0-beta-2.jar:lib/jts-1.13.jar:lib/langdetect-1.1-20120112.jar:lib/liblinear-1.95.jar:lib/liblinear-java-1.95.jar:lib/lucene-analyzers-3.6.0.jar:lib/lucene-core-3.6.0.jar:lib/slf4j-api-1.7.6.jar:lib/slf4j-log4j12-1.7.6.jar:lib/vecmath-1.3.2.jar:lib/xercesImpl-2.11.0.jar:lib/xml-apis-1.4.01.jar</classpath> 84 84 <built-to>../../dist</built-to> 85 85 <source-level>1.7</source-level> -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java
r31441 r31461 153 153 //System.out.println(anal.getFrequencies()); 154 154 //System.out.println(anal.getTopKMostFrequent(15)); 155 //System.out.println(anal.getWithFrequency(100)); 156 155 //System.out.println(anal.getWithFrequency(100)); 157 156 158 157 textualListFilePath = modelDirectory.getAbsolutePath()+"/textualList.txt"; … … 165 164 } catch (IOException ex) { 166 165 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 167 } 168 166 } 169 167 170 168 //writeTextualListToFile(textualFilePath, anal.getTopKMostFrequent(15)); … … 752 750 //System.out.println("file created"); 753 751 model.save(modelFile); 754 //System.out.println("saved");752 System.out.println("best model saved at: " + modelFile); 755 753 } catch (IOException ex) { 756 754 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); … … 881 879 //System.out.println("file created"); 882 880 model.save(modelFile); 883 System.out.println("model saved at: " + modelFile);881 System.out.println("model with classes saved at: " + modelFile); 884 882 } catch (IOException ex) { 885 883 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); … … 918 916 919 917 920 private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) 921 { 922 918 private static void writeTextualListToFile(String filePath, List<Map.Entry<String, Integer>> textualList) { 923 919 try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8"))) { 924 920 for(Map.Entry<String, Integer> entry : textualList){ -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/Analyzer.java
r31106 r31461 10 10 import java.util.Collections; 11 11 import java.util.Comparator; 12 import java.util.HashMap; 12 13 import java.util.HashSet; 13 14 import java.util.List; … … 17 18 import java.util.logging.Level; 18 19 import java.util.logging.Logger; 20 import org.apache.lucene.analysis.de.GermanAnalyzer; 19 21 import org.apache.lucene.analysis.el.GreekAnalyzer; 20 22 import org.apache.lucene.analysis.en.EnglishAnalyzer; 23 import org.apache.lucene.analysis.es.SpanishAnalyzer; 24 import org.apache.lucene.analysis.fr.FrenchAnalyzer; 25 import org.apache.lucene.analysis.hi.HindiAnalyzer; 26 import org.apache.lucene.analysis.ru.RussianAnalyzer; 27 import org.apache.lucene.analysis.standard.StandardAnalyzer; 28 import org.apache.lucene.analysis.tr.TurkishAnalyzer; 21 29 import org.apache.lucene.queryParser.ParseException; 22 30 import org.apache.lucene.queryParser.QueryParser; … … 24 32 25 33 /** 26 * Analyzes textual information. Language rdetection, stop words removal, stemming based on language.34 * Analyzes textual information. Language detection, stop words removal, stemming based on language. 27 35 * Provides methods for retrieving the textual list by frequency and top-K terms. 28 36 * @author imis-nkarag … … 69 77 } 70 78 71 int en=0; 72 int el=0; 79 Map<String, Integer> langs = new HashMap<>(); 80 langs.put("en", 0); 81 langs.put("el", 0); 82 langs.put("de", 0); 83 langs.put("es", 0); 84 langs.put("ru", 0); 85 langs.put("hi", 0); 86 langs.put("zh", 0); 87 langs.put("tr", 0); 88 langs.put("fr", 0); 89 73 90 for(String word : sampleList){ 74 91 //System.out.println("to be detected: " + word); … … 78 95 switch (lang) { 79 96 case "en": 80 en++; 97 //en++; 98 langs.put("en", langs.get("en")+1); 81 99 break; 82 100 case "el": 83 el++; 101 //el++; 102 langs.put("el", langs.get("el")+1); 103 break; 104 case "de": 105 //de++; 106 langs.put("de", langs.get("de")+1); 107 break; 108 case "es": 109 //es++; 110 langs.put("es", langs.get("es")+1); 111 break; 112 case "ru": 113 //ru++; 114 langs.put("ru", langs.get("ru")+1); 115 break; 116 case "fr": 117 //fr++; 118 langs.put("fr", langs.get("fr")+1); 119 break; 120 case "zh": 121 //zh++; 122 langs.put("zh", langs.get("zh")+1); 123 break; 124 case "tr": 125 //tr++; 126 langs.put("tr", langs.get("tr")+1); 127 break; 128 case "hi": 129 //hi++; 130 langs.put("hi", langs.get("hi")+1); 84 131 break; 85 132 //other lang, no support yet … … 90 137 } 91 138 } 92 if(el>en){93 //language = "el";94 normalizedList = stemGreek(normalizedList);95 }96 else{97 //language = "en";98 normalizedList = stemEnglish(normalizedList);99 }100 139 101 //List<Entry<String, Integer>> list = new ArrayList<>(set); 102 Collections.sort( normalizedList, new Comparator<Map.Entry<String, Integer>>() 140 int maxLangFreq = langs.get("en"); 141 String dominantLanguage = "en"; 142 for(Entry<String,Integer> lang : langs.entrySet()){ 143 if(lang.getValue()> maxLangFreq){ 144 maxLangFreq = lang.getValue(); 145 dominantLanguage = lang.getKey(); 146 } 147 } 148 149 switch (dominantLanguage) { 150 case "en": 151 normalizedList = stemEnglish(normalizedList); 152 break; 153 case "el": 154 normalizedList = stemGreek(normalizedList); 155 break; 156 case "de": 157 normalizedList = stemGerman(normalizedList); 158 break; 159 case "es": 160 normalizedList = stemSpanish(normalizedList); 161 break; 162 case "ru": 163 normalizedList = stemRussian(normalizedList); 164 break; 165 case "fr": 166 normalizedList = stemFrench(normalizedList); 167 break; 168 case "zh": 169 normalizedList = stemChinese(normalizedList); 170 break; 171 case "tr": 172 normalizedList = stemTurkish(normalizedList); 173 break; 174 case "hi": 175 normalizedList = stemHindi(normalizedList); 176 break; 177 default: 178 normalizedList = stemEnglish(normalizedList); 179 break; 180 } 181 182 Collections.sort(normalizedList, new Comparator<Map.Entry<String, Integer>>() 103 183 { 104 184 @Override … … 107 187 return (o2.getValue()).compareTo( o1.getValue() ); 108 188 } 109 } ); 110 189 } ); 111 190 setFrequencies(normalizedList); 112 191 } 113 192 114 private ArrayList<Map.Entry<String, Integer>> stemGreek(ArrayList<Map.Entry<String, Integer>> normalizedList) {193 private static ArrayList<Map.Entry<String, Integer>> stemGreek(List<Map.Entry<String, Integer>> normalizedList) { 115 194 org.apache.lucene.analysis.Analyzer greekAnalyzer = new GreekAnalyzer(Version.LUCENE_36); 116 195 QueryParser greekParser = new QueryParser(Version.LUCENE_36, "", greekAnalyzer); … … 122 201 String stemmedWord = greekParser.parse(entry.getKey()).toString(); 123 202 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 124 stemmedList.add(stemmed); 125 126 } catch (ParseException ex) { 127 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 128 } 129 } 130 } 131 return stemmedList; 132 } 133 134 private ArrayList<Map.Entry<String, Integer>> stemEnglish(ArrayList<Map.Entry<String, Integer>> normalizedList){ 203 if(!stemmedWord.equals("")){ 204 stemmedList.add(stemmed); 205 } 206 } catch (ParseException ex) { 207 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 208 } 209 } 210 } 211 return stemmedList; 212 } 213 214 private static ArrayList<Map.Entry<String, Integer>> stemEnglish(List<Map.Entry<String, Integer>> normalizedList){ 135 215 org.apache.lucene.analysis.Analyzer englishAnalyzer = new EnglishAnalyzer(Version.LUCENE_36); 136 216 QueryParser englishParser = new QueryParser(Version.LUCENE_36, "", englishAnalyzer); 137 217 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 138 for(Map.Entry<String, Integer> entry : normalizedList){ 218 for(Map.Entry<String, Integer> entry : normalizedList){ 139 219 if(!entry.getKey().isEmpty()){ 140 220 try { … … 142 222 String stemmedWord = englishParser.parse(entry.getKey()).toString(); 143 223 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 144 stemmedList.add(stemmed); 145 } catch (ParseException ex) { 146 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 147 } 148 } 149 } 150 return stemmedList; 151 } 224 if(!stemmedWord.equals("")){ 225 stemmedList.add(stemmed); 226 } 227 } catch (ParseException ex) { 228 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 229 } 230 } 231 } 232 return stemmedList; 233 } 234 235 private static ArrayList<Map.Entry<String, Integer>> stemGerman(List<Map.Entry<String, Integer>> normalizedList){ 236 org.apache.lucene.analysis.Analyzer germanAnalyzer = new GermanAnalyzer(Version.LUCENE_36); 237 QueryParser germanParser = new QueryParser(Version.LUCENE_36, "", germanAnalyzer); 238 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 239 for(Map.Entry<String, Integer> entry : normalizedList){ 240 if(!entry.getKey().isEmpty()){ 241 try { 242 //System.out.println("result: " + englishParser.parse(entry.getKey())); 243 String stemmedWord = germanParser.parse(entry.getKey()).toString(); 244 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 245 if(!stemmedWord.equals("")){ 246 stemmedList.add(stemmed); 247 } 248 } catch (ParseException ex) { 249 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 250 } 251 } 252 } 253 return stemmedList; 254 } 255 256 private static ArrayList<Map.Entry<String, Integer>> stemSpanish(List<Map.Entry<String, Integer>> normalizedList){ 257 org.apache.lucene.analysis.Analyzer spanishAnalyzer = new SpanishAnalyzer(Version.LUCENE_36); 258 QueryParser spanishParser = new QueryParser(Version.LUCENE_36, "", spanishAnalyzer); 259 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 260 for(Map.Entry<String, Integer> entry : normalizedList){ 261 if(!entry.getKey().isEmpty()){ 262 try { 263 //System.out.println("result: " + englishParser.parse(entry.getKey())); 264 String stemmedWord = spanishParser.parse(entry.getKey()).toString(); 265 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 266 if(!stemmedWord.equals("")){ 267 stemmedList.add(stemmed); 268 } 269 } catch (ParseException ex) { 270 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 271 } 272 } 273 } 274 return stemmedList; 275 } 276 277 private static ArrayList<Map.Entry<String, Integer>> stemRussian(List<Map.Entry<String, Integer>> normalizedList){ 278 org.apache.lucene.analysis.Analyzer russianAnalyzer = new RussianAnalyzer(Version.LUCENE_36); 279 QueryParser russianParser = new QueryParser(Version.LUCENE_36, "", russianAnalyzer); 280 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 281 for(Map.Entry<String, Integer> entry : normalizedList){ 282 if(!entry.getKey().isEmpty()){ 283 try { 284 //System.out.println("result: " + englishParser.parse(entry.getKey())); 285 String stemmedWord = russianParser.parse(entry.getKey()).toString(); 286 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 287 if(!stemmedWord.equals("")){ 288 stemmedList.add(stemmed); 289 } 290 } catch (ParseException ex) { 291 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 292 } 293 } 294 } 295 return stemmedList; 296 } 297 298 private static ArrayList<Map.Entry<String, Integer>> stemFrench(List<Map.Entry<String, Integer>> normalizedList){ 299 org.apache.lucene.analysis.Analyzer frenchAnalyzer = new FrenchAnalyzer(Version.LUCENE_36); 300 QueryParser frenchParser = new QueryParser(Version.LUCENE_36, "", frenchAnalyzer); 301 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 302 for(Map.Entry<String, Integer> entry : normalizedList){ 303 if(!entry.getKey().isEmpty()){ 304 try { 305 //System.out.println("result: " + englishParser.parse(entry.getKey())); 306 String stemmedWord = frenchParser.parse(entry.getKey()).toString(); 307 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 308 if(!stemmedWord.equals("")){ 309 stemmedList.add(stemmed); 310 } 311 } catch (ParseException ex) { 312 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 313 } 314 } 315 } 316 return stemmedList; 317 } 318 319 private static ArrayList<Map.Entry<String, Integer>> stemChinese(List<Map.Entry<String, Integer>> normalizedList){ 320 org.apache.lucene.analysis.Analyzer chineseAnalyzer = new StandardAnalyzer(Version.LUCENE_36); 321 QueryParser chineseParser = new QueryParser(Version.LUCENE_36, "", chineseAnalyzer); 322 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 323 for(Map.Entry<String, Integer> entry : normalizedList){ 324 if(!entry.getKey().isEmpty()){ 325 try { 326 //System.out.println("result: " + englishParser.parse(entry.getKey())); 327 String stemmedWord = chineseParser.parse(entry.getKey()).toString(); 328 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 329 if(!stemmedWord.equals("")){ 330 stemmedList.add(stemmed); 331 } 332 } catch (ParseException ex) { 333 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 334 } 335 } 336 } 337 return stemmedList; 338 } 339 340 private static ArrayList<Map.Entry<String, Integer>> stemTurkish(List<Map.Entry<String, Integer>> normalizedList){ 341 org.apache.lucene.analysis.Analyzer turkishAnalyzer = new TurkishAnalyzer(Version.LUCENE_36); 342 QueryParser turkishParser = new QueryParser(Version.LUCENE_36, "", turkishAnalyzer); 343 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 344 for(Map.Entry<String, Integer> entry : normalizedList){ 345 if(!entry.getKey().isEmpty()){ 346 try { 347 //System.out.println("result: " + englishParser.parse(entry.getKey())); 348 String stemmedWord = turkishParser.parse(entry.getKey()).toString(); 349 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 350 if(!stemmedWord.equals("")){ 351 stemmedList.add(stemmed); 352 } 353 } catch (ParseException ex) { 354 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 355 } 356 } 357 } 358 return stemmedList; 359 } 360 361 private static ArrayList<Map.Entry<String, Integer>> stemHindi(List<Map.Entry<String, Integer>> normalizedList){ 362 org.apache.lucene.analysis.Analyzer hindiAnalyzer = new HindiAnalyzer(Version.LUCENE_36); 363 QueryParser hindiParser = new QueryParser(Version.LUCENE_36, "", hindiAnalyzer); 364 ArrayList<Map.Entry<String, Integer>> stemmedList = new ArrayList<>(); 365 for(Map.Entry<String, Integer> entry : normalizedList){ 366 if(!entry.getKey().isEmpty()){ 367 try { 368 //System.out.println("result: " + englishParser.parse(entry.getKey())); 369 String stemmedWord = hindiParser.parse(entry.getKey()).toString(); 370 SimpleEntry<String, Integer> stemmed = new SimpleEntry<>(stemmedWord, entry.getValue()); 371 if(!stemmedWord.equals("")){ 372 stemmedList.add(stemmed); 373 } 374 } catch (ParseException ex) { 375 Logger.getLogger(Analyzer.class.getName()).log(Level.SEVERE, null, ex); 376 } 377 } 378 } 379 return stemmedList; 380 } 381 382 152 383 153 384 private void loadStopWords(){ … … 171 402 172 403 private void setFrequencies(ArrayList<Map.Entry<String, Integer>> frequencies){ 173 this.frequencies = frequencies; 404 this.frequencies = frequencies; 405 } 406 407 public List<Map.Entry<String, Integer>> getFrequencies(){ 408 return Collections.unmodifiableList(frequencies); 409 } 410 411 public List<Map.Entry<String, Integer>> getTopKMostFrequent(int topK){ 412 //todo recheck 413 if(topK > frequencies.size()){ 414 return Collections.unmodifiableList(frequencies); 415 } 416 else{ 417 return frequencies.subList(0, topK); 418 } 174 419 175 }176 177 public List<Map.Entry<String, Integer>> getFrequencies(){178 return frequencies;179 }180 181 public List<Map.Entry<String, Integer>> getTopKMostFrequent(int topK){182 return frequencies.subList(0, topK);183 420 } 184 421 -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java
r31402 r31461 14 14 /** 15 15 * Detects language of osm textual information 16 * 16 * 17 17 * @author imis-nkarag 18 18 */ 19 public class LanguageDetector { 19 20 20 public class LanguageDetector {21 22 21 private static LanguageDetector languageDetector = null; 23 24 private LanguageDetector() {22 23 private LanguageDetector() { 25 24 //prevent instatiation 26 25 } 27 28 public static LanguageDetector getInstance(String languageProfilesPath) {29 System.out.println("language profile path: \n" + languageProfilesPath + "/el");30 if (languageDetector == null){31 languageDetector = new LanguageDetector(); 26 27 public static LanguageDetector getInstance(String languageProfilesPath) { 28 //System.out.println("language profile path: \n" + languageProfilesPath + "/el"); 29 if (languageDetector == null) { 30 languageDetector = new LanguageDetector(); 32 31 loadProfilesFromStream(languageProfilesPath); 33 32 //profilesLoaded = true; 34 33 } 35 return languageDetector; 36 } 37 38 public static void loadProfilesFromStream(String languageProfilesPath){ //create profiles directory in system from stream and load them 34 return languageDetector; 35 } 39 36 40 InputStream languageProfilesInputStream1 = LanguageDetector.class.getResourceAsStream("/resources/profiles/el"); 41 InputStream languageProfilesInputStream2 = LanguageDetector.class.getResourceAsStream("/resources/profiles/en"); 42 //languageProfilesInputStream. 37 public static void loadProfilesFromStream(String languageProfilesPath) { //create profiles directory in system from stream and load them 43 38 44 if(!new File(languageProfilesPath).exists()){ 39 /* supported languages 40 el:greek, en:english, de:german, fr:french, es:spanish, ru:russian, tr:turkish, zh-cn:chinese, hi:hindi 41 */ 42 InputStream languageProfilesInputStreamEl = LanguageDetector.class.getResourceAsStream("/profiles/el"); 43 InputStream languageProfilesInputStreamEn = LanguageDetector.class.getResourceAsStream("/profiles/en"); 44 InputStream languageProfilesInputStreamDe = LanguageDetector.class.getResourceAsStream("/profiles/de"); 45 InputStream languageProfilesInputStreamFr = LanguageDetector.class.getResourceAsStream("/profiles/fr"); 46 InputStream languageProfilesInputStreamEs = LanguageDetector.class.getResourceAsStream("/profiles/es"); 47 InputStream languageProfilesInputStreamRu = LanguageDetector.class.getResourceAsStream("/profiles/ru"); 48 InputStream languageProfilesInputStreamTr = LanguageDetector.class.getResourceAsStream("/profiles/tr"); 49 InputStream languageProfilesInputStreamZh = LanguageDetector.class.getResourceAsStream("/profiles/zh-cn"); 50 InputStream languageProfilesInputStreamHi = LanguageDetector.class.getResourceAsStream("/profiles/hi"); 51 //InputStream languageProfilesInputStream2 = LanguageDetector.class.getResourceAsStream("/resources/profiles/en"); 52 53 if (!new File(languageProfilesPath).exists()) { 45 54 //new File(languageProfilesPath).mkdir(); 46 55 new File(languageProfilesPath).mkdirs(); 47 56 } 48 File languageProfilesOutputFile1 = new File(languageProfilesPath + "/el");49 File languageProfilesOutputFile2 = new File(languageProfilesPath +"/en");50 57 51 try { 52 System.out.println("languageProfilesOutputFile1.exists: " + languageProfilesOutputFile1.exists()); 53 System.out.println("languageProfilesOutputFile1.getAbsolutePath(): " + languageProfilesOutputFile1.getAbsolutePath()); 54 System.out.println("languageProfilesOutputFile1.canRead(): " + languageProfilesOutputFile1.canRead()); 55 System.out.println("languageProfilesOutputFile1.canWrite(): " + languageProfilesOutputFile1.canWrite()); 56 //System.out.println("languageProfilesOutputFile1.canRead(): " + languageProfilesOutputFile1.); 57 58 languageProfilesOutputFile1.createNewFile(); 59 languageProfilesOutputFile2.createNewFile(); 60 } catch (IOException ex) { 61 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 62 } 63 64 //languageProfilesOutputFile.mkdirs(); 65 66 FileOutputStream outputStream = null; 67 //FileOutputStream outputStream2 = null; 68 try { 69 outputStream = new FileOutputStream(languageProfilesOutputFile1); 70 //outputStream2 = new FileOutputStream(languageProfilesOutputFile2); 71 } catch (FileNotFoundException ex) { 72 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 73 } 74 //System.out.println("deb1"); 75 76 FileOutputStream outputStream2 = null; 77 //FileOutputStream outputStream2 = null; 78 try { 79 outputStream2 = new FileOutputStream(languageProfilesOutputFile2); 80 //outputStream2 = new FileOutputStream(languageProfilesOutputFile2); 81 } catch (FileNotFoundException ex) { 82 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 83 } 84 85 86 int read = 0; 87 byte[] bytes = new byte[1024]; 58 File languageProfilesOutputFileEl = new File(languageProfilesPath + "/el"); 59 File languageProfilesOutputFileEn = new File(languageProfilesPath + "/en"); 60 File languageProfilesOutputFileDe = new File(languageProfilesPath + "/de"); 61 File languageProfilesOutputFileFr = new File(languageProfilesPath + "/fr"); 62 File languageProfilesOutputFileEs = new File(languageProfilesPath + "/es"); 63 File languageProfilesOutputFileRu = new File(languageProfilesPath + "/ru"); 64 File languageProfilesOutputFileTr = new File(languageProfilesPath + "/tr"); 65 File languageProfilesOutputFileZh = new File(languageProfilesPath + "/zh-cn"); 66 File languageProfilesOutputFileHi = new File(languageProfilesPath + "/hi"); 88 67 89 68 try { 90 while ((read = languageProfilesInputStream1.read(bytes)) != -1) { 91 outputStream.write(bytes, 0, read); 92 } 69 70 languageProfilesOutputFileEl.createNewFile(); 71 languageProfilesOutputFileEn.createNewFile(); 72 languageProfilesOutputFileDe.createNewFile(); 73 languageProfilesOutputFileFr.createNewFile(); 74 languageProfilesOutputFileEs.createNewFile(); 75 languageProfilesOutputFileRu.createNewFile(); 76 languageProfilesOutputFileTr.createNewFile(); 77 languageProfilesOutputFileZh.createNewFile(); 78 languageProfilesOutputFileHi.createNewFile(); 79 93 80 } catch (IOException ex) { 94 81 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 95 82 } 96 83 84 FileOutputStream outputStreamEl = null; 85 FileOutputStream outputStreamEn = null; 86 FileOutputStream outputStreamDe = null; 87 FileOutputStream outputStreamFr = null; 88 FileOutputStream outputStreamEs = null; 89 FileOutputStream outputStreamRu = null; 90 FileOutputStream outputStreamTr = null; 91 FileOutputStream outputStreamZh = null; 92 FileOutputStream outputStreamHi = null; 93 94 try { 95 96 outputStreamEl = new FileOutputStream(languageProfilesOutputFileEl); 97 outputStreamEn = new FileOutputStream(languageProfilesOutputFileEn); 98 outputStreamDe = new FileOutputStream(languageProfilesOutputFileDe); 99 outputStreamFr = new FileOutputStream(languageProfilesOutputFileFr); 100 outputStreamEs = new FileOutputStream(languageProfilesOutputFileEs); 101 outputStreamRu = new FileOutputStream(languageProfilesOutputFileRu); 102 outputStreamTr = new FileOutputStream(languageProfilesOutputFileTr); 103 outputStreamZh = new FileOutputStream(languageProfilesOutputFileZh); 104 outputStreamHi = new FileOutputStream(languageProfilesOutputFileHi); 105 106 } catch (FileNotFoundException ex) { 107 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 108 } 97 109 98 int read2 = 0; 99 byte[] bytes2 = new byte[1024]; 110 int read = 0; 111 byte[] bytes = new byte[1024]; 112 try { 113 114 while ((read = languageProfilesInputStreamEl.read(bytes)) != -1) { 115 outputStreamEl.write(bytes, 0, read); 116 } 117 118 read = 0; 119 bytes = new byte[1024]; 120 121 while ((read = languageProfilesInputStreamEn.read(bytes)) != -1) { 122 outputStreamEn.write(bytes, 0, read); 123 } 124 125 read = 0; 126 bytes = new byte[1024]; 127 128 while ((read = languageProfilesInputStreamDe.read(bytes)) != -1) { 129 outputStreamDe.write(bytes, 0, read); 130 } 131 132 read = 0; 133 bytes = new byte[1024]; 134 135 while ((read = languageProfilesInputStreamFr.read(bytes)) != -1) { 136 outputStreamFr.write(bytes, 0, read); 137 } 138 139 read = 0; 140 bytes = new byte[1024]; 141 142 while ((read = languageProfilesInputStreamEs.read(bytes)) != -1) { 143 outputStreamEs.write(bytes, 0, read); 144 } 145 146 read = 0; 147 bytes = new byte[1024]; 148 149 while ((read = languageProfilesInputStreamRu.read(bytes)) != -1) { 150 outputStreamRu.write(bytes, 0, read); 151 } 152 153 read = 0; 154 bytes = new byte[1024]; 155 156 while ((read = languageProfilesInputStreamTr.read(bytes)) != -1) { 157 outputStreamTr.write(bytes, 0, read); 158 } 159 160 read = 0; 161 bytes = new byte[1024]; 162 163 while ((read = languageProfilesInputStreamZh.read(bytes)) != -1) { 164 outputStreamZh.write(bytes, 0, read); 165 } 166 167 read = 0; 168 bytes = new byte[1024]; 169 170 while ((read = languageProfilesInputStreamHi.read(bytes)) != -1) { 171 outputStreamHi.write(bytes, 0, read); 172 } 173 174 } catch (IOException ex) { 175 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 176 } 100 177 101 178 try { 102 while ((read2 = languageProfilesInputStream2.read(bytes2)) != -1) {103 outputStream2.write(bytes2, 0, read2);104 }105 } catch (IOException ex) {106 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);107 }108 try {109 110 179 111 180 DetectorFactory.loadProfile(languageProfilesPath); 112 //profilesLoaded = true;113 181 114 182 } catch (LangDetectException ex) { 115 //profilesLoaded = false;116 183 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 117 } 184 } 118 185 } 119 186 120 187 public String detect(String text) { 121 188 try { 122 189 Detector detector = DetectorFactory.create(); 123 190 detector.append(text); 124 return detector.detect(); 125 } catch (LangDetectException ex) { 191 String lang = detector.detect(); 192 //System.out.println("language detected: " + lang); 193 return lang; 194 } catch (LangDetectException ex) { 126 195 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 127 return "en"; //default lang to return 128 } 129 } 196 return "en"; //default lang to return if anything goes wrong at detection 197 } 198 } 130 199 } -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java
r31441 r31461 27 27 import java.awt.datatransfer.Transferable; 28 28 import java.awt.event.ActionEvent; 29 import java.awt.event.ActionListener;30 29 import java.awt.event.FocusAdapter; 31 30 import java.awt.event.FocusEvent; … … 43 42 import java.io.InputStream; 44 43 import java.text.DecimalFormat; 45 import java.text.Normalizer;46 44 import java.util.ArrayList; 47 45 import java.util.Arrays; … … 106 104 import org.openstreetmap.josm.actions.JosmAction; 107 105 import org.openstreetmap.josm.command.ChangePropertyCommand; 108 import org.openstreetmap.josm.command.Command;109 import org.openstreetmap.josm.command.SequenceCommand;110 106 import org.openstreetmap.josm.data.osm.Node; 111 107 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 168 164 private boolean useCustomSVMModel = false; 169 165 private String customSVMModelPath; 170 171 166 172 167 // Selection that we are editing by using both dialogs 173 168 Collection<OsmPrimitive> sel; … … 250 245 changedKey = null; 251 246 sel = Main.main.getInProgressSelection(); 252 if (sel == null || sel.isEmpty()) return;253 254 String key = tagData.getValueAt(row, 0).toString();255 objKey=key;247 //if (sel == null || sel.isEmpty()) return; 248 // String key = tagData.getValueAt(row, 0).toString(); 249 String key = ""; 250 // objKey=key; 256 251 257 252 @SuppressWarnings("unchecked") 253 Map<String, Integer> dumPar = new HashMap<>(); 254 dumPar.put(" ", -1); 258 255 final TrainingDialog editDialog = new TrainingDialog(key, row, 259 (Map<String, Integer>) tagData.getValueAt(row, 1), focusOnKey);256 dumPar, focusOnKey); 260 257 editDialog.showDialog(); 261 if (editDialog.getValue() !=1 ) return;262 editDialog.performTagEdit();258 //if (editDialog.getValue() !=1 ) return; 259 //editDialog.performTagEdit(); 263 260 } 264 261 … … 341 338 342 339 public final class TrainingDialog extends AbstractTagsDialog { 343 final String key;344 final Map<String, Integer> m;345 final int row;346 347 Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {348 @Override349 public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {350 boolean c1 = m.containsKey(o1.getValue());351 boolean c2 = m.containsKey(o2.getValue());352 if (c1 == c2)353 return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());354 else if (c1)355 return -1;356 else357 return +1;358 }359 };340 // final String key; 341 // final Map<String, Integer> m; 342 // final int row; 343 344 // Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() { 345 // @Override 346 // public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) { 347 // boolean c1 = m.containsKey(o1.getValue()); 348 // boolean c2 = m.containsKey(o2.getValue()); 349 // if (c1 == c2) 350 // return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue()); 351 // else if (c1) 352 // return -1; 353 // else 354 // return +1; 355 // } 356 // }; 360 357 361 358 ListCellRenderer<AutoCompletionListItem> cellRenderer = new ListCellRenderer<AutoCompletionListItem>() { … … 417 414 private UserDataExtractAndTrainWorker userDataExtractAndTrainWorker; 418 415 419 //public TrainWorker trainWorker;420 421 416 private TrainingDialog(String key, int row, Map<String, Integer> map, final boolean initialFocusOnKey) { 422 417 //super(Main.parent, tr("Training process configuration"), new String[] {tr("Start Training"),tr("Cancel")}); … … 427 422 setCancelButton(2); 428 423 //configureContextsensitiveHelp("/Dialog/EditValue", true /* show help button */); 429 this.key = key;430 this.row = row;431 this.m = map;424 // this.key = key; 425 // this.row = row; 426 // this.m = map; 432 427 433 428 JPanel mainPanel = new JPanel(new BorderLayout(10,10)); //6,6 … … 697 692 southPanel.add(resetConfigButton); 698 693 southPanel.add(trainFromUserCheckBox); 699 700 //Border checkBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE); 701 //trainFromUserCheckBox.setBorder(checkBorder); 702 //trainFromUserCheckBox.setBorderPainted(true); 703 694 704 695 userGroup.add(byAreaRadioButton); 705 696 userGroup.add(byTimeRadioButton); … … 763 754 Collections.sort(keyList, defaultACItemComparator); 764 755 765 keys = new AutoCompletingComboBox(key);766 keys.setPossibleACItems(keyList);767 keys.setEditable(true);768 keys.setSelectedItem(key);769 770 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));771 Collections.sort(valueList, usedValuesAwareComparator);772 final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey();773 values = new AutoCompletingComboBox(selection);774 values.setRenderer(cellRenderer);775 values.setEditable(true);776 values.setPossibleACItems(valueList);777 values.setSelectedItem(selection);778 values.getEditor().setItem(selection);779 values.getEditor().addActionListener(new ActionListener() {780 @Override781 public void actionPerformed(ActionEvent e) {782 buttonAction(0, null); // emulate OK button click783 }784 });785 addFocusAdapter(autocomplete, usedValuesAwareComparator);756 // keys = new AutoCompletingComboBox(key); 757 // keys.setPossibleACItems(keyList); 758 // keys.setEditable(true); 759 // keys.setSelectedItem(key); 760 761 // List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 762 // Collections.sort(valueList, usedValuesAwareComparator); 763 // final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey(); 764 // values = new AutoCompletingComboBox(selection); 765 // values.setRenderer(cellRenderer); 766 // values.setEditable(true); 767 // values.setPossibleACItems(valueList); 768 // values.setSelectedItem(selection); 769 // values.getEditor().setItem(selection); 770 // values.getEditor().addActionListener(new ActionListener() { 771 // @Override 772 // public void actionPerformed(ActionEvent e) { 773 // buttonAction(0, null); // emulate OK button click 774 // } 775 // }); 776 // addFocusAdapter(autocomplete, usedValuesAwareComparator); 786 777 787 778 setContent(mainPanel, false); … … 1020 1011 } 1021 1012 1022 /**1023 * Edit tags of multiple selected objects according to selected ComboBox values1024 * If value == "", tag will be deleted1025 * Confirmations may be needed.1026 */1027 private void performTagEdit() {1028 String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());1029 value = Normalizer.normalize(value, java.text.Normalizer.Form.NFC);1030 if (value.isEmpty()) {1031 value = null; // delete the key1032 }1033 String newkey = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());1034 newkey = Normalizer.normalize(newkey, java.text.Normalizer.Form.NFC);1035 if (newkey.isEmpty()) {1036 newkey = key;1037 value = null; // delete the key instead1038 }1039 if (key.equals(newkey) && tr("<different>").equals(value))1040 return;1041 if (key.equals(newkey) || value == null) {1042 Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value));1043 AutoCompletionManager.rememberUserInput(newkey, value, true);1044 } else {1045 for (OsmPrimitive osm: sel) {1046 if (osm.get(newkey) != null) {1047 if (!warnOverwriteKey(tr("You changed the key from ''{0}'' to ''{1}''.", key, newkey),1048 "overwriteEditKey"))1049 return;1050 break;1051 }1052 }1053 Collection<Command> commands = new ArrayList<>();1054 commands.add(new ChangePropertyCommand(sel, key, null));1055 if (value.equals(tr("<different>"))) {1056 Map<String, List<OsmPrimitive>> map = new HashMap<>();1057 for (OsmPrimitive osm: sel) {1058 String val = osm.get(key);1059 if (val != null) {1060 if (map.containsKey(val)) {1061 map.get(val).add(osm);1062 } else {1063 List<OsmPrimitive> v = new ArrayList<>();1064 v.add(osm);1065 map.put(val, v);1066 }1067 }1068 }1069 for (Map.Entry<String, List<OsmPrimitive>> e: map.entrySet()) {1070 commands.add(new ChangePropertyCommand(e.getValue(), newkey, e.getKey()));1071 }1072 } else {1073 commands.add(new ChangePropertyCommand(sel, newkey, value));1074 AutoCompletionManager.rememberUserInput(newkey, value, false);1075 }1076 Main.main.undoRedo.add(new SequenceCommand(1077 trn("Change properties of up to {0} object",1078 "Change properties of up to {0} objects", sel.size(), sel.size()),1079 commands));1080 }1081 1082 changedKey = newkey;1083 }1013 // /** 1014 // * Edit tags of multiple selected objects according to selected ComboBox values 1015 // * If value == "", tag will be deleted 1016 // * Confirmations may be needed. 1017 // */ 1018 // private void performTagEdit() { 1019 // String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); 1020 // value = Normalizer.normalize(value, java.text.Normalizer.Form.NFC); 1021 // if (value.isEmpty()) { 1022 // value = null; // delete the key 1023 // } 1024 // String newkey = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString()); 1025 // newkey = Normalizer.normalize(newkey, java.text.Normalizer.Form.NFC); 1026 // if (newkey.isEmpty()) { 1027 // newkey = key; 1028 // value = null; // delete the key instead 1029 // } 1030 // if (key.equals(newkey) && tr("<different>").equals(value)) 1031 // return; 1032 // if (key.equals(newkey) || value == null) { 1033 // Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value)); 1034 // AutoCompletionManager.rememberUserInput(newkey, value, true); 1035 // } else { 1036 // for (OsmPrimitive osm: sel) { 1037 // if (osm.get(newkey) != null) { 1038 // if (!warnOverwriteKey(tr("You changed the key from ''{0}'' to ''{1}''.", key, newkey), 1039 // "overwriteEditKey")) 1040 // return; 1041 // break; 1042 // } 1043 // } 1044 // Collection<Command> commands = new ArrayList<>(); 1045 // commands.add(new ChangePropertyCommand(sel, key, null)); 1046 // if (value.equals(tr("<different>"))) { 1047 // Map<String, List<OsmPrimitive>> map = new HashMap<>(); 1048 // for (OsmPrimitive osm: sel) { 1049 // String val = osm.get(key); 1050 // if (val != null) { 1051 // if (map.containsKey(val)) { 1052 // map.get(val).add(osm); 1053 // } else { 1054 // List<OsmPrimitive> v = new ArrayList<>(); 1055 // v.add(osm); 1056 // map.put(val, v); 1057 // } 1058 // } 1059 // } 1060 // for (Map.Entry<String, List<OsmPrimitive>> e: map.entrySet()) { 1061 // commands.add(new ChangePropertyCommand(e.getValue(), newkey, e.getKey())); 1062 // } 1063 // } else { 1064 // commands.add(new ChangePropertyCommand(sel, newkey, value)); 1065 // AutoCompletionManager.rememberUserInput(newkey, value, false); 1066 // } 1067 // Main.main.undoRedo.add(new SequenceCommand( 1068 // trn("Change properties of up to {0} object", 1069 // "Change properties of up to {0} objects", sel.size(), sel.size()), 1070 // commands)); 1071 // } 1072 // 1073 // changedKey = newkey; 1074 // } 1084 1075 } 1085 1076 … … 1130 1121 rememberWindowGeometry(geometry); 1131 1122 } 1132 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get()); 1123 if(keys != null){ 1124 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get()); 1125 } 1133 1126 } 1134 1127 super.setVisible(visible); … … 1150 1143 1151 1144 public void selectKeysComboBox() { 1152 selectACComboBoxSavingUnixBuffer(keys);1145 //selectACComboBoxSavingUnixBuffer(keys); 1153 1146 } 1154 1147 1155 1148 public void selectValuesCombobox() { 1156 selectACComboBoxSavingUnixBuffer(values);1149 //selectACComboBoxSavingUnixBuffer(values); 1157 1150 } 1158 1151 … … 1327 1320 this.add(mainPanel); 1328 1321 1329 //JOptionPane pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);1330 1322 JOptionPane pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 1331 //pane. 1332 JDialog dlg = pane.createDialog(Main.parent, tr("Model Settings")); 1333 1323 JDialog dlg = pane.createDialog(Main.parent, tr("Model Settings")); 1334 1324 dlg.setVisible(true); 1335 1325 //JButton ok = dlg.getRootPane().getDefaultButton(); … … 1367 1357 customSVMModelPath = fileChooser.getSelectedFile().getAbsolutePath(); 1368 1358 } 1369 1370 1359 1371 1360 if(useModelCombinationCheckbox.isSelected()){ 1372 1361 String svmModelPath = fileChooser.getSelectedFile().getAbsolutePath(); … … 1478 1467 weightsPanel.repaint(); 1479 1468 } 1480 1481 // private static List<Double> normalizeWeights(){1482 // divide by their sum, all elements should sum to 1.1483 // return weightsList;1484 // }1485 1469 } 1486 1470 … … 1502 1486 private List<String> textualList = new ArrayList<>(); 1503 1487 //private boolean useClassFeatures = false; 1504 private final JCheckBox useTagsCheckBox; 1505 1488 private final JCheckBox useTagsCheckBox; 1506 1489 1507 1490 public AddTagsDialog() { … … 1511 1494 configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */); 1512 1495 final AddTagsDialog lala = this; 1513 1514 1496 1515 1497 loadOntology(); … … 1539 1521 modelSettingsButton = new javax.swing.JButton("Model Settings"); 1540 1522 useTagsCheckBox = new javax.swing.JCheckBox("Predict using tags"); 1541 recommendedClassesLabel = new javax.swing.JLabel("Recommended Classes:"); 1542 1523 recommendedClassesLabel = new javax.swing.JLabel("Recommended Classes:"); 1543 1524 1544 1525 addAndContinueButton.addActionListener(new java.awt.event.ActionListener() { … … 1564 1545 } 1565 1546 else{ 1566 //useTagsCheckBox 1547 //recommend using tags: set the checkbox selected to avoid confusing the user 1548 useTagsCheckBox.setSelected(true); 1549 1567 1550 if(useTagsCheckBox.isSelected()){ 1568 1551 //load model with classes 1569 1552 modelWithClasses = true; 1570 1553 loadSVMmodel(); 1571 createOSMObject(sel); //create object including class features 1554 createOSMObject(sel); //create object including class features 1572 1555 } 1573 1556 else{ … … 1608 1591 modelWithClasses = true; 1609 1592 loadSVMmodel(); 1610 createOSMObject(sel); //create object including class features 1593 createOSMObject(sel); //create object including class features 1611 1594 } 1612 1595 else{ … … 1654 1637 1655 1638 mainPanel.add(keys, GBC.eop().fill()); 1656 1657 mainPanel.add(new JLabel(tr("Please select a value")), GBC.eol()); 1658 1639 mainPanel.add(new JLabel(tr("Please select a value")), GBC.eol()); 1659 1640 1660 1641 model = new DefaultListModel<>(); … … 1673 1654 modelWithClasses = false; 1674 1655 loadSVMmodel();//load original model 1675 createOSMObject(sel); //create object without class features 1676 1677 1656 createOSMObject(sel); //create object without class features 1678 1657 } 1679 1658 else{ 1659 //recommend using tags: set the checkbox selected to avoid confusing the user 1660 useTagsCheckBox.setSelected(true); 1680 1661 modelWithClasses = true; 1681 1662 loadSVMmodel();//load model with classes … … 1684 1665 } 1685 1666 1686 //createOSMObject(sel, false);1687 1688 1667 categoryList = new JList<>(model); 1689 1668 … … 1720 1699 categoryList.setModel(model); 1721 1700 1722 //System.out.println("components: \n" + mainPanel.getBounds());1723 1724 1701 values.setEditable(true); 1725 1702 mainPanel.add(values, GBC.eop().fill()); … … 1753 1730 suggestRecentlyAddedTags(mainPanel, recentTagsToShow, focus); 1754 1731 1755 //mainPanel.add(listPanel,GBC.eop().fill());1756 1757 1732 mainPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1758 1733 listPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); … … 1986 1961 } 1987 1962 } 1988 1989 1990 1963 1991 1964 try { … … 2001 1974 2002 1975 private void useCombinedSVMmodels(Collection<OsmPrimitive> sel, boolean useClassFeatures){ 2003 System.out.println("The system will combine " + filesAndWeights.size() + " SVM models."); 2004 1976 System.out.println("The system will combine " + filesAndWeights.size() + " SVM models."); 2005 1977 2006 1978 MathTransform transform = null; … … 2241 2213 else{ 2242 2214 scoreMap.put(predictedTag, finalRank); 2243 } 2244 2215 } 2245 2216 //add final weight - predicted tag 2246 2217 } -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java
r31106 r31461 242 242 Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Tags/Memberships")), KeyEvent.VK_P, 243 243 Shortcut.ALT_SHIFT), 150, true); 244 245 244 HelpUtil.setHelpContext(this, HelpUtil.ht("/Dialog/TagsMembership")); 246 245 247 246 setupTagsMenu(); 248 247 buildTagsTable(); //my … … 699 698 700 699 addAction.setEnabled(hasSelection); 701 editAction.setEnabled(hasTags || hasMemberships); 700 //editAction.setEnabled(hasTags || hasMemberships); 701 editAction.setEnabled(true); 702 702 deleteAction.setEnabled(hasTags || hasMemberships); 703 703 tagTable.setVisible(hasTags); … … 821 821 } 822 822 // double click, edit or add tag 823 else if (e.getSource() == tagTable ) {823 else if (e.getSource() == tagTable ) { 824 824 int row = tagTable.rowAtPoint(e.getPoint()); 825 825 if (row > -1) { … … 1041 1041 public void actionPerformed(ActionEvent e) { 1042 1042 //System.out.println("clicked recommend"); 1043 1044 1045 1043 editHelper.addTag(); 1046 btnAdd.requestFocusInWindow(); 1047 1044 btnAdd.requestFocusInWindow(); 1048 1045 } 1049 1046 } … … 1065 1062 //images/dialogs/train.png 1066 1063 //System.out.println("icon"); 1067 1064 setEnabled(true); 1068 1065 updateEnabledState(); 1069 1066 } … … 1078 1075 } else if (membershipTable.getSelectedRowCount() == 1) { 1079 1076 int row = membershipTable.getSelectedRow(); 1080 editMembership(row); 1081 } 1082 } 1083 1084 @Override 1085 protected void updateEnabledState() { 1086 setEnabled( 1087 (tagTable != null && tagTable.getSelectedRowCount() == 1) 1088 ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1) 1089 ); 1077 //System.out.println("tagTable: " + tagTable); 1078 //System.out.println("membershipTable: " + membershipTable); 1079 editHelper.editTag(row, false); 1080 //editMembership(row); 1081 } 1082 else{ 1083 editHelper.editTag(1, false); 1084 } 1085 } 1086 1087 @Override 1088 protected void updateEnabledState() { 1089 setEnabled(true); 1090 // setEnabled( 1091 // (tagTable != null && tagTable.getSelectedRowCount() == 1) 1092 // ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1) 1093 // ); 1090 1094 } 1091 1095
Note:
See TracChangeset
for help on using the changeset viewer.