keep break indicators [:-] during normalisation

All punctuation will be converted to '-'. Soft breaks : may be
added by preprocessors. The break signs are only used during
query analysis and are ignored during import token analysis.
This commit is contained in:
Sarah Hoffmann
2025-01-07 21:32:32 +01:00
parent d984100e23
commit 86ad9efa8a
3 changed files with 8 additions and 5 deletions

View File

@@ -9,16 +9,17 @@ normalization:
- "'nº' > 'no'" - "'nº' > 'no'"
- "ª > a" - "ª > a"
- "º > o" - "º > o"
- "[[:Punctuation:][:Symbol:]\u02bc] > ' '" - "[[:Punctuation:][:Symbol:][\u02bc] - [-:]]+ > '-'"
- "ß > 'ss'" # German szet is unambiguously equal to double ss - "ß > 'ss'" # German szet is unambiguously equal to double ss
- "[^[:alnum:] [:Canonical_Combining_Class=Virama:] [:Space:]] >" - "[^[:alnum:] [:Canonical_Combining_Class=Virama:] [:Space:] [-:]] >"
- "[:Lm:] >" - "[:Lm:] >"
- ":: [[:Number:]] Latin ()" - ":: [[:Number:]] Latin ()"
- ":: [[:Number:]] Ascii ();" - ":: [[:Number:]] Ascii ();"
- ":: [[:Number:]] NFD ();" - ":: [[:Number:]] NFD ();"
- "[[:Nonspacing Mark:] [:Cf:]] >;" - "[[:Nonspacing Mark:] [:Cf:]] >;"
- "[:Space:]+ > ' '" - "[-:]?[:Space:]+[-:]? > ' '"
transliteration: transliteration:
- "[-:] > ' '"
- ":: Latin ()" - ":: Latin ()"
- !include icu-rules/extended-unicode-to-asccii.yaml - !include icu-rules/extended-unicode-to-asccii.yaml
- ":: Ascii ()" - ":: Ascii ()"

View File

@@ -133,7 +133,7 @@ class ForwardGeocoder:
""" """
assert self.query_analyzer is not None assert self.query_analyzer is not None
qwords = [word for phrase in query.source qwords = [word for phrase in query.source
for word in re.split('[, ]+', phrase.text) if word] for word in re.split('[-,: ]+', phrase.text) if word]
if not qwords: if not qwords:
return return
@@ -146,7 +146,7 @@ class ForwardGeocoder:
distance = 0.0 distance = 0.0
norm = self.query_analyzer.normalize_text(' '.join((result.display_name, norm = self.query_analyzer.normalize_text(' '.join((result.display_name,
result.country_code or ''))) result.country_code or '')))
words = set((w for w in norm.split(' ') if w)) words = set((w for w in re.split('[-,: ]+', norm) if w))
if not words: if not words:
continue continue
for qword in qwords: for qword in qwords:

View File

@@ -25,6 +25,8 @@ class ICUTokenAnalysis:
def __init__(self, norm_rules: str, trans_rules: str, def __init__(self, norm_rules: str, trans_rules: str,
analysis_rules: Mapping[Optional[str], 'TokenAnalyzerRule']): analysis_rules: Mapping[Optional[str], 'TokenAnalyzerRule']):
# additional break signs are not relevant during name analysis
norm_rules += ";[[:Space:][-:]]+ > ' ';"
self.normalizer = Transliterator.createFromRules("icu_normalization", self.normalizer = Transliterator.createFromRules("icu_normalization",
norm_rules) norm_rules)
trans_rules += ";[:Space:]+ > ' '" trans_rules += ";[:Space:]+ > ' '"