Skip to content

Releases

v3.1.0

Choose a tag to compare

@github-actions github-actions released this 21 Nov 08:53
4b62c4a

kuromojin now analyzes text with its own analyzer and its own dictionary file. It no longer uses kuromoji.js at runtime, and it has no runtime dependencies.
The tokens are compatible with the ones of kuromoji.js, so most users only need to update.

Highlights

Faster and smaller

3.0.2 3.1.0 Reduction
Load of the dictionary 440 ms 51 ms 88%
Analysis of each line of js-primer 2,206 ms 167 ms 92%
Memory after the load 182 MB 27.2 MB 85%
Installed size with dependencies 47.7 MB 5.10 MB 89%
textlint with textlint-rule-preset-ja-technical-writing on js-primer 16.97 s 4.17 s 75%

The measurements are in #27 and #38.

One dictionary file

  • The dictionary of the package is one file, dict/kuromojin.dict (4.8 MB, was 17.8 MB in 12 files).
  • Node.js needs no setting.
  • A browser build with Vite or webpack 5 needs no setting either: the bundler copies the dictionary into the build (#37).
  • esbuild, or a page without a bundler, passes the URL of the dictionary as dicPath. A dicPath of a kuromoji.js dictionary directory still works.
  • Next.js on the server needs serverExternalPackages: ["kuromojin"].
import { tokenize } from "kuromojin";

// Node.js, Vite, and webpack 5: no setting
const tokens = await tokenize(text);

// esbuild or no bundler: pass the URL of the dictionary
const tokensFromCdn = await tokenize(text, {
    dicPath: "https://cdn.jsdelivr.net/npm/kuromojin@<version>/dict/kuromojin.dict"
});

Tokens are reused everywhere

  • tokenize() and tokenizeForSentence() of getTokenizer() share one cache, so a text is analyzed once (#13).
  • Both return the same read-only array for the same text.
  • The cache keeps the 1,000 most recently used texts (was 10,000), which uses less memory.

Dictionary versions

  • The new option dictionaryVersion chooses the dictionary by the date of a version, such as "2007-08-01".
  • A date that is not a released version is an error.
  • Without the option, the dictionary does not change within a major version.

Notes for upgrading

  • Types: The tokenizer of getTokenizer() returns Readonly<Readonly<KuromojiToken>[]>, the same type as tokenize(). TypeScript code that assigns the result to KuromojiToken[] needs the read-only type. Do not change the returned array or its tokens.
  • Deprecated: tokenize of the tokenizer of getTokenizer(). Use tokenize(text) of kuromojin, or tokenizeForSentence when the code can not await.
  • getTokenizer(): Its tokenizer has tokenize and tokenizeForSentence only. It is not the tokenizer object of kuromoji.js.
  • Bug fix: A character written as a surrogate pair, such as an emoji, is one character. kuromoji.js lost characters after it.
  • License: MIT AND Apache-2.0, because the analyzer is derived from kuromoji.js.

Documentation

  • The README is rewritten around tokenize(text). It explains a token with an example and lists the parts of speech.

Internal

  • lru_map is removed (#31).
  • The repository moved to the textlint organization, and it uses pnpm and Vitest (#33, #34).
  • pnpm run profile and pnpm run compare measure the performance, and CI compares a pull request with its base (#27).

Thanks

kuromojin has used kuromoji.js by Takuya Asano for more than ten years, and many textlint rules for Japanese exist because of it.
The analyzer of this release is a port of the tokenizer of kuromoji.js and of doublearray, and the dictionary is converted from the dictionary of kuromoji.js.
Thank you to Takuya Asano and the contributors of kuromoji.js, and to the authors of Kuromoji (Atilika) and mecab-ipadic, whose work it builds on.

What's Changed

Features

  • feat: analyze with an own analyzer and a dictionary file of kuromojin, and add a performance profile by @azu in #27
  • feat: reuse tokens in the tokenizer of getTokenizer by @azu in #28
  • feat: use the dictionary of the package in a browser build without a setting by @azu in #37

Documentation

  • docs: add sdev and specify the own analyzer and dictionary format by @azu in #24
  • docs: specify dictionary versions and the online playground by @azu in #25
  • docs: rewrite the README around which function to use by @azu in #29
  • docs: fold getTokenizer in the README and deprecate tokenize of the tokenizer by @azu in #30
  • docs: explain tokens with an example and list the parts of speech by @azu in #32
  • docs: update the package description by @azu in #36

Refactoring

  • refactor: remove the lru_map dependency by @azu in #31
  • perf: load the dictionary faster and keep less of it in memory by @azu in #38

Maintenance

  • chore: move to pnpm and update the dependencies by @azu in #33
  • chore: update repository URLs to textlint/kuromojin by @azu in #34

Full Changelog: v3.0.2...v3.1.0


Generated by Claude Code

v3.0.2

Choose a tag to compare

@github-actions github-actions released this 17 Nov 14:33
917cb77

What's Changed

Documentation

  • docs: add FAQ for duplicated kuromojin copies by @azu in #20

Refactoring

  • perf: resolve the default dictionary path only when loading the dictionary by @azu in #21

CI

  • ci: add release workflows for npm trusted publishing by @azu in #22

Full Changelog: v3.0.1...v3.0.2

v3.0.1

Choose a tag to compare

@azu azu released this 13 Apr 03:51
0d0faef

Bug Fixes

Features

v3.0.0

Choose a tag to compare

@azu azu released this 24 Apr 05:50

Bug Fixes

Features

  • use lru_map for caching (57952f8)

BREAKING CHANGES

  • deps: update to kuromoji@0.1.2

It includes bug fix, but some tokens will be changed.
takuyaa/kuromoji.js#37

v2.1.1

Choose a tag to compare

@azu azu released this 21 Dec 05:32

Bug Fixes

  • deps: Pin kuromoji@0.1.1 again (d2e54bd)

Revert 2.1.0 parts
#8

v2.1.0

Choose a tag to compare

@azu azu released this 21 Dec 05:21

Features

2.0.0

Choose a tag to compare

@azu azu released this 07 Jul 05:53

Code Refactoring

BREAKING CHANGES

Remove default function

kuromojin v1.1.0 export tokenize as default function.
kuromojin v2.0.0 remove the default function.

// v1.x
import kuromojin from "kuromojin";
// kuromojin === tokenize

V2.0 should use import {tokenize} from "kuromojin" instead of it

// v2.x
import {tokenize} from "kuromojin";

1.5.1

Choose a tag to compare

@azu azu released this 07 Jul 05:29

Clean Build

1.5.0

Choose a tag to compare

@azu azu released this 07 Jul 05:27

Features

  • kuromojin: support process.env.KUROMOJIN_DIC_PATH (6216102)

1.4.0

Choose a tag to compare

@azu azu released this 06 Oct 12:51

Features

  • browser: support window.kuromojin.dicPath global options (#3) (15c1bae)