{"id":20951198,"url":"https://github.com/lingdong-/rrpl","last_synced_at":"2025-04-04T07:08:17.406Z","repository":{"id":41420174,"uuid":"156568013","full_name":"LingDong-/rrpl","owner":"LingDong-","description":"Describing Chinese Characters with Recursive Radical Packing Language (RRPL) ","archived":false,"fork":false,"pushed_at":"2020-12-28T00:10:08.000Z","size":12763,"stargazers_count":938,"open_issues_count":8,"forks_count":47,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-28T06:08:41.466Z","etag":null,"topics":["chinese","cjk-characters","font","markup-language","radicals","typography"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LingDong-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-07T15:33:12.000Z","updated_at":"2025-03-28T00:06:02.000Z","dependencies_parsed_at":"2022-08-25T06:20:26.645Z","dependency_job_id":null,"html_url":"https://github.com/LingDong-/rrpl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingDong-%2Frrpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingDong-%2Frrpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingDong-%2Frrpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingDong-%2Frrpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LingDong-","download_url":"https://codeload.github.com/LingDong-/rrpl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chinese","cjk-characters","font","markup-language","radicals","typography"],"created_at":"2024-11-19T00:57:27.466Z","updated_at":"2025-04-04T07:08:17.373Z","avatar_url":"https://github.com/LingDong-.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](doc/screen000-1.png)\n# Recursive Radical Packing Language\n\nRecursive Radical Packing Language (RRPL) is a proposal for a method of describing arbitrary Chinese characters concisely while retaining their structural information. Potential fields for usage include font design and machine learning. In RRPL, each Chinese character is described as a short string of numbers, symbols, and references to other characters. Its syntax is inspired by markup languages such as LaTeX, as well as the traditional \"米\" grids used for calligraphy practice.\n\n\n**5000+** Traditional Chinese Characters and radicals are currently described using this language. You can download a .json file containing all of them (and unicode mapping) here: [dist/min-trad.json](./dist/min-trad.json)\n\nCheck out Chinese character \u0026 radical visualizations made with RRPL [here](https://chinese-radical-vis.glitch.me) and [here](https://cjk-morph.glitch.me).\n\n## Syntax\n\nEach Chinese character is described as a combination of components. These components can be other characters or radicals, as well as *building blocks*, which defines the simplest shapes that make up every component. Combination can be applied recursively to describe ever more complex glyphs.\n\nBelow is an overview of this syntax; You can also **check out the [Interactive Demo](https://lingdong-.github.io/rrpl/)** to play with it yourself.\n\n### Building Blocks\n\nA building block is a string of the alphabet {`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`}, in which the presence of a number indicates a corresponding stroke to be drawn on a \"米\" grid:\n\n```\n 1 2 3\n  \\|/\n8 -+- 4\n  /|\\\n 7 6 5\n```\n`0` indicates that no stroke should be drawn in this block.\n\n**Example:**\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003ctr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/1.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e48\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/2.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e24578\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Packing\n\nBuilding blocks can be packed horizontally or vertically using the `-` and `|` symbols respectively to compose more complex glyphs. These symbols can be chained to pack more than two symbols with equal room.\n\n**Example:**\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003ctr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/3.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e27-26-26\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/4.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e2468|24578\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Grouping\n\n`(` and `)` symbols can be used to group components together so mixed horizontal and vertical packing can happen in the correct order.\n\n**Example:**\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003ctr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/5.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e(48|37)-(25678|27)-(37|15)\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/6.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e(46-68)|(246-268)|(24-28)\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\n### Referencing\n\nOther characters and radicals can be referenced directly to build a new character. The parser will dump the contents of the reference glyph directly into the string, similar to C/C++ `#include` feature. This makes it especially easy to describe the more complicated Chinese characters, as most of them consist of radicals.\n\n\n**Example:**\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003cth\u003eResult\u003c/th\u003e\u003cth\u003eCode\u003c/th\u003e\u003ctr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/7.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e廿|468|由|(八)\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/8.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e((車|(山))-(殳))|(手)\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/9.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e((口)-(口))|(甲)|十\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./doc/svg/10.svg\"\u003e\u003c/td\u003e\u003ctd\u003e\u003ccode\u003e(((木)-(缶)-(木))|(冖))|((鬯)-(彡))\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\n## Parser\n\nAn baseline parser is included in `rrpl_parser.js`, which powers this [Interactive Demo](https://lingdong-.github.io/rrpl/). It can be used with browser-side JavaScript as well as Node.js:\n\n```javascript\n//require the module: (or in html, \u003cscript src=\"./rrpl_parser.js\"\u003e\u003c/script\u003e)\nvar parser = require('./rrpl_parser.js');\n\n//obtain an abstract syntax tree\nvar ast = parser.parse(\"(48|37)-(25678|27)-(37|15)\");\n\n//returns line segments (normalized 0.0-1.0) that can be used to render the character\nvar lines = parser.toLines(parser.toRects(ast));\n\n```\n## File Type\n\nRRPL data can be stored in a JSON file, whith the root object mapping unicode characters to their respective description, e.g.\n\n```javascript\n{\n  \"一\":\"48\",\n  \"丁\":\"468|26|27\",\n  \"上\":\"246|248\",\n  \"不\":\"(48-45678-48)|(3-26-1)\",\n  \"丕\":\"不|一\",\n  \"中\":\"(46-2468-68)|(24-2468-28)\",\n  \"串\":\"中|中\"\n}\n```\n\nThe references in these files are usually first expanded before rendering is attempted. This can be done in two ways. The first is using `parser.preprocess(json_object)` in `rrpl_parser.js`, while the second is using `compile.js`. More documentation can be found in the header comments of these files.\n\nThe JSON files can be further compressed into (and uncompressed from) a binary file around half of the size of the original using `compress.js`, by using a half byte to encode each symbol in the RRPL alphabet.\n\n\n## Downloads\n\n- **[dist/min-trad.json](dist/min-trad.json)** contains RRPL description of 5000+ traditional Chinese characters stored in JSON format.\n- **[dist/RRPL.ttf](dist/RRPL.ttf)** contains a True Type Font (ttf) containing 5000+ traditional Chinese characters with glyphs generated by the default parser. Below is a screenshot of the font in macOS TextEdit.app:\n![](doc/screen001.png)\n\n\n\n\n## Tools\n\n### Rendering\n\n\n- Generate a `preview.html` web page containing a rendering of all characters in a RRPL json file:\n\n```\n$node render.js preview path/to/input.json\n```\n\n- Generate a `realtime.html` web page where user inputs can be parsed and rendered interactively: (Characters defined in the input file will be available for referencing)\n\n```\n$node render.js realtime path/to/input.json\n```\n\n### Exporting\n\n- Export a folder of SVG (Scalable Vector Graphics) rendering of each character in a RRPL json file:\n\n```\n$node export_glyphs.js path/to/input.json path/to/output/folder 0\n```\nContrary to what `render.js` generates, these SVG's contains \"outlines\" of the glyphs instead of simple strokes. More settings such as thickness can be tweaked in the source code of `export_glyphs.js`; Command-line API will come later.\n \n- To generate a TTF (True Type) font from the aforementioned SVG's, [FontForge](https://fontforge.github.io/en-US/)'s python library can be used for this purpose. (`pip install fontforge`) An example can be found in `tools/forge_font.py`.\n \n\n\n## Applications\n\nSince RRPL reduces all Chinese characters to a short string of numbers, their structure can be learned by sequential models such as Markov chains, RNN's and LSTM's without much difficulty. I've applied RNN (Recurrent Neural Networks) to the language to hallucinate non-existent Chinese characters. Below are some characters generated by training overnight on ~1000 RRPL character descriptions, with the visuals rendered using a pix2pix model. A separate repo for that project will be created soon.\n\n![](doc/radicalrnn.png)\n\n## Contributing\n\n`rrpl.json` contains the latest, work-in-progress version. There're some 5,000 characters in there, but there're over 50,000 Chinese characters in existence! So help is very much appreciated. If you'd like to help with this project, please append new characters to the file and submit a pull request. For more info, contact me by sending an email to lingdonh[at]andrew[dot]cmu[dot]edu.\n\n\nBelow is a rendering of all 5000+ Chinese characters denoted using RRPL so far. Click on the image to enlarge.\n\n![](doc/screen002.png)\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flingdong-%2Frrpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flingdong-%2Frrpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flingdong-%2Frrpl/lists"}