MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / gentle_compare

Function gentle_compare

tests/gentle_compare.py:6–28  ·  view source on GitHub ↗

Check lists of "words" extractions for approximate equality. * both lists must have same length * word items must contain same word strings * word rectangles must be approximately equal

(w0, w1)

Source from the content-addressed store, hash-verified

4
5
6def gentle_compare(w0, w1):
7 """Check lists of "words" extractions for approximate equality.
8
9 * both lists must have same length
10 * word items must contain same word strings
11 * word rectangles must be approximately equal
12 """
13 tolerance = 1e-3 # maximum (Euclidean) norm of difference rectangle
14 word_count = len(w0) # number of words
15 if word_count != len(w1):
16 print(f"different number of words: {word_count}/{len(w1)}")
17 return False
18 for i in range(word_count):
19 if w0[i][4] != w1[i][4]: # word strings must be the same
20 print(f"word {i} mismatch")
21 return False
22 r0 = pymupdf.Rect(w0[i][:4]) # rect of first word
23 r1 = pymupdf.Rect(w1[i][:4]) # rect of second word
24 delta = (r1 - r0).norm() # norm of difference rectangle
25 if delta > tolerance:
26 print(f"word {i}: rectangle mismatch {delta}")
27 return False
28 return True
29
30
31def rms(a, b, verbose=None, out_prefix=''):

Callers 1

test_remove_rotationFunction · 0.90

Calls 1

normMethod · 0.45

Tested by 1

test_remove_rotationFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…