Skip to content

bokuweb/hojin-rs

Repository files navigation

hojin-rs

Compact, read-only search dictionaries for Japanese corporate names and corporate numbers.

hojin provides exact normalized-name lookup, address-aware ranking, corporate-number lookup, and prefix suggestions. Native indexes are memory-mapped, while variable-size records use independently compressed zstd frames. The same compact suggestion bundle can be searched from WebAssembly in browsers and Node.js.

Features

  • standalone Rust crate with no application-framework dependency
  • Unicode, legal-form, legacy-character, and Japanese-address normalization
  • exact corporate-name lookup with address-aware ranking
  • direct 13-digit corporate-number lookup
  • alternate name, English name, and furigana indexes
  • mmap-backed FST, compact fixed-width indexes, and delta-varint postings
  • block-addressable zstd record storage
  • compact prefix-suggestion bundle for WASM/npm
  • optional adapter for NTA headerless Unicode CSV files

Native use

[dependencies]
hojin = "0.1"
use hojin::CorporateDictionary;

let dictionary = CorporateDictionary::open("/opt/dictionaries/corporations-2026-06")?;
let candidates = dictionary.resolve_exact(
    "(株)ABC",
    Some("東京都千代田区丸の内1-1-1"),
)?;

let corporation = dictionary.get_by_corporate_number(7_000_012_050_002)?;
# Ok::<(), anyhow::Error>(())

Registered addresses are never overwritten by query text. Exact name-and-address matches rank first, followed by compatible address containment and name-only matches. Active corporations win ties.

Build from NTA CSV

Download and extract the Unicode CSV files from the NTA full-data download page, then run:

cargo run --release --features cli --bin build-hojin-dictionary -- \
  --output /tmp/corporations-2026-06 \
  /path/to/00_zenkoku_all_*.csv

See DATA-LICENSE.md before redistributing NTA-derived artifacts. Source data and generated nationwide dictionaries are deliberately excluded from the Rust crate, npm package, and repository.

WASM/npm suggestions

Build a browser package:

wasm-pack build crates/hojin-wasm \
  --release --target web --scope bokuweb --out-dir pkg-web

Build a Node.js package:

wasm-pack build crates/hojin-wasm \
  --release --target nodejs --scope bokuweb --out-dir pkg-node
import init, { CorporateSuggester } from "@bokuweb/hojin-wasm";

await init();
const response = await fetch("/dictionary/2026-06/suggestions.bin");
const suggester = new CorporateSuggester(
  new Uint8Array(await response.arrayBuffer()),
);

const candidates = suggester.suggest("鳥取簡易", {
  limit: 10,
  includeClosed: false,
});

Corporate numbers are returned to JavaScript as 13-digit strings. The npm package contains code only; versioned dictionary bundles should be served separately, preferably with Content-Encoding: br and optional prefecture or leading-character shards.

Artifact format

File Purpose Access
manifest.json schema, source/terms/files, processor version, counts, SHA-256 startup read
names.fst normalized name to posting offset mmap
numbers.idx 48-bit corporate number to record ID mmap + binary search
postings.bin delta-varint record IDs mmap
records.idx compact record-to-block location mmap
blocks.idx zstd frame offsets and lengths mmap
records.zst independently compressed record blocks mmap + selective decode
suggestions.bin lookup FST, postings, front-coded display/address tables WASM memory or native bytes

Do not overwrite dictionary files while readers have them mapped. Build a new versioned directory and atomically switch a symlink or configuration pointer.

Size reference

Measured with the NTA Tottori Unicode snapshot used during development: 20,153 corporations and 29,422 suggestion entries.

Artifact Size
complete dictionary directory 3,007,399 bytes
suggestions.bin 1,355,591 bytes
suggestions.bin with Brotli level 11 586,915 bytes
release WASM 126,763 bytes
npm tarball, without dictionary data 61,650 bytes

These measurements are reference points, not guarantees for other source snapshots.

License

Source code is licensed under the MIT License. NTA source data and artifacts derived from it are not relicensed under MIT; see DATA-LICENSE.md.

About

Compact Japanese corporate-name dictionary with mmap, zstd, and WASM suggestions

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages