LOG = logging.getLogger()
+
+def flatten_config_list(content, section=''):
+ """ Flatten YAML configuration lists that contain include sections
+ which are lists themselves.
+ """
+ if not content:
+ return []
+
+ if not isinstance(content, list):
+ raise UsageError(f"List expected in section '{section}'.")
+
+ output = []
+ for ele in content:
+ if isinstance(ele, list):
+ output.extend(flatten_config_list(ele, section))
+ else:
+ output.append(ele)
+
+ return output
+
+
class Configuration:
""" Load and manage the project configuration.
from icu import Transliterator
+from nominatim.config import flatten_config_list
from nominatim.db.properties import set_property, get_property
from nominatim.errors import UsageError
from nominatim.tokenizer.icu_name_processor import ICUNameProcessor
DBCFG_IMPORT_ANALYSIS_RULES = "tokenizer_import_analysis_rules"
-def _flatten_config_list(content):
- if not content:
- return []
-
- if not isinstance(content, list):
- raise UsageError("List expected in ICU configuration.")
-
- output = []
- for ele in content:
- if isinstance(ele, list):
- output.extend(_flatten_config_list(ele))
- else:
- output.append(ele)
-
- return output
-
-
class VariantRule:
""" Saves a single variant expansion.
if content is None:
return ''
- return ';'.join(_flatten_config_list(content)) + ';'
+ return ';'.join(flatten_config_list(content, section)) + ';'
def _parse_variant_list(self):
if not rules:
return
- rules = _flatten_config_list(rules)
+ rules = flatten_config_list(rules, 'variants')
vmaker = _VariantMaker(self.normalization_rules)