UNPKG

kusamoji

Version:

Japanese morphological analyzer for Node.js — Viterbi tokenizer with mmap dict loading and pluggable POS-source strategy

27 lines (21 loc) 618 B
"use strict"; /** * InHeapPosSource — strategy adapter that wraps the existing in-heap * pos_buffer. Behaviorally identical to upstream kusamoji. */ class InHeapPosSource { constructor(tokenInfoDictionary) { this._dict = tokenInfoDictionary; this._calls = 0; } getFeaturesById(token_info_id) { this._calls++; let pos_id = this._dict.dictionary.getInt(token_info_id + 6); return this._dict.pos_buffer.getString(pos_id); } stats() { return { kind: 'in-heap', calls: this._calls }; } close() {} } module.exports = { InHeapPosSource };