Enable passing options to subcommands
This commit is contained in:
20
index.js
20
index.js
@@ -1,7 +1,7 @@
|
|||||||
const { spawnSync } = require("child_process");
|
const { spawnSync } = require("child_process");
|
||||||
|
|
||||||
async function analyse(input) {
|
async function analyse(input, ...args) {
|
||||||
const { stdout } = spawnSync(MORFEUSZ_ANALYSER_BIN, [], { input });
|
const { stdout } = spawnSync(MORFEUSZ_ANALYSER_BIN, args, { input });
|
||||||
|
|
||||||
const linePattern = /^\s?(?<opening>\[)?(?<start>\d+),(?<end>\d+),(?<segment>,|(.+?)),(?<lemma>,|(.+?)),(?<tags>[\w:.]+),(?<frequency>_|(.+?)),(?<qualifiers>_|(.+?))(?<ending>\])?$/;
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runConcraftLocally(input) {
|
async function runConcraftLocally(input, ...args) {
|
||||||
const { stdout, stderr } = spawnSync(CONCRAFT_BIN, ["tag", CONCRAFT_MODEL], { input });
|
const { stdout, stderr } = spawnSync(CONCRAFT_BIN, ["tag", CONCRAFT_MODEL, ...args], { input });
|
||||||
|
|
||||||
const error = stderr.toString();
|
const error = stderr.toString();
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ async function invokeConcraftRemotely(dag) {
|
|||||||
return data.dag;
|
return data.dag;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function desambiguate(analysis) {
|
async function desambiguate(analysis, ...args) {
|
||||||
const input = analysis
|
const input = analysis
|
||||||
.flatMap(a => a)
|
.flatMap(a => a)
|
||||||
.map(a => ({ ...a, tags: Object.values(a.tags).filter(t => t).map(tag => tag.split(".")[0]).join(":") }))
|
.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");
|
.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 keys = ["start", "end", "segment", "lemma", "tags", "frequency", "qualifiers", "prob", "interp_meta", "eos", "seg_meta", "disamb"];
|
||||||
const output = [];
|
const output = [];
|
||||||
@@ -99,9 +99,9 @@ async function desambiguate(analysis) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function danalyse(input) {
|
async function danalyse(input, morfeuszArgs, concraftArgs) {
|
||||||
const analysis = await analyse(input);
|
const analysis = await analyse(input, morfeuszArgs);
|
||||||
return await desambiguate(analysis);
|
return await desambiguate(analysis, concraftArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate(input, ...tags) {
|
function generate(input, ...tags) {
|
||||||
@@ -197,4 +197,4 @@ async function main([ interpreter, script, action, ...args ]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main(process.argv);
|
main(process.argv);
|
||||||
Reference in New Issue
Block a user