osm-search / Nominatim

Open Source search based on OpenStreetMap data
https://nominatim.org
GNU General Public License v3.0
2.98k stars 701 forks source link

Now output name tags are configurable #3451

Closed JagdishAneshwar closed 4 days ago

JagdishAneshwar commented 2 weeks ago

Summary:

This PR makes the hard-coded list of output name tags configurable, addressing issue #3416. It allows users to specify their preferred name tags and languages via a configuration mechanism, enhancing the flexibility of the Locales class.

Context and Motivation:

Previously, the Locales class used a hard-coded list of name tags for localization purposes. This was inflexible for users who needed to customize these tags to fit their specific needs. By making these tags configurable, we provide greater flexibility and adaptability for different use cases.

Implementation Details:

Key Changes:

Documentation:

Updated the class docstring for Locales to include information about the new configuration parameter. Added comments in the code to explain the changes and the purpose of the configurable tags.

Acknowledgements:

Thanks to the community for highlighting the need for this feature. Special thanks to reviewers for their valuable feedback.

Example Usage:

Here's an example of how to use the new configurable tags feature:

custom_tags = {
    'simple_tags': ['name', 'brand'],
    'lang_tags': ['official_name', 'short_name']
}

# Create a Locales instance with preferred languages and custom tags
locales = Locales(langs=['en', 'fr'], configurable_tags=custom_tags)

# Example dictionary of names with different variants
names = {
    'name:en': 'English Name',
    'name:fr': 'French Name',
    'name': 'Default Name',
    'brand': 'Brand Name',
    'official_name:en': 'Official English Name',
    'short_name:fr': 'Short French Name'
}

# Display the best matching name
print("Best matching name:", locales.display_name(names))
lonvia commented 2 weeks ago

The PR description does not match the code in this PR. Was one or the other generated by AI?

JagdishAneshwar commented 2 weeks ago

Yes, As this is my first GitHub Contribution and I didn't know what do people write in PR. So I used AI to write PR, but the code is written by me only.

JagdishAneshwar commented 2 weeks ago

Is there any issue in the code, because I tested it before sharing. If you can give me feedback on the code or about PR, it would be helpful.

lonvia commented 1 week ago

There is no problem with you using ChatGPT to help you here and there. However, there is a problem if you paste the output of ChatGPT into a pull request without rereading and fact-checking it. The PR text is an essential part of the PR. It is meant to give the maintainer an idea of the contents of the PR before reading the code and provide the context necessary to understand the changes. If you think the code is self-explanatory, then I still prefer a one-liner written by you to a 500-word boiler plate written by some AI.

Please replace the PR description with something self-authored, add tests to your new code and find out how to create the actual configuration variable NOMINATIM_OUTPUT_NAMES mentioned in the issue.