rigour 0.3.2__tar.gz → 2.5.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-0.3.2 → rigour-2.5.0}/LICENSE +1 -1
- rigour-2.5.0/PKG-INFO +75 -0
- rigour-2.5.0/README.md +28 -0
- rigour-2.5.0/pyproject.toml +92 -0
- rigour-2.5.0/rigour/_core.pyi +322 -0
- rigour-2.5.0/rigour/addresses/__init__.py +96 -0
- rigour-2.5.0/rigour/addresses/cleaning.py +21 -0
- rigour-2.5.0/rigour/addresses/compare.py +157 -0
- rigour-2.5.0/rigour/addresses/format.py +128 -0
- rigour-2.5.0/rigour/addresses/normalize.py +266 -0
- rigour-2.5.0/rigour/boolean.py +19 -0
- rigour-2.5.0/rigour/data/__init__.py +20 -0
- rigour-2.5.0/rigour/data/addresses/data.py +483 -0
- rigour-2.5.0/rigour/data/addresses/formats.yml +1969 -0
- rigour-2.5.0/rigour/data/langs/iso639.py +16919 -0
- rigour-2.5.0/rigour/dates.py +203 -0
- rigour-2.5.0/rigour/env.py +68 -0
- rigour-2.5.0/rigour/ids/__init__.py +120 -0
- rigour-2.5.0/rigour/ids/common.py +21 -0
- rigour-2.5.0/rigour/ids/imo.py +125 -0
- rigour-2.5.0/rigour/ids/npi.py +43 -0
- rigour-2.5.0/rigour/ids/ogrn.py +54 -0
- rigour-2.5.0/rigour/ids/stdnum_.py +228 -0
- {rigour-0.3.2 → rigour-2.5.0}/rigour/ids/strict.py +7 -5
- rigour-2.5.0/rigour/ids/uei.py +47 -0
- {rigour-0.3.2 → rigour-2.5.0}/rigour/ids/wikidata.py +7 -3
- rigour-2.5.0/rigour/langs/__init__.py +147 -0
- rigour-2.5.0/rigour/langs/synonyms.py +43 -0
- rigour-2.5.0/rigour/langs/text.py +67 -0
- rigour-2.5.0/rigour/langs/util.py +7 -0
- rigour-2.5.0/rigour/mime/__init__.py +53 -0
- rigour-2.5.0/rigour/mime/filename.py +56 -0
- rigour-2.5.0/rigour/mime/mappings.py +96 -0
- rigour-2.5.0/rigour/mime/mime.py +21 -0
- rigour-2.5.0/rigour/mime/parse.py +86 -0
- rigour-2.5.0/rigour/mime/types.py +71 -0
- rigour-2.5.0/rigour/names/__init__.py +68 -0
- rigour-2.5.0/rigour/names/analyze.py +139 -0
- rigour-2.5.0/rigour/names/check.py +133 -0
- rigour-2.5.0/rigour/names/compare.py +34 -0
- rigour-2.5.0/rigour/names/name.py +24 -0
- rigour-2.5.0/rigour/names/ordering.py +13 -0
- rigour-2.5.0/rigour/names/org_types.py +191 -0
- rigour-2.5.0/rigour/names/part.py +23 -0
- rigour-2.5.0/rigour/names/pick.py +158 -0
- rigour-2.5.0/rigour/names/prefix.py +82 -0
- rigour-2.5.0/rigour/names/split_phrases.py +33 -0
- rigour-2.5.0/rigour/names/symbol.py +27 -0
- rigour-2.5.0/rigour/names/tag.py +87 -0
- rigour-2.5.0/rigour/names/tokenize.py +59 -0
- rigour-2.5.0/rigour/reset.py +48 -0
- rigour-2.5.0/rigour/territories/__init__.py +83 -0
- rigour-2.5.0/rigour/territories/lookup.py +172 -0
- rigour-2.5.0/rigour/territories/match.py +39 -0
- rigour-2.5.0/rigour/territories/territory.py +202 -0
- rigour-2.5.0/rigour/territories/util.py +58 -0
- rigour-2.5.0/rigour/text/__init__.py +25 -0
- rigour-2.5.0/rigour/text/checksum.py +21 -0
- rigour-2.5.0/rigour/text/cleaning.py +78 -0
- rigour-2.5.0/rigour/text/distance.py +115 -0
- rigour-2.5.0/rigour/text/normalize.py +247 -0
- rigour-2.5.0/rigour/text/phonetics.py +28 -0
- rigour-2.5.0/rigour/text/scripts.py +170 -0
- rigour-2.5.0/rigour/text/stopwords.py +155 -0
- rigour-2.5.0/rigour/text/translit.py +17 -0
- rigour-2.5.0/rigour/time.py +91 -0
- rigour-2.5.0/rigour/units.py +157 -0
- rigour-2.5.0/rigour/urls/__init__.py +5 -0
- rigour-2.5.0/rigour/urls/cleaning.py +119 -0
- rigour-2.5.0/rigour/urls/util.py +7 -0
- rigour-2.5.0/rigour/util.py +43 -0
- rigour-2.5.0/rust/Cargo.lock +1148 -0
- rigour-2.5.0/rust/Cargo.toml +84 -0
- rigour-2.5.0/rust/build.rs +76 -0
- rigour-2.5.0/rust/data/addresses/forms.json +838 -0
- rigour-2.5.0/rust/data/names/compare.json +108 -0
- rigour-2.5.0/rust/data/names/org_types.json +4698 -0
- rigour-2.5.0/rust/data/names/person_names.txt +157298 -0
- rigour-2.5.0/rust/data/names/stopwords.json +200 -0
- rigour-2.5.0/rust/data/names/symbols.json +4108 -0
- rigour-2.5.0/rust/data/territories/data.jsonl +619 -0
- rigour-2.5.0/rust/data/text/ordinals.json +5379 -0
- rigour-2.5.0/rust/data/text/stopwords.json +236 -0
- rigour-2.5.0/rust/src/addresses/analyze.rs +338 -0
- rigour-2.5.0/rust/src/addresses/compare.rs +504 -0
- rigour-2.5.0/rust/src/addresses/fingerprint.rs +123 -0
- rigour-2.5.0/rust/src/addresses/mod.rs +9 -0
- rigour-2.5.0/rust/src/addresses/tagger.rs +281 -0
- rigour-2.5.0/rust/src/addresses/token.rs +116 -0
- rigour-2.5.0/rust/src/constants.rs +7 -0
- rigour-2.5.0/rust/src/generated/.gitkeep +0 -0
- rigour-2.5.0/rust/src/lib.rs +367 -0
- rigour-2.5.0/rust/src/names/alignment.rs +239 -0
- rigour-2.5.0/rust/src/names/analyze.rs +441 -0
- rigour-2.5.0/rust/src/names/compare.rs +888 -0
- rigour-2.5.0/rust/src/names/constants.rs +23 -0
- rigour-2.5.0/rust/src/names/mod.rs +27 -0
- rigour-2.5.0/rust/src/names/name.rs +528 -0
- rigour-2.5.0/rust/src/names/ordering.rs +393 -0
- rigour-2.5.0/rust/src/names/org_types.rs +623 -0
- rigour-2.5.0/rust/src/names/pairing.rs +1113 -0
- rigour-2.5.0/rust/src/names/part.rs +413 -0
- rigour-2.5.0/rust/src/names/person_names.rs +74 -0
- rigour-2.5.0/rust/src/names/pick.rs +626 -0
- rigour-2.5.0/rust/src/names/prefix.rs +91 -0
- rigour-2.5.0/rust/src/names/stopwords.rs +61 -0
- rigour-2.5.0/rust/src/names/symbol.rs +284 -0
- rigour-2.5.0/rust/src/names/symbols.rs +56 -0
- rigour-2.5.0/rust/src/names/tag.rs +348 -0
- rigour-2.5.0/rust/src/names/tagger.rs +422 -0
- rigour-2.5.0/rust/src/territories.rs +95 -0
- rigour-2.5.0/rust/src/text/distance.rs +210 -0
- rigour-2.5.0/rust/src/text/matcher.rs +315 -0
- rigour-2.5.0/rust/src/text/mod.rs +13 -0
- rigour-2.5.0/rust/src/text/normalize.rs +633 -0
- rigour-2.5.0/rust/src/text/numbers.rs +397 -0
- rigour-2.5.0/rust/src/text/ordinals.rs +55 -0
- rigour-2.5.0/rust/src/text/phonetics.rs +70 -0
- rigour-2.5.0/rust/src/text/scripts.rs +193 -0
- rigour-2.5.0/rust/src/text/stopwords.rs +53 -0
- rigour-2.5.0/rust/src/text/tokenize.rs +371 -0
- rigour-2.5.0/rust/src/text/translit.rs +566 -0
- rigour-0.3.2/MANIFEST.in +0 -4
- rigour-0.3.2/PKG-INFO +0 -23
- rigour-0.3.2/README.md +0 -3
- rigour-0.3.2/rigour/env.py +0 -13
- rigour-0.3.2/rigour/ids/__init__.py +0 -75
- rigour-0.3.2/rigour/ids/common.py +0 -63
- rigour-0.3.2/rigour/ids/ogrn.py +0 -27
- rigour-0.3.2/rigour/ids/stdnum_.py +0 -84
- rigour-0.3.2/rigour/text/script_data.py +0 -660
- rigour-0.3.2/rigour/text/scripts.py +0 -60
- rigour-0.3.2/rigour/time.py +0 -11
- rigour-0.3.2/rigour/urls/__init__.py +0 -5
- rigour-0.3.2/rigour/urls/cleaning.py +0 -68
- rigour-0.3.2/rigour/urls/util.py +0 -6
- rigour-0.3.2/rigour.egg-info/PKG-INFO +0 -23
- rigour-0.3.2/rigour.egg-info/SOURCES.txt +0 -31
- rigour-0.3.2/rigour.egg-info/dependency_links.txt +0 -1
- rigour-0.3.2/rigour.egg-info/entry_points.txt +0 -3
- rigour-0.3.2/rigour.egg-info/namespace_packages.txt +0 -1
- rigour-0.3.2/rigour.egg-info/not-zip-safe +0 -1
- rigour-0.3.2/rigour.egg-info/requires.txt +0 -21
- rigour-0.3.2/rigour.egg-info/top_level.txt +0 -2
- rigour-0.3.2/setup.cfg +0 -11
- rigour-0.3.2/setup.py +0 -63
- {rigour-0.3.2 → rigour-2.5.0}/rigour/__init__.py +0 -0
- {rigour-0.3.2/rigour/text → rigour-2.5.0/rigour/data/addresses}/__init__.py +0 -0
- /rigour-0.3.2/rigour/py.typed → /rigour-2.5.0/rigour/data/langs/__init__.py +0 -0
- /rigour-0.3.2/rigour/util.py → /rigour-2.5.0/rigour/py.typed +0 -0
- {rigour-0.3.2 → rigour-2.5.0}/rigour/urls/compare.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023 OpenSanctions Datenbanken GmbH
|
|
3
|
+
Copyright (c) 2023-2025: OpenSanctions Datenbanken GmbH
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
rigour-2.5.0/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rigour
|
|
3
|
+
Version: 2.5.0
|
|
4
|
+
Classifier: Intended Audience :: Developers
|
|
5
|
+
Classifier: Operating System :: OS Independent
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Programming Language :: Rust
|
|
13
|
+
Requires-Dist: pyyaml>=5.0.0,<7.0.0
|
|
14
|
+
Requires-Dist: normality>=3.0.1,<4.0.0
|
|
15
|
+
Requires-Dist: prefixdate>=0.5.0,<1.0.0
|
|
16
|
+
Requires-Dist: orjson>=3.0.0,<4.0.0
|
|
17
|
+
Requires-Dist: python-stdnum>=2.0,<3.0.0
|
|
18
|
+
Requires-Dist: jinja2>=3.1.0,<4.0.0
|
|
19
|
+
Requires-Dist: pip>=10.0.0 ; extra == 'dev'
|
|
20
|
+
Requires-Dist: bump2version ; extra == 'dev'
|
|
21
|
+
Requires-Dist: wheel>=0.29.0 ; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruamel-yaml ; extra == 'dev'
|
|
23
|
+
Requires-Dist: ruff>=0.16.0,<0.17.0 ; extra == 'dev'
|
|
24
|
+
Requires-Dist: build ; extra == 'dev'
|
|
25
|
+
Requires-Dist: twine ; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy ; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
29
|
+
Requires-Dist: types-pyyaml ; extra == 'dev'
|
|
30
|
+
Requires-Dist: types-setuptools ; extra == 'dev'
|
|
31
|
+
Requires-Dist: coverage>=4.1 ; extra == 'dev'
|
|
32
|
+
Requires-Dist: pillow ; extra == 'docs'
|
|
33
|
+
Requires-Dist: cairosvg ; extra == 'docs'
|
|
34
|
+
Requires-Dist: mkdocs ; extra == 'docs'
|
|
35
|
+
Requires-Dist: mkdocstrings[python] ; extra == 'docs'
|
|
36
|
+
Requires-Dist: mkdocs-material ; extra == 'docs'
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Provides-Extra: docs
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Summary: Financial crime domain data validation and normalization library.
|
|
41
|
+
Author-email: OpenSanctions <info@opensanctions.org>
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
44
|
+
Project-URL: Documentation, https://rigour.followthemoney.tech/
|
|
45
|
+
Project-URL: Issues, https://github.com/opensanctions/rigour/issues
|
|
46
|
+
Project-URL: Repository, https://github.com/opensanctions/rigour.git
|
|
47
|
+
|
|
48
|
+
# rigour
|
|
49
|
+
|
|
50
|
+
Data cleaning and validation functions for processing various types of text emanating and describing the business world. This applies to human and company names, language, territory
|
|
51
|
+
and country codes, corporate and tax identifiers, etc.
|
|
52
|
+
|
|
53
|
+
The underlying idea is that handling these sorts of descriptors is easy on first glance, but reveals a dizzying set of complexity when carried into production. This is why `rigour` consolidates implementations that have already met some edge cases and are well-tested.
|
|
54
|
+
|
|
55
|
+
## Installing `rigour`
|
|
56
|
+
|
|
57
|
+
You can grab the latest release from PyPI:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -U rigour
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage & documentation
|
|
64
|
+
|
|
65
|
+
See: https://rigour.followthemoney.tech/
|
|
66
|
+
|
|
67
|
+
## Acknowledgements
|
|
68
|
+
|
|
69
|
+
The address formatting database contained in `rigour/data/addresses/formats.yml` is derived from `worldwide.yml` in the [OpenCageData address-formatting repository](https://github.com/OpenCageData/address-formatting). It is used to format addresses according to customs in the country that is been encoded.
|
|
70
|
+
|
|
71
|
+
`rigour` consolidates and includes a set of older Python libraries into a single codebase: `languagecodes`, `pantomime`, `fingerprints`. The development of these libraries was funded by OCCRP as part of the Aleph software project.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT. See `LICENSE`.
|
rigour-2.5.0/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# rigour
|
|
2
|
+
|
|
3
|
+
Data cleaning and validation functions for processing various types of text emanating and describing the business world. This applies to human and company names, language, territory
|
|
4
|
+
and country codes, corporate and tax identifiers, etc.
|
|
5
|
+
|
|
6
|
+
The underlying idea is that handling these sorts of descriptors is easy on first glance, but reveals a dizzying set of complexity when carried into production. This is why `rigour` consolidates implementations that have already met some edge cases and are well-tested.
|
|
7
|
+
|
|
8
|
+
## Installing `rigour`
|
|
9
|
+
|
|
10
|
+
You can grab the latest release from PyPI:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install -U rigour
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage & documentation
|
|
17
|
+
|
|
18
|
+
See: https://rigour.followthemoney.tech/
|
|
19
|
+
|
|
20
|
+
## Acknowledgements
|
|
21
|
+
|
|
22
|
+
The address formatting database contained in `rigour/data/addresses/formats.yml` is derived from `worldwide.yml` in the [OpenCageData address-formatting repository](https://github.com/OpenCageData/address-formatting). It is used to format addresses according to customs in the country that is been encoded.
|
|
23
|
+
|
|
24
|
+
`rigour` consolidates and includes a set of older Python libraries into a single codebase: `languagecodes`, `pantomime`, `fingerprints`. The development of these libraries was funded by OCCRP as part of the Aleph software project.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.13,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rigour"
|
|
7
|
+
version = "2.5.0"
|
|
8
|
+
description = "Financial crime domain data validation and normalization library."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [{ name = "OpenSanctions", email = "info@opensanctions.org" }]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Programming Language :: Rust",
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">= 3.10"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"pyyaml >= 5.0.0, < 7.0.0",
|
|
26
|
+
"normality >= 3.0.1, < 4.0.0",
|
|
27
|
+
"prefixdate >= 0.5.0, < 1.0.0",
|
|
28
|
+
"orjson >= 3.0.0, < 4.0.0",
|
|
29
|
+
"python-stdnum >= 2.0, < 3.0.0",
|
|
30
|
+
"jinja2 >= 3.1.0, < 4.0.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Documentation = "https://rigour.followthemoney.tech/"
|
|
35
|
+
Repository = "https://github.com/opensanctions/rigour.git"
|
|
36
|
+
Issues = "https://github.com/opensanctions/rigour/issues"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = [
|
|
40
|
+
"pip>=10.0.0",
|
|
41
|
+
"bump2version",
|
|
42
|
+
"wheel>=0.29.0",
|
|
43
|
+
"ruamel.yaml",
|
|
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",
|
|
49
|
+
"build",
|
|
50
|
+
"twine",
|
|
51
|
+
"mypy",
|
|
52
|
+
"pytest",
|
|
53
|
+
"pytest-cov",
|
|
54
|
+
"types-PyYAML",
|
|
55
|
+
"types-setuptools",
|
|
56
|
+
"coverage>=4.1",
|
|
57
|
+
]
|
|
58
|
+
docs = [
|
|
59
|
+
"pillow",
|
|
60
|
+
"cairosvg",
|
|
61
|
+
"mkdocs",
|
|
62
|
+
"mkdocstrings[python]",
|
|
63
|
+
"mkdocs-material",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.maturin]
|
|
67
|
+
# pyo3/generate-import-lib lets the Windows wheel job link without a
|
|
68
|
+
# real Python install (PyO3 generates a stub import library).
|
|
69
|
+
features = ["pyo3/extension-module", "pyo3/generate-import-lib", "python"]
|
|
70
|
+
module-name = "rigour._core"
|
|
71
|
+
manifest-path = "rust/Cargo.toml"
|
|
72
|
+
# `rigour/` is the Python package directory, sitting at the repo root. Maturin
|
|
73
|
+
# picks it up automatically; no `python-source` override needed.
|
|
74
|
+
include = [
|
|
75
|
+
{ path = "rigour/py.typed", format = "sdist" },
|
|
76
|
+
{ path = "rigour/_core.pyi", format = "sdist" },
|
|
77
|
+
]
|
|
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
|
+
|
|
91
|
+
[tool.coverage.run]
|
|
92
|
+
branch = true
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
def metaphone(token: str) -> str: ...
|
|
2
|
+
def soundex(token: str) -> str: ...
|
|
3
|
+
def codepoint_script(cp: int) -> str | None: ...
|
|
4
|
+
def text_scripts(text: str) -> set[str]: ...
|
|
5
|
+
def common_scripts(a: str, b: str) -> set[str]: ...
|
|
6
|
+
def should_ascii(text: str) -> bool: ...
|
|
7
|
+
def maybe_ascii(text: str, drop: bool = False) -> str: ...
|
|
8
|
+
def tokenize_name(text: str, token_min_length: int = 1) -> list[str]: ...
|
|
9
|
+
def _normalize(text: str, flags: int, cleanup: int) -> str | None: ...
|
|
10
|
+
def raw_levenshtein(a: str, b: str) -> int: ...
|
|
11
|
+
def raw_levenshtein_cutoff(a: str, b: str, cutoff: int) -> int: ...
|
|
12
|
+
def raw_jaro(a: str, b: str) -> float: ...
|
|
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 match_addresses(queries: list[str], results: list[str]) -> AddressMatch | None: ...
|
|
17
|
+
def address_fingerprint(text: str) -> str | None: ...
|
|
18
|
+
def pick_name(names: list[str]) -> str | None: ...
|
|
19
|
+
def pick_case(names: list[str]) -> str | None: ...
|
|
20
|
+
def reduce_names(names: list[str]) -> list[str]: ...
|
|
21
|
+
def replace_org_types_compare(text: str, flags: int, cleanup: int, generic: bool) -> str: ...
|
|
22
|
+
def replace_org_types_display(text: str, flags: int, cleanup: int) -> str: ...
|
|
23
|
+
def remove_org_types(text: str, flags: int, cleanup: int, replacement: str) -> str: ...
|
|
24
|
+
def extract_org_types(
|
|
25
|
+
text: str, flags: int, cleanup: int, generic: bool
|
|
26
|
+
) -> list[tuple[str, str]]: ...
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Resource accessors — plain data returners read once at import time
|
|
30
|
+
# by Python consumers.
|
|
31
|
+
def stopwords_list() -> list[str]: ...
|
|
32
|
+
def nullwords_list() -> list[str]: ...
|
|
33
|
+
def nullplaces_list() -> list[str]: ...
|
|
34
|
+
def person_name_prefixes_list() -> list[str]: ...
|
|
35
|
+
def org_name_prefixes_list() -> list[str]: ...
|
|
36
|
+
def obj_name_prefixes_list() -> list[str]: ...
|
|
37
|
+
def name_split_phrases_list() -> list[str]: ...
|
|
38
|
+
def generic_person_names_list() -> list[str]: ...
|
|
39
|
+
def ordinals_dict() -> dict[int, list[str]]: ...
|
|
40
|
+
def territories_jsonl() -> str: ...
|
|
41
|
+
|
|
42
|
+
MAX_NAME_LENGTH: int
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class AddressMatch:
|
|
46
|
+
"""The best pair out of a list×list address comparison, with the
|
|
47
|
+
evidence that produced it. Frozen; all attributes are read-only.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
score: float
|
|
51
|
+
"""Similarity of the winning pair in [0.0, 1.0]."""
|
|
52
|
+
query: str
|
|
53
|
+
"""Query-side address of the winning pair, as supplied."""
|
|
54
|
+
result: str
|
|
55
|
+
"""Result-side address of the winning pair, as supplied."""
|
|
56
|
+
detail: str
|
|
57
|
+
"""One-line alignment summary over comparable token forms:
|
|
58
|
+
aligned tokens in query order (`berlin` when identical,
|
|
59
|
+
`boulevard~blvd` when aligned by edit distance or class
|
|
60
|
+
equivalence), then `-tok` for query-only and `+tok` for
|
|
61
|
+
result-only tokens."""
|
|
62
|
+
|
|
63
|
+
def __repr__(self) -> str: ...
|
|
64
|
+
|
|
65
|
+
class SymbolCategory:
|
|
66
|
+
"""Sealed enum of symbol categories. See
|
|
67
|
+
[rigour.text.normalize][] for related flag-based design.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
ORG_CLASS: SymbolCategory
|
|
71
|
+
SYMBOL: SymbolCategory
|
|
72
|
+
DOMAIN: SymbolCategory
|
|
73
|
+
INITIAL: SymbolCategory
|
|
74
|
+
NAME: SymbolCategory
|
|
75
|
+
NICK: SymbolCategory
|
|
76
|
+
NUMERIC: SymbolCategory
|
|
77
|
+
LOCATION: SymbolCategory
|
|
78
|
+
PHONETIC: SymbolCategory
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def value(self) -> str:
|
|
82
|
+
"""Short serialisation key (e.g. ``"ORGCLS"``, ``"NUM"``)."""
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Symbol:
|
|
86
|
+
"""A semantic interpretation applied to one or more parts of a name.
|
|
87
|
+
|
|
88
|
+
Rust-backed struct holding a category and an interned string id.
|
|
89
|
+
Equal Symbols share one underlying `Arc<str>` allocation.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
# `Category` is re-exported from rigour/names/symbol.py as an
|
|
93
|
+
# alias for `SymbolCategory` — preserves the pre-port nested-
|
|
94
|
+
# class access pattern `Symbol.Category.ORG_CLASS`. Declared here
|
|
95
|
+
# so mypy knows about it.
|
|
96
|
+
Category: type[SymbolCategory]
|
|
97
|
+
|
|
98
|
+
category: SymbolCategory
|
|
99
|
+
|
|
100
|
+
def __init__(self, category: SymbolCategory, id: str | int) -> None:
|
|
101
|
+
"""`id` is decimal-stringified if passed as int."""
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def id(self) -> str:
|
|
105
|
+
"""The interned id string."""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class NameTypeTag:
|
|
109
|
+
"""Metadata on what sort of object is described by a name."""
|
|
110
|
+
|
|
111
|
+
UNK: NameTypeTag
|
|
112
|
+
ENT: NameTypeTag
|
|
113
|
+
PER: NameTypeTag
|
|
114
|
+
ORG: NameTypeTag
|
|
115
|
+
OBJ: NameTypeTag
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def value(self) -> str: ...
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class NamePartTag:
|
|
122
|
+
"""Within a name, identify name-part types."""
|
|
123
|
+
|
|
124
|
+
UNSET: NamePartTag
|
|
125
|
+
AMBIGUOUS: NamePartTag
|
|
126
|
+
TITLE: NamePartTag
|
|
127
|
+
GIVEN: NamePartTag
|
|
128
|
+
MIDDLE: NamePartTag
|
|
129
|
+
FAMILY: NamePartTag
|
|
130
|
+
TRIBAL: NamePartTag
|
|
131
|
+
PATRONYMIC: NamePartTag
|
|
132
|
+
MATRONYMIC: NamePartTag
|
|
133
|
+
HONORIFIC: NamePartTag
|
|
134
|
+
SUFFIX: NamePartTag
|
|
135
|
+
NICK: NamePartTag
|
|
136
|
+
STOP: NamePartTag
|
|
137
|
+
NUM: NamePartTag
|
|
138
|
+
LEGAL: NamePartTag
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def value(self) -> str: ...
|
|
142
|
+
|
|
143
|
+
def can_match(self, other: NamePartTag) -> bool: ...
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class NamePart:
|
|
147
|
+
"""A tagged component of a name. See rigour/names/part.py."""
|
|
148
|
+
|
|
149
|
+
form: str
|
|
150
|
+
index: int
|
|
151
|
+
tag: NamePartTag
|
|
152
|
+
latinize: bool
|
|
153
|
+
numeric: bool
|
|
154
|
+
ascii: str | None
|
|
155
|
+
integer: int | None
|
|
156
|
+
comparable: str
|
|
157
|
+
metaphone: str | None
|
|
158
|
+
|
|
159
|
+
def __init__(
|
|
160
|
+
self,
|
|
161
|
+
form: str,
|
|
162
|
+
index: int,
|
|
163
|
+
tag: NamePartTag = ...,
|
|
164
|
+
phonetics: bool = True,
|
|
165
|
+
) -> None: ...
|
|
166
|
+
|
|
167
|
+
def __len__(self) -> int: ...
|
|
168
|
+
|
|
169
|
+
@classmethod
|
|
170
|
+
def tag_sort(cls, parts: list[NamePart]) -> list[NamePart]: ...
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class Span:
|
|
174
|
+
"""A set of parts of a name tagged with a Symbol."""
|
|
175
|
+
|
|
176
|
+
parts: tuple[NamePart, ...]
|
|
177
|
+
symbol: Symbol
|
|
178
|
+
comparable: str
|
|
179
|
+
|
|
180
|
+
def __init__(self, parts: list[NamePart], symbol: Symbol) -> None: ...
|
|
181
|
+
|
|
182
|
+
def __len__(self) -> int: ...
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class Name:
|
|
186
|
+
"""A name — top of the rigour.names object graph."""
|
|
187
|
+
|
|
188
|
+
original: str
|
|
189
|
+
form: str
|
|
190
|
+
tag: NameTypeTag
|
|
191
|
+
parts: tuple[NamePart, ...]
|
|
192
|
+
spans: list[Span]
|
|
193
|
+
comparable: str
|
|
194
|
+
norm_form: str
|
|
195
|
+
|
|
196
|
+
def __init__(
|
|
197
|
+
self,
|
|
198
|
+
original: str,
|
|
199
|
+
form: str | None = None,
|
|
200
|
+
tag: NameTypeTag = ...,
|
|
201
|
+
phonetics: bool = True,
|
|
202
|
+
) -> None: ...
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def symbols(self) -> set[Symbol]: ...
|
|
206
|
+
|
|
207
|
+
def tag_text(
|
|
208
|
+
self, text: str, tag: NamePartTag, max_matches: int = 1
|
|
209
|
+
) -> None: ...
|
|
210
|
+
|
|
211
|
+
def apply_phrase(self, phrase: str, symbol: Symbol) -> None: ...
|
|
212
|
+
|
|
213
|
+
def apply_part(self, part: NamePart, symbol: Symbol) -> None: ...
|
|
214
|
+
|
|
215
|
+
def contains(self, other: Name) -> bool: ...
|
|
216
|
+
|
|
217
|
+
@classmethod
|
|
218
|
+
def consolidate_names(cls, names: object) -> set[Name]: ...
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def analyze_names(
|
|
222
|
+
type_tag: NameTypeTag,
|
|
223
|
+
names: list[str],
|
|
224
|
+
part_tags: dict[NamePartTag, list[str]] | None = None,
|
|
225
|
+
*,
|
|
226
|
+
infer_initials: bool = False,
|
|
227
|
+
symbols: bool = True,
|
|
228
|
+
phonetics: bool = True,
|
|
229
|
+
numerics: bool = True,
|
|
230
|
+
consolidate: bool = True,
|
|
231
|
+
rewrite: bool = True,
|
|
232
|
+
) -> set[Name]: ...
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def align_person_name_order(
|
|
236
|
+
left: list[NamePart],
|
|
237
|
+
right: list[NamePart],
|
|
238
|
+
) -> tuple[list[NamePart], list[NamePart]]: ...
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class Alignment:
|
|
242
|
+
"""One unit of name-comparison evidence.
|
|
243
|
+
|
|
244
|
+
Three modes:
|
|
245
|
+
|
|
246
|
+
- **Symbol-paired edge** — `symbol` is set; both sides carry
|
|
247
|
+
the same `Symbol`. Returned by `pair_symbols`. Default
|
|
248
|
+
`score` is `1.0`; consumers may override with a category
|
|
249
|
+
default (e.g. `SYM_SCORES[NAME] = 0.9`).
|
|
250
|
+
- **Residue cluster** — `symbol` is `None`, both sides
|
|
251
|
+
non-empty. Returned by `compare_parts` for parts that
|
|
252
|
+
aligned by edit distance.
|
|
253
|
+
- **Extra** — `symbol` is `None`, exactly one side is empty.
|
|
254
|
+
Represents a part that found no counterpart on the other
|
|
255
|
+
side; the matcher applies a side-specific weight.
|
|
256
|
+
|
|
257
|
+
`qps` / `rps` / `symbol` / `qstr` / `rstr` are immutable
|
|
258
|
+
post-construction. `score` and `weight` are mutable so the
|
|
259
|
+
matcher can apply policy passes (literal-equality rescue,
|
|
260
|
+
extras-weight override, family-name boost) in place.
|
|
261
|
+
|
|
262
|
+
`qstr` / `rstr` are the space-joined `comparable` forms of
|
|
263
|
+
each side, precomputed at construction. `__hash__` and
|
|
264
|
+
`__eq__` key on `(symbol, qps, rps)` — `NamePart` already
|
|
265
|
+
hashes by `(index, form)`, so position is preserved. `score`
|
|
266
|
+
and `weight` are not part of identity.
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
qps: tuple[NamePart, ...]
|
|
270
|
+
rps: tuple[NamePart, ...]
|
|
271
|
+
symbol: Symbol | None
|
|
272
|
+
score: float
|
|
273
|
+
weight: float
|
|
274
|
+
qstr: str
|
|
275
|
+
rstr: str
|
|
276
|
+
|
|
277
|
+
def __init__(
|
|
278
|
+
self,
|
|
279
|
+
qps: list[NamePart] | tuple[NamePart, ...],
|
|
280
|
+
rps: list[NamePart] | tuple[NamePart, ...],
|
|
281
|
+
symbol: Symbol | None = None,
|
|
282
|
+
score: float = 0.0,
|
|
283
|
+
weight: float = 1.0,
|
|
284
|
+
) -> None: ...
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def pair_symbols(query: Name, result: Name) -> list[tuple[Alignment, ...]]: ...
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
class CompareConfig:
|
|
291
|
+
"""Tunable cost / budget / clustering scalars for `compare_parts`.
|
|
292
|
+
|
|
293
|
+
Frozen — fields cannot be reassigned after construction. Sweep
|
|
294
|
+
scripts build a fresh instance per iteration; matchers cache one
|
|
295
|
+
per request.
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
cost_sep_drop: float
|
|
299
|
+
cost_confusable: float
|
|
300
|
+
cost_digit: float
|
|
301
|
+
budget_log_base: float
|
|
302
|
+
budget_short_floor: float
|
|
303
|
+
budget_tolerance: float
|
|
304
|
+
cluster_overlap_min: float
|
|
305
|
+
|
|
306
|
+
def __init__(
|
|
307
|
+
self,
|
|
308
|
+
cost_sep_drop: float = 0.2,
|
|
309
|
+
cost_confusable: float = 0.7,
|
|
310
|
+
cost_digit: float = 1.5,
|
|
311
|
+
budget_log_base: float = 2.35,
|
|
312
|
+
budget_short_floor: float = 2.0,
|
|
313
|
+
budget_tolerance: float = 1.0,
|
|
314
|
+
cluster_overlap_min: float = 0.51,
|
|
315
|
+
) -> None: ...
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def compare_parts(
|
|
319
|
+
qry: list[NamePart],
|
|
320
|
+
res: list[NamePart],
|
|
321
|
+
config: CompareConfig | None = None,
|
|
322
|
+
) -> list[Alignment]: ...
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a set of tools for handling postal/geographic addresses. It includes functions
|
|
3
|
+
for comparing addresses, normalising them, and for formatting addresses given in parts for
|
|
4
|
+
display as a single string.
|
|
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, match_addresses
|
|
13
|
+
|
|
14
|
+
score = compare_address("Bahnhofstr. 10, Augsburg", "Bahnhofstrasse 10, 86150 Augsburg")
|
|
15
|
+
match = match_addresses(
|
|
16
|
+
["Bahnhofstrasse 10, Augsburg"],
|
|
17
|
+
["Bahnhofstrase 10, 86150 Augsburg", "P.O. Box 71, Augsburg"],
|
|
18
|
+
)
|
|
19
|
+
# match.result == "Bahnhofstrase 10, 86150 Augsburg"
|
|
20
|
+
# match.detail == "bahnhofstrasse~bahnhofstrase 10 augsburg +86150"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
[compare_address_many][rigour.addresses.compare.compare_address_many]
|
|
24
|
+
is the same pairing returning only the score.
|
|
25
|
+
|
|
26
|
+
The comparison runs in native code over analyzed tokens — see
|
|
27
|
+
[compare_address][rigour.addresses.compare.compare_address] for the
|
|
28
|
+
mechanics and score semantics.
|
|
29
|
+
|
|
30
|
+
The same analysis backs a keying surface: use
|
|
31
|
+
[address_fingerprint][rigour.addresses.compare.address_fingerprint]
|
|
32
|
+
to reduce equivalent renderings of an address to one deterministic
|
|
33
|
+
string for deduplication or graph node identity:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from rigour.addresses import address_fingerprint
|
|
37
|
+
|
|
38
|
+
key = address_fingerprint("Main Boulevard 5, Syrian Arab Republic")
|
|
39
|
+
# "main blvd 5 sy" — same key as for "Main Blvd. 5, Syria"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Postal address formatting
|
|
43
|
+
|
|
44
|
+
This set of helpers is designed to help with the processing of real-world
|
|
45
|
+
addresses, including composing an address from individual parts, and cleaning it up.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from rigour.addresses import format_address_line
|
|
49
|
+
|
|
50
|
+
address = {
|
|
51
|
+
"road": "Bahnhofstr.",
|
|
52
|
+
"house_number": "10",
|
|
53
|
+
"postcode": "86150",
|
|
54
|
+
"city": "Augsburg",
|
|
55
|
+
"state": "Bayern",
|
|
56
|
+
"country": "Germany",
|
|
57
|
+
}
|
|
58
|
+
address_text = format_address_line(address, country="DE")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Acknowledgements
|
|
62
|
+
|
|
63
|
+
The address formatting database contained in `rigour/data/addresses/formats.yml` is
|
|
64
|
+
derived from `worldwide.yml` in the [OpenCageData address-formatting
|
|
65
|
+
repository](https://github.com/OpenCageData/address-formatting). It is used to
|
|
66
|
+
format addresses according to customs in the country that is been encoded.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
from rigour.addresses.cleaning import clean_address
|
|
70
|
+
from rigour.addresses.compare import (
|
|
71
|
+
AddressMatch,
|
|
72
|
+
address_fingerprint,
|
|
73
|
+
compare_address,
|
|
74
|
+
compare_address_many,
|
|
75
|
+
match_addresses,
|
|
76
|
+
)
|
|
77
|
+
from rigour.addresses.format import format_address, format_address_line
|
|
78
|
+
from rigour.addresses.normalize import (
|
|
79
|
+
normalize_address,
|
|
80
|
+
remove_address_keywords,
|
|
81
|
+
shorten_address_keywords,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
__all__ = [
|
|
85
|
+
"AddressMatch",
|
|
86
|
+
"address_fingerprint",
|
|
87
|
+
"clean_address",
|
|
88
|
+
"compare_address",
|
|
89
|
+
"compare_address_many",
|
|
90
|
+
"format_address",
|
|
91
|
+
"format_address_line",
|
|
92
|
+
"match_addresses",
|
|
93
|
+
"normalize_address",
|
|
94
|
+
"remove_address_keywords",
|
|
95
|
+
"shorten_address_keywords",
|
|
96
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
REPL = re.compile(r"(\s{2,}|\s,|,{2,}|^[,\s]|[,\s]$)", re.UNICODE)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _sub_match(match: re.Match[str]) -> str:
|
|
7
|
+
text = match.group()
|
|
8
|
+
if len(text) == 1:
|
|
9
|
+
return ""
|
|
10
|
+
if "," in text:
|
|
11
|
+
return ","
|
|
12
|
+
return " "
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def clean_address(full: str) -> str:
|
|
16
|
+
"""Remove common formatting errors from addresses."""
|
|
17
|
+
while True:
|
|
18
|
+
full, count = REPL.subn(_sub_match, full)
|
|
19
|
+
if count == 0:
|
|
20
|
+
break
|
|
21
|
+
return full.strip()
|