morfeusz2-node-bindings
v0.1.2
Published
Synchronous Node.js bindings for Morfeusz 2 (analysis + synthesis) using N-API (`node-addon-api`).
Downloads
274
Readme
morfeusz2-node
Synchronous Node.js bindings for Morfeusz 2 (analysis + synthesis) using N-API (node-addon-api).
Usage
const morfeusz = require("morfeusz2-node");
console.log(morfeusz.version());
console.log(morfeusz.getDictionaryInfo());
const res = morfeusz.analyse("Ala ma kota.", { returnGraph: true });
console.log(res.tokens[0]);
console.log(res.graph.nodes, res.graph.edges.length);
console.log(morfeusz.generate("piec:s", { dedupe: true }).slice(0, 10));
console.log(morfeusz.generateTagged("piec:s", "subst:sg:dat:m3"));Notes:
analyse().tokens[].start/endare Morfeusz graph node numbers (the same numbering used bygraph.edges[].from/to).- Input/output strings are UTF-8 (addon forces
Morfeusz::setCharset(UTF8)).
Dictionaries (embedded vs external)
This build is configured to use an external dictionary (DEFAULT_DICT_NAME=sgjp) and skip dictionary building.
- At runtime,
index.jscallssetDictionary(...)with a bundled dictionary directory if found (prefers./dict, then falls back to../vendor/dictin this monorepo layout). You can override this withMORFEUSZ2_DICT_DIR. - To switch dictionaries at runtime, use
setDictionary(...):setDictionary("sgjp")(dictionary name; searched inMorfeusz::dictionarySearchPaths)setDictionary("C:\\path\\to\\dictdir")(directory containingNAME-a.dictandNAME-s.dict)setDictionary("C:\\path\\to\\dictdir\\sgjp-a.dict")(points to a specific file; addon infers name + directory)
Embedding a default dictionary requires Morfeusz dictionary sources (to generate default_fsa.cpp / default_synth_fsa.cpp); this repo currently ships prebuilt .dict files instead.
Publishing
npm publish runs prepack, which:
- copies
../vendor/morfeuszinto./vendor/morfeuszand../vendor/dictinto./dict - builds the addon for the current platform
- stages the build into
./prebuilds/<platform>-<arch>/
Other platforms will fall back to building from source at install time (requires a working compiler toolchain + CMake).
