Repository navigation
Change/normalise values hyphens #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b1c985
1bc8ec1
cf4ed37
02585bb
2260c71
052089f
875d476
66586f6
d6d1875
7bc8503
f361438
930c046
ad62ea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,10 @@ | |
| from digital_land.datatype.point import PointDataType | ||
| from digital_land.datatype.factory import datatype_factory | ||
| import shapely.wkt | ||
| import re | ||
| import logging | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Storing mandatory fields in dict for now until added to specification | ||
|
|
@@ -202,7 +204,11 @@ def process(self, stream): | |
| if value: | ||
| harmonised_values = [] | ||
| for raw_value in self.category_values(value): | ||
| normalised_value = raw_value.replace(" ", "-") | ||
| normalised_value = re.sub( | ||
| r"(\b\s\-+\s\b)|(\b\s\b)", | ||
| "-", | ||
| raw_value.replace(r"\s", "-"), | ||
| ) | ||
|
Comment on lines
+207
to
+211
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| matching_value = next( | ||
| ( | ||
| v | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle repeated whitespace in categorical values.
The pattern accepts only one whitespace character on each side of a hyphen or between words. For example,
MAP - TO-VALID-VALUEis logged as an invalid category and is appended asraw_value.raw_value.replace(r"\s", "-")does not correct this becausestr.replacetreatsr"\s"as literal text. Use\s+or normalise whitespace before matching, and add this case to the regression test.Proposed fix
Committable suggestion