rigour 2.2.2__tar.gz → 2.3.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.
- {rigour-2.2.2 → rigour-2.3.0}/PKG-INFO +2 -3
- {rigour-2.2.2 → rigour-2.3.0}/pyproject.toml +18 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/_core.pyi +35 -36
- {rigour-2.2.2 → rigour-2.3.0}/rigour/addresses/__init__.py +7 -4
- {rigour-2.2.2 → rigour-2.3.0}/rigour/addresses/format.py +13 -12
- {rigour-2.2.2 → rigour-2.3.0}/rigour/addresses/normalize.py +13 -13
- {rigour-2.2.2 → rigour-2.3.0}/rigour/boolean.py +2 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/__init__.py +3 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/addresses/data.py +1 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/langs/iso639.py +454 -11
- {rigour-2.2.2 → rigour-2.3.0}/rigour/env.py +9 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/__init__.py +26 -27
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/common.py +2 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/imo.py +6 -6
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/npi.py +2 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/ogrn.py +2 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/stdnum_.py +15 -15
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/strict.py +1 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/uei.py +3 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/ids/wikidata.py +1 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/langs/__init__.py +32 -19
- {rigour-2.2.2 → rigour-2.3.0}/rigour/langs/synonyms.py +5 -6
- {rigour-2.2.2 → rigour-2.3.0}/rigour/langs/text.py +10 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/langs/util.py +1 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/__init__.py +7 -9
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/filename.py +10 -11
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/mappings.py +18 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/mime.py +3 -4
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/parse.py +16 -15
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/__init__.py +39 -34
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/analyze.py +3 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/check.py +6 -6
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/org_types.py +9 -4
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/pick.py +10 -11
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/prefix.py +2 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/split_phrases.py +1 -1
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/symbol.py +1 -2
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/tokenize.py +3 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/reset.py +15 -11
- {rigour-2.2.2 → rigour-2.3.0}/rigour/territories/__init__.py +10 -11
- {rigour-2.2.2 → rigour-2.3.0}/rigour/territories/lookup.py +14 -14
- {rigour-2.2.2 → rigour-2.3.0}/rigour/territories/match.py +6 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/territories/territory.py +27 -27
- {rigour-2.2.2 → rigour-2.3.0}/rigour/territories/util.py +3 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/__init__.py +14 -12
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/checksum.py +1 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/distance.py +3 -4
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/normalize.py +6 -6
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/scripts.py +1 -3
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/stopwords.py +4 -4
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/translit.py +1 -1
- rigour-2.3.0/rigour/time.py +91 -0
- rigour-2.3.0/rigour/urls/__init__.py +5 -0
- rigour-2.3.0/rigour/urls/cleaning.py +119 -0
- rigour-2.3.0/rigour/urls/util.py +7 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/util.py +2 -4
- {rigour-2.2.2 → rigour-2.3.0}/rust/Cargo.lock +29 -18
- {rigour-2.2.2 → rigour-2.3.0}/rust/Cargo.toml +1 -1
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/names/symbols.json +72 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/lib.rs +4 -8
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/compare.rs +24 -3
- rigour-2.3.0/rust/src/names/constants.rs +23 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/mod.rs +1 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/ordering.rs +18 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/pairing.rs +1 -5
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/part.rs +19 -6
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/pick.rs +6 -1
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/numbers.rs +3 -2
- rigour-2.2.2/rigour/time.py +0 -67
- rigour-2.2.2/rigour/urls/__init__.py +0 -5
- rigour-2.2.2/rigour/urls/cleaning.py +0 -68
- rigour-2.2.2/rigour/urls/util.py +0 -6
- {rigour-2.2.2 → rigour-2.3.0}/LICENSE +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/README.md +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/__init__.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/addresses/cleaning.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/addresses/__init__.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/addresses/formats.yml +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/data/langs/__init__.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/dates.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/mime/types.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/compare.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/name.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/ordering.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/part.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/names/tag.py +5 -5
- {rigour-2.2.2 → rigour-2.3.0}/rigour/py.typed +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/cleaning.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/text/phonetics.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/units.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rigour/urls/compare.py +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/build.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/names/compare.json +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/names/org_types.json +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/names/person_names.txt +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/names/stopwords.json +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/territories/data.jsonl +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/text/ordinals.json +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/data/text/stopwords.json +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/constants.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/generated/.gitkeep +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/alignment.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/analyze.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/matcher.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/name.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/org_types.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/person_names.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/prefix.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/stopwords.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/symbol.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/symbols.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/tag.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/names/tagger.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/territories.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/distance.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/mod.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/normalize.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/ordinals.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/phonetics.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/scripts.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/stopwords.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.0}/rust/src/text/tokenize.rs +0 -0
- {rigour-2.2.2 → rigour-2.3.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
|
+
Version: 2.3.0
|
|
4
4
|
Classifier: Intended Audience :: Developers
|
|
5
5
|
Classifier: Operating System :: OS Independent
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -20,7 +20,7 @@ Requires-Dist: pip>=10.0.0 ; extra == 'dev'
|
|
|
20
20
|
Requires-Dist: bump2version ; extra == 'dev'
|
|
21
21
|
Requires-Dist: wheel>=0.29.0 ; extra == 'dev'
|
|
22
22
|
Requires-Dist: ruamel-yaml ; extra == 'dev'
|
|
23
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: ruff>=0.16.0,<0.17.0 ; extra == 'dev'
|
|
24
24
|
Requires-Dist: build ; extra == 'dev'
|
|
25
25
|
Requires-Dist: twine ; extra == 'dev'
|
|
26
26
|
Requires-Dist: mypy ; extra == 'dev'
|
|
@@ -28,7 +28,6 @@ Requires-Dist: pytest ; extra == 'dev'
|
|
|
28
28
|
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
29
29
|
Requires-Dist: types-pyyaml ; extra == 'dev'
|
|
30
30
|
Requires-Dist: types-setuptools ; extra == 'dev'
|
|
31
|
-
Requires-Dist: types-pyyaml ; extra == 'dev'
|
|
32
31
|
Requires-Dist: coverage>=4.1 ; extra == 'dev'
|
|
33
32
|
Requires-Dist: pillow ; extra == 'docs'
|
|
34
33
|
Requires-Dist: cairosvg ; extra == 'docs'
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rigour"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.0"
|
|
8
8
|
description = "Financial crime domain data validation and normalization library."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -41,7 +41,11 @@ dev = [
|
|
|
41
41
|
"bump2version",
|
|
42
42
|
"wheel>=0.29.0",
|
|
43
43
|
"ruamel.yaml",
|
|
44
|
-
|
|
44
|
+
# Bounded on purpose: ruff's default rule selection moves between minor
|
|
45
|
+
# releases, so an unpinned range would change what `ruff check` reports
|
|
46
|
+
# without any change to this repo. genscripts/util.py also formats the
|
|
47
|
+
# generated data tables with it, so a bump can shift those files too.
|
|
48
|
+
"ruff >= 0.16.0, < 0.17.0",
|
|
45
49
|
"build",
|
|
46
50
|
"twine",
|
|
47
51
|
"mypy",
|
|
@@ -49,7 +53,6 @@ dev = [
|
|
|
49
53
|
"pytest-cov",
|
|
50
54
|
"types-PyYAML",
|
|
51
55
|
"types-setuptools",
|
|
52
|
-
"types-PyYAML",
|
|
53
56
|
"coverage>=4.1",
|
|
54
57
|
]
|
|
55
58
|
docs = [
|
|
@@ -73,5 +76,17 @@ include = [
|
|
|
73
76
|
{ path = "rigour/_core.pyi", format = "sdist" },
|
|
74
77
|
]
|
|
75
78
|
|
|
79
|
+
[tool.ruff.lint]
|
|
80
|
+
ignore = [
|
|
81
|
+
# `from x import y as y` is the explicit re-export form that mypy requires
|
|
82
|
+
# under no_implicit_reexport (implied by --strict). Ruff exempts it in
|
|
83
|
+
# __init__.py and stubs, but not in plain modules, so it fires on the
|
|
84
|
+
# modules that re-export symbols out of the Rust extension
|
|
85
|
+
# (rigour.names.pick, rigour.text.translit). Dropping the alias there
|
|
86
|
+
# would break `from rigour.names.pick import pick_name` for any
|
|
87
|
+
# strict-mode consumer.
|
|
88
|
+
"PLC0414",
|
|
89
|
+
]
|
|
90
|
+
|
|
76
91
|
[tool.coverage.run]
|
|
77
92
|
branch = true
|
|
@@ -7,7 +7,6 @@ def should_ascii(text: str) -> bool: ...
|
|
|
7
7
|
def maybe_ascii(text: str, drop: bool = False) -> str: ...
|
|
8
8
|
def tokenize_name(text: str, token_min_length: int = 1) -> list[str]: ...
|
|
9
9
|
def _normalize(text: str, flags: int, cleanup: int) -> str | None: ...
|
|
10
|
-
def string_number(text: str) -> float | None: ...
|
|
11
10
|
def raw_levenshtein(a: str, b: str) -> int: ...
|
|
12
11
|
def raw_levenshtein_cutoff(a: str, b: str, cutoff: int) -> int: ...
|
|
13
12
|
def raw_jaro(a: str, b: str) -> float: ...
|
|
@@ -36,26 +35,27 @@ def generic_person_names_list() -> list[str]: ...
|
|
|
36
35
|
def ordinals_dict() -> dict[int, list[str]]: ...
|
|
37
36
|
def territories_jsonl() -> str: ...
|
|
38
37
|
|
|
38
|
+
MAX_NAME_LENGTH: int
|
|
39
|
+
|
|
39
40
|
|
|
40
41
|
class SymbolCategory:
|
|
41
42
|
"""Sealed enum of symbol categories. See
|
|
42
43
|
[rigour.text.normalize][] for related flag-based design.
|
|
43
44
|
"""
|
|
44
45
|
|
|
45
|
-
ORG_CLASS:
|
|
46
|
-
SYMBOL:
|
|
47
|
-
DOMAIN:
|
|
48
|
-
INITIAL:
|
|
49
|
-
NAME:
|
|
50
|
-
NICK:
|
|
51
|
-
NUMERIC:
|
|
52
|
-
LOCATION:
|
|
53
|
-
PHONETIC:
|
|
46
|
+
ORG_CLASS: SymbolCategory
|
|
47
|
+
SYMBOL: SymbolCategory
|
|
48
|
+
DOMAIN: SymbolCategory
|
|
49
|
+
INITIAL: SymbolCategory
|
|
50
|
+
NAME: SymbolCategory
|
|
51
|
+
NICK: SymbolCategory
|
|
52
|
+
NUMERIC: SymbolCategory
|
|
53
|
+
LOCATION: SymbolCategory
|
|
54
|
+
PHONETIC: SymbolCategory
|
|
54
55
|
|
|
55
56
|
@property
|
|
56
57
|
def value(self) -> str:
|
|
57
58
|
"""Short serialisation key (e.g. ``"ORGCLS"``, ``"NUM"``)."""
|
|
58
|
-
...
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
class Symbol:
|
|
@@ -79,17 +79,16 @@ class Symbol:
|
|
|
79
79
|
@property
|
|
80
80
|
def id(self) -> str:
|
|
81
81
|
"""The interned id string."""
|
|
82
|
-
...
|
|
83
82
|
|
|
84
83
|
|
|
85
84
|
class NameTypeTag:
|
|
86
85
|
"""Metadata on what sort of object is described by a name."""
|
|
87
86
|
|
|
88
|
-
UNK:
|
|
89
|
-
ENT:
|
|
90
|
-
PER:
|
|
91
|
-
ORG:
|
|
92
|
-
OBJ:
|
|
87
|
+
UNK: NameTypeTag
|
|
88
|
+
ENT: NameTypeTag
|
|
89
|
+
PER: NameTypeTag
|
|
90
|
+
ORG: NameTypeTag
|
|
91
|
+
OBJ: NameTypeTag
|
|
93
92
|
|
|
94
93
|
@property
|
|
95
94
|
def value(self) -> str: ...
|
|
@@ -98,26 +97,26 @@ class NameTypeTag:
|
|
|
98
97
|
class NamePartTag:
|
|
99
98
|
"""Within a name, identify name-part types."""
|
|
100
99
|
|
|
101
|
-
UNSET:
|
|
102
|
-
AMBIGUOUS:
|
|
103
|
-
TITLE:
|
|
104
|
-
GIVEN:
|
|
105
|
-
MIDDLE:
|
|
106
|
-
FAMILY:
|
|
107
|
-
TRIBAL:
|
|
108
|
-
PATRONYMIC:
|
|
109
|
-
MATRONYMIC:
|
|
110
|
-
HONORIFIC:
|
|
111
|
-
SUFFIX:
|
|
112
|
-
NICK:
|
|
113
|
-
STOP:
|
|
114
|
-
NUM:
|
|
115
|
-
LEGAL:
|
|
100
|
+
UNSET: NamePartTag
|
|
101
|
+
AMBIGUOUS: NamePartTag
|
|
102
|
+
TITLE: NamePartTag
|
|
103
|
+
GIVEN: NamePartTag
|
|
104
|
+
MIDDLE: NamePartTag
|
|
105
|
+
FAMILY: NamePartTag
|
|
106
|
+
TRIBAL: NamePartTag
|
|
107
|
+
PATRONYMIC: NamePartTag
|
|
108
|
+
MATRONYMIC: NamePartTag
|
|
109
|
+
HONORIFIC: NamePartTag
|
|
110
|
+
SUFFIX: NamePartTag
|
|
111
|
+
NICK: NamePartTag
|
|
112
|
+
STOP: NamePartTag
|
|
113
|
+
NUM: NamePartTag
|
|
114
|
+
LEGAL: NamePartTag
|
|
116
115
|
|
|
117
116
|
@property
|
|
118
117
|
def value(self) -> str: ...
|
|
119
118
|
|
|
120
|
-
def can_match(self, other:
|
|
119
|
+
def can_match(self, other: NamePartTag) -> bool: ...
|
|
121
120
|
|
|
122
121
|
|
|
123
122
|
class NamePart:
|
|
@@ -144,7 +143,7 @@ class NamePart:
|
|
|
144
143
|
def __len__(self) -> int: ...
|
|
145
144
|
|
|
146
145
|
@classmethod
|
|
147
|
-
def tag_sort(cls, parts: list[
|
|
146
|
+
def tag_sort(cls, parts: list[NamePart]) -> list[NamePart]: ...
|
|
148
147
|
|
|
149
148
|
|
|
150
149
|
class Span:
|
|
@@ -189,10 +188,10 @@ class Name:
|
|
|
189
188
|
|
|
190
189
|
def apply_part(self, part: NamePart, symbol: Symbol) -> None: ...
|
|
191
190
|
|
|
192
|
-
def contains(self, other:
|
|
191
|
+
def contains(self, other: Name) -> bool: ...
|
|
193
192
|
|
|
194
193
|
@classmethod
|
|
195
|
-
def consolidate_names(cls, names:
|
|
194
|
+
def consolidate_names(cls, names: object) -> set[Name]: ...
|
|
196
195
|
|
|
197
196
|
|
|
198
197
|
def analyze_names(
|
|
@@ -31,15 +31,18 @@ format addresses according to customs in the country that is been encoded.
|
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
33
|
from rigour.addresses.cleaning import clean_address
|
|
34
|
-
from rigour.addresses.normalize import normalize_address
|
|
35
|
-
from rigour.addresses.normalize import remove_address_keywords, shorten_address_keywords
|
|
36
34
|
from rigour.addresses.format import format_address, format_address_line
|
|
35
|
+
from rigour.addresses.normalize import (
|
|
36
|
+
normalize_address,
|
|
37
|
+
remove_address_keywords,
|
|
38
|
+
shorten_address_keywords,
|
|
39
|
+
)
|
|
37
40
|
|
|
38
41
|
__all__ = [
|
|
39
42
|
"clean_address",
|
|
43
|
+
"format_address",
|
|
44
|
+
"format_address_line",
|
|
40
45
|
"normalize_address",
|
|
41
46
|
"remove_address_keywords",
|
|
42
47
|
"shorten_address_keywords",
|
|
43
|
-
"format_address",
|
|
44
|
-
"format_address_line",
|
|
45
48
|
]
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import yaml
|
|
2
|
-
from typing import Dict, Optional, TypedDict
|
|
3
1
|
from functools import cache
|
|
4
|
-
from
|
|
2
|
+
from typing import TypedDict
|
|
3
|
+
|
|
4
|
+
import yaml
|
|
5
|
+
from jinja2 import Environment, Template
|
|
5
6
|
|
|
7
|
+
from rigour.addresses.cleaning import clean_address
|
|
6
8
|
from rigour.data import DATA_PATH
|
|
7
9
|
from rigour.env import ENCODING
|
|
8
|
-
from rigour.addresses.cleaning import clean_address
|
|
9
10
|
|
|
10
11
|
env = Environment()
|
|
11
12
|
|
|
@@ -13,14 +14,14 @@ env = Environment()
|
|
|
13
14
|
class Format(TypedDict):
|
|
14
15
|
address_template: str
|
|
15
16
|
use_country: str
|
|
16
|
-
add_component:
|
|
17
|
+
add_component: dict[str, str]
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
@cache
|
|
20
|
-
def _load_formats() ->
|
|
21
|
+
def _load_formats() -> dict[str, Format]:
|
|
21
22
|
template_file = DATA_PATH / "addresses" / "formats.yml"
|
|
22
23
|
with open(template_file, "r", encoding=ENCODING) as fp:
|
|
23
|
-
data:
|
|
24
|
+
data: dict[str, Format] = yaml.load(fp, Loader=yaml.FullLoader)
|
|
24
25
|
return data
|
|
25
26
|
|
|
26
27
|
|
|
@@ -29,7 +30,7 @@ def _load_template(template: str) -> Template:
|
|
|
29
30
|
return env.from_string(template)
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
def _format(address:
|
|
33
|
+
def _format(address: dict[str, str | None], country: str | None = None) -> str:
|
|
33
34
|
country = country.upper() if country is not None else "default"
|
|
34
35
|
formats = _load_formats()
|
|
35
36
|
fmt = formats.get(country)
|
|
@@ -50,7 +51,7 @@ def _format(address: Dict[str, Optional[str]], country: Optional[str] = None) ->
|
|
|
50
51
|
address[key] = value
|
|
51
52
|
return _format(address, country=use_country)
|
|
52
53
|
|
|
53
|
-
cleaned_address:
|
|
54
|
+
cleaned_address: dict[str, str] = {}
|
|
54
55
|
for part, pvalue in address.items():
|
|
55
56
|
if pvalue is None:
|
|
56
57
|
continue
|
|
@@ -64,7 +65,7 @@ def _format(address: Dict[str, Optional[str]], country: Optional[str] = None) ->
|
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
def format_address(
|
|
67
|
-
address:
|
|
68
|
+
address: dict[str, str | None], country: str | None = None
|
|
68
69
|
) -> str:
|
|
69
70
|
"""Format the given address part into a multi-line string that matches the
|
|
70
71
|
conventions of the country of the given address.
|
|
@@ -90,7 +91,7 @@ def format_address(
|
|
|
90
91
|
A single-line string with the formatted address.
|
|
91
92
|
"""
|
|
92
93
|
text = _format(address, country=country)
|
|
93
|
-
prev:
|
|
94
|
+
prev: str | None = None
|
|
94
95
|
while prev != text:
|
|
95
96
|
prev = text
|
|
96
97
|
text = text.replace("\n\n", "\n").replace("\n ", "\n").strip()
|
|
@@ -98,7 +99,7 @@ def format_address(
|
|
|
98
99
|
|
|
99
100
|
|
|
100
101
|
def format_address_line(
|
|
101
|
-
address:
|
|
102
|
+
address: dict[str, str | None], country: str | None = None
|
|
102
103
|
) -> str:
|
|
103
104
|
"""Format the given address part into a single-line string that matches the
|
|
104
105
|
conventions of the country of the given address.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import re
|
|
2
3
|
import string
|
|
3
|
-
import logging
|
|
4
4
|
import unicodedata
|
|
5
5
|
from functools import cache
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
from normality import ascii_text
|
|
8
8
|
from normality.constants import WS
|
|
9
9
|
from normality.util import Categories
|
|
@@ -44,7 +44,7 @@ log = logging.getLogger(__name__)
|
|
|
44
44
|
|
|
45
45
|
def normalize_address(
|
|
46
46
|
address: str, latinize: bool = False, min_length: int = 4
|
|
47
|
-
) ->
|
|
47
|
+
) -> str | None:
|
|
48
48
|
"""Build a comparison key from an address.
|
|
49
49
|
|
|
50
50
|
Casefolds, replaces punctuation/symbols with whitespace,
|
|
@@ -67,11 +67,11 @@ def normalize_address(
|
|
|
67
67
|
Normalised address, or `None` when the result is shorter
|
|
68
68
|
than `min_length`.
|
|
69
69
|
"""
|
|
70
|
-
tokens:
|
|
71
|
-
token:
|
|
70
|
+
tokens: list[list[str]] = []
|
|
71
|
+
token: list[str] = []
|
|
72
72
|
for char in address.casefold():
|
|
73
73
|
if char in CHARS_ALLOWED:
|
|
74
|
-
chr:
|
|
74
|
+
chr: str | None = char
|
|
75
75
|
else:
|
|
76
76
|
cat = unicodedata.category(char)
|
|
77
77
|
chr = TOKEN_SEP_CATEGORIES.get(cat, char)
|
|
@@ -86,7 +86,7 @@ def normalize_address(
|
|
|
86
86
|
if len(token):
|
|
87
87
|
tokens.append(token)
|
|
88
88
|
|
|
89
|
-
parts:
|
|
89
|
+
parts: list[str] = []
|
|
90
90
|
for token in tokens:
|
|
91
91
|
token_str = "".join(token)
|
|
92
92
|
if latinize:
|
|
@@ -101,7 +101,7 @@ def normalize_address(
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
@cache
|
|
104
|
-
def _address_replacer(latinize: bool = False) ->
|
|
104
|
+
def _address_replacer(latinize: bool = False) -> tuple[re.Pattern[str], dict[str, str]]:
|
|
105
105
|
"""Build the (compiled regex, form → target mapping) tuple used by
|
|
106
106
|
`shorten_address_keywords` and `remove_address_keywords`.
|
|
107
107
|
|
|
@@ -111,13 +111,13 @@ def _address_replacer(latinize: bool = False) -> Tuple[re.Pattern[str], Dict[str
|
|
|
111
111
|
multi-token forms (e.g. `"united arab emirates"` → `"ae"`) win over
|
|
112
112
|
their single-token components.
|
|
113
113
|
"""
|
|
114
|
-
from rigour.data.addresses.data import FORMS
|
|
115
114
|
from rigour._core import ordinals_dict
|
|
115
|
+
from rigour.data.addresses.data import FORMS
|
|
116
116
|
|
|
117
117
|
ordinals = [(str(k), v) for k, v in ordinals_dict().items()]
|
|
118
118
|
forms = list(FORMS.items()) + ordinals
|
|
119
119
|
|
|
120
|
-
mapping:
|
|
120
|
+
mapping: dict[str, str] = {}
|
|
121
121
|
for repl, values in forms:
|
|
122
122
|
repl_norm = normalize_address(repl, latinize=latinize, min_length=1)
|
|
123
123
|
if repl_norm is None: # pragma: no cover
|
|
@@ -167,7 +167,7 @@ def _address_replacer(latinize: bool = False) -> Tuple[re.Pattern[str], Dict[str
|
|
|
167
167
|
forms_sorted = sorted(set(mapping.keys()), key=len, reverse=True)
|
|
168
168
|
pattern = re.compile(
|
|
169
169
|
r"(?<!\w)(%s)(?!\w)" % "|".join(re.escape(f) for f in forms_sorted),
|
|
170
|
-
re.
|
|
170
|
+
re.UNICODE | re.IGNORECASE,
|
|
171
171
|
)
|
|
172
172
|
# Lowercased-key mapping for the case-insensitive substitution
|
|
173
173
|
# callback. `normalize_address` already casefolds, but keeping the
|
|
@@ -179,7 +179,7 @@ def _address_replacer(latinize: bool = False) -> Tuple[re.Pattern[str], Dict[str
|
|
|
179
179
|
|
|
180
180
|
def remove_address_keywords(
|
|
181
181
|
address: str, latinize: bool = False, replacement: str = WS
|
|
182
|
-
) ->
|
|
182
|
+
) -> str | None:
|
|
183
183
|
"""Strip common address keywords from a normalised address.
|
|
184
184
|
|
|
185
185
|
Removes recognised forms (`"street"`, `"road"`, `"south"`,
|
|
@@ -209,7 +209,7 @@ def remove_address_keywords(
|
|
|
209
209
|
return pattern.sub(replacement, address)
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
def shorten_address_keywords(address: str, latinize: bool = False) ->
|
|
212
|
+
def shorten_address_keywords(address: str, latinize: bool = False) -> str | None:
|
|
213
213
|
"""Shorten common address keywords in a normalised address.
|
|
214
214
|
|
|
215
215
|
Replaces recognised forms with their canonical short form
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from functools import cache
|
|
2
|
-
from typing import Optional
|
|
3
2
|
|
|
4
3
|
|
|
5
|
-
def bool_text(value:
|
|
4
|
+
def bool_text(value: bool | None) -> str | None:
|
|
6
5
|
"""Convert a boolean value to a string representation. If the input is None, it returns
|
|
7
6
|
None. If the input is True, it returns 't'. If the input is False, it returns 'f'."""
|
|
8
7
|
if value is None:
|
|
@@ -11,7 +10,7 @@ def bool_text(value: Optional[bool]) -> Optional[str]:
|
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
@cache
|
|
14
|
-
def text_bool(text:
|
|
13
|
+
def text_bool(text: str | None) -> bool | None:
|
|
15
14
|
"""Convert a string representation of a boolean value to a boolean. If the input is None
|
|
16
15
|
or an empty string, it returns None."""
|
|
17
16
|
if text is None or len(text) == 0:
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# This file is automatically generated, do not edit it.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FORMS: Dict[str, List[str]] = {
|
|
2
|
+
FORMS: dict[str, list[str]] = {
|
|
5
3
|
"apt": ["apartment", "apartamento", "appartement", "appartamento", "flat"],
|
|
6
4
|
"av": ["avenue", "ave", "avenida", "avinguda", "авеню"],
|
|
7
5
|
"rd": ["road"],
|