Skip to content

CJK char frequency #36

Closed
Closed

Description

@yhahn

TL;DR

  • good news is that there are definitely commonly used chinese characters that we can bundle together into special glyph PBFs.
  • bad news is that this amounts to about ~3000-4000 characters which will amount to a ~2-3MB overhead and it's not likely we can reduce this overhead much.
  • other good news is this approach will likely work for hangul (korean) which has similar size/range waste issues though not as bad as cjk.

Notes from weekend analysis (source committed here https://github.com/mapbox/fontserver/tree/char-spec/spec).

Background

Prep

Approach

Assuming a character that falls into the 4096 most freq character use can be grabbed from a set of CJK common PBFs or so, we can analyze the range count for our 12 vector tiles:

none (78 ranges)
[ '0-255',
  '19968-20223',
  '20224-20479',
  '20736-20991',
  '20992-21247',
  '21248-21503',
  '21504-21759',
  '21760-22015',
  '22016-22271',
  '22272-22527',
  '22528-22783',
  '22784-23039',
  '23040-23295',
  '23296-23551',
  '23552-23807',
  '23808-24063',
  '24064-24319',
  '24320-24575',
  '24576-24831',
  '24832-25087',
  '25088-25343',
  '25344-25599',
  '256-511',
  '25600-25855',
  '25856-26111',
  '26112-26367',
  '26368-26623',
  '26624-26879',
  '26880-27135',
  '27136-27391',
  '27392-27647',
  '27648-27903',
  '27904-28159',
  '28160-28415',
  '28416-28671',
  '28672-28927',
  '28928-29183',
  '29184-29439',
  '29440-29695',
  '29696-29951',
  '29952-30207',
  '30208-30463',
  '30464-30719',
  '30720-30975',
  '30976-31231',
  '31232-31487',
  '31488-31743',
  '31744-31999',
  '32000-32255',
  '32256-32511',
  '32512-32767',
  '32768-33023',
  '33280-33535',
  '33536-33791',
  '33792-34047',
  '34048-34303',
  '34304-34559',
  '34560-34815',
  '34816-35071',
  '35072-35327',
  '35584-35839',
  '35840-36095',
  '36096-36351',
  '36608-36863',
  '36864-37119',
  '37120-37375',
  '37888-38143',
  '38144-38399',
  '38400-38655',
  '38656-38911',
  '38912-39167',
  '39168-39423',
  '39424-39679',
  '39936-40191',
  '40448-40703',
  '40704-40959',
  '8192-8447',
  '8448-8703' ]

osm (26 ranges)
[ '0-255',
  '20224-20479',
  '20992-21247',
  '256-511',
  '28416-28671',
  '29440-29695',
  '29952-30207',
  '33536-33791',
  '38912-39167',
  '8192-8447',
  '8448-8703',
  'cjk-common-0',
  'cjk-common-1',
  'cjk-common-10',
  'cjk-common-11',
  'cjk-common-12',
  'cjk-common-13',
  'cjk-common-14',
  'cjk-common-2',
  'cjk-common-3',
  'cjk-common-4',
  'cjk-common-5',
  'cjk-common-6',
  'cjk-common-7',
  'cjk-common-8',
  'cjk-common-9' ]

modern (34 ranges)
[ '0-255',
  '22272-22527',
  '256-511',
  '26880-27135',
  '27136-27391',
  '27648-27903',
  '27904-28159',
  '28416-28671',
  '29184-29439',
  '29952-30207',
  '30976-31231',
  '32512-32767',
  '33280-33535',
  '33536-33791',
  '34304-34559',
  '39424-39679',
  '8192-8447',
  '8448-8703',
  'cjk-common-0',
  'cjk-common-1',
  'cjk-common-10',
  'cjk-common-11',
  'cjk-common-12',
  'cjk-common-13',
  'cjk-common-14',
  'cjk-common-15',
  'cjk-common-2',
  'cjk-common-3',
  'cjk-common-4',
  'cjk-common-5',
  'cjk-common-6',
  'cjk-common-7',
  'cjk-common-8',
  'cjk-common-9' ]

The scripts assume we split up the cjk-common PBF into chunks of 256. It looks like you will want most if not all of these 4096 characters as a baseline, always, all the time (if you run the script with 1 or 2 tiles alone you will often end up with 12-16 of the common ranges). You basically end up grabbing the common characters no matter what.

So combining the common glyphs into a single pack and eliminating the non cjk ranges from the list to reduce noise, we're down to:

osm (8 ranges)
[ '20224-20479',
  '20992-21247',
  '28416-28671',
  '29440-29695',
  '29952-30207',
  '33536-33791',
  '38912-39167',
  'cjk-common' ]

modern (15 ranges)
[ '22272-22527',
  '26880-27135',
  '27136-27391',
  '27648-27903',
  '27904-28159',
  '28416-28671',
  '29184-29439',
  '29952-30207',
  '30976-31231',
  '32512-32767',
  '33280-33535',
  '33536-33791',
  '34304-34559',
  '39424-39679',
  'cjk-common' ]

Conclusion + questions

Overall having a cjk-common glyph that takes precedence if a character falls into a fixed list of n (I picked 4096 based on a few runs -- 3000 not enough, 5000 has diminishing returns) looks like a good approach. You'll have most commonly used characters loaded and cached and will fire off requests as normal for other ranges as you hit less common characters.

The discrepancy between OSM's top characters and other analysis' top characters is worth some study though. Note that once we set this list changing it is very painful. It will affect any implementations using these endpoints and likely means we need to spec and version any endpoints around this strictly.

  • "Place language" differs from normal usage significantly in english, german, etc. This is likely (?) the case for Chinese as well and could lead to this discrepancy.
  • OSM data quality in China is an unknown to me. Setting a list of character frequency list based on the current state of OSM could be a bad idea without some overall confidence in current OSM data in China being representative of Chinese-language maps as a whole and future OSM data/map data.

Next actions

  • Similar analysis for Hangul
  • Branch of fontserver that can generate a PBF from a charlist rather than a start/end range,
  • Branch of llmr that uses a cjk charlist to request the common CJK PBF and fallback to normal range glyphs otherwise,
  • Test IRL
  • Consult/further research on chinese char freq questions

cc @mikemorris @kkaefer @ansis @nickidlugash

Activity

  1. yhahn commented on Jun 1, 2014

    @yhahn
    ContributorAuthor

    Added to the test above a first example of what happens when there are no common character range PBFs around (78 range requests).

  2. self-assigned this
    on Jun 18, 2014
  3. yhahn commented on Jun 19, 2014

    @yhahn
    ContributorAuthor

    @mikemorris answering some of your questions:

    we'll need to build separate common glyphs for korean and japanese?

    These languages all have a shared characteristic: Their writing systems all completely or partly use Chinese characters — Hànzì in Chinese, kanji in Japanese, hanja in Korean, and Chữ Nôm in Vietnamese. Chinese is written in Chinese characters only and requires approximately 4,000 characters for general literacy although there are up to 40,000 characters for reasonably complete coverage.

    From http://en.wikipedia.org/wiki/CJK_characters

    Basically: Korean, Japanese writing systems often include chinese characters for kind of "old-school" writing, and then have their own character/alphabet systems for the majority of normal use. For example, in Korea newspaper headlines are often have some CJK characters, and then the article will be in the Hangul character set.

    Ideally we do not need to build separate common CJK glyph range PBFs for other languages that use CJK. We would only need to do this if the frequency distribution of character usage in Korean or Japanese of CJK characters is very different from Chinese. Let's stick with a single set of common CJK for now.

    Korean: Hangul

    There is the separate issue of whether Korean Hangul (a very different character set and also very large portion of unicode) needs a common glyph freq analysis. It is a big character range in unicode (http://jrgraphix.net/r/Unicode/AC00-D7AF) though not nearly as huge as CJK:

    > parseInt('d7af',16) - parseInt('ac00',16);
    11183
    

    I did a quick analysis of this using a seoul OSM extract and recall from the results that likely a 256-512 set of common glyphs would have a very good impact. I haven't run an analysis that covers North/South Korea and that is what I think would be the next step here.

    *Japanese: Hiragana + Katakana

    I am less familiar with Japanese but these are two charactersets that do not cause as many headaches as CJK/Hangul. http://jrgraphix.net/r/Unicode/3040-309F, http://jrgraphix.net/r/Unicode/30A0-30FF

    > parseInt('30ff',16) - parseInt('3040',16);
    191
    
  4. mikemorris commented on Jun 19, 2014

    @mikemorris
    Contributor
  5. lxbarth commented on Jun 19, 2014

    @lxbarth

    @mikemorris - per chat, use the Overpass API to download extracts. You can create a download URL with bbox and curl it.

    @ajashton says there's also http://overpass-turbo.eu/ where you can use the wizard to easily make complex queries, eg place=city in "North Korea".

  6. mikemorris commented on Jun 19, 2014

    @mikemorris
    Contributor

    Thanks @lxbarth, got extracts of North Korea and South Korea to analyze now.

  7. mikemorris commented on Jun 20, 2014

    @mikemorris
    Contributor
  8. mikemorris commented on Jun 23, 2014

    @mikemorris
    Contributor

    Per chat with @nickidlugash, should we possibly do another analysis for traditional Chinese characters used in Taiwan, Hong Kong and Macau?

  9. yhahn commented on Jun 23, 2014

    @yhahn
    ContributorAuthor

    Start by adding more tile fixtures for these areas to

    and running analysis of what the request profile looks like using the existing common-cjk ranges. If these fare badly/worse than the current tests, then yes, I think you should look into finding out why.

  10. mikemorris commented on Jun 23, 2014

    @mikemorris
    Contributor

    [For Hangul], a 256-512 set of common glyphs would have a very good impact

    Committed results of a full analysis of North and South Korea. North Korea has very limited OSM coverage, but the entirety of glyphs in use ended up being just 445. It also appears that none of the glyphs in the Hangul Compatibility Jamo are used.

  11. mikemorris commented on Jun 24, 2014

    @mikemorris
    Contributor

    If these fare badly/worse than the current tests, then yes, I think you should look into finding out why.

    @yhahn These look significantly worse than mainland China to me, I think we'll be needing a cjk-traditional common set as well.

  12. mikemorris commented on Jun 24, 2014

    @mikemorris
    Contributor

    About 30% of simplified Chinese characters match simplified kanji (see shinjitai).[28] This makes it easier for people who know simplified characters to be able to read and understand Japanese kanji. For example, the character 国 (country) is written the same way in Japanese (国) although in traditional Chinese it is 國. However, those who understand traditional Chinese will understand a much greater proportion of Japanese Kanji, as the current standard Japanese character set is much more similar to traditional Chinese.
    https://en.wikipedia.org/wiki/Debate_on_traditional_and_simplified_Chinese_characters#Aesthetics

  13. mikemorris commented on Jun 25, 2014

    @mikemorris
    Contributor

    Adding all Hangul Unicode ranges:

  14. 3 remaining items

  15. mikemorris commented on Jun 26, 2014

    @mikemorris
    Contributor

    Best attempt so far at splitting cjk-common isn't all that impressive, feels like I'm just spinning wheels here and that even the best solution here is still incredibly fragile.

    In this test, cjk-osm is built only from the China OSM extract, and cjk-extended-osm is built from China, Taiwan and Japan extracts deduped against cjk-osm.

    cjk-combined-osm is the union of cjk-osm and cjk-extended-osm.

    range sizes
    cjk-osm 4096
    cjk-extended-osm 2048
    cjk-combined-osm 6144
    hangul-osm 1024
    
    china
    cjk-osm (10 ranges)
    cjk-extended-osm (79 ranges)
    cjk-combined-osm (7 ranges)
    
    taiwan
    cjk-osm (85 ranges)
    cjk-extended-osm (91 ranges)
    cjk-combined-osm (17 ranges)
    
    hong-kong
    cjk-osm (20 ranges)
    cjk-extended-osm (87 ranges)
    cjk-combined-osm (8 ranges)
    
    macau
    cjk-osm (6 ranges)
    cjk-extended-osm (83 ranges)
    cjk-combined-osm (4 ranges)
    
    north-korea
    hangul-osm (2 ranges)
    
    south-korea
    hangul-osm (7 ranges)
    
  16. mikemorris commented on Jun 26, 2014

    @mikemorris
    Contributor

    Only real way to fix Taiwan is to not trim at all.

    range sizes
    cjk-osm 4096
    cjk-extended-osm 2309
    cjk-combined-osm 6405
    
    china
    cjk-osm (10 ranges)
    cjk-extended-osm (79 ranges)
    cjk-combined-osm (6 ranges)
    
    taiwan
    cjk-osm (85 ranges)
    cjk-extended-osm (91 ranges)
    cjk-combined-osm (10 ranges)
    
    hong-kong
    cjk-osm (20 ranges)
    cjk-extended-osm (87 ranges)
    cjk-combined-osm (6 ranges)
    
    macau
    cjk-osm (6 ranges)
    cjk-extended-osm (83 ranges)
    cjk-combined-osm (4 ranges)
    
  17. mikemorris commented on Jun 26, 2014

    @mikemorris
    Contributor

    Added test fixtures for Japan:

    japan
    none (95 ranges)
    cjk-osm (14 ranges)
    cjk-modern (111 ranges)
    hangul-osm (95 ranges)
    ranges [ '0-255',
      '1024-1279',
      '12288-12543',
      '13312-13567',
      '256-511',
      '55296-55551',
      '57088-57343',
      '64000-64255',
      '65280-65535',
      '8192-8447',
      '8448-8703',
      '8704-8959',
      '9472-9727',
      'cjk-common' ]
    

    Interesting that there appear to be requests for characters in the High Surrogates and Low Surrogates ranges, which all appear as � to me.

  18. mikemorris commented on Aug 5, 2015

    @mikemorris
    Contributor

    TypeKit went with "dynamic subsetsetting", allowing requests for any number and combination of glyphs rather than predefined blocks.

    Instead of redownloading an entirely new font, we can now simply request the additional glyphs, and perform the update right in your browser. Need one glyph? We can do that! And when you need another, no need to download the first again.

    http://blog.typekit.com/2015/06/15/announcing-east-asian-web-font-support/

    It also sounds like this was a really easy issue for them to solve:

    After many years — working across four teams, on three continents, and in five time zones — we are proud to announce that we’ve extended Typekit’s web font service to support Chinese, Japanese and Korean fonts.

  19. kkaefer commented on Aug 6, 2015

    @kkaefer
    Member

    Super interesting read, thanks for posting!

  20. removed their assignment
    on Oct 19, 2016
  21. huangyingjie commented on Nov 4, 2016

    @huangyingjie

    hi @mikemorris , what about the recent schedule? It's in great request for me. And is there any way to take part in?

  22. glzcc commented on Dec 8, 2016

    @glzcc

    image
    download the file,how use this file?

  23. jayantchens commented on Jun 22, 2017

    @jayantchens

    @yhahn @mikemorris Thank you for your answer. Could you tell me the exact details? Developing webGL.js (javaScript) in web web pages?

  24. jcary741 commented on Oct 12, 2026

    @jcary741

    Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions