mathml - 语音规则引擎 3.2 中的行为变化?
问题描述
我正在使用语音规则引擎从 MathML 生成英文文本。尝试从 v3.1.1 升级到 v3.2.0 时,我看到测试失败,原因我不明白。
我创建了一个简单的两个文件项目来说明这个问题:
包.json
{
"name": "failure-example",
"license": "UNLICENSED",
"private": true,
"engines": {
"node": "14.15.5",
"npm": "6.14.11"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"speech-rule-engine": "3.2.0"
},
"devDependencies": {
"jest": "^26.6.3"
},
"jest": {
"notify": false,
"silent": true,
"verbose": true
}
}
例子.test.js
const sre = require('speech-rule-engine');
beforeAll(() => {
sre.setupEngine({
domain: 'mathspeak'
});
});
test('simple single math', () => {
expect(JSON.parse(JSON.stringify(sre.engineSetup(), ['domain', 'locale', 'speech', 'style'])))
.toEqual({
locale: 'en',
speech: 'none',
style: 'default',
domain: 'mathspeak',
});
expect(sre.engineReady())
.toBeTruthy();
expect(sre.toSpeech('<math><mrow><msup><mn>3</mn><mn>7</mn></msup></mrow></math>'))
.toBe('3 Superscript 7');
});
运行npm install
并npm run test
导致失败,因为 SRE 返回37而不是3 Superscript 7。编辑 package.json 以使用引擎的 v3.1.1 并重新运行导致通过测试。
显然有些事情发生了变化,但我完全错过了我需要做的适应。有没有其他人遇到过这个,或者看到我显然没有?
解决方案
在 SRE 维护者的帮助下,问题解决了。问题不在 3.2.0 中,而是 jest 没有等待 sre 准备好。由于规则已编译到核心中,因此测试仅在 3.1.1 中偶然正确。以下测试在 3.1.1 中使用上述设置失败,并且未加载语言环境:
expect(sre.toSpeech('<math><mo>=</mo></math>'))
.toBe('equals');
Expected: "equals"
Received: "="
主要原因是 jest 无法加载语言环境文件。设置"silent": false
会显示错误:
Unable to load file: /tmp/tests/node_modules/speech-rule-engine/lib/mathmaps/en.js
TypeError: Cannot read property 'readFileSync' of null
这个错误的原因是 jest 不知道它在 node.js 中运行。添加:
"testEnvironment": "node",
到开玩笑的配置package.json
会导致预期的行为。
推荐阅读
- android - react native android release apk无法从互联网接收数据
- angular - vmware 清晰度 datagrid 什么是数据网格上显示的项目数
- python - 使用 pytest-django、pytest-splinter 和 pytest-bdd 时使用真实数据回滚数据库
- java - 如何正确构建 Java 代码以将命名键下的值保存到 Firebase 实时数据库
- html - sublime text macos中mac光标更改的问题
- java - 可以创建基于模板的代码生成器以使用 java 生成基本的微服务应用程序
- netlogo - 如何使用 NetLogo 找到四分位数或五分位数?
- ubuntu - 无法(编译和)链接多个包含 openMPI 的 f90 程序
- solr - 获取用 SolrJ 编写的 Suggester 代码的 ClasscastException
- java - 允许在 jsoup 选择器中缺少父级