From 799a4c9ab63996d2ef3977baf774316c03fc9fde Mon Sep 17 00:00:00 2001 From: AntoJvlt Date: Mon, 17 May 2021 23:00:22 +0200 Subject: [PATCH 1/1] Documentation update and small code fixes --- docs/admin/Customization.md | 30 +++++++++++ docs/admin/Import.md | 52 +------------------ .../tools/special_phrases/sp_importer.py | 4 +- .../tools/special_phrases/sp_wiki_loader.py | 4 +- 4 files changed, 35 insertions(+), 55 deletions(-) diff --git a/docs/admin/Customization.md b/docs/admin/Customization.md index 76f0f85a..646465af 100644 --- a/docs/admin/Customization.md +++ b/docs/admin/Customization.md @@ -69,3 +69,33 @@ entire US adds about 10GB to your database. See the [developer's guide](../develop/data-sources.md#us-census-tiger) for more information on how the data got preprocessed. +## Special phrases import + +As described in the [Importation chapter](Import.md), it is possible to +import special phrases from the wiki with the following command: + +```sh +nominatim special-phrases --import-from-wiki +``` + +But, it is also possible to import some phrases from a csv file. +To do so, you have access to the following command: + +```sh +nominatim special-phrases --import-from-csv +``` + +Note that the 2 previous import commands will update the phrases from your database. +This means that if you import some phrases from a csv file, only the phrases +present in the csv file will be kept into the database. All other phrases will +be removed. + +If you want to only add new phrases and not update the other ones you can add +the argument `--no-replace` to the import command. For example: + +```sh +nominatim special-phrases --import-from-csv --no-replace +``` + +This will add the phrases present in the csv file into the database without +removing the other ones. diff --git a/docs/admin/Import.md b/docs/admin/Import.md index 264b46f4..3701df92 100644 --- a/docs/admin/Import.md +++ b/docs/admin/Import.md @@ -284,53 +284,5 @@ nominatim special-phrases --import-from-wiki Note that this command downloads the phrases from the wiki link above. You need internet access for the step. -You can also import some phrases from a csv file. -To do so, you have access to the following command: - -```sh -nominatim special-phrases --import-from-csv -``` - -Note that the 2 previous commands will update the phrases from your database. -This mean that if you import some phrases from a csv file, only the phrases -present in the csv file will be kept into the database. All other phrases will -be removed. - -If you want to only add new phrases and not update the other ones you can add -the argument `--no-replace` to the import command. For example: - -```sh -nominatim special-phrases --import-from-csv --no-replace -``` - -This will add the phrases present in the csv file into the database without -removing the other ones. - -## Installing Tiger housenumber data for the US - -Nominatim is able to use the official [TIGER](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html) -address set to complement the OSM house number data in the US. You can add -TIGER data to your own Nominatim instance by following these steps. The -entire US adds about 10GB to your database. - - 1. Get preprocessed TIGER 2020 data: - - cd $PROJECT_DIR - wget https://nominatim.org/data/tiger2020-nominatim-preprocessed.tar.gz - - 2. Import the data into your Nominatim database: - - nominatim add-data --tiger-data tiger2020-nominatim-preprocessed.tar.gz - - 3. Enable use of the Tiger data in your `.env` by adding: - - echo NOMINATIM_USE_US_TIGER_DATA=yes >> .env - - 4. Apply the new settings: - - nominatim refresh --functions - - -See the [developer's guide](../develop/data-sources.md#us-census-tiger) for more -information on how the data got preprocessed. - +You can also import special phrases from a csv file, for more +information please read the [Customization chapter](Customization.md). diff --git a/nominatim/tools/special_phrases/sp_importer.py b/nominatim/tools/special_phrases/sp_importer.py index ef4e85bd..48764518 100644 --- a/nominatim/tools/special_phrases/sp_importer.py +++ b/nominatim/tools/special_phrases/sp_importer.py @@ -61,7 +61,7 @@ class SPImporter(): for phrase in loaded_phrases: result = self._process_phrase(phrase) if result: - class_type_pairs.update(result) + class_type_pairs.add(result) self._create_place_classtype_table_and_indexes(class_type_pairs) if should_replace: @@ -143,7 +143,7 @@ class SPImporter(): self.word_phrases.add((phrase.p_label, phrase.p_class, phrase.p_type, phrase.p_operator)) - return set({(phrase.p_class, phrase.p_type)}) + return (phrase.p_class, phrase.p_type) def _create_place_classtype_table_and_indexes(self, class_type_pairs): diff --git a/nominatim/tools/special_phrases/sp_wiki_loader.py b/nominatim/tools/special_phrases/sp_wiki_loader.py index e9cbfdb2..914e1539 100644 --- a/nominatim/tools/special_phrases/sp_wiki_loader.py +++ b/nominatim/tools/special_phrases/sp_wiki_loader.py @@ -13,15 +13,13 @@ class SPWikiLoader(Iterator): Handles loading of special phrases from the wiki. """ def __init__(self, config, languages=None): - if languages is not None and not isinstance(languages, list): - raise TypeError('The \'languages\' parameter should be of type list.') super().__init__() self.config = config #Compile the regex here to increase performances. self.occurence_pattern = re.compile( r'\| *([^\|]+) *\|\| *([^\|]+) *\|\| *([^\|]+) *\|\| *([^\|]+) *\|\| *([\-YN])' ) - self.languages = self._load_languages() if not languages else languages + self.languages = self._load_languages() if not languages else list(languages) def __next__(self): if not self.languages: -- 2.45.1