mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-10 12:04:06 +00:00
Added command line (default 0) min argument for minimum filtering, updated args.py to reflect this
This commit is contained in:
@@ -136,6 +136,7 @@ class NominatimArgs:
|
|||||||
import_from_wiki: bool
|
import_from_wiki: bool
|
||||||
import_from_csv: Optional[str]
|
import_from_csv: Optional[str]
|
||||||
no_replace: bool
|
no_replace: bool
|
||||||
|
min: int
|
||||||
|
|
||||||
# Arguments to all query functions
|
# Arguments to all query functions
|
||||||
format: str
|
format: str
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ class ImportSpecialPhrases:
|
|||||||
help='Import special phrases from a CSV file')
|
help='Import special phrases from a CSV file')
|
||||||
group.add_argument('--no-replace', action='store_true',
|
group.add_argument('--no-replace', action='store_true',
|
||||||
help='Keep the old phrases and only add the new ones')
|
help='Keep the old phrases and only add the new ones')
|
||||||
|
group.add_argument('--min', type=int, default=0,
|
||||||
|
help='Restrict special phrases by minimum occurance')
|
||||||
|
|
||||||
def run(self, args: NominatimArgs) -> int:
|
def run(self, args: NominatimArgs) -> int:
|
||||||
|
|
||||||
@@ -82,7 +84,9 @@ class ImportSpecialPhrases:
|
|||||||
|
|
||||||
tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
|
tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
|
||||||
should_replace = not args.no_replace
|
should_replace = not args.no_replace
|
||||||
|
min = args.min
|
||||||
|
|
||||||
with connect(args.config.get_libpq_dsn()) as db_connection:
|
with connect(args.config.get_libpq_dsn()) as db_connection:
|
||||||
SPImporter(
|
SPImporter(
|
||||||
args.config, db_connection, loader
|
args.config, db_connection, loader
|
||||||
).import_phrases(tokenizer, should_replace)
|
).import_phrases(tokenizer, should_replace, min)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class SPImporter():
|
|||||||
|
|
||||||
return db_combinations
|
return db_combinations
|
||||||
|
|
||||||
def import_phrases(self, tokenizer: AbstractTokenizer, should_replace: bool) -> None:
|
def import_phrases(self, tokenizer: AbstractTokenizer, should_replace: bool, min: int) -> None:
|
||||||
"""
|
"""
|
||||||
Iterate through all SpecialPhrases extracted from the
|
Iterate through all SpecialPhrases extracted from the
|
||||||
loader and import them into the database.
|
loader and import them into the database.
|
||||||
@@ -107,7 +107,7 @@ class SPImporter():
|
|||||||
if result:
|
if result:
|
||||||
class_type_pairs.add(result)
|
class_type_pairs.add(result)
|
||||||
|
|
||||||
self._create_classtype_table_and_indexes(class_type_pairs)
|
self._create_classtype_table_and_indexes(class_type_pairs, min)
|
||||||
if should_replace:
|
if should_replace:
|
||||||
self._remove_non_existent_tables_from_db()
|
self._remove_non_existent_tables_from_db()
|
||||||
|
|
||||||
@@ -186,7 +186,8 @@ class SPImporter():
|
|||||||
return (phrase.p_class, phrase.p_type)
|
return (phrase.p_class, phrase.p_type)
|
||||||
|
|
||||||
def _create_classtype_table_and_indexes(self,
|
def _create_classtype_table_and_indexes(self,
|
||||||
class_type_pairs: Iterable[Tuple[str, str]]) -> None:
|
class_type_pairs: Iterable[Tuple[str, str]],
|
||||||
|
min: int) -> None:
|
||||||
"""
|
"""
|
||||||
Create table place_classtype for each given pair.
|
Create table place_classtype for each given pair.
|
||||||
Also create indexes on place_id and centroid.
|
Also create indexes on place_id and centroid.
|
||||||
@@ -200,7 +201,7 @@ class SPImporter():
|
|||||||
with self.db_connection.cursor() as db_cursor:
|
with self.db_connection.cursor() as db_cursor:
|
||||||
db_cursor.execute("CREATE INDEX idx_placex_classtype ON placex (class, type)")
|
db_cursor.execute("CREATE INDEX idx_placex_classtype ON placex (class, type)")
|
||||||
|
|
||||||
allowed_special_phrases = self.get_classtype_pairs()
|
allowed_special_phrases = self.get_classtype_pairs(min)
|
||||||
|
|
||||||
for pair in class_type_pairs:
|
for pair in class_type_pairs:
|
||||||
phrase_class = pair[0]
|
phrase_class = pair[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user