Skip to content

Packedcat/simple-pinyin-ime

Repository files navigation

Demo

This repo only implements the pinyin engine and does not have a virtual keyboard

demo

How to build dict

  1. download rawdict_utf16_65105_freq.txt from PinyinIME archive
  2. extra PinyinIME-refs_heads_main/jni/data/rawdict_utf16_65105_freq.txt to scripts folder
  3. convert encode to UTF-8
iconv -f UTF-16 -t UTF-8 rawdict_utf16_65105_freq.txt  > google_pinyin_rawdict_utf8_65105_freq.txt
  1. build dict
node scripts/preprocess.mjs

Dict structure

const dict = {
  b: [
    { w: '菝', f: 2.53953332627 }, // ba
    { w: '柏', f: 794.770968525 }, // bai
  ],
  ba: [
    { w: '菝', f: 2.53953332627 },
    { w: '办案', f: 824.018360007 }, // ban'an
  ],
}

Use

// dict structure ⬆️
const ime = new PinyinIME(dict)
ime.input('nou')
// read this field to get all hanzi candidates
console.log(ime.candidates)
// read this field to get current hanzi&pinyin combo
console.log(ime.label)

const ret = ime.pickCandidate(0)
// pickCandidate will return the result
interface Result {
  cadence: boolean // true mean all pinyin has converted to hanzi
  word: string // current picked word
  token: string //current picked token
}

Inspiration

https://leetcode.com/problems/word-break-ii/

https://github.com/dongyuwei/web-pinyin-ime

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors