kusamoji
Version:
Japanese morphological analyzer for Node.js — Viterbi tokenizer with mmap dict loading and pluggable POS-source strategy
29 lines (24 loc) • 864 B
JavaScript
;
/**
* POS-source strategy factory.
*
* Selects the POS feature lookup implementation based on env vars.
* When KUSAMOJI_LAZY_POS=1, returns a LazyDiskPosSource that disk-backs
* the ~1.3 GB tid_pos blob. Otherwise returns null (upstream in-heap).
*/
let { InHeapPosSource } = require("./in-heap");
let { LazyDiskPosSource } = require("./lazy-disk");
/**
* @param {object} opts
* @param {object} opts.tokenInfoDictionary
* @param {string} opts.dictPath
* @returns {object|null}
*/
function selectPosSource({ tokenInfoDictionary, dictPath }) {
let lazy = (process.env.KUSAMOJI_LAZY_POS || "").trim();
if (lazy === "1" || lazy === "true" || lazy === "on") {
return new LazyDiskPosSource({ tokenInfoDictionary, dictPath });
}
return null;
}
module.exports = { selectPosSource, InHeapPosSource, LazyDiskPosSource };