graflo.link.candidates¶
Gather the entities a staged record may be, without a model.
:func:gather_candidates runs after :func:~graflo.link.resolve.resolve_records
(and, on a live graph, after its write) and lists, for each staged record, the
entities it may be, by three kinds of evidence:
alternate: the entities a stated secondary identity matched -- several, or the record would have resolved (ambiguous);exact/key/normalized/alias/compatible: :func:~graflo.hq.lookup.lookup_candidatesover the label fields the record states, the values of fields others are derived from, and the caller's lookup text for it;relation: a relation stated between the record and a resolved one -- "the customer" that RAISED a resolved HD-4411 gives the customers linked to HD-4411 byRAISED;context: a neighbour of the record's type, one hop from an entity the same source resolved by key or a subject it is known to concern -- "the unit" of a ticket about one unit.
One candidate per entity carries every lane that found it, best first, and
the record's other stated properties graded against the entity's stored
values (:mod:graflo.architecture.schema.compare: exact, compatible,
differs, conflict, unknown); stored values are never returned.
Candidates never close a record: only keys do. A pick, a declared rule, an
agent or a person chooses among them, and :func:support says whether a
candidate's features identify it. A candidate whose stored key or
secondary-identity values conflict with what the record states is left out: a
record that states email is not an entity holding another email. Nor is
the entity a record of the same source, related to this one by a stated
relation, resolved to: the relation states two entities.
Attributes¶
Comparable = Callable[[str, str], bool]
module-attribute
¶
IDENTIFYING_LANES = frozenset({'key', 'alternate', 'exact', 'normalized'})
module-attribute
¶
LANE_ORDER = {'alternate': 0, 'exact': 1, 'key': 2, 'normalized': 3, 'alias': 4, 'compatible': 5, 'relation': 6, 'metadata': 7, 'context': 8}
module-attribute
¶
LookupText = Callable[[PartialRecord], str | None]
module-attribute
¶
Classes¶
Functions:¶
gather_candidates(schema, resolution, db=None, *, guard=None, spec=None, lookup_text=None, comparable=None, subjects=None, max_candidates=10)
¶
The entities each staged record of resolution may be, best first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Schema the records were resolved against. |
required |
resolution
|
Resolution
|
What :func: |
required |
db
|
Any | None
|
An open connection. Without one, only the batch's resolved records
are searched (the |
None
|
guard
|
FilterExpression | None
|
A trusted read guard every graph read passes, as in
|
None
|
spec
|
LookupSpec | None
|
Lookup spec for the label lanes (key patterns, alias hops,
label field overrides). Its |
None
|
lookup_text
|
LookupText | None
|
Words to look each staged record up by besides the label
values it states, such as the passage it was read from; typically
taken from the caller's own |
None
|
comparable
|
Comparable | None
|
Which stated properties may be read and compared, as
|
None
|
subjects
|
Mapping[str, Sequence[KnownSubject]] | None
|
Per source id, the entities the source is known to concern
(from its metadata), anchors of the |
None
|
max_candidates
|
int
|
Most candidates per record, counted as entities after
lanes are merged and keys checked; |
10
|
Returns:
| Type | Description |
|---|---|
list[StagedCandidates]
|
One entry per staged record, in the resolution's order; an entry with |
list[StagedCandidates]
|
no candidates when nothing was found. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
A guard on a backend that cannot apply one. |
Source code in graflo/link/candidates.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
support(candidate)
¶
accept when a feature identifies candidate and nothing conflicts.
Identifying: a hit in an identifying lane (key, alternate,
exact, normalized), an exclusive field stated and stored alike, an
alias naming only it in the reader's view, or a compatible form no
other entity of its type holds there. A compatible form several
entities hold, like an alias with several targets, is generic; a
context hit never identifies.