Algorithm Search⌘K

Algorithmadvanced

R-Swoosh

Also called Swoosh algorithms, generic entity resolution.

Resolve entities with black-box match and merge functions: merge each record with the first resolved record it matches and put the result back. Under the ICAR properties the output is exact.

Time
O(n^2) worst · averageO(n) best
Space
O(n) extra
Where
n = the number of input records
Properties
deterministicexactnot externalnot in placeofflineiterative
Origin
Omar Benjelloun, Hector Garcia Molina, David Menestrina, Qi Su, Steven Euijong Whang, Jennifer Widom, 2009

R-Swoosh is an algorithm for entity resolution in which the match rule and the merge rule are black boxes. It keeps a list of resolved records. It takes the input records one by one, compares each with the resolved records, and at the first match it merges the two and puts the merged record back into the input. The merged record is compared again, so information from one record can join two others that did not match on their own. If the functions have the four ICAR properties (idempotence, commutativity, associativity and representativity), the output is exactly the set of maximal records of the merge closure. Methods such as the sorted neighborhood method and blocking decide which pairs to compare and do not merge records; collective entity resolution also uses links between records.

In plain words

You have a pile of records about people, and you can ask two questions about any two records: "are these the same person?" and "what is the combined record?". You keep a second pile of finished records. You take a record from the first pile and check it against the finished pile. If it matches one, you join the two, take the old one out of the finished pile, and put the joined record back on the first pile, because it now knows more and can match records that neither part matched. If it matches none, it goes on the finished pile. When the first pile is empty, the finished pile is the answer.

The problem

The input is a finite set II of nn records, a match function match(r,s)\mathit{match}(r, s) that returns true or false, and a merge function merge(r,s)\mathit{merge}(r, s) that returns a new record for two matching records. Write r≈sr \approx s for a match and ⟨r,s⟩\langle r, s \rangle for the merge. The merge closure Iˉ\bar I is the smallest set that holds II and every merge of two matching records in it. A record rr is dominated by ss if r≈sr \approx s and ⟨r,s⟩=s\langle r, s \rangle = s: ss already holds all that rr adds. The result ER(I)ER(I) is the set of records of Iˉ\bar I that no other record of Iˉ\bar I dominates.

The ICAR properties are:

  • Idempotence. r≈rr \approx r and ⟨r,r⟩=r\langle r, r \rangle = r.
  • Commutativity. r≈sr \approx s if and only if s≈rs \approx r, and then ⟨r,s⟩=⟨s,r⟩\langle r, s \rangle = \langle s, r \rangle.
  • Associativity. ⟨r,⟨s,t⟩⟩=⟨⟨r,s⟩,t⟩\langle r, \langle s, t \rangle \rangle = \langle \langle r, s \rangle, t \rangle when both are defined.
  • Representativity. If u=⟨r,s⟩u = \langle r, s \rangle and r≈tr \approx t, then u≈tu \approx t: a merged record matches everything its parts match.

A typical example is a record as a set of attribute values, merge as the union, and a match rule that asks for shared values, such as "the same email, or the same name and the same phone".

The algorithm

  1. R-Swoosh(I, match, merge)
  2. 1R ← I; R' ← ∅ ▷ R: records to do, R': resolved records
  3. 2while R ≠ ∅ do
  4. 3r ← remove a record from R
  5. 4buddy ← nil
  6. 5for each s in R' do
  7. 6if match(r, s) then buddy ← s; exit the loop
  8. 7if buddy = nil then add r to R'
  9. 8else remove buddy from R'; add merge(r, buddy) to R
  10. 9return R'

Line L6 stops at the first match, so each step makes at most ∣R′∣|R'| calls. Line L8 drops both rr and its buddy: under ICAR the merged record dominates both, so they can never be needed again. The implementation keeps RR as a queue, so a merged record waits behind the records that are still to do, and keeps R′R' as a list.

Example

The rule is "the same email, or the same name and the same phone", and merge is the union of the values.

record name phone email
r1 ann p1
r2 ann e1
r3 p1 e1
r4 bob p1

Of the 6 pairs, only r2 and r3 match. The transitive closure of the pairs gives the clusters {r1}, {r2, r3} and {r4}. R-Swoosh runs as follows.

step taken from R compared with result R' after
1 r1 none no match r1
2 r2 r1 no match r1, r2
3 r3 r1, r2 match r2: m = (ann, p1, e1) goes to R r1
4 r4 r1 no match r1, r4
5 m r1 match r1 (same name and phone): m' = (ann, p1, e1) from r1, r2, r3 goes to R r4
6 m' r4 no match r4, m'

The output is {r1, r2, r3} and {r4}, after 6 calls. The merged record of r2 and r3 has both a name and a phone, so it matches r1, which neither part matched. Record r4 shares the phone but not the name, so it stays apart.

A larger run. On generated data with 40 people and 108 records (119 true duplicate pairs, Python seed 42), with copies that lose their email or phone, R-Swoosh made 3488 calls (all pairs are 5778) and returned 46 clusters with pairwise precision 0.926 and recall 0.840. Precision is below 1 because some people share a name and a phone number. On this data the clusters were the same as the closure of the pairwise matches. These numbers are measurements on that data only.

Correctness

Each step either moves a record to R′R' or merges it, so R′R' never holds two records that match. The merge of two records dominates both of them, and domination is a partial order under ICAR. From these facts, every input record is dominated by an output record. The set of records dominated by an output record is also closed under merges, so it covers all of Iˉ\bar I. Since no two output records match, each one is maximal. So under ICAR the output is exactly ER(I)ER(I), for any order of the input. Without the properties the output can be wrong, and the paper gives G-Swoosh for that case. The full proof is in the proof page.

Proof: Under the ICAR properties R-Swoosh returns the maximal records of the merge closure, with at most (n-1)^2 match callsfull

We use the pseudocode of the page. II is the input, a finite set of nn records. We write r≈sr \approx s for match(r,s)=true\mathit{match}(r, s) = \text{true} and ⟨r,s⟩\langle r, s \rangle for merge(r,s)\mathit{merge}(r, s), which is defined when r≈sr \approx s. The merge closure Iˉ\bar I is the smallest set of records that contains II and contains ⟨r,s⟩\langle r, s \rangle for all r,sr, s in it with r≈sr \approx s. The record rr is dominated by ss, written r≤sr \le s, if r≈sr \approx s and ⟨r,s⟩=s\langle r, s \rangle = s.

The ICAR properties are:

  • Idempotence. r≈rr \approx r and ⟨r,r⟩=r\langle r, r \rangle = r for every record rr.
  • Commutativity. r≈sr \approx s if and only if s≈rs \approx r, and then ⟨r,s⟩=⟨s,r⟩\langle r, s \rangle = \langle s, r \rangle.
  • Associativity. ⟨r,⟨s,t⟩⟩=⟨⟨r,s⟩,t⟩\langle r, \langle s, t \rangle \rangle = \langle \langle r, s \rangle, t \rangle whenever both sides are defined.
  • Representativity. If u=⟨r,s⟩u = \langle r, s \rangle and r≈tr \approx t, then u≈tu \approx t.

Termination and the bound on the calls hold for any functions match\mathit{match} and merge\mathit{merge} that always return. The correctness part uses ICAR.

Termination and the number of calls

Let a=∣R∣a = |R| and b=∣R′∣b = |R'|. A step is one run of lines L3 to L8. In a no-match step line L7 runs, the step makes bb calls, and (a,b)(a, b) becomes (a−1,b+1)(a - 1, b + 1). In a merge step line L8 runs, the step makes at most bb calls, and (a,b)(a, b) becomes (a,b−1)(a, b - 1), because rr leaves RR, the merged record enters RR, and the buddy leaves R′R'.

So a+ba + b falls by one in each merge step and stays the same in each no-match step. It starts at nn and is never negative, so there are at most nn merge steps. The value aa never grows, and each no-match step lowers it by one, so there are at most nn no-match steps. The loop stops after at most 2n2n steps, and it stops only when a=0a = 0, so there are exactly nn no-match steps. If the output has jj records, then a+ba + b fell from nn to jj, so there are exactly n−jn - j merge steps and 2n−j2n - j steps.

Lemma 1. The number of calls is at most (n−1)2−(j−1)(j−2)/2(n - 1)^2 - (j - 1)(j - 2)/2 for n≥1n \ge 1.

Proof. The calls are at most the sum of bb before each step. The sequence of steps is a word of nn no-match steps (N) and n−jn - j merge steps (M). The last step is N, because only N makes a=0a = 0. A merge step needs b≥1b \ge 1 before it, and every step needs a≥1a \ge 1, which holds for any order of the first 2n−j−12n - j - 1 steps because they hold only n−1n - 1 no-match steps. Exchanging an adjacent pair MN among these steps for NM changes the two values of bb before these steps from (h,h−1)(h, h - 1) to (h,h+1)(h, h + 1), so the sum grows by 2. Hence the sum is largest for the word Nn−1Mn−jNN^{n-1} M^{n-j} N. Its values of bb are 0,1,…,n−20, 1, \ldots, n - 2, then n−1,n−2,…,jn - 1, n - 2, \ldots, j, then j−1j - 1. The sum is

(n−1)(n−2)2+n(n−1)2−j(j−1)2+(j−1)=(n−1)2−(j−1)(j−2)2.□\frac{(n-1)(n-2)}{2} + \frac{n(n-1)}{2} - \frac{j(j-1)}{2} + (j - 1) = (n - 1)^2 - \frac{(j-1)(j-2)}{2}. \qquad \square

For j=1j = 1 the bound is (n−1)2(n - 1)^2, and the tests reach it for each n≤9n \le 9 with a match rule that makes each merged record match only the last record of R′R'. For j=nj = n there are no merge steps, and the count is exactly 0+1+⋯+(n−1)=n(n−1)/20 + 1 + \cdots + (n - 1) = n(n-1)/2.

Correctness under ICAR

Lemma 2 (≤\le is a partial order). Reflexive: r≈rr \approx r and ⟨r,r⟩=r\langle r, r \rangle = r by idempotence. Antisymmetric: if r≤sr \le s and s≤rs \le r, then s=⟨r,s⟩=⟨s,r⟩=rs = \langle r, s \rangle = \langle s, r \rangle = r by commutativity. Transitive: let r≤s≤tr \le s \le t. From s≈rs \approx r and t=⟨s,t⟩t = \langle s, t \rangle, representativity gives t≈rt \approx r, so ⟨r,t⟩\langle r, t \rangle is defined. Also ⟨⟨r,s⟩,t⟩=⟨s,t⟩\langle \langle r, s \rangle, t \rangle = \langle s, t \rangle is defined, and associativity gives ⟨r,t⟩=⟨r,⟨s,t⟩⟩=⟨⟨r,s⟩,t⟩=⟨s,t⟩=t\langle r, t \rangle = \langle r, \langle s, t \rangle \rangle = \langle \langle r, s \rangle, t \rangle = \langle s, t \rangle = t. □\square

Lemma 3 (a merge dominates its parts). If r≈sr \approx s and m=⟨r,s⟩m = \langle r, s \rangle, then r≤mr \le m and s≤ms \le m.

Proof. From r≈rr \approx r and m=⟨r,s⟩m = \langle r, s \rangle, representativity gives m≈rm \approx r. Both ⟨r,m⟩\langle r, m \rangle and ⟨⟨r,r⟩,s⟩=⟨r,s⟩\langle \langle r, r \rangle, s \rangle = \langle r, s \rangle are defined, so associativity gives ⟨r,m⟩=⟨⟨r,r⟩,s⟩=⟨r,s⟩=m\langle r, m \rangle = \langle \langle r, r \rangle, s \rangle = \langle r, s \rangle = m. So r≤mr \le m. By commutativity m=⟨s,r⟩m = \langle s, r \rangle, and the same argument gives s≤ms \le m. □\square

Let OO be the list R′R' at line L9.

Lemma 4 (invariants). At the start of each step: (a) every record in R∪R′R \cup R' is in Iˉ\bar I; (b) no two records at different positions of R′R' match; (c) every record of II is dominated by some record in R∪R′R \cup R'.

Proof. All three hold at the start, with R=IR = I and R′=∅R' = \emptyset, using reflexivity for (c). (a) A step adds only rr, which is already there, or ⟨r,s⟩\langle r, s \rangle with r,s∈Iˉr, s \in \bar I and r≈sr \approx s, which is in Iˉ\bar I by its definition. (b) Line L7 adds rr to R′R' only after lines L5 and L6 found that rr matches no record of R′R', and line L8 only removes a record from R′R'. (c) A no-match step moves rr from RR to R′R'. A merge step removes rr and its buddy ss and adds m=⟨r,s⟩m = \langle r, s \rangle, and r≤mr \le m, s≤ms \le m by Lemma 3. A record of II that rr or ss dominated is now dominated by mm, by transitivity (Lemma 2). □\square

Theorem. Under ICAR, OO is exactly the set of maximal records of Iˉ\bar I under ≤\le, with each record once.

Proof. At the end R=∅R = \emptyset, so by Lemma 4, O⊆IˉO \subseteq \bar I, no two records of OO match, and every record of II is dominated by a record of OO. Two equal records match by idempotence, so the records of OO are distinct.

Let D={y:y≤o for some o∈O}D = \{ y : y \le o \text{ for some } o \in O \}. We show that DD is closed under merges. Let y1≤o1y_1 \le o_1 and y2≤o2y_2 \le o_2 with o1,o2∈Oo_1, o_2 \in O and y1≈y2y_1 \approx y_2. From y1≈y2y_1 \approx y_2 and o1=⟨y1,o1⟩o_1 = \langle y_1, o_1 \rangle, representativity gives o1≈y2o_1 \approx y_2. From y2≈o1y_2 \approx o_1 and o2=⟨y2,o2⟩o_2 = \langle y_2, o_2 \rangle, it gives o2≈o1o_2 \approx o_1. No two different records of OO match, so o1=o2=oo_1 = o_2 = o. Let u=⟨y1,y2⟩u = \langle y_1, y_2 \rangle. From y1≈oy_1 \approx o, representativity gives u≈ou \approx o. Both ⟨u,o⟩\langle u, o \rangle and ⟨y1,⟨y2,o⟩⟩=⟨y1,o⟩\langle y_1, \langle y_2, o \rangle \rangle = \langle y_1, o \rangle are defined, and associativity gives ⟨u,o⟩=⟨y1,⟨y2,o⟩⟩=⟨y1,o⟩=o\langle u, o \rangle = \langle y_1, \langle y_2, o \rangle \rangle = \langle y_1, o \rangle = o. So u≤ou \le o and u∈Du \in D.

DD contains II and is closed under merges, so Iˉ⊆D\bar I \subseteq D: every record of Iˉ\bar I is dominated by a record of OO.

Now let o∈Oo \in O and o≤yo \le y with y∈Iˉy \in \bar I. Then y≤o′y \le o' for some o′∈Oo' \in O, so o≤o′o \le o' by transitivity. If o≠o′o \ne o', they would match, which (b) forbids. So o=o′o = o', and o≤y≤oo \le y \le o gives y=oy = o by antisymmetry. So every record of OO is maximal in Iˉ\bar I. Conversely, let xx be maximal in Iˉ\bar I. Then x≤ox \le o for some o∈O⊆Iˉo \in O \subseteq \bar I, and maximality gives x=o∈Ox = o \in O. ■\blacksquare

Remarks. The result does not depend on the order in which line L3 takes records from RR or on the order of the scan in line L5, because the set of maximal records of Iˉ\bar I does not. The number of calls does depend on these orders. Without representativity the theorem can fail: R-Swoosh drops rr and its buddy after a merge, and a later record that matches rr but not the merged record is then never merged with the information of rr.

Complexity

  • Calls. There are exactly nn steps without a match and n−jn - j merge steps, where jj is the size of the output. The number of match calls is at most (n−1)2−(j−1)(j−2)/2(n - 1)^2 - (j - 1)(j - 2)/2, so at most (n−1)2(n - 1)^2. With no matches it is exactly n(n−1)/2n(n-1)/2.
  • Best case. If every record matches the first resolved record, each step makes at most one call, about 2n2n in total.
  • Time. The calls times the cost of one call to match\mathit{match}, plus n−jn - j calls to merge\mathit{merge}. In practice the match rule is the main cost.
  • Space. At most nn records in RR and R′R' together, but a merged record can be as large as all its parts.

Properties

  • Exact under ICAR. The output equals ER(I)ER(I) when the four properties hold. It is a heuristic when they do not.
  • Order independent result. The output does not depend on the input order, but the number of calls does.
  • No transitive closure needed. Merging replaces the closure step of pairwise methods, and it can join more records than the closure of the pairs.
  • Black box. It needs nothing about the records except the two functions. It does not build an index, so it compares more pairs than blocking methods.

Variants and improvements

  • G-Swoosh. Makes no assumption on the functions. It compares all pairs of records, merged ones included, keeps the source records, and removes dominated records at the end. It can make many more calls.
  • F-Swoosh. Assumes the match rule is a disjunction of feature comparisons. It records the feature values already compared, so a merged record does not repeat comparisons that failed before.
  • With blocking. On large data, R-Swoosh runs inside each block of a blocking or sorted neighborhood pass, which cuts the quadratic cost.

When to use it

Use it when you have a reliable match rule and a merge that keeps all information, such as the union of attribute values, and want merged records instead of clusters of pairs. It suits small or blocked inputs, because its cost is quadratic. When the match rule gives a score instead of a yes or no, a probabilistic model such as Fellegi-Sunter decides the pairs, and a closure with union-find groups them.

Pitfalls

  • A merge that loses values. If merge keeps only one of two values, for example the longer name, representativity can fail, and a record that matched a part no longer matches the merged record.
  • Rules with thresholds. A rule such as "similarity at least 0.8" on a merged record is often not representative, because the merged value can be farther from a third record than one of its parts.
  • Idempotence of the rule. A record must match itself. With the rule of the example, a record with no email and no phone does not, so the theory does not cover it.
  • Large merged records. Each merge makes a larger record, and the cost of a match grows with it.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

r_swoosh.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/r-swoosh/. The authors are listed in prov/92B1R4.jsonl.
"""R-Swoosh: generic entity resolution with black-box match and merge functions.

match(r, s) returns a bool and merge(r, s) returns a new record; merge is called
only on records that match. When the two functions have the ICAR properties
(idempotence, commutativity, associativity, representativity), the result is
the set of maximal records of the merge closure of the input.

The module also has a record type for tests and examples: a record is a pair
(values, ids), where values is a frozenset of (attribute, value) pairs and ids
is the frozenset of input record numbers merged into it. union_merge and
rule_match below have the ICAR properties.
"""

from collections import deque


def r_swoosh(records, match, merge):
    """Return (resolved records, number of match calls)."""
    R = deque(records)  # @line L1
    done = []  # @line L1
    calls = 0
    while R:  # @line L2
        r = R.popleft()  # @line L3
        buddy = None  # @line L4
        for k, other in enumerate(done):  # @line L5
            calls += 1
            if match(r, other):  # @line L6
                buddy = k  # @line L6
                break  # @line L6
        if buddy is None:  # @line L7
            done.append(r)  # @line L7
        else:
            other = done.pop(buddy)  # @line L8
            R.append(merge(r, other))  # @line L8
    return done, calls  # @line L9


def comparison_bound(n, j):
    """The worst case number of match calls for n inputs and j outputs: (n-1)^2 - (j-1)(j-2)/2."""
    if n == 0:
        return 0
    return (n - 1) ** 2 - (j - 1) * (j - 2) // 2


def make_record(i, **fields):
    """A record with the input number i and the given attribute values (None means missing)."""
    values = frozenset((a, v) for a, v in fields.items() if v is not None)
    return (values, frozenset([i]))


def union_merge(r, s):
    """Merge by union of the values and of the input numbers."""
    return (r[0] | s[0], r[1] | s[1])


def shares(r, s, attr):
    vr = {v for a, v in r[0] if a == attr}
    return any((attr, v) in s[0] for v in vr)


def rule_match(r, s):
    """Match if the records share an email, or share both a name and a phone."""
    return shares(r, s, "email") or (shares(r, s, "name") and shares(r, s, "phone"))


def dominated(r, s, match, merge):
    """r <= s: r matches s and merging r into s gives s."""
    return match(r, s) and merge(r, s) == s


def merge_closure(records, match, merge, limit=100000):
    """The smallest set that holds the input and is closed under merges of matching records."""
    S = set(records)
    frontier = list(S)
    while frontier:
        new = []
        items = sorted(S, key=repr)
        for x in frontier:
            for y in items:
                if x != y and match(x, y):
                    z = merge(x, y)
                    if z not in S:
                        S.add(z)
                        new.append(z)
                        if len(S) > limit:
                            raise ValueError("closure too large")
        items = None
        frontier = new
    return S


def maximal_records(records, match, merge):
    """ER(I) under ICAR: the records of the merge closure that no other record dominates."""
    S = merge_closure(records, match, merge)
    return {x for x in S if not any(y != x and dominated(x, y, match, merge) for y in S)}
test_r_swoosh.py 138 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/r-swoosh/. The authors are listed in prov/92B1R4.jsonl.
import random
import unittest

from r_swoosh import (
    comparison_bound,
    make_record,
    maximal_records,
    r_swoosh,
    rule_match,
    union_merge,
)

EMAILS = ["e1", "e2", "e3", "e4"]
NAMES = ["ann", "bob", "cal"]
PHONES = ["p1", "p2", "p3"]


def random_records(rng, n):
    out = []
    for i in range(n):
        while True:
            email = rng.choice(EMAILS + [None, None])
            name = rng.choice(NAMES + [None])
            phone = rng.choice(PHONES + [None])
            # Every record matches itself, so the match rule is idempotent.
            if email is not None or (name is not None and phone is not None):
                break
        out.append(make_record(i, email=email, name=name, phone=phone))
    return out


class TestRSwoosh(unittest.TestCase):
    def test_page_example(self):
        r1 = make_record(1, name="ann", phone="p1")
        r2 = make_record(2, name="ann", email="e1")
        r3 = make_record(3, phone="p1", email="e1")
        r4 = make_record(4, name="bob", phone="p1")
        out, calls = r_swoosh([r1, r2, r3, r4], rule_match, union_merge)
        self.assertEqual(sorted(sorted(r[1]) for r in out), [[1, 2, 3], [4]])
        self.assertEqual(calls, 6)
        # The pairs alone match only r2 and r3.
        recs = [r1, r2, r3, r4]
        pairs = [(a + 1, b + 1) for a in range(4) for b in range(a + 1, 4) if rule_match(recs[a], recs[b])]
        self.assertEqual(pairs, [(2, 3)])

    def test_against_merge_closure(self):
        rng = random.Random(20261118)
        for _ in range(300):
            n = rng.randint(0, 7)
            recs = random_records(rng, n)
            out, calls = r_swoosh(recs, rule_match, union_merge)
            self.assertEqual(len(out), len(set(out)))
            self.assertEqual(set(out), maximal_records(recs, rule_match, union_merge))
            for a in range(len(out)):
                for b in range(a + 1, len(out)):
                    self.assertFalse(rule_match(out[a], out[b]))
            self.assertLessEqual(calls, comparison_bound(n, len(out)))

    def test_order_does_not_change_result(self):
        rng = random.Random(9)
        for _ in range(100):
            recs = random_records(rng, rng.randint(1, 8))
            first, _ = r_swoosh(recs, rule_match, union_merge)
            shuffled = recs[:]
            rng.shuffle(shuffled)
            second, _ = r_swoosh(shuffled, rule_match, union_merge)
            self.assertEqual(set(first), set(second))

    def test_bound_is_reached(self):
        # A match rule (not ICAR) that makes every match the last record of R'.
        for n in range(1, 10):
            def match(r, s, n=n):
                u = r | s
                return not (r & s) and (n - 1) in u and max(u) - min(u) + 1 == len(u)

            recs = [frozenset([i]) for i in range(n)]
            out, calls = r_swoosh(recs, match, lambda r, s: r | s)
            self.assertEqual(out, [frozenset(range(n))])
            self.assertEqual(calls, comparison_bound(n, 1))
            self.assertEqual(calls, (n - 1) ** 2)
        # The ICAR rule of the page reaches the bound 4 for n = 3.
        r1 = make_record(1, name="ann", phone="p1")
        r2 = make_record(2, name="ann", email="e1")
        r3 = make_record(3, phone="p1", email="e1")
        out, calls = r_swoosh([r1, r2, r3], rule_match, union_merge)
        self.assertEqual(len(out), 1)
        self.assertEqual(calls, 4)

    def test_no_matches(self):
        for n in range(0, 12):
            recs = [make_record(i, email="x%d" % i) for i in range(n)]
            out, calls = r_swoosh(recs, rule_match, union_merge)
            self.assertEqual(len(out), n)
            self.assertEqual(calls, n * (n - 1) // 2)
            self.assertLessEqual(calls, comparison_bound(n, n))

    def test_precision_recall_synthetic(self):
        rng = random.Random(42)
        recs, truth = [], []
        for e in range(40):
            email = "mail%d" % e
            name = rng.choice(["ann", "bob", "cal", "dan", "eve", "fay", "gus", "hal"])
            phone = "ph%d" % rng.randint(0, 59)
            for _ in range(rng.randint(1, 4)):
                fields = {"email": email, "name": name, "phone": phone}
                drop = rng.random()
                if drop < 0.4:
                    fields["email"] = None
                elif drop < 0.6:
                    fields["phone"] = None
                if fields["email"] is None and fields["phone"] is None:
                    fields["phone"] = phone
                if fields["email"] is None and fields["name"] is None:
                    fields["name"] = name
                recs.append(make_record(len(recs), **fields))
                truth.append(e)
        out, calls = r_swoosh(recs, rule_match, union_merge)
        found = set()
        for r in out:
            ids = sorted(r[1])
            found |= {(a, b) for i, a in enumerate(ids) for b in ids[i + 1:]}
        n = len(recs)
        true = {(a, b) for a in range(n) for b in range(a + 1, n) if truth[a] == truth[b]}
        hit = len(found & true)
        precision = hit / len(found)
        recall = hit / len(true)
        self.assertEqual(sum(len(r[1]) for r in out), n)
        # The numbers on the page: 108 records, 119 true pairs, 46 clusters.
        self.assertEqual((n, len(true), len(out), calls), (108, 119, 46, 3488))
        self.assertEqual(round(precision, 3), 0.926)
        self.assertEqual(round(recall, 3), 0.840)
        self.assertLessEqual(calls, comparison_bound(n, len(out)))


if __name__ == "__main__":
    unittest.main()

History

Benjelloun, Garcia-Molina, Menestrina, Su, Whang and Widom of the Stanford InfoLab described the generic model of entity resolution and the Swoosh family of algorithms in The VLDB Journal in 2009. The model treats match and merge as black boxes given by a domain expert and asks which properties of these functions make the result well defined and the algorithms efficient. The paper defines the ICAR properties, the domination order and the result ER(I)ER(I), and gives G-Swoosh for arbitrary functions, R-Swoosh for ICAR functions and F-Swoosh for feature-level rules. It also compares the algorithms in experiments on real data.

References

  1. Omar Benjelloun, Hector Garcia-Molina, David Menestrina, Qi Su, Steven Euijong Whang and Jennifer Widom, Swoosh: a generic approach to entity resolution, The VLDB Journal 18(1), 2009, pages 255 to 276, the generic model with match and merge functions, the ICAR properties and the domination order, and the algorithms G-Swoosh, R-Swoosh and F-Swoosh with their experiments

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/92B1R4/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • at least three sources
  • a scene preset for the example