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

feat-3416: configurable-output-name-tags #3486

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

DevilLord9967
Copy link

This PR makes the hard-coded list of output name tags configurable, addressing issue #3416. It allows users to specify their preferred output name tags via an environment setting NOMINATIM_OUTPUT_NAMES as suggested in the issue #3416.

Description

  • Moved previously hard-coded settings as a default behavior in case environment config is not provided to function _build_default_output_name_tags
  • Added new function _build_output_name_tags
    • Executes when environment config NOMINATIM_OUTPUT_NAMES is provided
    • Configuration input format: name:XX,name,brand,official_name:XX,short_name:XX,official_name,short_name,ref
      • Coma separated
      • :XX identifies lang tags
      • consecutive :XX identifies multiple lang tags to-be added at the same time
      • subsequent parts after lang tags (till next lang tag) identifies batch of tags

Related Issue

#3416

Motivation and Context

How Has This Been Tested?

  • Added pytest cases to test the implementation
  • test_default_output_name_tags tests the default setting (previously hardcoded) in case environment config is not provided
  • test_configurable_output_name_tags tests the output name tags when environment config is provided

Change will not affect other areas of code since previous behavior is preserved while enhancing the configurability if required

@DevilLord9967 DevilLord9967 marked this pull request as ready for review July 24, 2024 10:10
@lonvia
Copy link
Member

lonvia commented Jul 24, 2024

The issue didn't ask for an environment variable but for a configuration setting.

@DevilLord9967
Copy link
Author

DevilLord9967 commented Jul 25, 2024

I see that configuration setting is managed by dotenv as quoted in Configuring Nominatim

Nominatim uses dotenv to manage its configuration settings. There are two means to set configuration variables: through an .env configuration file or through an environment variable

This means that NOMINATIM_OUTPUT_NAMES setting will be loaded into the environment either directly or via .env fle using dotenv.

Please correct me if there is mistake.

@lonvia
Copy link
Member

lonvia commented Jul 26, 2024

https://nominatim.org/release-docs/latest/library/Configuration/ has some more details on the Configuration object, which holds the configuration options that have been loaded. You shouldn't query the configuration in the Locale class directly though. Just hand in an optional output like in #3451 and make sure the current configuration is handed in at the appropriate places.

@DevilLord9967
Copy link
Author

Now accessing the setting via configuration object which can be provided optionally. Please review.

@DevilLord9967
Copy link
Author

@lonvia please suggest if there are further changes required.

And let's discuss some more issues to which I can contribute. I am eager to dive deeper in to the core programming of python.

Copy link
Member

@lonvia lonvia left a comment

Choose a reason for hiding this comment

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

Your code so far has no effect when actually running Nominatim because you haven't changed anything in the code where Locale() is used. Please set up an installation of Nominatim, and test your changes on it. You should be able to observe the effects of changes to your new configuration variable with both, nominatim serve and nominatim search.

When adding a new configuration option, you also need to add a default in https://github.com/osm-search/Nominatim/blob/master/settings/env.defaults and documentation in https://github.com/osm-search/Nominatim/blob/master/docs/customize/Settings.md.

"""

def __init__(self, langs: Optional[List[str]] = None):
def __init__(self, langs: Optional[List[str]] = None, config: Optional[Configuration] = None):
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to avoid a dependency on Configuration. Please just hand in the content on the configuration option, i.e. a string.

Copy link
Author

Choose a reason for hiding this comment

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

I am puzzled on how to use the config directly to access the configuration, hence modified the args and accepting the config value directly

src/nominatim_api/localization.py Outdated Show resolved Hide resolved
src/nominatim_api/localization.py Outdated Show resolved Hide resolved
- Coma separated
- `:XX` identifies lang tags
- consecutive `:XX` identifies multiple lang tags to-be added at the same time
- subsequent parts after lang tags (till next lang tag) identifies batch of tags
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the formatting conventions.

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure about the mistake here, So I rewrote the class doc string in a format I found on official website

test/python/api/test_localization.py Outdated Show resolved Hide resolved
test/python/api/test_localization.py Outdated Show resolved Hide resolved
test/python/api/test_localization.py Outdated Show resolved Hide resolved
"""
nominatim_output_names = nominatim_output_names.split(",")
lang_tags = []
tags = []
Copy link
Member

Choose a reason for hiding this comment

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

This seems wrong. Order matters here. The name tag list must be in exactly the same order as the input list.

Copy link
Author

Choose a reason for hiding this comment

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

I need more context on this. These variables are initialized to build the tags in order as specified in the format, they work in batches.

consider default: name:XX,name,brand,official_name:XX,short_name:XX,official_name,short_name,ref

  1. for name:XX add "name" to lang_tags
  2. for name add "name" to tags, check if lang_tags has elements then call _add_lang_tags(*lang_tags) and initialize lang_tags = [] again.

In this way tags are processed in batches

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.

Make hard-coded list of output name tags configurable
2 participants