naadam-math-glossary 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
package/index.js ADDED
@@ -0,0 +1,37 @@
1
+ // index.js
2
+ const { open } = require('lmdb');
3
+ const path = require('path');
4
+ const katex = require('katex');
5
+
6
+ // Open the compiled database in high-performance read-only mode
7
+ const db = open({
8
+ path: path.join(__dirname, 'data', 'glossary.db'),
9
+ readOnly: true
10
+ });
11
+
12
+ /**
13
+ * Looks up a spoken phrase and returns pre-rendered KaTeX HTML.
14
+ * @param {string} spokenPhrase - The transcribed speech text to check
15
+ * @returns {string|null} - Formatted HTML string or null if no match found
16
+ */
17
+ function getMathHtml(spokenPhrase) {
18
+ if (!spokenPhrase) return null;
19
+
20
+ const cleanKey = spokenPhrase.trim().toLowerCase();
21
+ const record = db.get(cleanKey);
22
+
23
+ if (!record) return null;
24
+
25
+ try {
26
+ const renderedHtml = katex.renderToString(record.latex, {
27
+ displayMode: false,
28
+ throwOnError: true
29
+ });
30
+ return `<span class="highlight">${renderedHtml}</span>`;
31
+ } catch (e) {
32
+ // Fallback display format if KaTeX parsing encounters syntax constraints
33
+ return `<span class="highlight">$$${record.latex}$$</span>`;
34
+ }
35
+ }
36
+
37
+ module.exports = { getMathHtml };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "naadam-math-glossary",
3
+ "version": "1.0.0",
4
+ "description": "High-performance binary math glossary and phonetic-to-LaTeX lookup engine for real-time CART.",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "katex": "^0.16.9",
8
+ "lmdb": "^3.0.1"
9
+ },
10
+ "scripts": {
11
+ "compile": "node compile_db.js"
12
+ },
13
+ "keywords": [
14
+ "cart",
15
+ "math",
16
+ "katex",
17
+ "accessibility",
18
+ "speech-to-text"
19
+ ],
20
+ "author": "Revathi",
21
+ "license": "MIT"
22
+ }