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)
| 4 | |
| 5 | |
| 6 | def 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 | |
| 31 | def rms(a, b, verbose=None, out_prefix=''): |
searching dependent graphs…