Changeset 9023 in josm


Ignore:
Timestamp:
2015-11-19T00:33:55+01:00 (6 years ago)
Author:
Don-vip
Message:

see #12102 - cleanup TagChecker

  • code refactor/cleanup/simplification
  • clean list of ignored tags by removing tags that have been added to internal presets during past years
  • add unit test to detect these tags if we add new tags to internal presets that are currently being ignored
Location:
trunk
Files:
3 edited

Legend:

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

    r7449 r9023  
    7575;
    7676K:type=is_in
    77 K:bridge=viaduct
    78 K:bridge=aqueduct
    7977K:bridge=swing
    8078;
    8179; Highway Key/Value Pairs
    8280;
    83 K:highway=motorway_link
    84 K:highway=trunk_link
    85 K:highway=primary_link
    86 K:highway=secondary_link
    8781K:oneway=-1
    88 ;
    89 ; traffic_calming Tags
    90 ;
    91 K:traffic_calming=yes
    92 K:traffic_calming=bump
    93 K:traffic_calming=chicane
    94 K:traffic_calming=cushion
    95 K:traffic_calming=hump
    96 K:traffic_calming=rumble_strip
    97 K:traffic_calming=table
    98 K:traffic_calming=choker
    99 ;
    100 ; Aeroway Key/Value Pairs
    101 ;
    102 K:aeroway=apron
    103 K:aeroway=hanger
    104 K:aeroway=helipad
    105 K:aeroway=runway
    106 K:aeroway=taxiway
    107 K:aeroway=terminal
    108 K:aeroway=aerodrome
    10982;
    11083; Amenity Key/Value Pairs
    11184;
    112 K:amenity=arts_centre
    113 K:amenity=atm
    114 K:amenity=baby_hatch
    115 K:amenity=bank
    116 K:amenity=bbq
    117 K:amenity=bench
    118 K:amenity=biergarten
    119 K:amenity=bicycle_parking
    120 K:amenity=bicycle_rental
    121 K:amenity=bureau_de_change
    122 K:amenity=bus_station
    123 K:amenity=brothel
    124 K:amenity=cafe
    125 K:amenity=car_rental
    126 K:amenity=car_sharing
    127 K:amenity=cinema
    128 K:amenity=college
    129 K:amenity=courthouse
    13085K:amenity=crematorium
    131 K:amenity=dentist
    132 K:amenity=doctors
    133 K:amenity=drinking_water
    134 K:amenity=embassy
    13586K:amenity=emergency_phone
    136 K:amenity=fast_food
    137 K:amenity=ferry_terminal
    138 K:amenity=fire_station
    139 K:amenity=food_court
    140 K:amenity=fountain
    141 K:amenity=fuel
    14287K:amenity=gallery
    143 K:amenity=grave_yard
    144 K:amenity=grit_bin
    14588K:amenity=gym
    146 K:amenity=hospital
    147 K:amenity=hunting_stand
    148 K:amenity=kindergarten
    149 K:amenity=library
    150 K:amenity=marketplace
    151 K:amenity=nightclub
    152 K:amenity=parking
    153 K:amenity=pharmacy
    154 K:amenity=place_of_worship
    155 K:amenity=police
    156 K:amenity=post_box
    157 K:amenity=post_office
    158 K:amenity=prison
    159 K:amenity=pub
    160 K:amenity=public_building
    161 K:amenity=recycling
    162 K:amenity=restaurant
    163 K:amenity=school
    164 K:amenity=shelter
    16589K:amenity=signpost
    166 K:amenity=studio
    167 K:amenity=taxi
    168 K:amenity=telephone
    169 K:amenity=theatre
    170 K:amenity=toilets
    171 K:amenity=townhall
    172 K:amenity=university
    173 K:amenity=vending_machine
    174 K:amenity=veterinary
    175 K:amenity=waste_basket
    176 K:amenity=waste_disposal
    17790;
    17891; Cuisine Tags
    17992;
    18093K:cuisine=coffee_shop
    181 K:cuisine=fish_and_chips
    18294K:cuisine=pie
    183 ;
    184 ; Cycleway Tags
    185 ;
    186 K:cycleway=lane
    187 K:cycleway=track
    188 K:cycleway=opposite_lane
    189 K:cycleway=opposite
    190 K:cycleway=opposite_track
    19195;
    19296; Historic Tags
    19397;
    194 K:historic=castle
    195 K:historic=monument
    196 K:historic=memorial
    197 K:historic=archaeological_site
    198 K:historic=ruins
    199 K:historic=battlefield
    20098K:historic=wreck
    20199K:historic=yes
     
    212110; Natural Tags
    213111;
    214 K:natural=bay
    215 K:natural=beach
    216 K:natural=cave_entrance
    217 K:natural=cliff
    218 K:natural=fell
    219 K:natural=glacier
    220 K:natural=heath
    221112K:natural=marsh
    222 K:natural=mud
    223 K:natural=peak
    224 K:natural=scree
    225 K:natural=scrub
    226 K:natural=spring
    227 K:natural=tree
    228 K:natural=volcano
    229 K:natural=wetland
    230 ;
    231 ; Surface Key/Value Pairs
    232 ;
    233 K:surface=dirt
    234 K:surface=wood
    235113;
    236114; Relation Tags
     
    241119; Christian Denominations
    242120;
    243 K:denomination=anglican
    244121K:denomination=apostolic
    245 K:denomination=baptist
    246 K:denomination=catholic
    247122K:denomination=christian_community
    248123K:denomination=christian_scientist
     
    250125K:denomination=czechoslovak_hussite
    251126K:denomination=dutch_reformed
    252 K:denomination=evangelical
    253127K:denomination=foursquare
    254 K:denomination=greek_orthodox
    255 K:denomination=jehovahs_witness
    256128K:denomination=kabbalah
    257129K:denomination=karaite
    258130K:denomination=living_waters_church
    259 K:denomination=lutheran
    260131K:denomination=maronite
    261132K:denomination=mennonite
    262 K:denomination=methodist
    263 K:denomination=mormon
    264 K:denomination=new_apostolic
    265133K:denomination=nondenominational
    266 K:denomination=old_catholic
    267 K:denomination=orthodox
    268 K:denomination=pentecostal
    269 K:denomination=presbyterian
    270 K:denomination=protestant
    271 K:denomination=quaker
    272 K:denomination=roman_catholic
    273 K:denomination=russian_orthodox
    274134K:denomination=salvation_army
    275135K:denomination=serbian_orthodox
    276 K:denomination=seventh_day_adventist
    277136K:denomination=united
    278137K:denomination=united_reformed
     
    283142K:denomination=alternative
    284143K:denomination=ashkenazi
    285 K:denomination=conservative
    286144K:denomination=hasidic
    287145K:denomination=humanistic
     
    290148K:denomination=neo_orthodox
    291149K:denomination=nondenominational
    292 K:denomination=orthodox
    293150K:denomination=progressive
    294151K:denomination=reconstructionist
    295 K:denomination=reform
    296152K:denomination=renewal
    297153K:denomination=samaritan
     
    302158K:denomination=alaouite
    303159K:denomination=druze
    304 K:denomination=ibadi
    305160K:denomination=ismaili
    306161K:denomination=nondenominational
    307 K:denomination=shia
    308 K:denomination=sunni
    309162;
    310163; Pastafarian Denominations
     
    318171; Shop Key/Value Pairs
    319172;
    320 K:shop=alcohol
    321 K:shop=bakery
    322 K:shop=beverages
    323 K:shop=bicycle
    324 K:shop=books
    325 K:shop=butcher
    326 K:shop=car
    327 K:shop=car_repair
    328 K:shop=chemist
    329 K:shop=clothes
    330 K:shop=computer
    331 K:shop=confectionery
    332 K:shop=convenience
    333 K:shop=department_store
    334 K:shop=dry_cleaning
    335 K:shop=doityourself
    336 K:shop=electronics
    337 K:shop=florist
    338 K:shop=furniture
    339 K:shop=garden_centre
    340 K:shop=greengrocer
    341 K:shop=hairdresser
    342 K:shop=hardware
    343 K:shop=hifi
    344 K:shop=kiosk
    345 K:shop=laundry
    346 K:shop=mall
    347 K:shop=motorcycle
    348 K:shop=optician
    349173K:shop=organic
    350 K:shop=outdoor
    351 K:shop=sports
    352 K:shop=stationery
    353 K:shop=supermarket
    354 K:shop=shoes
    355 K:shop=toys
    356 K:shop=travel_agency
    357 K:shop=video
    358174;
    359175; Sports Tags
     
    364180; Tourism Tags
    365181;
    366 K:tourism=alpine_hut
    367 K:tourism=attraction
    368 K:tourism=artwork
    369 K:tourism=camp_site
    370 K:tourism=caravan_site
    371 K:tourism=chalet
    372 K:tourism=guest_house
    373 K:tourism=hostel
    374 K:tourism=hotel
    375 K:tourism=information
    376 K:tourism=motel
    377 K:tourism=museum
    378 K:tourism=picnic_site
    379 K:tourism=theme_park
    380 K:tourism=viewpoint
    381 K:tourism=zoo
    382182K:tourism=yes
    383183;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r8969 r9023  
    8080    private static final List<String> ignoreDataEquals = new ArrayList<>();
    8181    private static final List<String> ignoreDataEndsWith = new ArrayList<>();
    82     private static final List<IgnoreKeyPair> ignoreDataKeyPair = new ArrayList<>();
     82    private static final List<Tag> ignoreDataTag = new ArrayList<>();
    8383
    8484    /** The preferences prefix */
     
    159159        ignoreDataEquals.clear();
    160160        ignoreDataEndsWith.clear();
    161         ignoreDataKeyPair.clear();
     161        ignoreDataTag.clear();
    162162        harmonizedKeys.clear();
    163163
     
    207207                            break;
    208208                        case "K:":
    209                             IgnoreKeyPair tmp = new IgnoreKeyPair();
    210                             int mid = line.indexOf('=');
    211                             tmp.key = line.substring(0, mid);
    212                             tmp.value = line.substring(mid+1);
    213                             ignoreDataKeyPair.add(tmp);
     209                            ignoreDataTag.add(Tag.ofString(line));
    214210                        }
    215211                    } else if (tagcheckerfile) {
     
    309305
    310306    /**
     307     * Determines if the given key is in internal presets.
     308     * @param key key
     309     * @return {@code true} if the given key is in internal presets
     310     * @since 9023
     311     */
     312    public static boolean isKeyInPresets(String key) {
     313        return presetsValueData.get(key) != null;
     314    }
     315
     316    /**
     317     * Determines if the given tag is in internal presets.
     318     * @param key key
     319     * @param value value
     320     * @return {@code true} if the given tag is in internal presets
     321     * @since 9023
     322     */
     323    public static boolean isTagInPresets(String key, String value) {
     324        final Set<String> values = presetsValueData.get(key);
     325        return values != null && (values.isEmpty() || values.contains(value));
     326    }
     327
     328    /**
     329     * Returns the list of ignored tags.
     330     * @return the list of ignored tags
     331     * @since 9023
     332     */
     333    public static List<Tag> getIgnoredTags() {
     334        return new ArrayList<>(ignoreDataTag);
     335    }
     336
     337    /**
     338     * Determines if the given tag is ignored for checks "key/tag not in presets".
     339     * @param key key
     340     * @param value value
     341     * @return {@code true} if the given tag is ignored
     342     * @since 9023
     343     */
     344    public static boolean isTagIgnored(String key, String value) {
     345        boolean tagInPresets = isTagInPresets(key, value);
     346        boolean ignore = false;
     347
     348        for (String a : ignoreDataStartsWith) {
     349            if (key.startsWith(a)) {
     350                ignore = true;
     351            }
     352        }
     353        for (String a : ignoreDataEquals) {
     354            if (key.equals(a)) {
     355                ignore = true;
     356            }
     357        }
     358        for (String a : ignoreDataEndsWith) {
     359            if (key.endsWith(a)) {
     360                ignore = true;
     361            }
     362        }
     363
     364        if (!tagInPresets) {
     365            for (Tag a : ignoreDataTag) {
     366                if (key.equals(a.getKey()) && value.equals(a.getValue())) {
     367                    ignore = true;
     368                }
     369            }
     370        }
     371        return ignore;
     372    }
     373
     374    /**
    311375     * Checks the primitive tags
    312376     * @param p The primitive to check
     
    373437            }
    374438            if (checkValues && key != null && value != null && !value.isEmpty() && presetsValueData != null) {
    375                 final Set<String> values = presetsValueData.get(key);
    376                 final boolean keyInPresets = values != null;
    377                 final boolean tagInPresets = values != null && (values.isEmpty() || values.contains(prop.getValue()));
    378 
    379                 boolean ignore = false;
    380                 for (String a : ignoreDataStartsWith) {
    381                     if (key.startsWith(a)) {
    382                         ignore = true;
    383                     }
    384                 }
    385                 for (String a : ignoreDataEquals) {
    386                     if (key.equals(a)) {
    387                         ignore = true;
    388                     }
    389                 }
    390                 for (String a : ignoreDataEndsWith) {
    391                     if (key.endsWith(a)) {
    392                         ignore = true;
    393                     }
    394                 }
    395 
    396                 if (!tagInPresets) {
    397                     for (IgnoreKeyPair a : ignoreDataKeyPair) {
    398                         if (key.equals(a.key) && value.equals(a.value)) {
    399                             ignore = true;
    400                         }
    401                     }
    402                 }
    403 
    404                 if (!ignore) {
    405                     if (!keyInPresets) {
     439                if (!isTagIgnored(key, value)) {
     440                    if (!isKeyInPresets(key)) {
    406441                        String prettifiedKey = harmonizeKey(key);
    407442                        String fixedKey = harmonizedKeys.get(prettifiedKey);
     
    420455                            withErrors.put(p, "UPK");
    421456                        }
    422                     } else if (!tagInPresets) {
     457                    } else if (!isTagInPresets(key, value)) {
    423458                        // try to fix common typos and check again if value is still unknown
    424459                        String fixedValue = harmonizeValue(prop.getValue());
    425                         Map<String, String> possibleValues = getPossibleValues(values);
     460                        Map<String, String> possibleValues = getPossibleValues(presetsValueData.get(key));
    426461                        if (possibleValues.containsKey(fixedValue)) {
    427462                            fixedValue = possibleValues.get(fixedValue);
     
    642677
    643678        return false;
    644     }
    645 
    646     protected static class IgnoreKeyPair {
    647         public String key;
    648         public String value;
    649679    }
    650680
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    r8863 r9023  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
    56
    67import java.io.IOException;
     8import java.util.ArrayList;
    79import java.util.List;
    810
     
    1214import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1315import org.openstreetmap.josm.data.osm.OsmUtils;
     16import org.openstreetmap.josm.data.osm.Tag;
    1417import org.openstreetmap.josm.data.validation.TestError;
    1518import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
     
    6871        assertEquals("Value 'forrest' for key 'landuse' not in presets.", errors.get(0).getDescription());
    6972    }
     73
     74    /**
     75     * Checks that tags specifically ignored are effectively not in internal presets.
     76     * @throws IOException if any I/O error occurs
     77     */
     78    @Test
     79    public void testIgnoredTagsNotInPresets() throws IOException {
     80        List<String> errors = new ArrayList<>();
     81        new TagChecker().initialize();
     82        for (Tag tag : TagChecker.getIgnoredTags()) {
     83            if (TagChecker.isTagInPresets(tag.getKey(), tag.getValue())) {
     84                errors.add(tag.toString());
     85            }
     86        }
     87        assertTrue(errors.toString(), errors.isEmpty());
     88    }
    7089}
Note: See TracChangeset for help on using the changeset viewer.