Enable passing options to subcommands

This commit is contained in:
2026-01-08 14:33:49 +01:00
parent cc6875dcc5
commit 1f89717734

View File

@@ -1,7 +1,7 @@
const { spawnSync } = require("child_process");
async function analyse(input) {
const { stdout } = spawnSync(MORFEUSZ_ANALYSER_BIN, [], { input });
async function analyse(input, ...args) {
const { stdout } = spawnSync(MORFEUSZ_ANALYSER_BIN, args, { input });
const linePattern = /^\s?(?<opening>\[)?(?<start>\d+),(?<end>\d+),(?<segment>,|(.+?)),(?<lemma>,|(.+?)),(?<tags>[\w:.]+),(?<frequency>_|(.+?)),(?<qualifiers>_|(.+?))(?<ending>\])?$/;
@@ -38,8 +38,8 @@ async function analyse(input) {
return output;
}
async function runConcraftLocally(input) {
const { stdout, stderr } = spawnSync(CONCRAFT_BIN, ["tag", CONCRAFT_MODEL], { input });
async function runConcraftLocally(input, ...args) {
const { stdout, stderr } = spawnSync(CONCRAFT_BIN, ["tag", CONCRAFT_MODEL, ...args], { input });
const error = stderr.toString();
@@ -65,7 +65,7 @@ async function invokeConcraftRemotely(dag) {
return data.dag;
}
async function desambiguate(analysis) {
async function desambiguate(analysis, ...args) {
const input = analysis
.flatMap(a => a)
.map(a => ({ ...a, tags: Object.values(a.tags).filter(t => t).map(tag => tag.split(".")[0]).join(":") }))
@@ -73,7 +73,7 @@ async function desambiguate(analysis) {
.join("\n");
const response = await (CONCRAFT_MODE === 'local' ? runConcraftLocally : invokeConcraftRemotely)(input);
const response = await (CONCRAFT_MODE === 'local' ? runConcraftLocally : invokeConcraftRemotely)(input, ...args);
const keys = ["start", "end", "segment", "lemma", "tags", "frequency", "qualifiers", "prob", "interp_meta", "eos", "seg_meta", "disamb"];
const output = [];
@@ -99,9 +99,9 @@ async function desambiguate(analysis) {
return output;
}
async function danalyse(input) {
const analysis = await analyse(input);
return await desambiguate(analysis);
async function danalyse(input, morfeuszArgs, concraftArgs) {
const analysis = await analyse(input, morfeuszArgs);
return await desambiguate(analysis, concraftArgs);
}
function generate(input, ...tags) {