muckrake 0.2.1__py3-none-any.whl

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 (48) hide show
  1. muckrake/__init__.py +61 -0
  2. muckrake/artifacts.py +72 -0
  3. muckrake/cli.py +522 -0
  4. muckrake/crawl.py +223 -0
  5. muckrake/dataset.py +231 -0
  6. muckrake/db.py +478 -0
  7. muckrake/dedupe/README.md +52 -0
  8. muckrake/dedupe/__init__.py +37 -0
  9. muckrake/dedupe/cluster.py +534 -0
  10. muckrake/dedupe/dedupe.py +133 -0
  11. muckrake/dedupe/dedupe_edges.py +214 -0
  12. muckrake/dedupe/review.py +329 -0
  13. muckrake/entity_query.py +114 -0
  14. muckrake/entity_write.py +244 -0
  15. muckrake/env.py +52 -0
  16. muckrake/export.py +40 -0
  17. muckrake/extract/__init__.py +0 -0
  18. muckrake/extract/fetch.py +186 -0
  19. muckrake/extract/ner/README.md +210 -0
  20. muckrake/extract/ner/__init__.py +4 -0
  21. muckrake/extract/ner/engines/__init__.py +32 -0
  22. muckrake/extract/ner/engines/base.py +14 -0
  23. muckrake/extract/ner/engines/delimited.py +39 -0
  24. muckrake/extract/ner/engines/llm.py +164 -0
  25. muckrake/extract/ner/engines/llm_prompt.py +44 -0
  26. muckrake/extract/ner/materialize.py +255 -0
  27. muckrake/extract/ner/pipeline.py +151 -0
  28. muckrake/extract/ner/review.py +706 -0
  29. muckrake/extract/ner/storage.py +200 -0
  30. muckrake/id.py +3 -0
  31. muckrake/load.py +70 -0
  32. muckrake/logging.py +56 -0
  33. muckrake/py.typed +0 -0
  34. muckrake/release.py +356 -0
  35. muckrake/runs.py +228 -0
  36. muckrake/search.py +335 -0
  37. muckrake/serialize.py +119 -0
  38. muckrake/settings.py +41 -0
  39. muckrake/store.py +117 -0
  40. muckrake/util.py +27 -0
  41. muckrake/utils/__init__.py +13 -0
  42. muckrake/utils/dates.py +438 -0
  43. muckrake/utils/gb_coh.py +36 -0
  44. muckrake/view.py +58 -0
  45. muckrake-0.2.1.dist-info/METADATA +136 -0
  46. muckrake-0.2.1.dist-info/RECORD +48 -0
  47. muckrake-0.2.1.dist-info/WHEEL +4 -0
  48. muckrake-0.2.1.dist-info/entry_points.txt +3 -0
muckrake/db.py ADDED
@@ -0,0 +1,478 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from typing import cast
5
+
6
+ from nomenklatura.db import get_engine, get_metadata, make_statement_table
7
+ from nomenklatura.resolver import Identifier, Resolver
8
+ from sqlalchemy import Column, Integer, MetaData, String, Table, Text, inspect, text
9
+ from sqlalchemy.engine import Engine
10
+
11
+ from muckrake.settings import PUBLISHED_SQL_URI, SQL_URI
12
+ from org_id import is_org_id
13
+
14
+ log = logging.getLogger(__name__)
15
+
16
+ # Monkey patch Nomenklatura's Identifier to prioritize org-id.guide IDs.
17
+ # This ensures GB-COH- style IDs win over NK- or Q- IDs during merges.
18
+ _original_identifier_init = Identifier.__init__
19
+
20
+
21
+ def _patched_identifier_init(self, id: str) -> None:
22
+ _original_identifier_init(self, id)
23
+ if is_org_id(id):
24
+ # Weight 1: Hashed/Dataset IDs
25
+ # Weight 2: NK- (Nomenklatura random)
26
+ # Weight 3: Q (Wikidata)
27
+ # Weight 4: Org-IDs (Companies House, etc)
28
+ self.weight = 4
29
+ self.canonical = True
30
+
31
+
32
+ Identifier.__init__ = _patched_identifier_init
33
+
34
+
35
+ def _resolved_metadata(metadata: MetaData | None = None) -> MetaData:
36
+ if metadata is None:
37
+ return cast(MetaData, get_metadata())
38
+ return metadata
39
+
40
+
41
+ def get_ner_candidates_table(metadata: MetaData | None = None) -> Table:
42
+ metadata = _resolved_metadata(metadata)
43
+ return Table(
44
+ "ner_candidates",
45
+ metadata,
46
+ Column("id", Integer(), primary_key=True, autoincrement=True),
47
+ Column("dataset", String(), nullable=False),
48
+ Column("entity_id", String(), nullable=False),
49
+ Column("schema", String(), nullable=False),
50
+ Column("property_name", String(), nullable=False),
51
+ Column("source_text", Text(), nullable=False),
52
+ Column("fingerprint", String(), nullable=False),
53
+ Column("extractor", String(), nullable=False),
54
+ Column("extractor_version", String(), nullable=False),
55
+ Column("status", String(), nullable=False),
56
+ Column("reviewer", String(), nullable=True),
57
+ Column("reviewed_at", String(), nullable=True),
58
+ Column("extraction_json", Text(), nullable=False),
59
+ Column("created_at", String(), nullable=False),
60
+ Column("updated_at", String(), nullable=False),
61
+ extend_existing=True,
62
+ )
63
+
64
+
65
+ def get_dataset_runs_table(metadata: MetaData | None = None) -> Table:
66
+ metadata = _resolved_metadata(metadata)
67
+ return Table(
68
+ "dataset_runs",
69
+ metadata,
70
+ Column("id", Integer(), primary_key=True, autoincrement=True),
71
+ Column("dataset_name", String(), nullable=False),
72
+ Column("run_type", String(), nullable=False),
73
+ Column("status", String(), nullable=False),
74
+ Column("triggered_by", String(), nullable=True),
75
+ Column("code_version", String(), nullable=True),
76
+ Column("config_version", String(), nullable=True),
77
+ Column("run_key", String(), nullable=True),
78
+ Column("error_message", Text(), nullable=True),
79
+ Column("stats_json", Text(), nullable=True),
80
+ Column("started_at", String(), nullable=False),
81
+ Column("finished_at", String(), nullable=True),
82
+ extend_existing=True,
83
+ )
84
+
85
+
86
+ def get_dataset_run_artifacts_table(metadata: MetaData | None = None) -> Table:
87
+ metadata = _resolved_metadata(metadata)
88
+ return Table(
89
+ "dataset_run_artifacts",
90
+ metadata,
91
+ Column("id", Integer(), primary_key=True, autoincrement=True),
92
+ Column("dataset_run_id", Integer(), nullable=False),
93
+ Column("artifact_type", String(), nullable=False),
94
+ Column("storage_backend", String(), nullable=False),
95
+ Column("storage_key", String(), nullable=False),
96
+ Column("content_type", String(), nullable=True),
97
+ Column("sha256", String(), nullable=False),
98
+ Column("size_bytes", Integer(), nullable=False),
99
+ Column("metadata_json", Text(), nullable=True),
100
+ Column("created_at", String(), nullable=False),
101
+ extend_existing=True,
102
+ )
103
+
104
+
105
+ def get_releases_table(metadata: MetaData | None = None) -> Table:
106
+ metadata = _resolved_metadata(metadata)
107
+ return Table(
108
+ "releases",
109
+ metadata,
110
+ Column("id", Integer(), primary_key=True, autoincrement=True),
111
+ Column("status", String(), nullable=False),
112
+ Column("triggered_by", String(), nullable=True),
113
+ Column("code_version", String(), nullable=True),
114
+ Column("notes", Text(), nullable=True),
115
+ Column("error_message", Text(), nullable=True),
116
+ Column("created_at", String(), nullable=False),
117
+ Column("finished_at", String(), nullable=True),
118
+ Column("published_at", String(), nullable=True),
119
+ extend_existing=True,
120
+ )
121
+
122
+
123
+ def get_resolver_lock_table(metadata: MetaData | None = None) -> Table:
124
+ metadata = _resolved_metadata(metadata)
125
+ return Table(
126
+ "resolver_lock",
127
+ metadata,
128
+ Column("pair_key", String(), primary_key=True),
129
+ Column("left_id", String(), nullable=False),
130
+ Column("right_id", String(), nullable=False),
131
+ Column("user_id", String(), nullable=False),
132
+ Column("user_name", String(), nullable=True),
133
+ Column("locked_at", String(), nullable=False),
134
+ Column("expires_at", String(), nullable=False),
135
+ Column("updated_at", String(), nullable=False),
136
+ extend_existing=True,
137
+ )
138
+
139
+
140
+ def get_resolver_cluster_skip_table(metadata: MetaData | None = None) -> Table:
141
+ metadata = _resolved_metadata(metadata)
142
+ return Table(
143
+ "resolver_cluster_skip",
144
+ metadata,
145
+ Column("pair_key", String(), primary_key=True),
146
+ Column("left_id", String(), nullable=False),
147
+ Column("right_id", String(), nullable=False),
148
+ Column("user_id", String(), primary_key=True),
149
+ Column("created_at", String(), nullable=False),
150
+ Column("expires_at", String(), nullable=False),
151
+ extend_existing=True,
152
+ )
153
+
154
+
155
+ def get_release_inputs_table(metadata: MetaData | None = None) -> Table:
156
+ metadata = _resolved_metadata(metadata)
157
+ return Table(
158
+ "release_inputs",
159
+ metadata,
160
+ Column("id", Integer(), primary_key=True, autoincrement=True),
161
+ Column("release_id", Integer(), nullable=False),
162
+ Column("dataset_run_id", Integer(), nullable=False),
163
+ Column("dataset_name", String(), nullable=False),
164
+ extend_existing=True,
165
+ )
166
+
167
+
168
+ def get_release_artifacts_table(metadata: MetaData | None = None) -> Table:
169
+ metadata = _resolved_metadata(metadata)
170
+ return Table(
171
+ "release_artifacts",
172
+ metadata,
173
+ Column("id", Integer(), primary_key=True, autoincrement=True),
174
+ Column("release_id", Integer(), nullable=False),
175
+ Column("artifact_type", String(), nullable=False),
176
+ Column("storage_backend", String(), nullable=False),
177
+ Column("storage_key", String(), nullable=False),
178
+ Column("content_type", String(), nullable=True),
179
+ Column("sha256", String(), nullable=False),
180
+ Column("size_bytes", Integer(), nullable=False),
181
+ Column("metadata_json", Text(), nullable=True),
182
+ Column("created_at", String(), nullable=False),
183
+ extend_existing=True,
184
+ )
185
+
186
+
187
+ def get_resolver(uri: str = SQL_URI, begin: bool = False) -> Resolver:
188
+ """Get the resolver backed by the main database."""
189
+ resolver = Resolver(get_engine(uri), MetaData(), create=True)
190
+ if begin:
191
+ resolver.begin()
192
+ return resolver
193
+
194
+
195
+ def get_database_dialect(uri: str = SQL_URI) -> str:
196
+ return get_engine(uri).dialect.name
197
+
198
+
199
+ def is_postgres_uri(uri: str = SQL_URI) -> bool:
200
+ return get_database_dialect(uri) in ("postgresql", "postgres")
201
+
202
+
203
+ def is_sqlite_uri(uri: str = SQL_URI) -> bool:
204
+ return get_database_dialect(uri) == "sqlite"
205
+
206
+
207
+ def init_database(uri: str = SQL_URI) -> Engine:
208
+ engine = get_engine(uri)
209
+ metadata = MetaData()
210
+ statement_table = make_statement_table(metadata)
211
+ resolver = Resolver(engine, MetaData(), create=True)
212
+ ner_candidates = get_ner_candidates_table(metadata)
213
+ dataset_runs = get_dataset_runs_table(metadata)
214
+ dataset_run_artifacts = get_dataset_run_artifacts_table(metadata)
215
+ releases = get_releases_table(metadata)
216
+ resolver_lock = get_resolver_lock_table(metadata)
217
+ resolver_cluster_skip = get_resolver_cluster_skip_table(metadata)
218
+ release_inputs = get_release_inputs_table(metadata)
219
+ release_artifacts = get_release_artifacts_table(metadata)
220
+
221
+ inspector = inspect(engine)
222
+ for table in [
223
+ statement_table,
224
+ ner_candidates,
225
+ dataset_runs,
226
+ dataset_run_artifacts,
227
+ releases,
228
+ resolver_lock,
229
+ resolver_cluster_skip,
230
+ release_inputs,
231
+ release_artifacts,
232
+ ]:
233
+ if inspector.has_table(table.name):
234
+ continue
235
+ table.create(bind=engine, checkfirst=True)
236
+ _ensure_ner_candidates_constraints(engine)
237
+ _ensure_dataset_run_constraints(engine)
238
+ _ensure_release_constraints(engine)
239
+ _ensure_resolver_lock_constraints(engine)
240
+ _ensure_resolver_cluster_skip_constraints(engine)
241
+ _sync_postgres_sequences(
242
+ engine,
243
+ [
244
+ resolver._table,
245
+ ner_candidates,
246
+ dataset_runs,
247
+ dataset_run_artifacts,
248
+ releases,
249
+ release_inputs,
250
+ release_artifacts,
251
+ ],
252
+ )
253
+ return engine
254
+
255
+
256
+ def ensure_resolver_lock_schema(uri: str = SQL_URI) -> Engine:
257
+ engine = get_engine(uri)
258
+ metadata = MetaData()
259
+ _ = Resolver(engine, metadata, create=True)
260
+ resolver_lock = get_resolver_lock_table(metadata)
261
+ resolver_cluster_skip = get_resolver_cluster_skip_table(metadata)
262
+ metadata.create_all(
263
+ bind=engine,
264
+ tables=[resolver_lock, resolver_cluster_skip],
265
+ checkfirst=True,
266
+ )
267
+ _ensure_resolver_lock_constraints(engine)
268
+ _ensure_resolver_cluster_skip_constraints(engine)
269
+ return engine
270
+
271
+
272
+ def init_published_database(uri: str = PUBLISHED_SQL_URI) -> Engine:
273
+ engine = get_engine(uri)
274
+ metadata = MetaData()
275
+ statement_table = make_statement_table(metadata)
276
+ resolver = Resolver(engine, metadata, create=True)
277
+ if not inspect(engine).has_table(statement_table.name):
278
+ statement_table.create(bind=engine, checkfirst=True)
279
+ _sync_postgres_sequences(engine, [resolver._table])
280
+ return engine
281
+
282
+
283
+ def refresh_postgres_search(uri: str = SQL_URI) -> None:
284
+ if not is_postgres_uri(uri):
285
+ return
286
+
287
+ engine = get_engine(uri)
288
+ with engine.begin() as conn:
289
+ conn.execute(text("CREATE EXTENSION IF NOT EXISTS unaccent"))
290
+ conn.execute(text("CREATE EXTENSION IF NOT EXISTS pg_trgm"))
291
+ conn.execute(text("DROP MATERIALIZED VIEW IF EXISTS entity_search"))
292
+ conn.execute(
293
+ text(
294
+ """
295
+ CREATE MATERIALIZED VIEW entity_search AS
296
+ SELECT
297
+ s.canonical_id AS id,
298
+ MIN(CASE WHEN s.prop = 'name' THEN s.value END) AS display_name,
299
+ MIN(s.schema) AS schema,
300
+ string_agg(DISTINCT s.value, ' ')
301
+ FILTER (WHERE s.prop IN ('name', 'alias', 'previousName', 'weakAlias', 'abbreviation'))
302
+ AS names_text,
303
+ to_tsvector(
304
+ 'simple',
305
+ unaccent(
306
+ COALESCE(
307
+ string_agg(DISTINCT s.value, ' ')
308
+ FILTER (WHERE s.prop IN ('name', 'alias', 'previousName', 'weakAlias', 'abbreviation')),
309
+ ''
310
+ )
311
+ )
312
+ ) AS tsv
313
+ FROM statement AS s
314
+ WHERE s.schema IN ('Company', 'LegalEntity', 'Organization', 'Person', 'PublicBody')
315
+ AND s.canonical_id IS NOT NULL
316
+ GROUP BY s.canonical_id
317
+ """
318
+ )
319
+ )
320
+ conn.execute(
321
+ text(
322
+ "CREATE UNIQUE INDEX IF NOT EXISTS entity_search_id_idx ON entity_search (id)"
323
+ )
324
+ )
325
+ conn.execute(
326
+ text(
327
+ "CREATE INDEX IF NOT EXISTS entity_search_tsv_idx ON entity_search USING GIN (tsv)"
328
+ )
329
+ )
330
+ conn.execute(
331
+ text(
332
+ "CREATE INDEX IF NOT EXISTS entity_search_display_name_trgm_idx "
333
+ "ON entity_search USING GIN (display_name gin_trgm_ops)"
334
+ )
335
+ )
336
+ conn.execute(
337
+ text(
338
+ "CREATE INDEX IF NOT EXISTS entity_search_names_text_trgm_idx "
339
+ "ON entity_search USING GIN (names_text gin_trgm_ops)"
340
+ )
341
+ )
342
+
343
+
344
+ def _ensure_ner_candidates_constraints(engine: Engine) -> None:
345
+ with engine.begin() as conn:
346
+ conn.execute(
347
+ text(
348
+ """
349
+ CREATE UNIQUE INDEX IF NOT EXISTS ner_candidates_unique_key
350
+ ON ner_candidates(
351
+ dataset, entity_id, property_name, fingerprint, extractor, extractor_version
352
+ )
353
+ """
354
+ )
355
+ )
356
+ conn.execute(
357
+ text(
358
+ """
359
+ CREATE INDEX IF NOT EXISTS ner_candidates_lookup
360
+ ON ner_candidates(dataset, status, updated_at)
361
+ """
362
+ )
363
+ )
364
+
365
+
366
+ def _ensure_dataset_run_constraints(engine: Engine) -> None:
367
+ with engine.begin() as conn:
368
+ conn.execute(
369
+ text(
370
+ """
371
+ CREATE INDEX IF NOT EXISTS dataset_runs_lookup
372
+ ON dataset_runs(dataset_name, status, started_at)
373
+ """
374
+ )
375
+ )
376
+ conn.execute(
377
+ text(
378
+ """
379
+ CREATE UNIQUE INDEX IF NOT EXISTS dataset_run_artifacts_unique_key
380
+ ON dataset_run_artifacts(dataset_run_id, artifact_type, storage_key)
381
+ """
382
+ )
383
+ )
384
+
385
+
386
+ def _ensure_release_constraints(engine: Engine) -> None:
387
+ with engine.begin() as conn:
388
+ conn.execute(
389
+ text(
390
+ """
391
+ CREATE INDEX IF NOT EXISTS releases_status_created_at
392
+ ON releases(status, created_at)
393
+ """
394
+ )
395
+ )
396
+ conn.execute(
397
+ text(
398
+ """
399
+ CREATE UNIQUE INDEX IF NOT EXISTS release_inputs_unique_run
400
+ ON release_inputs(release_id, dataset_run_id)
401
+ """
402
+ )
403
+ )
404
+ conn.execute(
405
+ text(
406
+ """
407
+ CREATE UNIQUE INDEX IF NOT EXISTS release_artifacts_unique_key
408
+ ON release_artifacts(release_id, artifact_type, storage_key)
409
+ """
410
+ )
411
+ )
412
+
413
+
414
+ def _ensure_resolver_lock_constraints(engine: Engine) -> None:
415
+ with engine.begin() as conn:
416
+ conn.execute(
417
+ text(
418
+ """
419
+ CREATE INDEX IF NOT EXISTS resolver_lock_user_expires_at
420
+ ON resolver_lock(user_id, expires_at)
421
+ """
422
+ )
423
+ )
424
+ conn.execute(
425
+ text(
426
+ """
427
+ CREATE INDEX IF NOT EXISTS resolver_lock_expires_at
428
+ ON resolver_lock(expires_at)
429
+ """
430
+ )
431
+ )
432
+
433
+
434
+ def _ensure_resolver_cluster_skip_constraints(engine: Engine) -> None:
435
+ with engine.begin() as conn:
436
+ conn.execute(
437
+ text(
438
+ """
439
+ CREATE INDEX IF NOT EXISTS resolver_cluster_skip_user_expires_at
440
+ ON resolver_cluster_skip(user_id, expires_at)
441
+ """
442
+ )
443
+ )
444
+ conn.execute(
445
+ text(
446
+ """
447
+ CREATE INDEX IF NOT EXISTS resolver_cluster_skip_expires_at
448
+ ON resolver_cluster_skip(expires_at)
449
+ """
450
+ )
451
+ )
452
+
453
+
454
+ def _sync_postgres_sequences(engine: Engine, tables: list[Table]) -> None:
455
+ if engine.dialect.name not in ("postgresql", "postgres"):
456
+ return
457
+
458
+ with engine.begin() as conn:
459
+ for table in tables:
460
+ if "id" not in table.c:
461
+ continue
462
+ table_name = table.name
463
+ conn.execute(
464
+ text(
465
+ """
466
+ SELECT setval(
467
+ pg_get_serial_sequence(:table_name, 'id'),
468
+ COALESCE((SELECT MAX(id) FROM """
469
+ + table_name
470
+ + """), 1),
471
+ (SELECT COUNT(*) > 0 FROM """
472
+ + table_name
473
+ + """)
474
+ )
475
+ """
476
+ ),
477
+ {"table_name": table_name},
478
+ )
@@ -0,0 +1,52 @@
1
+ One of the most important features of muckrake is the ability to deduplicate unique legal entities. For example, if we have a record for "BP" from one source and "British Petroleum" from another source, we want to display information about both records on the same page.
2
+
3
+ Muckrake largely relies on the [`nomenklatura`](https://github.com/opensanctions/nomenklatura) library to generate resolver suggestions for pairs of records that may represent the same entity. We run `uv run muckrake xref` to generate these suggestions, which are stored in the `resolver` table in the database. By default, `nomenklatura` comes with a TUI for reviewing these suggestions, with options to approve, reject, or skip each suggestion.
4
+
5
+ We have additionally [implemented](./review.py) a web-based review interface replicating the functionality of the TUI, allowing for this to be done outside of the terminal. One major benefit to this is the deduplication is now available to multiple users at the same time.
6
+
7
+ ## Clusters
8
+
9
+ One of the major limitations of the default `nomenklatura` review model is that it is pairwise. This means that if we have three records A, B, and C, and the resolver generates suggestions for A-B and B-C, but not A-C, we would have to approve both A-B and B-C to get all three records into the same cluster. This can be tedious for large clusters.
10
+
11
+ We have [implemented](./cluster.py) a basic cluster review system that allows reviewers to review whole clusters of records at once. Ultimately, we want to replace the pairwise review system.
12
+
13
+ The current MVP does not implement a full clustering algorithm. Instead, it:
14
+
15
+ 1. takes the next unresolved resolver pair
16
+ 2. looks at the current unresolved suggestion rows returned by `resolver.get_candidates(...)`
17
+ 3. builds a small local connected group around that seed pair
18
+ 4. limits the number of members in the displayed batch
19
+ 5. locks all unresolved resolver pairs whose endpoints are inside that displayed batch
20
+
21
+ When the user submits the form:
22
+
23
+ - `Match` records positive judgements on locked resolver pairs where both endpoints are selected
24
+ - `No match` records negative judgements on locked resolver pairs where both endpoints are selected
25
+ - `Unsure` records unsure judgements on locked resolver pairs where both endpoints are selected
26
+ - unchecked records remain unresolved
27
+ - `Skip` hides the cluster for that reviewer for a short TTL
28
+
29
+ Unlike the pairwise review, cluster actions only write judgements for locked suggestion edges that are inside the selected subset.
30
+
31
+ Users can also skip clusters. There is a small locking mechanism that hides skipped clusters for a TTL period. The skip list is per-user, not global. `resolver_lock` is still used for concurrency control.
32
+
33
+ ### Dedupe-style review
34
+
35
+ Beyond the current implementation, there are a few other approaches that could work.
36
+
37
+ [Dedupe](https://docs.dedupe.io/en/latest/index.html) is a popular Python library for deduplication, I've used it for a few projects in the past. It also generates pairwise suggestions. They used to have a web review UI that is no longer available, but [recordings of it still exist](https://youtu.be/9wEA90Fz-lU?si=y4UHS4Ky7yVygJWg&t=689). In these recordings, users are able to review clusters and check which records belong together. [According to their docs](https://docs.dedupe.io/en/latest/how-it-works/Grouping-duplicates.html), they found that **hierarchical clustering with centroid linkage** gave the best results. [The relevant code is here](https://github.com/dedupeio/dedupe/blob/main/dedupe/clustering.py).
38
+
39
+ We should explore this approach in the future.
40
+
41
+ ### Next steps
42
+
43
+ The next improvement I would make is better cluster construction before adding more actions.
44
+
45
+ Good next options:
46
+
47
+ - score thresholding before expansion
48
+ - schema-aware grouping
49
+ - canonical-seed grouping instead of plain graph expansion
50
+ - limiting low-confidence bridge edges
51
+
52
+ The main remaining improvement is better cluster construction, so a single selection is more likely to cover exactly the records a reviewer wants to judge together.
@@ -0,0 +1,37 @@
1
+ from .dedupe import (
2
+ load_statements,
3
+ run_dedupe,
4
+ run_dedupe_explode,
5
+ run_merge,
6
+ run_prune,
7
+ run_xref,
8
+ )
9
+ from .dedupe_edges import run_dedupe_edges
10
+ from .cluster import (
11
+ get_next_dedupe_cluster,
12
+ record_dedupe_cluster_judgement,
13
+ skip_dedupe_cluster,
14
+ )
15
+ from .review import (
16
+ DedupeLockError,
17
+ get_lock_engine,
18
+ get_next_dedupe_candidate,
19
+ record_dedupe_judgement,
20
+ )
21
+
22
+ __all__ = [
23
+ "load_statements",
24
+ "run_xref",
25
+ "run_dedupe",
26
+ "run_dedupe_explode",
27
+ "run_merge",
28
+ "run_prune",
29
+ "run_dedupe_edges",
30
+ "DedupeLockError",
31
+ "get_lock_engine",
32
+ "get_next_dedupe_candidate",
33
+ "get_next_dedupe_cluster",
34
+ "record_dedupe_cluster_judgement",
35
+ "record_dedupe_judgement",
36
+ "skip_dedupe_cluster",
37
+ ]