DEV Community

Cover image for When Apple Vision Drops the Minus Sign in a Document Diff
John
John

Posted on Originally published at hexisteme.github.io

When Apple Vision Drops the Minus Sign in a Document Diff

Originally published on hexisteme notes.

I drew Balance: -1,250.50 USD in Helvetica and asked Apple Vision to read it. The result was Balance: 1,250.50 USD. The comma, decimal point and currency survived. The one mark that reversed the meaning of the line disappeared. I got the same result for that line in Times New Roman, Apple SD Gothic Neo and Hiragino Sans.

This mattered in a scanning app where a reader can compare two documents and show only changes involving numbers. A reader looking for a changed balance has a good reason to use that filter. If both pages yield the same recognized string, the comparison has nothing to highlight. And if a separator gets attached to the wrong number, the filter can send the reader to a change that exists only in the app.

A probe with the original still in hand

I rendered eight short lines in each of the four fonts. I ran a VNRecognizeTextRequest at the accurate recognition level with language correction enabled and Korean, English and Japanese as the recognition languages. For each line I kept the input beside the top recognized text. Rendering the line myself meant I could answer a question that a pair of OCR outputs alone couldn't settle. I knew exactly which marks were in the image.

Here are three excerpts from the Helvetica run.

Printed Recognized
Balance: -1,250.50 USD Balance: 1,250.50 USD
Refund -$100.00 Discount -$5 Refund-$100.00 Discount-$5
- 3 - - 3-

The refund still contained a minus before each dollar sign. The change was where the whitespace landed. A parser that splits on whitespace and looks for tokens beginning with a sign could walk right past the first refund. In the page-number example the trailing dash moved next to the digit. Its new position gave it no new meaning. The reader could still see a page decoration.

Those are different failures. For the refund, the string still carries evidence a parser can use. For the balance, the top recognized string contains precisely the characters you would expect from a positive balance. A rule that supplies a missing minus there would make the same change to a genuinely positive source line. The four fonts are a handy way to reproduce this example. They don't tell me how often it happens on customer scans.

The rule that made a date look like an amount

An earlier change joined a standalone dash to the number that followed it. That gave the parser a way to handle a minus read with an extra space. The problem surfaced when the same code saw dates and lists. Consider the text between the endpoints of this range.

2026.12.01 - 2026.12.31
2026.12.01 – 2026.12.31
Enter fullscreen mode Exit fullscreen mode

Both lines name the same dates. Only the separator changed. If a tokenizer consumes the first line's dash as the sign of the second endpoint, a typographic edit looks like a numeric one. A line ending in a dash followed by a date on the next line exposed the same assumption. A page printed as - 3 - supplied an even shorter test case. I'd have to explain to a reader why cleaning up a page number changed an amount.

The placement of the filter also matters. A reader can ask for all text edits or narrow the results to numeric changes. Seeing a change in the first list doesn't establish that it belongs in the second. My test for the identifier checks both outputs, so a revision that simply hides the entire text edit would fail for a different reason.

I took out the rule that merged a lone dash. I kept the narrower cases where there was still a clue in the token. The regression suite compares Refund-$100.00 with a positive refund, and checks that removing the sign counts as a numeric change. It also checks a minus glued between a Korean label and an amount. A dash within an identifier such as A-1 has a different job. Changing that identifier can still be a text edit without promoting it into the numbers filter.

A test for the amount we still miss

Two regression expectations describe the compromise more precisely than a claim about improved accuracy.

Inputs to the comparison Recorded expectation
A date range with a hyphen, then the same range with an en dash The range compares as identical.
Balance - 100, then Balance 100 These also compare as identical. A genuine separated sign can be missed.

The comparison tests for the attached sign, lone dash and separated sign all passed on these text inputs. The second assertion is uncomfortable to read in a passing suite. That's why I kept it. It tells the next person exactly which case to revisit if the comparison gains another source of evidence. A change that handles the separated balance also has to pass the date, bullet, page-number and line-break examples. Testing only the balance would bring back the bug that prompted the rollback.

The screen now warns that recognition can miss small symbols such as a minus and directs the reader to check the original. That matters especially when the numbers filter is empty. A quiet comparison can mean the recognized amounts match. In the balance probe, the pixels retained a distinction that the strings had already lost.

For another document diff, I'd keep two small fixtures beside the parser tests. One would start from an image with a known printed sign and record what recognition actually delivered. The other would start from that delivered text and check what the comparison reported. They answer different debugging questions. The first tells me where the sign went. The second tells me whether the app made an additional mistake with what it received.

Email list for these notes: hexisteme.beehiiv.com — no issue has gone out yet, so you would be on it before the first one. No welcome sequence, no course, no upsell.

More notes at hexisteme.github.io/notes.

Top comments (0)