]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tokenizer/sanitizers/kanji_utils.py
Correction to PR's comment
[nominatim.git] / nominatim / tokenizer / sanitizers / kanji_utils.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 This is a file for a function that converts Kanji (Japanese) numerals to Arabic numerals.
9 """
10
11 def convert_kanji_sequence_to_number(sequence: str) -> str:
12     """Converts Kanji numbers to Arabic numbers
13     """
14     kanji_map = {
15       '零': '0',
16       '一': '1',
17       '二': '2',
18       '三': '3',
19       '四': '4',
20       '五': '5',
21       '六': '6',
22       '七': '7',
23       '八': '8',
24       '九': '9'
25     }
26     converted = ''
27     current_number = ''
28     for char in sequence:
29         if char in kanji_map:
30             current_number += kanji_map[char]
31         else:
32             converted += current_number
33             current_number = ''
34             converted += char
35     converted += current_number
36     return converted