entitylinkage 0.1.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 (35) hide show
  1. entitylinkage-0.1.0/.github/workflows/ci.yml +70 -0
  2. entitylinkage-0.1.0/.github/workflows/publish.yml +77 -0
  3. entitylinkage-0.1.0/.gitignore +8 -0
  4. entitylinkage-0.1.0/LICENSE +201 -0
  5. entitylinkage-0.1.0/PKG-INFO +114 -0
  6. entitylinkage-0.1.0/README.md +104 -0
  7. entitylinkage-0.1.0/docs/dogfood/twdisaster.md +24 -0
  8. entitylinkage-0.1.0/docs/superpowers/plans/2026-09-27-entitylinkage-v0.1.0.md +169 -0
  9. entitylinkage-0.1.0/docs/superpowers/specs/2026-09-27-entitylinkage-design.md +198 -0
  10. entitylinkage-0.1.0/examples/ambiguous/entitylinkage.yaml +24 -0
  11. entitylinkage-0.1.0/examples/basic/entitylinkage.yaml +46 -0
  12. entitylinkage-0.1.0/examples/manual-review/entitylinkage.yaml +26 -0
  13. entitylinkage-0.1.0/pyproject.toml +32 -0
  14. entitylinkage-0.1.0/src/entitylinkage/__init__.py +5 -0
  15. entitylinkage-0.1.0/src/entitylinkage/audit.py +26 -0
  16. entitylinkage-0.1.0/src/entitylinkage/cli.py +90 -0
  17. entitylinkage-0.1.0/src/entitylinkage/config.py +412 -0
  18. entitylinkage-0.1.0/src/entitylinkage/errors.py +6 -0
  19. entitylinkage-0.1.0/src/entitylinkage/matcher.py +249 -0
  20. entitylinkage-0.1.0/src/entitylinkage/model.py +143 -0
  21. entitylinkage-0.1.0/src/entitylinkage/normalize.py +20 -0
  22. entitylinkage-0.1.0/src/entitylinkage/output.py +144 -0
  23. entitylinkage-0.1.0/src/entitylinkage/overrides.py +50 -0
  24. entitylinkage-0.1.0/tests/cli/test_cli.py +134 -0
  25. entitylinkage-0.1.0/tests/unit/test_audit.py +41 -0
  26. entitylinkage-0.1.0/tests/unit/test_config.py +276 -0
  27. entitylinkage-0.1.0/tests/unit/test_examples.py +76 -0
  28. entitylinkage-0.1.0/tests/unit/test_matcher.py +324 -0
  29. entitylinkage-0.1.0/tests/unit/test_model.py +112 -0
  30. entitylinkage-0.1.0/tests/unit/test_normalize.py +32 -0
  31. entitylinkage-0.1.0/tests/unit/test_output.py +167 -0
  32. entitylinkage-0.1.0/tests/unit/test_overrides.py +143 -0
  33. entitylinkage-0.1.0/tests/unit/test_package.py +8 -0
  34. entitylinkage-0.1.0/tests/unit/test_publish_workflow.py +56 -0
  35. entitylinkage-0.1.0/uv.lock +167 -0
@@ -0,0 +1,70 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ verify:
13
+ name: Python ${{ matrix.python-version }}
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.11", "3.12", "3.13"]
19
+ steps:
20
+ - name: Check out repository
21
+ uses: actions/checkout@v7
22
+
23
+ - name: Set up Python
24
+ uses: actions/setup-python@v7
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+
28
+ - name: Set up uv
29
+ uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
30
+
31
+ - name: Install locked development dependencies
32
+ run: uv sync --locked --all-groups
33
+
34
+ - name: Lint, format, and test
35
+ run: |
36
+ uv run --locked ruff check .
37
+ uv run --locked ruff format --check .
38
+ uv run --locked pytest
39
+
40
+ - name: Build wheel and source distribution
41
+ run: uv build
42
+
43
+ - name: Install wheel into a clean environment and smoke-test CLI
44
+ shell: bash
45
+ run: |
46
+ set -euo pipefail
47
+ wheel="$(find dist -maxdepth 1 -type f -name '*.whl' -print -quit)"
48
+ test -n "$wheel"
49
+ venv="$RUNNER_TEMP/entitylinkage-wheel"
50
+ uv venv --python "${{ matrix.python-version }}" "$venv"
51
+ uv pip install --python "$venv/bin/python" "$GITHUB_WORKSPACE/$wheel"
52
+ cd "$RUNNER_TEMP"
53
+ app="$venv/bin/entitylinkage"
54
+ "$venv/bin/python" -c 'import entitylinkage, pathlib; location = pathlib.Path(entitylinkage.__file__).resolve(); assert "site-packages" in location.parts, location'
55
+ "$app" validate "$GITHUB_WORKSPACE/examples/basic"
56
+ "$app" inspect source-record-001 "$GITHUB_WORKSPACE/examples/basic"
57
+
58
+ first="$RUNNER_TEMP/linkage-first"
59
+ second="$RUNNER_TEMP/linkage-second"
60
+ "$app" link "$GITHUB_WORKSPACE/examples/basic" --output "$first"
61
+ "$app" link "$GITHUB_WORKSPACE/examples/basic" --output "$second"
62
+ "$venv/bin/python" -c 'import json, pathlib, sys; summary = json.loads(pathlib.Path(sys.argv[1]).read_text(encoding="utf-8")); assert summary["status_counts"] == {"ambiguous": 1, "not_applicable": 1, "resolved": 1, "unresolved": 1}, summary' "$first/summary.json"
63
+ set +e
64
+ "$app" audit "$GITHUB_WORKSPACE/examples/basic"
65
+ audit_status=$?
66
+ set -e
67
+ test "$audit_status" -eq 1
68
+ cmp "$first/linkage.json" "$second/linkage.json"
69
+ cmp "$first/linkage.csv" "$second/linkage.csv"
70
+ cmp "$first/summary.json" "$second/summary.json"
@@ -0,0 +1,77 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ name: Test and build release distributions
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ steps:
17
+ - name: Check out release tag
18
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ with:
20
+ ref: ${{ github.event.release.tag_name }}
21
+
22
+ - name: Set up Python
23
+ uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
24
+ with:
25
+ python-version: "3.13"
26
+
27
+ - name: Set up uv
28
+ uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
29
+
30
+ - name: Verify release tag matches project version
31
+ shell: bash
32
+ run: |
33
+ expected_tag="v$(uv version --short)"
34
+ if [[ "$GITHUB_REF_NAME" != "$expected_tag" ]]; then
35
+ echo "Release tag $GITHUB_REF_NAME does not match package version $expected_tag" >&2
36
+ exit 1
37
+ fi
38
+
39
+ - name: Install locked development dependencies
40
+ run: uv sync --locked --all-groups
41
+
42
+ - name: Lint, format, and test
43
+ run: |
44
+ uv run --locked ruff check .
45
+ uv run --locked ruff format --check .
46
+ uv run --locked pytest
47
+
48
+ - name: Build distributions
49
+ run: uv build
50
+
51
+ - name: Upload release distributions
52
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
53
+ with:
54
+ name: release-dists
55
+ path: dist/
56
+ if-no-files-found: error
57
+ retention-days: 1
58
+
59
+ publish:
60
+ name: Publish release distributions to PyPI
61
+ needs: build
62
+ runs-on: ubuntu-latest
63
+ environment:
64
+ name: pypi
65
+ url: https://pypi.org/p/entitylinkage
66
+ permissions:
67
+ contents: read
68
+ id-token: write
69
+ steps:
70
+ - name: Download release distributions
71
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
72
+ with:
73
+ name: release-dists
74
+ path: dist/
75
+
76
+ - name: Publish package distributions to PyPI
77
+ uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
@@ -0,0 +1,8 @@
1
+ .worktrees/
2
+ .venv/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ dist/
6
+ build/
7
+ __pycache__/
8
+ *.py[cod]
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.5
2
+ Name: entitylinkage
3
+ Version: 0.1.0
4
+ Summary: Conservative, explainable entity linkage for external records
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: pyyaml<7,>=6.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # EntityLinkage
12
+
13
+ EntityLinkage is a small Python library and command-line tool for linking external records to a canonical set of entities. It makes conservative, explainable decisions from configured identity rules and preserves ambiguity and missing data for review.
14
+
15
+ > EntityLinkage was extracted from conservative identity-matching patterns developed for a real-world multi-source data pipeline.
16
+
17
+ ## Decisions stay conservative
18
+
19
+ - **`resolved`** — exactly one candidate remains after all configured constraints.
20
+ - **`ambiguous`** — multiple candidates remain; EntityLinkage does not pick one by score or order.
21
+ - **`unresolved`** — no candidate remains. Reason codes distinguish missing identity information from usable values that matched nothing and from constraints that rejected candidates.
22
+ - **`not_applicable`** — the record is explicitly outside the configured entity scope.
23
+
24
+ Every result includes candidate IDs, stable reason codes, and evidence for candidate rules, constraints, and any reviewed override. A declared alias is evidence supplied by the configuration; the tool does not invent aliases or use fuzzy matching, external services, or machine learning.
25
+
26
+ ## Install and try the examples
27
+
28
+ EntityLinkage requires Python 3.11 or newer. From a source checkout, install the locked development environment with [uv](https://docs.astral.sh/uv/):
29
+
30
+ ```sh
31
+ uv sync --locked
32
+ ```
33
+
34
+ You can also install the package from a checkout with `python -m pip install .`. PyYAML is the only runtime dependency.
35
+
36
+ Validate and link the synthetic basic example:
37
+
38
+ ```sh
39
+ uv run --locked entitylinkage validate examples/basic
40
+ uv run --locked entitylinkage link examples/basic --output ./entitylinkage-output
41
+ uv run --locked entitylinkage inspect source-record-001 examples/basic
42
+ ```
43
+
44
+ `link` writes `linkage.json`, `linkage.csv`, and `summary.json`. It returns success when the reports are written, even when records are ambiguous or unresolved. Use `audit` as a quality gate; it returns exit code 1 when either status occurs:
45
+
46
+ ```sh
47
+ uv run --locked entitylinkage audit examples/basic
48
+ ```
49
+
50
+ The examples under [`examples/`](examples/) use fictional publication and catalog names. They demonstrate alias matching, a year constraint, ambiguity, an unmatched record, an out-of-scope record, and a reviewed manual decision.
51
+
52
+ ## Configuration
53
+
54
+ Each input is a YAML file or a directory containing `entitylinkage.yaml`. The top-level document has `version: 1`, `entities`, `records`, and `matching`, with an optional `overrides` list. See [`examples/basic/entitylinkage.yaml`](examples/basic/entitylinkage.yaml) for a complete example.
55
+
56
+ An entity has a unique `id`, a canonical `name`, optional explicit string `aliases`, and optional flat scalar `attributes`. A record has a unique `id`, an optional `name`, flat `attributes`, and an optional `applicable` flag. Attribute keys are user-defined flat field names. Values may be strings, integers, finite floats, booleans, or null; nested mappings and lists are rejected. Quote date-like strings in YAML so they are not parsed as dates. Empty strings are present values for constraints, while omitted and null attribute values are missing.
57
+
58
+ `matching.normalization` requires `case_fold` and `punctuation` (`preserve`, `remove`, or `space`). Names are normalized with Unicode NFKC, configured punctuation handling, optional case folding, and whitespace collapse. The same settings apply to canonical names, aliases, and record names; normalized record names appear in inspection output.
59
+
60
+ At least one candidate rule is required:
61
+
62
+ - `normalized_name` compares a record name with entity names and declared aliases.
63
+ - `exact_value` compares configured `name` or `attributes.<key>` fields using type-sensitive equality. Empty identity values do not create candidates.
64
+
65
+ Candidate rules are OR-combined: every entity supported by any rule remains a candidate. Constraints are AND-combined and filter each candidate. The `equal` constraint compares fields exactly and requires `missing: ignore` or `missing: reject`. Ignoring a missing value keeps the candidate without treating missing data as match evidence; rejecting it removes the candidate.
66
+
67
+ ## Reviewed overrides
68
+
69
+ Overrides are intended for explicit reviewed decisions. Set `matching.apply_overrides: true` to enable them. A `resolved` override requires a known `entity_id`; a `not_applicable` override omits it. Both require a stable reason code such as `reviewed_identity_match`. Unknown IDs, duplicate override record IDs, invalid reason codes, disabled overrides, and overrides that contradict an input marked not applicable are rejected. When enabled, a valid override takes precedence over automatic matching and its reason appears in the result evidence.
70
+
71
+ ## Python API
72
+
73
+ ```python
74
+ from pathlib import Path
75
+
76
+ from entitylinkage import Linker
77
+ from entitylinkage.config import load_config
78
+
79
+ inputs = load_config(Path("examples/basic"))
80
+ results = Linker(inputs.config).link(inputs.entities, inputs.records)
81
+ for result in results:
82
+ print(result.record_id, result.status, result.entity_id, result.reason_codes)
83
+ ```
84
+
85
+ The core API accepts `Entity`, `Record`, and `LinkageConfig` values directly; configuration loading, file output, and command-line behavior remain separate from matching. `load_config` rejects duplicate YAML keys, unknown schema keys, malformed scalar values, invalid references, and duplicate normalized labels within one entity. Name or alias collisions across different entities are valid and result in ambiguity when both remain candidates.
86
+
87
+ ## Reports and inspection
88
+
89
+ The CLI provides four noninteractive commands:
90
+
91
+ ```text
92
+ entitylinkage validate PATH
93
+ entitylinkage link PATH [--output DIR]
94
+ entitylinkage audit PATH
95
+ entitylinkage inspect RECORD_ID PATH
96
+ ```
97
+
98
+ JSON uses stable key ordering and compact encoding. CSV has the fixed columns `record_id,status,entity_id,candidate_entity_ids,reason_codes,evidence`; structured cells contain canonical JSON and rows end with LF. Reports include the EntityLinkage version and Unicode database version, contain no timestamps or filesystem paths, and are byte-identical for equivalent inputs under the same runtime versions. `inspect` shows the input record, normalized record name, rule evidence, candidate IDs, reasons, and final decision.
99
+
100
+ ## Scope and limitations
101
+
102
+ EntityLinkage performs deterministic exact matching; it does not infer dates, apply domain-specific substitutions, score similarity, or guarantee that declared data is true. Review the evidence and source provenance before using a manual override. Unicode normalization behavior can vary with the runtime's Unicode database version, which is recorded in report metadata.
103
+
104
+ EntityLinkage can produce mapping evidence for tools such as EvidenceMatrix, which analyzes entity-by-source evidence coverage. It does not require or replace EvidenceMatrix. It also does not provide LineageGuard's artifact provenance and chain-of-custody functions.
105
+
106
+ The public TWDisaster files currently include event-source relationships and observations already connected to events. Those mappings are not independent labels for validating a source-to-event resolver, so this project does not claim a TWDisaster dogfood result or copy TWDisaster data. See the [read-only review](docs/dogfood/twdisaster.md).
107
+
108
+ ## Development
109
+
110
+ ```sh
111
+ uv run --locked pytest
112
+ uv run --locked ruff check .
113
+ uv run --locked ruff format --check .
114
+ ```
@@ -0,0 +1,104 @@
1
+ # EntityLinkage
2
+
3
+ EntityLinkage is a small Python library and command-line tool for linking external records to a canonical set of entities. It makes conservative, explainable decisions from configured identity rules and preserves ambiguity and missing data for review.
4
+
5
+ > EntityLinkage was extracted from conservative identity-matching patterns developed for a real-world multi-source data pipeline.
6
+
7
+ ## Decisions stay conservative
8
+
9
+ - **`resolved`** — exactly one candidate remains after all configured constraints.
10
+ - **`ambiguous`** — multiple candidates remain; EntityLinkage does not pick one by score or order.
11
+ - **`unresolved`** — no candidate remains. Reason codes distinguish missing identity information from usable values that matched nothing and from constraints that rejected candidates.
12
+ - **`not_applicable`** — the record is explicitly outside the configured entity scope.
13
+
14
+ Every result includes candidate IDs, stable reason codes, and evidence for candidate rules, constraints, and any reviewed override. A declared alias is evidence supplied by the configuration; the tool does not invent aliases or use fuzzy matching, external services, or machine learning.
15
+
16
+ ## Install and try the examples
17
+
18
+ EntityLinkage requires Python 3.11 or newer. From a source checkout, install the locked development environment with [uv](https://docs.astral.sh/uv/):
19
+
20
+ ```sh
21
+ uv sync --locked
22
+ ```
23
+
24
+ You can also install the package from a checkout with `python -m pip install .`. PyYAML is the only runtime dependency.
25
+
26
+ Validate and link the synthetic basic example:
27
+
28
+ ```sh
29
+ uv run --locked entitylinkage validate examples/basic
30
+ uv run --locked entitylinkage link examples/basic --output ./entitylinkage-output
31
+ uv run --locked entitylinkage inspect source-record-001 examples/basic
32
+ ```
33
+
34
+ `link` writes `linkage.json`, `linkage.csv`, and `summary.json`. It returns success when the reports are written, even when records are ambiguous or unresolved. Use `audit` as a quality gate; it returns exit code 1 when either status occurs:
35
+
36
+ ```sh
37
+ uv run --locked entitylinkage audit examples/basic
38
+ ```
39
+
40
+ The examples under [`examples/`](examples/) use fictional publication and catalog names. They demonstrate alias matching, a year constraint, ambiguity, an unmatched record, an out-of-scope record, and a reviewed manual decision.
41
+
42
+ ## Configuration
43
+
44
+ Each input is a YAML file or a directory containing `entitylinkage.yaml`. The top-level document has `version: 1`, `entities`, `records`, and `matching`, with an optional `overrides` list. See [`examples/basic/entitylinkage.yaml`](examples/basic/entitylinkage.yaml) for a complete example.
45
+
46
+ An entity has a unique `id`, a canonical `name`, optional explicit string `aliases`, and optional flat scalar `attributes`. A record has a unique `id`, an optional `name`, flat `attributes`, and an optional `applicable` flag. Attribute keys are user-defined flat field names. Values may be strings, integers, finite floats, booleans, or null; nested mappings and lists are rejected. Quote date-like strings in YAML so they are not parsed as dates. Empty strings are present values for constraints, while omitted and null attribute values are missing.
47
+
48
+ `matching.normalization` requires `case_fold` and `punctuation` (`preserve`, `remove`, or `space`). Names are normalized with Unicode NFKC, configured punctuation handling, optional case folding, and whitespace collapse. The same settings apply to canonical names, aliases, and record names; normalized record names appear in inspection output.
49
+
50
+ At least one candidate rule is required:
51
+
52
+ - `normalized_name` compares a record name with entity names and declared aliases.
53
+ - `exact_value` compares configured `name` or `attributes.<key>` fields using type-sensitive equality. Empty identity values do not create candidates.
54
+
55
+ Candidate rules are OR-combined: every entity supported by any rule remains a candidate. Constraints are AND-combined and filter each candidate. The `equal` constraint compares fields exactly and requires `missing: ignore` or `missing: reject`. Ignoring a missing value keeps the candidate without treating missing data as match evidence; rejecting it removes the candidate.
56
+
57
+ ## Reviewed overrides
58
+
59
+ Overrides are intended for explicit reviewed decisions. Set `matching.apply_overrides: true` to enable them. A `resolved` override requires a known `entity_id`; a `not_applicable` override omits it. Both require a stable reason code such as `reviewed_identity_match`. Unknown IDs, duplicate override record IDs, invalid reason codes, disabled overrides, and overrides that contradict an input marked not applicable are rejected. When enabled, a valid override takes precedence over automatic matching and its reason appears in the result evidence.
60
+
61
+ ## Python API
62
+
63
+ ```python
64
+ from pathlib import Path
65
+
66
+ from entitylinkage import Linker
67
+ from entitylinkage.config import load_config
68
+
69
+ inputs = load_config(Path("examples/basic"))
70
+ results = Linker(inputs.config).link(inputs.entities, inputs.records)
71
+ for result in results:
72
+ print(result.record_id, result.status, result.entity_id, result.reason_codes)
73
+ ```
74
+
75
+ The core API accepts `Entity`, `Record`, and `LinkageConfig` values directly; configuration loading, file output, and command-line behavior remain separate from matching. `load_config` rejects duplicate YAML keys, unknown schema keys, malformed scalar values, invalid references, and duplicate normalized labels within one entity. Name or alias collisions across different entities are valid and result in ambiguity when both remain candidates.
76
+
77
+ ## Reports and inspection
78
+
79
+ The CLI provides four noninteractive commands:
80
+
81
+ ```text
82
+ entitylinkage validate PATH
83
+ entitylinkage link PATH [--output DIR]
84
+ entitylinkage audit PATH
85
+ entitylinkage inspect RECORD_ID PATH
86
+ ```
87
+
88
+ JSON uses stable key ordering and compact encoding. CSV has the fixed columns `record_id,status,entity_id,candidate_entity_ids,reason_codes,evidence`; structured cells contain canonical JSON and rows end with LF. Reports include the EntityLinkage version and Unicode database version, contain no timestamps or filesystem paths, and are byte-identical for equivalent inputs under the same runtime versions. `inspect` shows the input record, normalized record name, rule evidence, candidate IDs, reasons, and final decision.
89
+
90
+ ## Scope and limitations
91
+
92
+ EntityLinkage performs deterministic exact matching; it does not infer dates, apply domain-specific substitutions, score similarity, or guarantee that declared data is true. Review the evidence and source provenance before using a manual override. Unicode normalization behavior can vary with the runtime's Unicode database version, which is recorded in report metadata.
93
+
94
+ EntityLinkage can produce mapping evidence for tools such as EvidenceMatrix, which analyzes entity-by-source evidence coverage. It does not require or replace EvidenceMatrix. It also does not provide LineageGuard's artifact provenance and chain-of-custody functions.
95
+
96
+ The public TWDisaster files currently include event-source relationships and observations already connected to events. Those mappings are not independent labels for validating a source-to-event resolver, so this project does not claim a TWDisaster dogfood result or copy TWDisaster data. See the [read-only review](docs/dogfood/twdisaster.md).
97
+
98
+ ## Development
99
+
100
+ ```sh
101
+ uv run --locked pytest
102
+ uv run --locked ruff check .
103
+ uv run --locked ruff format --check .
104
+ ```
@@ -0,0 +1,24 @@
1
+ # TWDisaster identity evidence review
2
+
3
+ **Inspected:** 2026-09-28 (read-only)
4
+ **Upstream revision:** [`d600dee84d7e9646395d147722e95c7115f81582`](https://github.com/KageRyo/TWDisaster/commit/d600dee84d7e9646395d147722e95c7115f81582), the `main` tip observed during inspection.
5
+
6
+ ## Public model and files
7
+
8
+ The public data model describes four UTF-8 CSV tables: events, observations, sources, and event-source relationships. At the inspected revision, they contain 76 events, 395 observations, 88 sources, and 89 event-source relationships. Events expose a canonical `name` and `aliases_json`. Sources expose publication metadata including `title` and `url`. Each observation already carries both `event_id` and `source_id`; `event_sources.csv` records source/event pairs that support at least one included observation.
9
+
10
+ This structure does not provide an independent source-specific event label for EntityLinkage to evaluate. The observation rows already join a source to an event, and the event-source table records that same relationship. Treating either as an input crosswalk would reuse the mapping under evaluation. A source can also support more than one event, so a source title is not necessarily a single-entity identity.
11
+
12
+ ## Read-only title comparison
13
+
14
+ As a narrow diagnostic, source titles were compared with event names and declared aliases using NFKC normalization, Unicode case folding, and whitespace collapse. One source title exactly matched a canonical event name or alias; that event/source pair was already present in `event_sources.csv`. A substring scan found 36 source titles containing at least one normalized event name or alias; 32 of the resulting event/source pairs were already in the published relationship table. These are candidate-text observations only: substring containment does not establish identity, and the existing crosswalk cannot serve as independent confirmation.
15
+
16
+ No source rows were copied into this repository, no aliases or mappings were invented, and no private implementation details were inspected. This dataset therefore is not claimed as a TWDisaster dogfood validation. The examples in this project remain fully synthetic. Reassess only if TWDisaster publishes source-specific event identity labels independent of its observation and event-source mappings.
17
+
18
+ ## Sources
19
+
20
+ - [TWDisaster data model](https://github.com/KageRyo/TWDisaster/blob/main/docs/data-model.md)
21
+ - [events.csv](https://github.com/KageRyo/TWDisaster/blob/main/data/events.csv)
22
+ - [observations.csv](https://github.com/KageRyo/TWDisaster/blob/main/data/observations.csv)
23
+ - [sources.csv](https://github.com/KageRyo/TWDisaster/blob/main/data/sources.csv)
24
+ - [event_sources.csv](https://github.com/KageRyo/TWDisaster/blob/main/data/event_sources.csv)