This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I checked the database for Germany and wrote transformations for the most common tagging errors. The helper allows tags that can be transformed to conform the pattern. Everything else is removed.
- Loading branch information
Showing
8 changed files
with
170 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package.path = package.path .. ";/processing/topics/helper/?.lua" | ||
|
||
require("SanitizeTrafficSign") | ||
|
||
function DeriveTrafficSigns(tags) | ||
local results = { | ||
['traffic_sign'] = SanitizeTrafficSign(tags.traffic_sign) or SanitizeTrafficSign(tags['traffic_sign:both']), | ||
['traffic_sign:forward'] = SanitizeTrafficSign(tags['traffic_sign:forward']), | ||
['traffic_sign:backward'] = SanitizeTrafficSign(tags['traffic_sign:backward']) | ||
} | ||
return results | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Remove all whitespaces after delimeters | ||
local function stripWhitespaces(traffic_sign) | ||
local stripped = string.gsub(traffic_sign, ', ', ',') | ||
stripped = string.gsub(stripped, '; ', ';') | ||
return stripped | ||
end | ||
|
||
--- Cleanup the `traffic_sign=*` tag | ||
--- @param traffic_sign string | ||
--- @returns string | ||
function SanitizeTrafficSign(traffic_sign) | ||
if traffic_sign == nil then | ||
return nil | ||
end | ||
if traffic_sign == "no" or traffic_sign == 'none' then | ||
return "none" | ||
end | ||
|
||
-- Docs: patterns with "^" target beginning of string | ||
|
||
-- This is the correct tagging, all traffic signs should start with DE: | ||
if string.find(traffic_sign, '^DE:%S') then | ||
return stripWhitespaces(traffic_sign) | ||
end | ||
|
||
local substitutions = { | ||
['^DE: '] = 'DE:', | ||
['^DE.'] = 'DE:', | ||
['^D:'] = 'DE:', | ||
['^D%.'] = 'DE:', | ||
['^de:'] = 'DE:', | ||
['^DE1'] = 'DE:1', | ||
['^DE2'] = 'DE:2', | ||
['^2'] = 'DE:2', | ||
['^1'] = 'DE:1', | ||
-- These patterns could handle all the above in a more generalized way | ||
-- ['^DE?[:.]%s?'] = 'DE:', | ||
-- ['^de?[:.]%s?'] = 'DE:' | ||
-- ['^DE(%d)'] = 'DE:%1' | ||
-- ['^(%d)'] = 'DE:%1' | ||
} | ||
for pattern, substitude in pairs(substitutions) do | ||
local val, n = string.gsub(traffic_sign, pattern, substitude) | ||
if n > 0 then | ||
-- TODO: add to todo list | ||
return stripWhitespaces(val) | ||
end | ||
end | ||
|
||
-- Discard everything else | ||
return nil | ||
end |
73 changes: 73 additions & 0 deletions
73
processing/topics/helper/__tests__/SanitizeTrafficSign.test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require("osm2pgsql") | ||
|
||
describe("SanitizeTrafficSign", function() | ||
package.path = package.path .. ";/processing/topics/helper/?.lua" | ||
require("SanitizeTrafficSign") | ||
|
||
-- Cleanup | ||
it('renames `no` to `none`', function() | ||
assert.are.same(SanitizeTrafficSign("no"), "none") | ||
end) | ||
|
||
it('renames `DE:SPACE` to `DE:`', function() | ||
assert.are.same(SanitizeTrafficSign("DE: 123"), "DE:123") | ||
end) | ||
|
||
it('renames `DE234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE234"), "DE:234") | ||
end) | ||
|
||
it('renames `DE1010` to `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("DE1010"), "DE:1010") | ||
end) | ||
|
||
it('renames `D:234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("D:234"), "DE:234") | ||
end) | ||
|
||
it('renames `de:234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("de:234"), "DE:234") | ||
end) | ||
|
||
it('renames `234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("234"), "DE:234") | ||
end) | ||
|
||
it('renames `1010` to `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("1010"), "DE:1010") | ||
end) | ||
|
||
it('renames `DE.234` to `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE.234"), "DE:234") | ||
end) | ||
|
||
it('cleans spaces `DE:123, 1010; 234` to `DE:123,1010;234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:123, 1010; 234"), "DE:123,1010;234") | ||
end) | ||
|
||
-- Allow | ||
it('allows `DE:234`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:234"), "DE:234") | ||
end) | ||
|
||
it('allows `DE:1010`', function() | ||
assert.are.same(SanitizeTrafficSign("DE:1010"), "DE:1010") | ||
end) | ||
|
||
it('allows `none` as value', function() | ||
assert.are.same(SanitizeTrafficSign("none"), "none") | ||
end) | ||
|
||
-- Disallow | ||
it('handles nil', function() | ||
assert.are.same(SanitizeTrafficSign(nil), nil) | ||
end) | ||
it('disallows everything else', function() | ||
assert.are.same(SanitizeTrafficSign("foobar"), nil) | ||
assert.are.same(SanitizeTrafficSign("yes"), nil) | ||
assert.are.same(SanitizeTrafficSign("unkown"), nil) | ||
assert.are.same(SanitizeTrafficSign("AT:foobar"), nil) | ||
assert.are.same(SanitizeTrafficSign("pictogram"), nil) | ||
assert.are.same(SanitizeTrafficSign("(comment)"), nil) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters