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

Localize all or nothing #129

Merged
merged 41 commits into from
Oct 27, 2022
Merged

Localize all or nothing #129

merged 41 commits into from
Oct 27, 2022

Conversation

lily-chai
Copy link
Contributor

This PR cleans up the function localize. This function now only returns either

  • features with all language, worldview, class properties localized; or
  • features with none of the language, worldview, class properties localized.

See README.md for more detail.

@lily-chai lily-chai marked this pull request as ready for review October 25, 2022 21:16
@lily-chai lily-chai requested a review from a team October 25, 2022 21:16
Copy link
Contributor

@johnk1 johnk1 left a comment

Choose a reason for hiding this comment

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

Haven't gotten too far yet, but wanted to send what I have before a meeting

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/module_utils.hpp Outdated Show resolved Hide resolved
// no-op on any property called "worldview" if worldviews have been
// created dynamically from _mbx_wordlview
if (!worldview.empty() && property.first == "worldview")
if (property.first == worldview_key) // safeguard – should always evaluate to false
Copy link
Contributor

@johnk1 johnk1 Oct 26, 2022

Choose a reason for hiding this comment

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

why should this always be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in the current implementation, when we encounter {worldview_property} or {worldview_prefix}{worldview_property} while looping through the properties, we only store the worldviews to create in the worldviews_to_create variable but not add them to the final_properties vector. After we're done looping through the properties, we decide how many clones of the feature to build (for now we are limiting to 1) and what each clone should have as its {worldview_property} .

This safeguard is to prevent future code change that might accidentally/unintentionally add worldview to final_properties, and also to make clear for humans that worldview_key of the property always come from worldview_val.

src/vtcomposite.cpp Outdated Show resolved Hide resolved
while (auto property = feature.next_property())
{
// if already know we'll be skipping this feature, don't need to comb through its properties
if (skip_feature)
Copy link
Contributor

Choose a reason for hiding this comment

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

could this added to the while? while (property = next_property && !skip_feature)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no, that turns property into bool type.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear I meant something like
while (!skip_feature && auto feature = layer.next_feature())
rather than have the skip_feature check on L739.
It's not a very important detail but would be a little more readable IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The while loop while (auto feature = layer.next_feature()) is for looping through the features one by one; we don't know whether we can skip a feature or not before we look at its properties, so skip_feature is always false when we evaluate this while condition. The skip_feature flag changes to true when we encounter a property that suggests we can discard this feature, and the flag resets to false when we are done with one feature and moves on to the next feature. I'll add a comment to clarify this.

while (!skip_feature && auto property = feature.next_property()) results in this error:

../src/vtcomposite.cpp:736:45: error: expected expression
                    while (!skip_feature && auto property = feature.next_property())
                                            ^
../src/vtcomposite.cpp:744:52: error: use of undeclared identifier 'property'
                        std::string property_key = property.key().to_string();
                                                   ^

and while (auto property = feature.next_property() && !skip_feature) results in this error:

../src/vtcomposite.cpp:744:60: error: member reference base type 'bool' is not a structure or union
                        std::string property_key = property.key().to_string();
                                                   ~~~~~~~~^~~~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more details to the comments re: skip_feature in 759e709.

src/vtcomposite.cpp Show resolved Hide resolved
src/vtcomposite.cpp Outdated Show resolved Hide resolved
src/vtcomposite.cpp Outdated Show resolved Hide resolved
src/vtcomposite.cpp Outdated Show resolved Hide resolved
src/vtcomposite.cpp Outdated Show resolved Hide resolved
src/vtcomposite.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@johnk1 johnk1 left a comment

Choose a reason for hiding this comment

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

This looks good to me! My only real request is to move to v2. Other things are less critical code style and so on.

Copy link
Contributor

@mapsam mapsam left a comment

Choose a reason for hiding this comment

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

@lily-chai initial read-through looks really great, nice to see some explicit variable names set to help dictate the flow of the feature/property parsing.

I left some questions just to ask for clarifications. But after reading through all of your tests I'm feeling quite confident in the changes here!

package.json Outdated Show resolved Hide resolved
language_key = baton_data_->language_property + "_" + baton_data_->language;
// {language_prefix}{language_property}_{language} -> drop
language_key_prefixed = baton_data_->language_prefix + language_key;
keep_every_worldview = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

why reset to true if the default is already true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for clarity – this way it's easier for the human brain to see the difference between the configuration localized tile (the if block) and the configuration for non-localized tile (the else block). If you're not against leaving this in, I'll add a comment to explain this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment in 3711e05.

src/vtcomposite.cpp Outdated Show resolved Hide resolved
test/vtcomposite-localize-class.test.js Show resolved Hide resolved
localize(params, (err, vtBuffer) => {
assert.ifError(err);
const tile = vtinfo(vtBuffer);
assert.deepEqual(tile.layers, {}, 'has no feature');
Copy link
Contributor

Choose a reason for hiding this comment

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

just to confirm, we're dropping this feature because we anticipate another feature with _mbx_worldview to exist with the value assigned as US ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

'name_fr': 'Allemagne', // choosing first encountered property in (name_fr, _mbx_name_fr)
name: 'Allemagne', // name_{language} takes precedence over _mbx_name_{language}
name_local: 'Germany',
_mbx_other: 'Alemania'
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we drop arbitrary _mbx* fields anymore?

Ask because I'd expect someone to add fields to their data expecting us to remove them as "internal-only" fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the params for language, worldview and class more consistent:

  • Before: we can specify a prefix for language, but not for class and worldview. It isn't clear why.
  • After: we can specify a prefix for language, worldview and class. The prefixes can be different.

But that makes dropping fields confusing: for example, do we drop fields that match any of the 3 prefixes? Why do we want to drop a field that is irrelevant to e.g. worldview only because it has the the same prefix as worldview?

If we want to drop arbitrary _mbx_* fields, I suggest having just one prefix param and call it something like params.hidden_prefix.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to drop arbitrary mbx* fields, I suggest having just one prefix param and call it something like params.hidden_prefix.

Irrespective of dropping all fields or not - I like this idea just to simplify the interface. I don't guess someone would set a different prefix for each kind of localizable field, yea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to one hidden_prefix and drops any property that starts with this prefix in 00b9398.

lily-chai and others added 3 commits October 27, 2022 05:12
Co-authored-by: Sam Matthews <sam@mapbox.com>
Co-authored-by: John Klancer <john.klancer@mapbox.com>
Copy link
Contributor

@johnk1 johnk1 left a comment

Choose a reason for hiding this comment

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

🎈 thanks for taking on this slightly head spinning work!

@lily-chai lily-chai merged commit d01d84d into main Oct 27, 2022
@lily-chai lily-chai deleted the localised-vs-nonlocalised branch October 27, 2022 18:03
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