kuromojin
Provide a high level wrapper for kuromoji.js.
Features
- Promise based API
- Cache Layer
- Fetch the dictionary at once
- Return same tokens for same text
Installation
npm install kuromojin
Usage
Export two API.
getTokenizer()
return Promise
that is resolved with kuromoji.js's tokenizer
instance.kuromojin as default
return Promise
that is resolved with analyzed text.
import {tokenize, getTokenizer} from "kuromojin";
getTokenizer().then(tokenizer => {
});
tokenize(text).then(results => {
console.log(results)
});
For browser/global options
If window.kuromojin.dicPath
is defined, kuromojin use it as default dict path.
import {getTokenizer} from "kuromojin";
window.kuromojin = {
dicPath: "https://cdn.jsdelivr.net/npm/kuromoji@0.1.2/dict"
};
getTokenizer();
getTokenizer({dicPath: "https://cdn.jsdelivr.net/npm/kuromoji@0.1.2/dict"})
:memo: Test dictionary URL
Note: backward compatibility for <= 1.1.0
kuromojin v1.1.0 export tokenize
as default function.
kuromojin v2.0.0 remove the default function.
import kuromojin from "kuromojin";
Recommended: use import {tokenize} from "kuromojin"
instead of it
import {tokenize} from "kuromojin";
Note: kuromoji version is pinned
kuromojin pin kuromoji's version.
It aim to dedupe kuromoji's dictionary.
The dictionary is large and avoid to duplicated dictionary.
Tests
npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT