Changeset 14490 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-12-02T16:04:34+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r13923 r14490 12 12 import java.util.Arrays; 13 13 import java.util.Collection; 14 import java.util.Collections; 14 15 import java.util.HashMap; 15 16 import java.util.List; … … 257 258 okValue = line.substring(1); 258 259 } else if (line.charAt(0) == '-' && okValue != null) { 259 harmonizedKeys.put(harmonizeKey(line.substring(1)), okValue); 260 String hk = harmonizeKey(line.substring(1)); 261 if (!okValue.equals(hk)) { 262 if (harmonizedKeys.put(hk, okValue) != null) { 263 Logging.debug(tr("Line was ignored: {0}", line)); 264 } 265 } 260 266 } else { 261 267 Logging.error(tr("Invalid spellcheck line: {0}", line)); … … 313 319 314 320 private static void addPresetValue(KeyedItem ky) { 315 Collection<String> values = ky.getValues(); 316 if (ky.key != null && values != null) { 317 harmonizedKeys.put(harmonizeKey(ky.key), ky.key); 321 if (ky.key != null && ky.getValues() != null) { 322 String hk = harmonizeKey(ky.key); 323 if (!ky.key.equals(hk)) { 324 harmonizedKeys.put(hk, ky.key); 325 } 318 326 } 319 327 } … … 415 423 @Override 416 424 public void check(OsmPrimitive p) { 425 if (!p.isTagged()) 426 return; 427 417 428 // Just a collection to know if a primitive has been already marked with error 418 429 MultiMap<OsmPrimitive, String> withErrors = new MultiMap<>(); … … 502 513 if (!isKeyInPresets(key)) { 503 514 String prettifiedKey = harmonizeKey(key); 504 String fixedKey = harmonizedKeys.get(prettifiedKey);515 String fixedKey = isKeyInPresets(prettifiedKey) ? prettifiedKey : harmonizedKeys.get(prettifiedKey); 505 516 if (fixedKey != null && !"".equals(fixedKey) && !fixedKey.equals(key)) { 506 517 // misspelled preset key … … 525 536 String fixedValue = harmonizeValue(prop.getValue()); 526 537 Map<String, String> possibleValues = getPossibleValues(getPresetValues(key)); 538 List<String> fixVals = new ArrayList<>(); 539 if (!possibleValues.containsKey(fixedValue)) { 540 int minDist = 2; 541 String closest = null; 542 for (String possibleVal : possibleValues.keySet()) { 543 int dist = Utils.getLevenshteinDistance(possibleVal, fixedValue); 544 if (dist < minDist) { 545 closest = possibleVal; 546 minDist = dist; 547 fixVals.clear(); 548 fixVals.add(possibleVal); 549 } else if (dist == minDist) { 550 fixVals.add(possibleVal); 551 } 552 } 553 if (minDist <= 1) { 554 if (fixVals.size() < 2) { 555 fixedValue = closest; 556 } else { 557 Collections.sort(fixVals); 558 // misspelled preset value with multiple good alternatives 559 errors.add(TestError.builder(this, Severity.WARNING, MISSPELLED_VALUE) 560 .message(tr("Misspelled property value"), 561 marktr("Value ''{0}'' for key ''{1}'' looks like one of {2}."), prop.getValue(), key, fixVals) 562 .primitives(p) 563 .build()); 564 withErrors.put(p, "WPV"); 565 continue; 566 } 567 } 568 } 527 569 if (possibleValues.containsKey(fixedValue)) { 528 570 final String newValue = possibleValues.get(fixedValue); … … 596 638 } 597 639 598 checkComplex = Config.getPref().getBoolean(PREF_CHECK_COMPLEX, true) ;640 checkComplex = Config.getPref().getBoolean(PREF_CHECK_COMPLEX, true) && !checkerData.isEmpty(); 599 641 if (isBeforeUpload) { 600 642 checkComplex = checkComplex && Config.getPref().getBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, true);
Note:
See TracChangeset
for help on using the changeset viewer.