rigour 2.3.0__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. {rigour-2.3.0 → rigour-2.4.0}/PKG-INFO +1 -1
  2. {rigour-2.3.0 → rigour-2.4.0}/pyproject.toml +1 -1
  3. {rigour-2.3.0 → rigour-2.4.0}/rigour/_core.pyi +3 -0
  4. {rigour-2.3.0 → rigour-2.4.0}/rigour/addresses/__init__.py +40 -1
  5. rigour-2.4.0/rigour/addresses/compare.py +111 -0
  6. {rigour-2.3.0 → rigour-2.4.0}/rigour/addresses/normalize.py +24 -0
  7. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/addresses/data.py +216 -21
  8. rigour-2.4.0/rigour/langs/text.py +67 -0
  9. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/normalize.py +12 -2
  10. {rigour-2.3.0 → rigour-2.4.0}/rust/Cargo.lock +38 -17
  11. {rigour-2.3.0 → rigour-2.4.0}/rust/Cargo.toml +1 -1
  12. rigour-2.4.0/rust/data/addresses/forms.json +838 -0
  13. {rigour-2.3.0 → rigour-2.4.0}/rust/data/names/person_names.txt +14 -14
  14. rigour-2.4.0/rust/src/addresses/analyze.rs +280 -0
  15. rigour-2.4.0/rust/src/addresses/compare.rs +305 -0
  16. rigour-2.4.0/rust/src/addresses/fingerprint.rs +101 -0
  17. rigour-2.4.0/rust/src/addresses/mod.rs +9 -0
  18. rigour-2.4.0/rust/src/addresses/tagger.rs +263 -0
  19. rigour-2.4.0/rust/src/addresses/token.rs +115 -0
  20. {rigour-2.3.0 → rigour-2.4.0}/rust/src/constants.rs +1 -0
  21. {rigour-2.3.0 → rigour-2.4.0}/rust/src/lib.rs +30 -0
  22. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/mod.rs +0 -1
  23. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/org_types.rs +2 -2
  24. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/tagger.rs +3 -28
  25. {rigour-2.3.0 → rigour-2.4.0}/rust/src/territories.rs +38 -0
  26. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/mod.rs +1 -0
  27. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/normalize.rs +26 -2
  28. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/numbers.rs +39 -1
  29. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/tokenize.rs +159 -7
  30. rigour-2.3.0/rigour/langs/text.py +0 -42
  31. {rigour-2.3.0 → rigour-2.4.0}/LICENSE +0 -0
  32. {rigour-2.3.0 → rigour-2.4.0}/README.md +0 -0
  33. {rigour-2.3.0 → rigour-2.4.0}/rigour/__init__.py +0 -0
  34. {rigour-2.3.0 → rigour-2.4.0}/rigour/addresses/cleaning.py +0 -0
  35. {rigour-2.3.0 → rigour-2.4.0}/rigour/addresses/format.py +0 -0
  36. {rigour-2.3.0 → rigour-2.4.0}/rigour/boolean.py +0 -0
  37. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/__init__.py +0 -0
  38. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/addresses/__init__.py +0 -0
  39. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/addresses/formats.yml +0 -0
  40. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/langs/__init__.py +0 -0
  41. {rigour-2.3.0 → rigour-2.4.0}/rigour/data/langs/iso639.py +0 -0
  42. {rigour-2.3.0 → rigour-2.4.0}/rigour/dates.py +0 -0
  43. {rigour-2.3.0 → rigour-2.4.0}/rigour/env.py +0 -0
  44. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/__init__.py +0 -0
  45. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/common.py +0 -0
  46. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/imo.py +0 -0
  47. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/npi.py +0 -0
  48. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/ogrn.py +0 -0
  49. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/stdnum_.py +0 -0
  50. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/strict.py +0 -0
  51. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/uei.py +0 -0
  52. {rigour-2.3.0 → rigour-2.4.0}/rigour/ids/wikidata.py +0 -0
  53. {rigour-2.3.0 → rigour-2.4.0}/rigour/langs/__init__.py +0 -0
  54. {rigour-2.3.0 → rigour-2.4.0}/rigour/langs/synonyms.py +0 -0
  55. {rigour-2.3.0 → rigour-2.4.0}/rigour/langs/util.py +0 -0
  56. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/__init__.py +0 -0
  57. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/filename.py +0 -0
  58. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/mappings.py +0 -0
  59. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/mime.py +0 -0
  60. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/parse.py +0 -0
  61. {rigour-2.3.0 → rigour-2.4.0}/rigour/mime/types.py +0 -0
  62. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/__init__.py +0 -0
  63. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/analyze.py +0 -0
  64. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/check.py +0 -0
  65. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/compare.py +0 -0
  66. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/name.py +0 -0
  67. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/ordering.py +0 -0
  68. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/org_types.py +0 -0
  69. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/part.py +0 -0
  70. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/pick.py +0 -0
  71. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/prefix.py +0 -0
  72. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/split_phrases.py +0 -0
  73. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/symbol.py +0 -0
  74. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/tag.py +0 -0
  75. {rigour-2.3.0 → rigour-2.4.0}/rigour/names/tokenize.py +0 -0
  76. {rigour-2.3.0 → rigour-2.4.0}/rigour/py.typed +0 -0
  77. {rigour-2.3.0 → rigour-2.4.0}/rigour/reset.py +0 -0
  78. {rigour-2.3.0 → rigour-2.4.0}/rigour/territories/__init__.py +0 -0
  79. {rigour-2.3.0 → rigour-2.4.0}/rigour/territories/lookup.py +0 -0
  80. {rigour-2.3.0 → rigour-2.4.0}/rigour/territories/match.py +0 -0
  81. {rigour-2.3.0 → rigour-2.4.0}/rigour/territories/territory.py +0 -0
  82. {rigour-2.3.0 → rigour-2.4.0}/rigour/territories/util.py +0 -0
  83. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/__init__.py +0 -0
  84. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/checksum.py +0 -0
  85. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/cleaning.py +0 -0
  86. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/distance.py +0 -0
  87. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/phonetics.py +0 -0
  88. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/scripts.py +0 -0
  89. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/stopwords.py +0 -0
  90. {rigour-2.3.0 → rigour-2.4.0}/rigour/text/translit.py +0 -0
  91. {rigour-2.3.0 → rigour-2.4.0}/rigour/time.py +0 -0
  92. {rigour-2.3.0 → rigour-2.4.0}/rigour/units.py +0 -0
  93. {rigour-2.3.0 → rigour-2.4.0}/rigour/urls/__init__.py +0 -0
  94. {rigour-2.3.0 → rigour-2.4.0}/rigour/urls/cleaning.py +0 -0
  95. {rigour-2.3.0 → rigour-2.4.0}/rigour/urls/compare.py +0 -0
  96. {rigour-2.3.0 → rigour-2.4.0}/rigour/urls/util.py +0 -0
  97. {rigour-2.3.0 → rigour-2.4.0}/rigour/util.py +0 -0
  98. {rigour-2.3.0 → rigour-2.4.0}/rust/build.rs +0 -0
  99. {rigour-2.3.0 → rigour-2.4.0}/rust/data/names/compare.json +0 -0
  100. {rigour-2.3.0 → rigour-2.4.0}/rust/data/names/org_types.json +0 -0
  101. {rigour-2.3.0 → rigour-2.4.0}/rust/data/names/stopwords.json +0 -0
  102. {rigour-2.3.0 → rigour-2.4.0}/rust/data/names/symbols.json +0 -0
  103. {rigour-2.3.0 → rigour-2.4.0}/rust/data/territories/data.jsonl +0 -0
  104. {rigour-2.3.0 → rigour-2.4.0}/rust/data/text/ordinals.json +0 -0
  105. {rigour-2.3.0 → rigour-2.4.0}/rust/data/text/stopwords.json +0 -0
  106. {rigour-2.3.0 → rigour-2.4.0}/rust/src/generated/.gitkeep +0 -0
  107. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/alignment.rs +0 -0
  108. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/analyze.rs +0 -0
  109. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/compare.rs +0 -0
  110. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/constants.rs +0 -0
  111. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/name.rs +0 -0
  112. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/ordering.rs +0 -0
  113. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/pairing.rs +0 -0
  114. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/part.rs +0 -0
  115. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/person_names.rs +0 -0
  116. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/pick.rs +0 -0
  117. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/prefix.rs +0 -0
  118. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/stopwords.rs +0 -0
  119. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/symbol.rs +0 -0
  120. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/symbols.rs +0 -0
  121. {rigour-2.3.0 → rigour-2.4.0}/rust/src/names/tag.rs +0 -0
  122. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/distance.rs +0 -0
  123. {rigour-2.3.0/rust/src/names → rigour-2.4.0/rust/src/text}/matcher.rs +0 -0
  124. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/ordinals.rs +0 -0
  125. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/phonetics.rs +0 -0
  126. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/scripts.rs +0 -0
  127. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/stopwords.rs +0 -0
  128. {rigour-2.3.0 → rigour-2.4.0}/rust/src/text/translit.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rigour
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Classifier: Intended Audience :: Developers
5
5
  Classifier: Operating System :: OS Independent
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "rigour"
7
- version = "2.3.0"
7
+ version = "2.4.0"
8
8
  description = "Financial crime domain data validation and normalization library."
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -11,6 +11,9 @@ def raw_levenshtein(a: str, b: str) -> int: ...
11
11
  def raw_levenshtein_cutoff(a: str, b: str, cutoff: int) -> int: ...
12
12
  def raw_jaro(a: str, b: str) -> float: ...
13
13
  def raw_jaro_winkler(a: str, b: str) -> float: ...
14
+ def compare_address(query: str, result: str) -> float: ...
15
+ def compare_address_many(queries: list[str], results: list[str]) -> float: ...
16
+ def address_fingerprint(text: str) -> str | None: ...
14
17
  def pick_name(names: list[str]) -> str | None: ...
15
18
  def pick_case(names: list[str]) -> str | None: ...
16
19
  def reduce_names(names: list[str]) -> list[str]: ...
@@ -1,8 +1,39 @@
1
1
  """
2
2
  This module provides a set of tools for handling postal/geographic addresses. It includes functions
3
- for normalising addresses for comparison purposes, and for formatting addresses given in parts for
3
+ for comparing addresses, normalising them, and for formatting addresses given in parts for
4
4
  display as a single string.
5
5
 
6
+ ## Address comparison
7
+
8
+ Score whether two address strings (or two sets of them) denote the
9
+ same place:
10
+
11
+ ```python
12
+ from rigour.addresses import compare_address, compare_address_many
13
+
14
+ score = compare_address("Bahnhofstr. 10, Augsburg", "Bahnhofstrasse 10, 86150 Augsburg")
15
+ best = compare_address_many(
16
+ ["Bahnhofstr. 10, Augsburg"],
17
+ ["Bahnhofstrasse 10, 86150 Augsburg", "P.O. Box 71, Augsburg"],
18
+ )
19
+ ```
20
+
21
+ The comparison runs in native code over analyzed tokens — see
22
+ [compare_address][rigour.addresses.compare.compare_address] for the
23
+ mechanics and score semantics.
24
+
25
+ The same analysis backs a keying surface: use
26
+ [address_fingerprint][rigour.addresses.compare.address_fingerprint]
27
+ to reduce equivalent renderings of an address to one deterministic
28
+ string for deduplication or graph node identity:
29
+
30
+ ```python
31
+ from rigour.addresses import address_fingerprint
32
+
33
+ key = address_fingerprint("Main Boulevard 5, Syrian Arab Republic")
34
+ # "main blvd 5 sy" — same key as for "Main Blvd. 5, Syria"
35
+ ```
36
+
6
37
  ## Postal address formatting
7
38
 
8
39
  This set of helpers is designed to help with the processing of real-world
@@ -31,6 +62,11 @@ format addresses according to customs in the country that is been encoded.
31
62
  """
32
63
 
33
64
  from rigour.addresses.cleaning import clean_address
65
+ from rigour.addresses.compare import (
66
+ address_fingerprint,
67
+ compare_address,
68
+ compare_address_many,
69
+ )
34
70
  from rigour.addresses.format import format_address, format_address_line
35
71
  from rigour.addresses.normalize import (
36
72
  normalize_address,
@@ -39,7 +75,10 @@ from rigour.addresses.normalize import (
39
75
  )
40
76
 
41
77
  __all__ = [
78
+ "address_fingerprint",
42
79
  "clean_address",
80
+ "compare_address",
81
+ "compare_address_many",
43
82
  "format_address",
44
83
  "format_address_line",
45
84
  "normalize_address",
@@ -0,0 +1,111 @@
1
+ """Compare postal address strings for referring to the same place."""
2
+
3
+ from rigour._core import address_fingerprint as _address_fingerprint
4
+ from rigour._core import compare_address as _compare_address
5
+ from rigour._core import compare_address_many as _compare_address_many
6
+
7
+ __all__ = ["address_fingerprint", "compare_address", "compare_address_many"]
8
+
9
+
10
+ def compare_address(query: str, result: str) -> float:
11
+ """Compare two address strings, scoring how likely they denote
12
+ the same place.
13
+
14
+ Both strings are analyzed into classed tokens (numbers, keyword
15
+ signifiers like `str.`/`ул.`, territory names, free text) and
16
+ greedily aligned: numbers must match exactly, keywords match
17
+ across alias forms (`boulevard`/`blvd`), territory names match
18
+ across languages via their code (`Syria`/`Сирия`), and free text
19
+ matches by edit distance over transliterated forms. The score is
20
+ the length-weighted share of aligned tokens, and a pair of
21
+ numbers where each side asserts a value the other lacks (a
22
+ differing house or unit number) is penalized far beyond its
23
+ length. Comparison is order-independent, so differently arranged
24
+ address parts do not lower the score.
25
+
26
+ Score semantics, measured on the labelled benchmark corpus in
27
+ `contrib/address_bench`: equivalent renderings of one address
28
+ score 1.0; transliterated or partly translated matches typically
29
+ land between 0.5 and 0.9; an address and its less specific
30
+ prefix (street dropped, city kept) around 0.6; pairs with
31
+ conflicting house or unit numbers are pushed toward 0.0. The
32
+ accuracy-optimal decision threshold on that corpus is ~0.3 —
33
+ substantially lower than typical name-similarity calibrations.
34
+
35
+ Analysis results are memoized in a process-wide cache, so
36
+ comparing one address against many candidates re-analyzes the
37
+ repeated side only once. The GIL is released while comparing.
38
+
39
+ Args:
40
+ query: An address, as one full string.
41
+ result: The address to compare against, as one full string.
42
+
43
+ Returns:
44
+ A similarity score between 0.0 and 1.0. Empty or
45
+ punctuation-only input scores 0.0 against everything.
46
+ """
47
+ return _compare_address(query, result)
48
+
49
+
50
+ def compare_address_many(queries: list[str], results: list[str]) -> float:
51
+ """Compare two sets of address strings and return the best
52
+ pairwise score.
53
+
54
+ Scores every query against every result with
55
+ [compare_address][rigour.addresses.compare.compare_address] and
56
+ returns the maximum — the natural shape for matching two
57
+ entities that each carry several address renderings. Each
58
+ distinct string is analyzed only once, so the list×list loop is
59
+ substantially cheaper than the equivalent pairwise calls.
60
+
61
+ Args:
62
+ queries: Addresses of one entity, each as one full string.
63
+ results: Addresses of the other entity, each as one full
64
+ string.
65
+
66
+ Returns:
67
+ The highest pairwise similarity score between 0.0 and 1.0;
68
+ 0.0 when either list is empty or nothing is comparable.
69
+ """
70
+ return _compare_address_many(queries, results)
71
+
72
+
73
+ def address_fingerprint(text: str) -> str | None:
74
+ """Serialize an address string into a deterministic key for
75
+ deduplication and graph node identity.
76
+
77
+ The address is analyzed into classed tokens and each token is
78
+ reduced to its most canonical form: numbers become plain digit
79
+ strings (`№17`, `17.` and `17` all key as `17`), address
80
+ keywords become their canonical short form (`Boulevard` and
81
+ `blvd.` both key as `blvd`), unambiguous territory names in any
82
+ supported language become their territory code (`Syria`, `Syrian
83
+ Arab Republic` and `Сирия` all key as `sy`), and free text is
84
+ transliterated where a narrow, systematic romanization exists.
85
+ Token order is preserved: addresses that differ only by
86
+ transposed numbers (`д. 17 стр. 1` versus `д. 1 стр. 17`) must
87
+ not key identically, so differently ordered renderings of one
88
+ address also produce different keys — collapsing those is left
89
+ to fuzzier machinery. Use this function to key or deduplicate address
90
+ records; to score how similar two addresses are, use
91
+ [compare_address][rigour.addresses.compare.compare_address],
92
+ which shares the same analysis (and its cache) but aligns tokens
93
+ order-independently and fuzzily.
94
+
95
+ The output is lowercase, space-separated, and ASCII except for
96
+ free-text tokens in scripts without a systematic romanization
97
+ (Chinese, Arabic, ...), which pass through in their native
98
+ script. Callers that require pure-ASCII identifiers should
99
+ slug-encode the result (e.g. `normality.slugify`). Fingerprints
100
+ are stable within one version of rigour but may change between
101
+ versions as the underlying resources grow; do not persist them
102
+ across upgrades without re-keying.
103
+
104
+ Args:
105
+ text: An address, as one full string.
106
+
107
+ Returns:
108
+ The fingerprint string, or `None` when the input is empty or
109
+ contains nothing analyzable (only punctuation).
110
+ """
111
+ return _address_fingerprint(text)
@@ -2,6 +2,7 @@ import logging
2
2
  import re
3
3
  import string
4
4
  import unicodedata
5
+ import warnings
5
6
  from functools import cache
6
7
 
7
8
  from normality import ascii_text
@@ -182,6 +183,11 @@ def remove_address_keywords(
182
183
  ) -> str | None:
183
184
  """Strip common address keywords from a normalised address.
184
185
 
186
+ Deprecated:
187
+ Use [compare_address][rigour.addresses.compare.compare_address]
188
+ to compare addresses instead of comparing keyword-stripped
189
+ strings. This function will be removed in a future version.
190
+
185
191
  Removes recognised forms (`"street"`, `"road"`, `"south"`,
186
192
  territory names, ordinals, …) by substituting each match with
187
193
  `replacement`. Consecutive matches produce consecutive
@@ -204,6 +210,12 @@ def remove_address_keywords(
204
210
  Returns:
205
211
  The address with recognised keywords removed.
206
212
  """
213
+ warnings.warn(
214
+ "rigour.addresses.remove_address_keywords is deprecated, "
215
+ "use rigour.addresses.compare_address instead",
216
+ DeprecationWarning,
217
+ stacklevel=2,
218
+ )
207
219
  with resource_lock:
208
220
  pattern, _ = _address_replacer(latinize=latinize)
209
221
  return pattern.sub(replacement, address)
@@ -212,6 +224,12 @@ def remove_address_keywords(
212
224
  def shorten_address_keywords(address: str, latinize: bool = False) -> str | None:
213
225
  """Shorten common address keywords in a normalised address.
214
226
 
227
+ Deprecated:
228
+ Use [address_fingerprint][rigour.addresses.compare.address_fingerprint],
229
+ which reduces keywords to the same canonical short forms as
230
+ part of a full keying serialization. This function will be
231
+ removed in a future version.
232
+
215
233
  Replaces recognised forms with their canonical short form
216
234
  (`"street"` → `"st"`, `"avenue"` → `"av"`, `"united arab
217
235
  emirates"` → `"ae"`, …). Multi-token forms beat single-token
@@ -231,6 +249,12 @@ def shorten_address_keywords(address: str, latinize: bool = False) -> str | None
231
249
  The address with recognised keywords shortened. Tokens
232
250
  that don't match any alias pass through unchanged.
233
251
  """
252
+ warnings.warn(
253
+ "rigour.addresses.shorten_address_keywords is deprecated, "
254
+ "use rigour.addresses.address_fingerprint instead",
255
+ DeprecationWarning,
256
+ stacklevel=2,
257
+ )
234
258
  pattern, mapping = _address_replacer(latinize=latinize)
235
259
 
236
260
  def _sub(match: re.Match[str]) -> str:
@@ -1,8 +1,28 @@
1
1
  # This file is automatically generated, do not edit it.
2
2
  FORMS: dict[str, list[str]] = {
3
- "apt": ["apartment", "apartamento", "appartement", "appartamento", "flat"],
4
- "av": ["avenue", "ave", "avenida", "avinguda", "авеню"],
5
- "rd": ["road"],
3
+ "apt": [
4
+ "apartment",
5
+ "daire",
6
+ "apartmani",
7
+ "apartmanı",
8
+ "apartamento",
9
+ "appartement",
10
+ "appartamento",
11
+ "flat",
12
+ ],
13
+ "av": [
14
+ "avenue",
15
+ "cad",
16
+ "cadde",
17
+ "caddesi",
18
+ "ave",
19
+ "avenida",
20
+ "avinguda",
21
+ "viale",
22
+ "avda",
23
+ "авеню",
24
+ ],
25
+ "rd": ["road", "marg", "yol", "yolu"],
6
26
  "no": [
7
27
  "number",
8
28
  "num",
@@ -16,7 +36,7 @@ FORMS: dict[str, list[str]] = {
16
36
  "número",
17
37
  "номер",
18
38
  ],
19
- "d": ["dom", "дом", "house", "hse"],
39
+ "d": ["dom", "дом", "д", "house", "hse"],
20
40
  "condo": ["condominium", "condominio", "condomínio", "kondominium"],
21
41
  "twr": ["tower", "towers", "toren", "torre", "torres", "torre"],
22
42
  "c": ["calle"],
@@ -36,10 +56,14 @@ FORMS: dict[str, list[str]] = {
36
56
  "Gebäude",
37
57
  "buildings",
38
58
  "gebouw",
59
+ "будова",
39
60
  ],
40
61
  "zone": ["zone", "sone", "zona", "zone", "zóna", "ζώνη", "зона"],
41
62
  "kv": [
42
63
  "area",
64
+ "mah",
65
+ "mahalle",
66
+ "mahallesi",
43
67
  "район",
44
68
  "neighborhood",
45
69
  "nachbarschaft",
@@ -61,16 +85,30 @@ FORMS: dict[str, list[str]] = {
61
85
  "кв",
62
86
  ],
63
87
  "bch": ["beach", "пляж"],
64
- "blk": ["block", "блок"],
88
+ "blk": ["block", "blocks", "блок", "blok", "bloque", "bloc"],
65
89
  "nat": ["national"],
66
90
  "fed": ["federal"],
67
91
  "alley": ["alley", "allée", "аллея", "проезд", "проїзд", "proezd"],
68
92
  "int": ["international"],
69
- "sec": ["section", "сектор"],
93
+ "sec": ["section", "sections", "сектор", "sector", "sektor", "sección", "secteur"],
70
94
  "wing": ["крыло"],
71
- "blvd": ["boulevard", "bulevar", "бульвар"],
95
+ "blvd": [
96
+ "boulevard",
97
+ "boulevards",
98
+ "bulvar",
99
+ "bulvari",
100
+ "bulvarı",
101
+ "bulevar",
102
+ "бульвар",
103
+ "bld",
104
+ "大道",
105
+ ],
72
106
  "st": [
73
107
  "strasse",
108
+ "sokak",
109
+ "sok",
110
+ "sokagi",
111
+ "sokağı",
74
112
  "straße",
75
113
  "strase",
76
114
  "street",
@@ -81,13 +119,26 @@ FORMS: dict[str, list[str]] = {
81
119
  "rue",
82
120
  "стр",
83
121
  "saint",
122
+ "via",
123
+ "jalan",
124
+ "jln",
84
125
  ],
85
- "pr": ["pr-kt", "prospekt", "prospect", "просп", "проспект"],
86
- "ul": ["ulitsa", "улица", "вул", "ул"],
87
- "k": ["корпус", "korpus"],
126
+ "pr": ["pr-kt", "пр-кт", "prospekt", "prospect", "просп", "проспект"],
127
+ "ul": ["ulitsa", "ulica", "ulice", "улица", "вул", "ул"],
128
+ "k": ["корпус", "korpus", "korp", "корп"],
88
129
  "mk": ["mikrorayon", "микрорайон", "мкр"],
89
130
  "dr": ["drive"],
90
- "ln": ["lane", "laan", "переулок", "pereulok", "per", "пер"],
131
+ "ln": [
132
+ "lane",
133
+ "lanes",
134
+ "laan",
135
+ "chemin",
136
+ "chemins",
137
+ "переулок",
138
+ "pereulok",
139
+ "per",
140
+ "пер",
141
+ ],
91
142
  "pt": ["point"],
92
143
  "ct": ["court"],
93
144
  "cir": ["circle"],
@@ -110,23 +161,76 @@ FORMS: dict[str, list[str]] = {
110
161
  "studios",
111
162
  "penthouse",
112
163
  ],
113
- "pl": ["platz", "plaza", "place", "plot"],
114
- "cty": ["county", "counties", "Okrug", "okr"],
164
+ "plot": ["plot"],
165
+ "cty": ["county", "counties", "Okrug", "okr", "округ"],
115
166
  "prov": ["province", "пров"],
116
- "sq": ["square"],
167
+ "sq": [
168
+ "square",
169
+ "squares",
170
+ "chowk",
171
+ "platz",
172
+ "plaza",
173
+ "place",
174
+ "piazza",
175
+ "plaza de",
176
+ "plazuela",
177
+ "praça",
178
+ "plein",
179
+ "площадь",
180
+ "площ",
181
+ "пл",
182
+ "площа",
183
+ "广场",
184
+ ],
117
185
  "cnr": ["corner"],
118
186
  "sub": ["subdivision"],
119
187
  "brgh": ["borough"],
120
188
  "ft": ["fort"],
121
189
  "hts": ["hgts", "heights"],
122
190
  "mt": ["mount", "montaña", "mountain", "montagna", "montagne", "montanha"],
123
- "hl": ["hill", "hills", "heuvel", "heuvels", "hügel"],
191
+ "hl": [
192
+ "hill",
193
+ "hills",
194
+ "bukit",
195
+ "colina",
196
+ "colline",
197
+ "холм",
198
+ "heuvel",
199
+ "heuvels",
200
+ "hügel",
201
+ ],
124
202
  "co": ["c o", "c/o", "care of", "℅"],
125
- "pza": ["piazza"],
126
- "ctr": ["center", "centre", "central"],
203
+ "ctr": [
204
+ "center",
205
+ "centre",
206
+ "central",
207
+ "centro",
208
+ "centrum",
209
+ "zentrum",
210
+ "центр",
211
+ "中心",
212
+ ],
127
213
  "pk": ["park", "parc", "parco", "parque"],
128
- "gd": ["garden", "gardens"],
129
- "rep": ["republic", "republik", "republique", "repubblica", "республіки"],
214
+ "gd": [
215
+ "garden",
216
+ "gardens",
217
+ "bagh",
218
+ "taman",
219
+ "jardin",
220
+ "jardín",
221
+ "giardino",
222
+ "сад",
223
+ "花园",
224
+ ],
225
+ "rep": [
226
+ "republic",
227
+ "republik",
228
+ "republique",
229
+ "repubblica",
230
+ "республіки",
231
+ "республика",
232
+ "республіка",
233
+ ],
130
234
  "est": ["estate", "estates"],
131
235
  "stn": [
132
236
  "stazione",
@@ -158,7 +262,7 @@ FORMS: dict[str, list[str]] = {
158
262
  "バンガロー",
159
263
  "平房",
160
264
  ],
161
- "ind": ["industrial"],
265
+ "ind": ["industrial", "sanayi"],
162
266
  "cmrc": [
163
267
  "commercial",
164
268
  "коммерция",
@@ -182,6 +286,7 @@ FORMS: dict[str, list[str]] = {
182
286
  "fl": [
183
287
  "floor",
184
288
  "flr",
289
+ "kat",
185
290
  "story",
186
291
  "storey",
187
292
  "level",
@@ -237,6 +342,8 @@ FORMS: dict[str, list[str]] = {
237
342
  ],
238
343
  "kab": ["cabinet", "Kabinet"],
239
344
  "pom": [
345
+ "premises",
346
+ "premise",
240
347
  "pomeshch",
241
348
  "pomeshchenie",
242
349
  "pomeshtenie",
@@ -251,6 +358,7 @@ FORMS: dict[str, list[str]] = {
251
358
  "nab.",
252
359
  "набережная",
253
360
  "набережн",
361
+ "наб",
254
362
  "embankment",
255
363
  "embankments",
256
364
  ],
@@ -271,6 +379,8 @@ FORMS: dict[str, list[str]] = {
271
379
  "postbus",
272
380
  "postfach",
273
381
  "почтовый ящик",
382
+ "pob",
383
+ "box",
274
384
  ],
275
385
  "zip": [
276
386
  "zipcode",
@@ -282,7 +392,92 @@ FORMS: dict[str, list[str]] = {
282
392
  "post code",
283
393
  ],
284
394
  "lit": ["letter", "liter", "litera", "літер", "лит", "литера", "літера", "литер"],
285
- "rn": ["region", "регіон", "обл", "область", "oblast"],
395
+ "rn": ["region", "регіон", "обл", "область", "oblast", "край", "krai", "kray"],
286
396
  "ir": ["irn"],
287
397
  "ae": ["uae"],
398
+ "city": ["city", "ciudad", "ville", "cité", "город", "гор", "城市"],
399
+ "town": [
400
+ "town",
401
+ "towns",
402
+ "settlement",
403
+ "settlements",
404
+ "pueblo",
405
+ "bourg",
406
+ "посёлок",
407
+ "поселок",
408
+ "пос",
409
+ ],
410
+ "vlg": [
411
+ "village",
412
+ "villages",
413
+ "hamlet",
414
+ "desa",
415
+ "aldeia",
416
+ "villaggio",
417
+ "dorf",
418
+ "村庄",
419
+ "aldea",
420
+ "hameau",
421
+ "деревня",
422
+ "дер",
423
+ "село",
424
+ ],
425
+ "twp": ["township"],
426
+ "pref": ["prefecture", "prefectura", "préfecture", "префектура"],
427
+ "comm": ["community", "comunidad", "communauté", "община", "сообщество", "社区"],
428
+ "auton": [
429
+ "autonomous",
430
+ "autónoma",
431
+ "autónomo",
432
+ "autonome",
433
+ "автономный",
434
+ "автономная",
435
+ "автономного",
436
+ "авт",
437
+ "自治",
438
+ ],
439
+ "cplx": ["complex", "sitesi", "complejo", "complexe", "комплекс", "综合楼"],
440
+ "phase": ["phase", "fase", "фаза"],
441
+ "yd": ["courtyard", "courtyards", "yard", "yards", "patio", "cour", "двор"],
442
+ "way": ["way", "voie"],
443
+ "dev": ["development", "desarrollo", "développement", "развитие", "开发"],
444
+ "shop": ["shop", "tienda", "magasin", "boutique", "магазин", "商店"],
445
+ "ward": ["ward", "wards", "phuong", "phường"],
446
+ "mans": ["mansion", "mansions", "mansión", "manoir", "особняк"],
447
+ "shpg": [
448
+ "shopping",
449
+ "shopping centre",
450
+ "shopping center",
451
+ "shopping mall",
452
+ "centro comercial",
453
+ "centre commercial",
454
+ "торговый центр",
455
+ "购物中心",
456
+ ],
457
+ "cmpd": ["compound", "compounds", "大院"],
458
+ "gvnr": [
459
+ "governorate",
460
+ "governorates",
461
+ "gobernación",
462
+ "gouvernorat",
463
+ "губерния",
464
+ "محافظة",
465
+ ],
466
+ "cmne": ["commune", "communes", "comuna", "коммуна", "公社"],
467
+ "entr": [
468
+ "entrance",
469
+ "kapi",
470
+ "kapı",
471
+ "entrances",
472
+ "entry",
473
+ "entrada",
474
+ "entrée",
475
+ "подъезд",
476
+ "вход",
477
+ "入口",
478
+ ],
479
+ "hbr": ["harbor", "harbour", "harbors", "harbours", "гавань", "港口"],
480
+ "metro": ["metro", "métro", "метро", "subway", "地铁"],
481
+ "upr": ["upper", "superior", "supérieur"],
482
+ "lwr": ["lower", "inferior", "inférieur"],
288
483
  }
@@ -0,0 +1,67 @@
1
+ from typing import TypeVar
2
+
3
+ from rigour.data.langs.iso639 import ISO3_ALL
4
+
5
+ LangStrT = TypeVar("LangStrT", bound="LangStr")
6
+
7
+
8
+ class LangStr(str):
9
+ """A string carrying an optional language tag.
10
+
11
+ Use this to keep track of which language a piece of multilingual
12
+ content is written in while still passing it around as a `str`.
13
+
14
+ The language tag is part of the value's identity:
15
+
16
+ * With no tag (`lang is None`), a `LangStr` is indistinguishable from
17
+ its content string: it compares equal to the plain `str`, hashes the
18
+ same, and deduplicates against it in sets and dict keys.
19
+ * With a tag, a `LangStr` is a distinct value identified by the pair
20
+ `(content, lang)`. It is not equal to the bare content string, nor
21
+ to a `LangStr` with a different or missing tag, and it never
22
+ deduplicates against them.
23
+
24
+ Ordinary `str` methods (`.upper()`, slicing, concatenation, …) return
25
+ plain `str` and drop the tag.
26
+
27
+ Args:
28
+ content: The text.
29
+ lang: An ISO 639-3 language code, or `None` for untagged text.
30
+
31
+ Raises:
32
+ ValueError: If `lang` is not a known ISO 639-3 code.
33
+ """
34
+
35
+ __slots__ = ("lang",)
36
+
37
+ def __new__(
38
+ cls: type[LangStrT], content: str, lang: str | None = None
39
+ ) -> LangStrT:
40
+ return str.__new__(cls, content)
41
+
42
+ def __init__(self, content: str, lang: str | None = None) -> None:
43
+ if lang is not None and lang not in ISO3_ALL:
44
+ raise ValueError(f"Invalid ISO 639-3 language code: {lang}")
45
+ self.lang = lang
46
+
47
+ def __repr__(self) -> str:
48
+ if self.lang is not None:
49
+ return f'"{super().__str__()}"@{self.lang}'
50
+ return super().__repr__()
51
+
52
+ def __hash__(self) -> int:
53
+ if self.lang is None:
54
+ return super().__hash__()
55
+ return hash((super().__str__(), self.lang))
56
+
57
+ def __eq__(self, value: object) -> bool:
58
+ if not isinstance(value, str):
59
+ return NotImplemented
60
+ other_lang = value.lang if isinstance(value, LangStr) else None
61
+ return super().__eq__(value) and self.lang == other_lang
62
+
63
+ def __ne__(self, value: object) -> bool:
64
+ equal = self.__eq__(value)
65
+ if equal is NotImplemented:
66
+ return NotImplemented
67
+ return not equal