3.0.0 • Published 4 years ago

kuromojin v3.0.0

Weekly downloads
7,737
License
MIT
Repository
github
Last release
4 years ago

kuromojin Actions Status: test

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 => {
    // kuromoji.js's `tokenizer` instance
});

tokenize(text).then(results => {
    console.log(results)
    /*
    [ {
        word_id: 509800,          // 辞書内での単語ID
        word_type: 'KNOWN',       // 単語タイプ(辞書に登録されている単語ならKNOWN, 未知語ならUNKNOWN)
        word_position: 1,         // 単語の開始位置
        surface_form: '黒文字',    // 表層形
        pos: '名詞',               // 品詞
        pos_detail_1: '一般',      // 品詞細分類1
        pos_detail_2: '*',        // 品詞細分類2
        pos_detail_3: '*',        // 品詞細分類3
        conjugated_type: '*',     // 活用型
        conjugated_form: '*',     // 活用形
        basic_form: '黒文字',      // 基本形
        reading: 'クロモジ',       // 読み
        pronunciation: 'クロモジ'  // 発音
      } ]
    */
});

For browser/global options

If window.kuromojin.dicPath is defined, kuromojin use it as default dict path.

import {getTokenizer} from "kuromojin";
// Affect all module that are used kuromojin.
window.kuromojin = {
    dicPath: "https://cdn.jsdelivr.net/npm/kuromoji@0.1.2/dict"
};
// this `getTokenizer` function use "https://kuromojin.netlify.com/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";
// kuromojin === tokenize

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

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

nonnoun@everything-registry/sub-chunk-2036textlint-rule-ja-no-abusagetextlint-rule-ja-no-inappropriate-wordstextlint-rule-ja-no-inappropriate-words-resolatextlint-rule-ja-no-orthographic-variantstextlint-rule-ja-no-redundant-expressiontextlint-rule-ja-no-successive-wordtextlint-rule-ja-no-weak-phrasetextlint-rule-ja-simple-user-dictionarytextlint-rule-ja-sudachi-synonym-suggestiontextlint-rule-azure-service-nametextlint-rule-ieice-fukushitextlint-rule-ja-hiragana-daimeishitextlint-rule-ja-hiragana-fukushitextlint-rule-ja-hiragana-hojodoushitextlint-rule-ja-hiragana-keishikimeishitextlint-rule-ja-hirakutextlint-rule-ja-keishikimeishitextlint-rule-no-double-negative-jatextlint-rule-no-doubled-conjunctiontextlint-rule-no-doubled-conjunctive-particle-gatextlint-rule-max-appearence-count-of-wordstextlint-rule-max-tentextlint-rule-ja-tojihirakitextlint-rule-no-doubled-joshitextlint-rule-no-dropping-the-ratextlint-rule-no-dropping-the-ra-resolatextlint-rule-single-nadotextlint-rule-ondul-styletextlint-rule-no-duplicated-bunmatsu-hyougentextlint-rule-no-hoso-kinshi-yogotextlint-rule-no-parallel-katextlint-rule-no-renyo-chushitextstat-plugin-jakuromojistkuronurikuromoji-clike2dairajptext-to-emojigit-log-to-erratanlcst-parse-japanesenegaposi-analyzer-ja@azu/term-extract-js@kmuto/textlint-rule-kmu-termcheck@n00p3/ve-js@smori1983/vuepress-plugin-flexsearch@doujinreviewers/textlint-rule-for-creation@textlint-ja/textlint-rule-morpheme-match@textlint-ja/textlint-rule-no-dropping-i@textlint-ja/textlint-rule-no-filler@textlint-ja/textlint-rule-no-insert-dropping-sa@textlint-ja/textlint-rule-no-insert-re@zalastax/nolb-kuranalyze-desumasu-dearu
3.0.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

7 years ago

1.3.3

7 years ago

1.3.2

8 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago