Skip to content

Commit

Permalink
Ensure domain existence
Browse files Browse the repository at this point in the history
  • Loading branch information
zorkow committed Apr 2, 2024
1 parent c3f3b2e commit c7c8b28
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"postcommonjs": "node -e 'require(\"fs\").writeFileSync(\"cjs/package.json\", \"{\\n \\\"type\\\": \\\"commonjs\\\"\\n}\\n\");'",
"module": "pnpm tsc --module nodenext --outDir js --moduleResolution nodenext",
"postmodule": "node -e 'require(\"fs\").writeFileSync(\"js/package.json\", \"{\\n \\\"type\\\": \\\"module\\\"\\n}\\n\");'",
"pretest": "git submodule update --remote --merge; pnpm run compile; cd sre-tests; ln -s .. speech-rule-engine; npm install",
"compile": "pnpm run module",
"pretest": "git submodule update --remote --merge; pnpm compile; cd sre-tests; ln -s .. speech-rule-engine; npm install",
"compile": "pnpm module",
"clean": "rimraf js lib cjs",
"actionTest": "cd sre-tests; export SRE_JSON_PATH=../lib/mathmaps; pnpm jest --silent ",
"cleanAll": "make clean; make clean_min",
"prepublish": "pnpm run cleanAll; pnpm run build",
"build": "make -j 12 all; pnpm run commonjs; pnpm run module; pnpm webpack"
"prepublish": "pnpm cleanAll; pnpm buildAll",
"build": "make -j 12 all; pnpm module; pnpm webpack",
"buildAll": "make -j 12 all; pnpm commonjs; pnpm module; pnpm webpack"
},
"maintainers": [
"Volker Sorge <[email protected]> (http://www.cs.bham.ac.uk/~vxs)"
Expand Down
55 changes: 43 additions & 12 deletions ts/common/engine_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,49 @@ import { Engine, EnginePromise } from './engine.js';
import * as FileUtil from './file_util.js';
import { SystemExternal } from './system_external.js';

const MATHSPEAK_ONLY: string[] = ['ca', 'da', 'es'];

const EN_RULES: string[] = [
'chromevox', 'clearspeak', 'mathspeak', 'emacspeak', 'html'
];

function ensureDomain(feature: { [key: string]: boolean | string }) {
// This preserves the possibility to specify default as domain.
// < 3.2 this lead to the use of chromevox rules in English.
// >= 3.2 this defaults to Mathspeak. It also ensures that in other locales
// we get a meaningful output.
if ((feature.modality && feature.modality !== 'speech') ||
(!feature.modality && Engine.getInstance().modality !== 'speech')) {
return;
}
if (!feature.domain) {
return;
}
if (feature.domain === 'default') {
feature.domain = 'mathspeak';
return;
}
const locale = (feature.locale || Engine.getInstance().locale) as string;
const domain = feature.domain as string;
if (MATHSPEAK_ONLY.indexOf(locale) !== -1) {
if (domain !== 'mathspeak') {
feature.domain = 'mathspeak';
}
return;
}
if (locale === 'en') {
if (EN_RULES.indexOf(domain) === -1) {
feature.domain = 'mathspeak';
}
return;
}
if (domain !== 'mathspeak' && domain !== 'clearspeak') {
feature.domain = 'mathspeak';
}
}

// Engine setup method.

/**
* Method to setup and initialize the speech rule engine. Currently the
* feature parameter is ignored, however, this could be used to fine tune the
Expand All @@ -36,19 +78,8 @@ import { SystemExternal } from './system_external.js';
* @returns The promise that resolves once setup is complete.
*/
export async function setup(feature: { [key: string]: boolean | string }) {
ensureDomain(feature);
const engine = Engine.getInstance() as any;
// This preserves the possibility to specify default as domain.
// < 3.2 this lead to the use of chromevox rules in English.
// >= 3.2 this defaults to Mathspeak. It also ensures that in other locales
// we get a meaningful output.
if (
feature.domain === 'default' &&
(feature.modality === 'speech' ||
!feature.modality ||
engine.modality === 'speech')
) {
feature.domain = 'mathspeak';
}
const setIf = (feat: string) => {
if (typeof feature[feat] !== 'undefined') {
engine[feat] = !!feature[feat];
Expand Down

0 comments on commit c7c8b28

Please sign in to comment.