Tools,

Zawgyi to Unicode, tested: detect first

24 of 24

Unicode passages each of 4 converters broke

None of the 4 converters checks what it gets. A detector does.

Burmese scans to text, no OCR install

Converters break text that is already Unicode

On Unicode text, ICU's output was 2,005 edits away from the 8,929 true code points (22.5%). In the first passage, the first syllable, မင်း, came back as မငျး.

Google's detector on 24 passages: Zawgyi when over 0.95
Text Unicode flagged Zawgyi found
Whole passages 0 24
First 5 code points 1 15
First 10 code points 0 19
First 20 or 40 code points 0 24

Unicode to Zawgyi: Rabbit's came back exact

Each converter wrote Zawgyi, and each read every writer's Zawgyi back.

Passages read back right, of 24
Writer Read by ICU, Rabbit or myanmar-tools Read by python-myanmar
Rabbit 1.0.4 24 12
ICU 79.1 20 4
myanmar-tools 1.1.3 20 4
python-myanmar 1.10.0 1 16

Real Zawgyi: ICU agrees with Google's converter

Google's test file: a government news text typed in Zawgyi, 63 lines. Its expected Unicode is Google's own converter output, so a match is agreement, not proof.

Reader Lines equal to Google's file Zawgyi forms left
ICU 79.1 63 0
myanmar-tools 1.1.3 63 0
Rabbit 1.0.4 57 0
python-myanmar 1.10.0 32 8

Detect, then convert: the code

Python: Google's detector, then ICU's uconv (ICU 79.1):

pip install myanmartools==1.2.1
brew install icu4c  # uconv is not on PATH: add it
export PATH="$(brew --prefix icu4c)/bin:$PATH"
import subprocess
from myanmartools import ZawgyiDetector


def to_unicode(text):
    if ZawgyiDetector().get_zawgyi_probability(text) <= 0.95:
        return text  # already Unicode: leave it
    cmd = ["uconv", "-f", "utf-8", "-t", "utf-8", "-x", "Zawgyi-my"]
    return subprocess.run(cmd, input=text.encode(), capture_output=True, check=True).stdout.decode()

Node: Rabbit, and myanmar-tools 1.1.3 for the detector (not 1.2.0):

npm install rabbit-node@1.0.4 myanmar-tools@1.1.3

Myanmar PDF to Word: copy, join, convert

Our typed Zawgyi PDF held Zawgyi codes, and pdftotext copied them exactly.

Our Zawgyi PDF, 24 pages
Route Characters right Pages exact
pdftotext, line breaks out, then Rabbit or ICU 100.0% 24
pdftotext, then Rabbit or ICU 99.6% 13
pdftotext, read as if Unicode 65.0% 0
OCR, Tesseract mya 68.0% 0
OCR, the same pages in a Unicode font 69.7% 0

Myanmar PDF to Word in 3 commands

pdftotext -enc UTF-8 in.pdf zawgyi.txt
node zawgyi-pdf.js zawgyi.txt > unicode.md
pandoc -f markdown -M lang=my -o out.docx unicode.md
zawgyi-pdf.js, the whole script
// node zawgyi-pdf.js zawgyi.txt > unicode.md  (zawgyi.txt from: pdftotext -enc UTF-8 in.pdf zawgyi.txt)
// Needs: npm install rabbit-node@1.0.4 myanmar-tools@1.1.3
const fs = require("fs");
const Rabbit = require("rabbit-node");
const { ZawgyiDetector } = require("myanmar-tools");
const det = new ZawgyiDetector();
const pages = fs.readFileSync(process.argv[2], "utf8").split("\f");
const out = pages
  .map((p) => p.replace(/\n/g, "")) // line breaks out: a Zawgyi vowel sign can sit before a break
  .filter(Boolean)
  .map((p) => (det.getZawgyiProbability(p) > 0.95 ? Rabbit.zg2uni(p) : p));
process.stdout.write(out.join("\n\n") + "\n");

npm's myanmar-tools 1.2.0 fails on require

npm install myanmar-tools gives 1.2.0, the latest since July 2020. Its index.js fails:

Cannot find module './build_node/zawgyi_detector'

The 1.2.0 package has no build_node folder. 1.1.3 has it, so pin that.

Our Actor is for scans, not Zawgyi PDFs

Our Apify Actor, PDF to Markdown OCR, kept our Zawgyi PDF's own text: Zawgyi codes, with some marks moved (90.8% after Rabbit). Use the 3 commands above.

It is for scans: a scan holds no Zawgyi, and OCR wrote Unicode here. But Burmese OCR is weak: 60.1% on these pages as images (plain Tesseract 68.0%). See our Burmese OCR test.

The API call (not run here)
curl -s -X POST "https://api.apify.com/v2/acts/brasspage~pdf-ocr-to-markdown/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"documentUrls": ["https://example.com/your-scan.pdf"], "language": "mya"}' \
  | jq -r '.[].markdown' > out.md

What I tested, and what I did not

How I tested
  • Unicode truth: the 24 Burmese Wikipedia passages (CC BY-SA 4.0) of my Khmer and Myanmar OCR test, 8,929 code points.
  • Each of the 4 converters wrote Zawgyi, and each read every writer's Zawgyi back: 16 pairs. Right: equal to the true Unicode after NFC.
  • Real Zawgyi: resources/mmgov_zawgyi_src.txt of myanmar-tools 1.1.3, a news text from statecounsellor.gov.mm, July 26, 2018. There is no human truth for it, so I compared each reader with Google's mmgov_unicode_out.txt.
  • Zawgyi forms: code points in U+1060 to U+1097, where Zawgyi keeps its glyph forms. The real text had 272. All 4 readers agree on 30 of 63 lines.
  • The PDFs: the 24 passages, one a page, as Rabbit's Zawgyi in Noto Sans Zawgyi and as Unicode in Noto Sans Myanmar, printed by Playwright's Chromium headless shell, build 1255 (A4, 14 pt).
  • Characters right: 1 minus the edit distance over the true length, after NFC with all whitespace out, per page.
  • OCR: Tesseract 5.5.4, tessdata_fast mya 4.1.0, --psm 4, 300 dpi. pdftotext 26.03.0.
  • The .docx: pandoc -M lang=my, read back as all the w:t text of word/document.xml. LibreOffice's .docx held 16,252 code points for 8,185 true ones.
  • Our Actor: its code at commit 0f6d3a5b, language mya, on the PDF (text layer kept on 24 of 24 pages, 87.3% of the Zawgyi codes) and on the pages as PNG images (OCR, 24 of 24).
  • The wrong way: ICU and myanmar-tools 2,005 wrong code points, Rabbit 1,869, python-myanmar 1,574. Detect, then convert: python-myanmar 36 of 48.
  • One Mac with Apple silicon, local CPU only, at background priority.
Licenses and versions
  • ICU 79.1 (uconv, Homebrew icu4c@79): Unicode License.
  • Rabbit: rabbit-node 1.0.4 is MIT. The main Rabbit repo is WTFPL.
  • Google myanmar-tools 1.1.3 (npm): Apache-2.0.
  • myanmartools 1.2.1 (PyPI, detector only): Apache-2.0.
  • python-myanmar 1.10.0: MIT.
  • Tesseract 5.5.4 and tessdata_fast 4.1.0: Apache-2.0.
Sources

Questions people ask

How do I convert Zawgyi to Unicode?

Check the text with Google's Zawgyi detector, and convert only what scores over 0.95. On a real Zawgyi news text, ICU's Zawgyi-my and myanmar-tools agreed with Google's own converter test on 63 of 63 lines.

How can I tell if Burmese text is Zawgyi or Unicode?

Use Google's detector, myanmartools in Python or myanmar-tools 1.1.3 in Node. It flagged 0 of 24 Unicode passages and found all 24 in Zawgyi. On 5 or 10 code points it missed some, so test whole lines.

How do I convert a Myanmar PDF to Word?

For a typed Zawgyi PDF: copy its text with pdftotext, take the line breaks out of each page, convert, then let pandoc write the .docx. Here that kept 99.9% of the characters. OCR of the same pages got 68.0%.

What is Zawgyi?

A Burmese font encoding that uses the same code point range as Unicode in its own, incompatible way. Myanmar's government set 1 October 2019 as U-Day, its official switch to Unicode.