Synchronous Node.js bindings for Morfeusz 2 (analysis + synthesis) using N-API (`node-addon-api`).
npm install morfeusz2-node-bindingsSynchronous Node.js bindings for Morfeusz 2 (analysis + synthesis) using N-API (node-addon-api).
``js
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/end are Morfeusz graph node numbers (the same numbering used by graph.edges[].from/to).Morfeusz::setCharset(UTF8)
- Input/output strings are UTF-8 (addon forces ).
This build is configured to use an external dictionary (DEFAULT_DICT_NAME=sgjp) and skip dictionary building.
- At runtime, index.js calls setDictionary(...) with a bundled dictionary directory if found (prefers ./dict, then falls back to ../vendor/dict in this monorepo layout). You can override this with MORFEUSZ2_DICT_DIR.setDictionary(...)
- To switch dictionaries at runtime, use :setDictionary("sgjp")
- (dictionary name; searched in Morfeusz::dictionarySearchPaths)setDictionary("C:\\path\\to\\dictdir")
- (directory containing NAME-a.dict and NAME-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.
npm publish runs prepack, which:../vendor/morfeusz
- copies into ./vendor/morfeusz and ../vendor/dict into ./dict./prebuilds/
- builds the addon for the current platform
- stages the build into
Other platforms will fall back to building from source at install time (requires a working compiler toolchain + CMake).