Reverse-Engineering Apple Dictionary (2020)
fmentzer.github.io
fmentzer.github.io
I wound up doing this a while ago for a similar toy project. After some poking around, it turned out that dictionary bundles are entirely supported by system APIs in CoreServices! The APIs are private, but Apple accidentally shipped a header file with documentation for them in the 10.7 SDK [1]. You can load a dictionary with `IDXCreateIndexObject()`, read through its indices with the search methods (and the convenient `kIDXSearchAllMatch`), and get pointers to its entry data with `IDXGetFieldDataPtrs()`.
It takes a bit of fiddling to figure out the structure (there are multiple indices for headwords, search keywords, cross-references, etc., and the API is a general-purpose trie library) and request the right fields, but those property lists in the bundle are there to help! (As the author of this article discovered, the entries are compressed and are proceeded with a 4-byte length marker.)
[1] https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10...
To find the Kit in question, simply Google "com.apple.TrieAccessMethod" and you should find it online.
binwalk --dd='.*' *.asset
Edit: should have read the comments before I posted this, because enragedcacti already mentioned this tool an hour ago.I used it and was able to figure out the remaining bits of the file format thanks to you and other tips in this thread.
https://josephg.com/blog/reverse-engineering-apple-dictionar...
There's also a command-line tool that can query the dictionary:
https://github.com/takumakei/osx-dictionary
Something I haven't yet reverse-engineered is Apple's word segmentation. I can get the word breaks in Chinese by pressing option + right arrow + space, repeatedly. But I have no idea how the backend for that works.
Unless they changed it, it's probably similar to CFStringTokenizer which used ICU Boundary Analysis (and maybe mecab for Japanese).
https://unicode-org.github.io/icu/userguide/boundaryanalysis...
Is that the same as the macOS dictionary being parsed here? It seems like a pretty big file to grep every time!
I assume at compile time it's converted to a more efficient query format
However, I'm concerned that the dictionary is copyrighted. Is there any precedent that says whether such a tool would be legal/illegal?
https://linux.die.net/man/1/dictfmt http://www.catb.org/jargon/oldversions/jarg447.txt
What's it good for?
I've used your article and other previous attempts to clear up the remaining unknown bits of the file format and build apple-peeler, a tool for extracting the XML from the dictionary files.
Just to mention that Core Foundation includes tokenisers (CFStringTokenizer) and lemmatisers (NSLinguisticTagger) of its own in case you ever wanted to avoid the Python processing!
But be aware (i.e. "beware") that Apple can pull the rug out of unpublished APIs, without warning.
I have been caught out, by this, myself.
So the difficulty we’re seeing here isn’t deliberate obfuscation, but rather just an dev using a database structure to make app design and word lookup easier.
If there really was licensing concerns I would expect there to at-least be some basic encryption, not just some basic compression.
http://toastytech.com/guis/ns20mail.png
(Edit: beaten by 30 seconds!)
Maybe not all of it. But I wouldn't doubt if bits of it went all the way back to the early days where a fancy dictionary was one of the star features of NeXTStep.
After I wrote my post about Apple's dictionary files, I got a mysterious email showing up in my inbox. The email was from someone who's spent some time writing code to do the same thing, but doesn't want to post it under his own name in case he falls fowl of his country's DMCA equivalent. Crazy. He said I could post his code under the condition that I took his name off it.
I'm personally using the route of digitizing an existing dictionary, albeit manually because that can't be automated in this case.
A paper I wrote nine years ago on related issues is here, in case you are interested:
“Kokugo Dictionaries as Tools for Learners: Problems and Potential”
https://researchmap.jp/multidatabases/multidatabase_contents...
I browsed some entries of your dictionary and indeed their are (sometimes quite elaborate) explanations. I could easily why it ran out of steam, especially even a basic compiling is a daunting task. Also contributors are fews. On the Jibiki.fr (Japanese-French) project, most of the corrections are made by two members. They're starting from an existing dictionary and it still took years to just check the headwords.
Thanks very much for the paper. I'll read it. I actually already had one of your paper on my machine (Asialex 2011 proceedings) but haven't read it yet.
It also seems to have some unevenness in coverage. For example, the entry for the word “anecdata” (a word discussed recently at [1]), has five illustrative quotations, which are quite handy [2]. The entry for the more mundane “anecdote,” however, has none [3]. Such unevenness might be inevitable in volunteer dictionary projects, as volunteers like to work on the more interesting words.
[1] https://news.ycombinator.com/item?id=28375767
We're translating some strings on our software user interface, and checking the abbreviations and acronyms used. Sometimes there are amusing or [nsfw] connotations in other languages! Thank you Wiktionary for warning us about abbreviating "low pressure" as "LP" in Taiwan.
Q: Is it possible to download Wiktionary?
A: Yes. https://dumps.wikimedia.org/enwiktionary/ should have the latest copy of the main namespace. The cleanest navigation page is https://dumps.wikimedia.org/. Just download a -articles.xml.bz2 file and some software to read it (for nix, for Windows).
Q: Can I use data from Wiktionary in my program?
A: As long as you meet the conditions of the GNU Free Documentation License or Creative Commons Attribution/Share-Alike License, certainly.
Latest dump for English is from September 1. I wouldn’t know whether it has all the data or how easy it is to parse it.
Indeed, it depends on the language and your goals - I had a very high success rate plucking out Russian grammatical tables from English Wiktionary with a few hours of scripting the data cleaning (https://github.com/thombles/declensions). I have a theory that you could get better results using an offline archive of the page sources but haven't tried this yet.
https://github.com/nikvdp/dictionary-api/blob/master/convert...