AutoKanji
Javascript library that provides autocomplete suggestions for kanji based on a kana input. The kana to kanji translations are based off the JMDict Dictionary Project.
Installation
npm i autokanji
Usage
After installing and requiring the autokanji library the following functionality can be used:
- Find - returns an array of matches in descending leniency
var autoKanji = require("autokanji");
var kanji;
kanji = autokanji.find("γγ£γγ"); // Returns: ['ε¦ζ ‘']
- SetLenience - changes the level of leniency we check when determining possible matches. Setting this to 1 makes sure all characters in input must match the kanji translation and 2 makes sure every character but the last one matches and so on. The default is 2.
var autoKanji = require("autokanji");
kanji = autoKanji.find("γγ€γ") // Returns: ['η±γ','ζγ','εγ','ε§','ε']
autoKanji.setLenience(3);
kanji = autoKanji.find("γγ€γ") // Returns: ['η±γ','ζγ','εγ','ε§','ε','δΊ']
autoKanji.setLenience(1);
kanji = autoKanji.find("γγ€γ") // Returns: ['η±γ','ζγ','εγ']
Dictionary
The dictionary of kana to kanji translations is based of a JMDict file acquired on 12/7/2019. The file was translated to JSON using JMdict Parser that transformed to a json object containing only words that had kana to kanji representations using the JQ tool. This was then used to construct a trie using the JSONTrie CLI tool and compressed to be included with this package.
Bundlers
To use this package with a bundler like webpack it is necessary to emit the "AutoKanjiTrie.json.gz" dictionary to the root of your project.
module.exports = {
entry: ['./src/index.js', './node_modules/autokanji/AutoKanjiTrie.json.gz'],
...
module: {
rules: [
{
test: /\.gz/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: '../',
publicPath: '../'
}
}
]
}
}