Skip to content
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

support semi-colon delimited names #589

Merged
merged 5 commits into from
Feb 24, 2025
Merged

support semi-colon delimited names #589

merged 5 commits into from
Feb 24, 2025

Conversation

missinglink
Copy link
Member

@missinglink missinglink commented Feb 24, 2025

replaces #581

note: commits need to be squashed and correctly prefixed (with feat:) before merging.

This PR adds support for semi-colon delimited names in OSM.
see: https://wiki.openstreetmap.org/wiki/Talk:Semi-colon_value_separator

Compared to #581 I added:

  • Cleaning parsed values (trimming whitespace and filtering empty strings, ie. '' or foo;;bar)
  • Support for semi-colon delimited names in lang fields (ie. name:en) as well as those in NAME_SCHEMA.
  • Moved parseSemicolonDelimitedValues() function to it's own module as it's used in the address_extractor too.
  • Removed this weird _primary key from NAME_SCHEMA which probably seemed like a good idea at the time but is unnecessarily confusing.
  • Updated the code which hunts for a default name when one wasn't available, also made this semi-colon aware.
  • Code modernisation & cleanup - variables were confusingly named, code was dated (using var instead of const etc.)

closes #581

@missinglink
Copy link
Member Author

missinglink commented Feb 24, 2025

There are some confusing aspects of this code, I probably wrote a bunch of this so I'm guilty, but revisiting it after so long I felt it wasn't super intuitive, I made some attempts to improve it.

Some things which are still a bit clunky are:

  • The way doc.setName() and doc.setNameAlias() work is kinda clunky, it requires the caller to know if that specific name property was previously set before selecting a method to use. It would be much easier if we could just call a single function and have pelias/model figure it out.
  • We loop over the OSM tags once to save CPU, this seems ok, however we are looking for the name key to set as a primary value (ie. first in the name values list), so there is a conditional IF inside the loop to handle that value differently.

@@ -38,14 +35,4 @@ var OSM_NAMING_SCHEMA = {
// 'sorting_name': 'sorting'
};

// this property is considered the 'primary name'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was kinda weird and overly fancy, I removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over the years we've learned many things you can do with Javascript, but shouldn't :P

@missinglink
Copy link
Member Author

cc/ @SiarheiFedartsou, @orangejulius

Copy link

@SiarheiFedartsou SiarheiFedartsou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

.map(v => v.trim())
.filter(v => v.length);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/util/parseSemicolonDelimitedValues.js b/util/parseSemicolonDelimitedValues.js
index 08e21ac..39c123b 100644
--- a/util/parseSemicolonDelimitedValues.js
+++ b/util/parseSemicolonDelimitedValues.js
@@ -5,8 +5,8 @@ const _ = require('lodash');
 function parseSemicolonDelimitedValues(value) {
   return (_.isString(value) ? value : '')
     .split(';')
-    .map(Function.prototype.call, String.prototype.trim)
-    .filter(Boolean);
+    .map(v => v.trim())
+    .filter(v => v.length);
 }

 module.exports = parseSemicolonDelimitedValues;
\ No newline at end of file

@missinglink missinglink merged commit 018797e into master Feb 24, 2025
6 checks passed
@missinglink missinglink deleted the name-aliases branch February 24, 2025 14:28
Copy link
Member

@orangejulius orangejulius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner after these changes. I had one idea for a further improvement but it's not mandatory at all.

@@ -38,14 +35,4 @@ var OSM_NAMING_SCHEMA = {
// 'sorting_name': 'sorting'
};

// this property is considered the 'primary name'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over the years we've learned many things you can do with Javascript, but shouldn't :P

Comment on lines +42 to +47
langValues.forEach(( langValue, i ) => {
if ( i === 0 ) {
doc.setName( langCode, langValue );
} else {
doc.setNameAlias( langCode, langValue );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice this is much cleaner.

...parseSemicolonDelimitedValues(_.get(tags, 'nat_name')),
...parseSemicolonDelimitedValues(_.get(tags, 'reg_name')),
...parseSemicolonDelimitedValues(doc.getName('en'))
].filter(Boolean);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More fanciness :P

So just to confirm, this is because you can't use || when assigning to const, yeah?

Might actually be a use case for let in that case, as it's much more clear what the intention is, plus each of these function calls has to always be evaluated, whereas chained || will have an early return as soon as there's a truthy value, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants