Changeset 14897 in josm for trunk


Ignore:
Timestamp:
2019-03-18T09:10:55+01:00 (5 years ago)
Author:
GerdP
Message:

fix #17468: Validator produces wrong warning for misspelled tag key

TODO: further improve words.cfg

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/validator/ignoretags.cfg

    r14881 r14897  
    22; This is used for checks "key/tag not in presets"
    33; K:  the given tag will not produce a "tag not in presets" error, but it is
    4 ;     used as dictionary entry for spell checking the given key.
    5 ; E:  ignore tags with this key
    6 ; S:  ignore tag if key starts with this string
    7 ; F:  ignore tag if key ends with this string
     4;     used as dictionary entry for spell checking the given key and also
     5;     for the key/value combination.
     6; E:  ignore tags with this key and add the key to the spell check dictionary.
     7; S:  ignore tag if key starts with this string.
     8; F:  ignore tag if key ends with this string.
    89;
    910;
  • trunk/data/validator/words.cfg

    r14490 r14897  
    88# There must not be any white space before or after words, unless they are to be included in
    99# the bad spelling.
    10 # There is no need to add bad spelling with different upper/lower case.
     10# There is no need to add bad spelling with different upper/lower case for keys
     11#   which appear in the presets or the ignoreTags.cfg (prefixes E: and K:)
    1112# There is no need to add bad spelling with leading or trailing blanks.
    1213
     
    4041-maenity
    4142-emenity
     43+barrier
     44-barier
    4245+bicycle
    4346-bycycle
     
    5053+commercial
    5154-comercial
    52 +created_by
    53 -cretaed_by
    54 -crated_by
    55 -creared_by
    56 -creayed_by
    57 -{created_by
    58 -creeated_by
    59 -created_bu
    6055+denomination
    6156-denonimation
     
    161156-oeway
    162157-eway
    163 +osmarender:nameDirection
    164 -name_direction
    165 -osmarender:name_direction
    166158+railway
    167159-raillway
     
    178170-waterwy
    179171-wateway
    180 +unknown
    181 -unknwon
    182172#
    183173# Not sorted.
     
    208198-bulding
    209199-buildinq
    210 +city
    211 -citya
    212200+complete
    213201-complite
     
    221209-desription
    222210-decription
    223 +feature
    224 -featuer
    225211+freight
    226212-frieght
    227213+full_name:fa
    228214-full_name:Fa
    229 +highway_border
    230 -highway_boarder
    231 -highway_boreder
    232215+int_name
    233216-iint_name
     
    290273+old_name
    291274-oldname
    292 +osmarender:renderName
    293 -osmarender:rendername
    294 -soamrender:renderName
    295 +osmarender:renderRef
    296 -osmrender:renderRef
    297275+postal_code
    298276-posatl_code
     
    324302-tracltype
    325303-trackype
    326 +tramline
    327 -tram_line
    328304+tunnel
    329305-tunne
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r14869 r14897  
    297297            case "E:":
    298298                ignoreDataEquals.add(line);
     299                addToKeyDictionary(line);
    299300                break;
    300301            case "F:":
     
    305306                ignoreDataTag.add(tag);
    306307                oftenUsedTags.put(tag.getKey(), tag.getValue());
     308                addToKeyDictionary(tag.getKey());
    307309                break;
    308310            default:
     
    314316            Logging.error("Invalid line in {0} : {1}", source, e.getMessage());
    315317            Logging.trace(e);
     318        }
     319    }
     320
     321    private static void addToKeyDictionary(String key) {
     322        if (key != null) {
     323            String hk = harmonizeKey(key);
     324            if (!key.equals(hk)) {
     325                harmonizedKeys.put(hk, key);
     326            }
    316327        }
    317328    }
     
    356367    private static void addPresetValue(KeyedItem ky) {
    357368        if (ky.key != null && ky.getValues() != null) {
    358             String hk = harmonizeKey(ky.key);
    359             if (!ky.key.equals(hk)) {
    360                 harmonizedKeys.put(hk, ky.key);
    361             }
     369            addToKeyDictionary(ky.key);
    362370        }
    363371    }
     
    602610    private void spellCheckKey(MultiMap<OsmPrimitive, String> withErrors, OsmPrimitive p, String key) {
    603611        String prettifiedKey = harmonizeKey(key);
    604         String fixedKey = isKeyInPresets(prettifiedKey) ? prettifiedKey : harmonizedKeys.get(prettifiedKey);
     612        String fixedKey;
     613        if (ignoreDataEquals.contains(prettifiedKey)) {
     614            fixedKey = prettifiedKey;
     615        } else {
     616            fixedKey = isKeyInPresets(prettifiedKey) ? prettifiedKey : harmonizedKeys.get(prettifiedKey);
     617        }
     618        if (fixedKey == null) {
     619            for (Tag a : ignoreDataTag) {
     620                if (a.getKey().equals(prettifiedKey)) {
     621                    fixedKey = prettifiedKey;
     622                    break;
     623                }
     624            }
     625        }
     626
    605627        if (fixedKey != null && !"".equals(fixedKey) && !fixedKey.equals(key)) {
     628            final String proposedKey = fixedKey;
    606629            // misspelled preset key
    607630            final TestError.Builder error = TestError.builder(this, Severity.WARNING, MISSPELLED_KEY)
    608                     .message(tr("Misspelled property key"), marktr("Key ''{0}'' looks like ''{1}''."), key, fixedKey)
     631                    .message(tr("Misspelled property key"), marktr("Key ''{0}'' looks like ''{1}''."), key, proposedKey)
    609632                    .primitives(p);
    610633            if (p.hasKey(fixedKey)) {
    611634                errors.add(error.build());
    612635            } else {
    613                 errors.add(error.fix(() -> new ChangePropertyKeyCommand(p, key, fixedKey)).build());
     636                errors.add(error.fix(() -> new ChangePropertyKeyCommand(p, key, proposedKey)).build());
    614637            }
    615638            withErrors.put(p, "WPK");
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    r14732 r14897  
    8484
    8585    /**
     86     * Check for misspelled key where the suggested alternative is given with prefix E: in ignoreTags.cfg.
     87     * The error should be fixable.
     88     * @throws IOException if any I/O error occurs
     89     */
     90    @Test
     91    public void testUpperCaseIgnoredKey() throws IOException {
     92        // ticket 17468
     93        final List<TestError> errors = test(OsmUtils.createPrimitive("node wheelchair:Description=bla"));
     94        assertEquals(1, errors.size());
     95        assertEquals("Misspelled property key", errors.get(0).getMessage());
     96        assertEquals("Key 'wheelchair:Description' looks like 'wheelchair:description'.", errors.get(0).getDescription());
     97        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     98        assertTrue(errors.get(0).isFixable());
     99    }
     100
     101    /**
     102     * Check for misspelled key where the suggested alternative is given with prefix K: in ignoreTags.cfg.
     103     * The error should be fixable.
     104     * @throws IOException if any I/O error occurs
     105     */
     106    @Test
     107    public void testUpperCaseInKeyIgnoredTag() throws IOException {
     108        // ticket 17468
     109        final List<TestError> errors = test(OsmUtils.createPrimitive("node land_Area=administrative"));
     110        assertEquals(1, errors.size());
     111        assertEquals("Misspelled property key", errors.get(0).getMessage());
     112        assertEquals("Key 'land_Area' looks like 'land_area'.", errors.get(0).getDescription());
     113        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     114        assertTrue(errors.get(0).isFixable());
     115    }
     116
     117    /**
    86118     * Check for unknown key.
    87119     * @throws IOException if any I/O error occurs
Note: See TracChangeset for help on using the changeset viewer.