@keymanapp/kmc-model 17.0.85-alpha → 17.0.87-alpha

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.
Files changed (144) hide show
  1. package/package.json +6 -5
  2. package/.nyc_output/coverage-10524-1681239236645-0.json +0 -1
  3. package/Makefile +0 -38
  4. package/build/cjs-src/lexical-model-compiler.cjs +0 -152688
  5. package/build/test/helpers/index.d.ts +0 -69
  6. package/build/test/helpers/index.d.ts.map +0 -1
  7. package/build/test/helpers/index.js +0 -160
  8. package/build/test/helpers/index.js.map +0 -1
  9. package/build/test/test-compile-model-with-pseudoclosure.d.ts +0 -2
  10. package/build/test/test-compile-model-with-pseudoclosure.d.ts.map +0 -1
  11. package/build/test/test-compile-model-with-pseudoclosure.js +0 -200
  12. package/build/test/test-compile-model-with-pseudoclosure.js.map +0 -1
  13. package/build/test/test-compile-model.d.ts +0 -2
  14. package/build/test/test-compile-model.d.ts.map +0 -1
  15. package/build/test/test-compile-model.js +0 -30
  16. package/build/test/test-compile-model.js.map +0 -1
  17. package/build/test/test-compile-trie.d.ts +0 -2
  18. package/build/test/test-compile-trie.d.ts.map +0 -1
  19. package/build/test/test-compile-trie.js +0 -125
  20. package/build/test/test-compile-trie.js.map +0 -1
  21. package/build/test/test-default-apply-case.d.ts +0 -2
  22. package/build/test/test-default-apply-case.d.ts.map +0 -1
  23. package/build/test/test-default-apply-case.js +0 -105
  24. package/build/test/test-default-apply-case.js.map +0 -1
  25. package/build/test/test-default-search-term-to-key.d.ts +0 -2
  26. package/build/test/test-default-search-term-to-key.d.ts.map +0 -1
  27. package/build/test/test-default-search-term-to-key.js +0 -148
  28. package/build/test/test-default-search-term-to-key.js.map +0 -1
  29. package/build/test/test-error-logger.d.ts +0 -2
  30. package/build/test/test-error-logger.d.ts.map +0 -1
  31. package/build/test/test-error-logger.js +0 -26
  32. package/build/test/test-error-logger.js.map +0 -1
  33. package/build/test/test-join-word-breaker.d.ts +0 -2
  34. package/build/test/test-join-word-breaker.d.ts.map +0 -1
  35. package/build/test/test-join-word-breaker.js +0 -84
  36. package/build/test/test-join-word-breaker.js.map +0 -1
  37. package/build/test/test-model-definitions.d.ts +0 -2
  38. package/build/test/test-model-definitions.d.ts.map +0 -1
  39. package/build/test/test-model-definitions.js +0 -165
  40. package/build/test/test-model-definitions.js.map +0 -1
  41. package/build/test/test-override-script-defaults.d.ts +0 -2
  42. package/build/test/test-override-script-defaults.d.ts.map +0 -1
  43. package/build/test/test-override-script-defaults.js +0 -28
  44. package/build/test/test-override-script-defaults.js.map +0 -1
  45. package/build/test/test-parse-wordlist.d.ts +0 -2
  46. package/build/test/test-parse-wordlist.d.ts.map +0 -1
  47. package/build/test/test-parse-wordlist.js +0 -110
  48. package/build/test/test-parse-wordlist.js.map +0 -1
  49. package/build/test/test-punctuation.d.ts +0 -2
  50. package/build/test/test-punctuation.d.ts.map +0 -1
  51. package/build/test/test-punctuation.js +0 -31
  52. package/build/test/test-punctuation.js.map +0 -1
  53. package/build/test/tsconfig.tsbuildinfo +0 -1
  54. package/build/test/wordbreakers/data.d.ts +0 -35
  55. package/build/test/wordbreakers/data.d.ts.map +0 -1
  56. package/build/test/wordbreakers/data.js +0 -1778
  57. package/build/test/wordbreakers/data.js.map +0 -1
  58. package/build/test/wordbreakers/default-wordbreaker-esm.d.ts +0 -10
  59. package/build/test/wordbreakers/default-wordbreaker-esm.d.ts.map +0 -1
  60. package/build/test/wordbreakers/default-wordbreaker-esm.js +0 -354
  61. package/build/test/wordbreakers/default-wordbreaker-esm.js.map +0 -1
  62. package/build/tsconfig.tsbuildinfo +0 -1
  63. package/build.sh +0 -73
  64. package/coverage/lcov-report/base.css +0 -224
  65. package/coverage/lcov-report/block-navigation.js +0 -87
  66. package/coverage/lcov-report/favicon.png +0 -0
  67. package/coverage/lcov-report/index.html +0 -161
  68. package/coverage/lcov-report/prettify.css +0 -1
  69. package/coverage/lcov-report/prettify.js +0 -2
  70. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  71. package/coverage/lcov-report/sorter.js +0 -196
  72. package/coverage/lcov-report/src/build-trie.ts.html +0 -1618
  73. package/coverage/lcov-report/src/index.html +0 -221
  74. package/coverage/lcov-report/src/join-word-breaker-decorator.ts.html +0 -487
  75. package/coverage/lcov-report/src/lexical-model-compiler.ts.html +0 -622
  76. package/coverage/lcov-report/src/main.ts.html +0 -271
  77. package/coverage/lcov-report/src/model-compiler-errors.ts.html +0 -691
  78. package/coverage/lcov-report/src/model-defaults.ts.html +0 -415
  79. package/coverage/lcov-report/src/model-definitions.ts.html +0 -748
  80. package/coverage/lcov-report/src/script-overrides-decorator.ts.html +0 -310
  81. package/coverage/lcov-report/test/helpers/index.html +0 -116
  82. package/coverage/lcov-report/test/helpers/index.ts.html +0 -646
  83. package/coverage/lcov-report/test/index.html +0 -266
  84. package/coverage/lcov-report/test/test-compile-model-with-pseudoclosure.ts.html +0 -802
  85. package/coverage/lcov-report/test/test-compile-model.ts.html +0 -187
  86. package/coverage/lcov-report/test/test-compile-trie.ts.html +0 -541
  87. package/coverage/lcov-report/test/test-default-apply-case.ts.html +0 -466
  88. package/coverage/lcov-report/test/test-default-search-term-to-key.ts.html +0 -628
  89. package/coverage/lcov-report/test/test-error-logger.ts.html +0 -196
  90. package/coverage/lcov-report/test/test-join-word-breaker.ts.html +0 -376
  91. package/coverage/lcov-report/test/test-model-definitions.ts.html +0 -676
  92. package/coverage/lcov-report/test/test-override-script-defaults.ts.html +0 -184
  93. package/coverage/lcov-report/test/test-parse-wordlist.ts.html +0 -466
  94. package/coverage/lcov-report/test/test-punctuation.ts.html +0 -190
  95. package/coverage/lcov-report/test/wordbreakers/data.ts.html +0 -5413
  96. package/coverage/lcov-report/test/wordbreakers/default-wordbreaker-esm.ts.html +0 -1234
  97. package/coverage/lcov-report/test/wordbreakers/index.html +0 -131
  98. package/coverage/lcov.info +0 -5969
  99. package/src/build-trie.ts +0 -511
  100. package/src/join-word-breaker-decorator.ts +0 -134
  101. package/src/lexical-model-compiler.ts +0 -179
  102. package/src/lexical-model.ts +0 -150
  103. package/src/main.ts +0 -62
  104. package/src/model-compiler-errors.ts +0 -203
  105. package/src/model-defaults.ts +0 -111
  106. package/src/model-definitions.ts +0 -222
  107. package/src/script-overrides-decorator.ts +0 -75
  108. package/test/README.md +0 -15
  109. package/test/fixtures/example.qaa.joinwordbreaker/example.qaa.joinwordbreaker.model.ts +0 -10
  110. package/test/fixtures/example.qaa.joinwordbreaker/wordlist.tsv +0 -3
  111. package/test/fixtures/example.qaa.scriptusesspaces/example.qaa.scriptusesspaces.model.ts +0 -10
  112. package/test/fixtures/example.qaa.scriptusesspaces/wordlist.tsv +0 -8
  113. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.kmp.json +0 -45
  114. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.kps +0 -35
  115. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.ts +0 -6
  116. package/test/fixtures/example.qaa.sencoten/wordlist.tsv +0 -10
  117. package/test/fixtures/example.qaa.smp/example.qaa.smp.model.ts +0 -6
  118. package/test/fixtures/example.qaa.smp/wordlist.tsv +0 -5
  119. package/test/fixtures/example.qaa.trivial/example.qaa.trivial.model.ts +0 -5
  120. package/test/fixtures/example.qaa.trivial/wordlist.tsv +0 -3
  121. package/test/fixtures/example.qaa.utf16be/example.qaa.utf16be.model.ts +0 -5
  122. package/test/fixtures/example.qaa.utf16be/wordlist.txt +0 -0
  123. package/test/fixtures/example.qaa.utf16le/example.qaa.utf16le.model.ts +0 -5
  124. package/test/fixtures/example.qaa.utf16le/wordlist.txt +0 -0
  125. package/test/fixtures/example.qaa.wordbreaker/example.qaa.wordbreaker.model.ts +0 -9
  126. package/test/fixtures/example.qaa.wordbreaker/wordlist.tsv +0 -3
  127. package/test/helpers/index.ts +0 -187
  128. package/test/test-compile-model-with-pseudoclosure.ts +0 -239
  129. package/test/test-compile-model.ts +0 -34
  130. package/test/test-compile-trie.ts +0 -152
  131. package/test/test-default-apply-case.ts +0 -128
  132. package/test/test-default-search-term-to-key.ts +0 -181
  133. package/test/test-error-logger.ts +0 -38
  134. package/test/test-join-word-breaker.ts +0 -97
  135. package/test/test-model-definitions.ts +0 -198
  136. package/test/test-override-script-defaults.ts +0 -33
  137. package/test/test-parse-wordlist.ts +0 -127
  138. package/test/test-punctuation.ts +0 -35
  139. package/test/tsconfig.json +0 -22
  140. package/test/wordbreakers/README.md +0 -3
  141. package/test/wordbreakers/data.ts +0 -1776
  142. package/test/wordbreakers/default-wordbreaker-esm.ts +0 -383
  143. package/tools/create-override-script-regexp.ts +0 -145
  144. package/tsconfig.json +0 -17
@@ -1,69 +0,0 @@
1
- import { LogMessage, KeymanCompilerError } from '../../src/model-compiler-errors.js';
2
- export interface CompilationResult {
3
- hasSyntaxError: boolean;
4
- modelConstructorName: string;
5
- error: Error;
6
- exportedModel: object;
7
- }
8
- /**
9
- * Builds a path to the fixture with the given path components.
10
- *
11
- * e.g., makePathToFixture('example.qaa.trivial')
12
- * e.g., makePathToFixture('example.qaa.trivial', 'model.ts')
13
- *
14
- * @param components One or more path components.
15
- */
16
- export declare function makePathToFixture(...components: string[]): string;
17
- /**
18
- * Given source code of a model (as produced by the compiler), this evaluates
19
- * it!
20
- *
21
- * That way, you can determine if the source code was syntactically-valid,
22
- * whether it raise an exception during construction, and you can even inspect
23
- * the resultant LexicalModel for yourself!
24
- *
25
- * @param code
26
- */
27
- export declare function compileModelSourceCode(code: string): {
28
- error: Error;
29
- exportedModel: object;
30
- hasSyntaxError: boolean;
31
- modelConstructorName: string;
32
- };
33
- /**
34
- * Enables one to query log messages after they have been logged.
35
- */
36
- export declare class LogHoarder {
37
- private messages;
38
- /**
39
- * Get rid of all log messages seen.
40
- */
41
- clear(): void;
42
- /**
43
- * Hoards a log message for later perusal.
44
- */
45
- handleLog(log: LogMessage): void;
46
- /**
47
- * Has an error message with this code been witnessed?
48
- */
49
- hasSeenCode(code: KeymanCompilerError): boolean;
50
- /**
51
- * Have any warnings been logged?
52
- */
53
- hasSeenWarnings(): boolean;
54
- /**
55
- * Overrides the global log handler, allowing one to browse log messages
56
- * later.
57
- *
58
- * Remember to uninstall the log handler afterwards!
59
- */
60
- install(): this;
61
- /**
62
- * Return the log message handler to its default.
63
- *
64
- * Note: You MUST uninstall the hoarder after use!
65
- * It's recommended you put this in an afterEach() callback.
66
- */
67
- uninstall(): void;
68
- }
69
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../test/helpers/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAA0D,MAAM,oCAAoC,CAAC;AAE5I,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,OAAO,CAAC;IACxB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACF,wBAAgB,iBAAiB,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAElE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM;;;;;EAkFlD;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAoB;IAEpC;;OAEG;IACH,KAAK;IAIL;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,UAAU;IAIzB;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO;IAI/C;;OAEG;IACH,eAAe,IAAI,OAAO;IAM1B;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAKf;;;;;OAKG;IACH,SAAS;CAGV"}
@@ -1,160 +0,0 @@
1
- /// <reference types="@keymanapp/models-types" />
2
- /**
3
- * Helpers and utilities for the Mocha tests.
4
- */
5
- import * as path from 'path';
6
- import { fileURLToPath } from 'url';
7
- import { assert } from 'chai';
8
- import { redirectLogMessagesTo, resetLogMessageHandler, LogLevel } from '../../src/model-compiler-errors.js';
9
- /**
10
- * Builds a path to the fixture with the given path components.
11
- *
12
- * e.g., makePathToFixture('example.qaa.trivial')
13
- * e.g., makePathToFixture('example.qaa.trivial', 'model.ts')
14
- *
15
- * @param components One or more path components.
16
- */
17
- export function makePathToFixture(...components) {
18
- return fileURLToPath(new URL(path.join('..', '..', '..', 'test', 'fixtures', ...components), import.meta.url));
19
- }
20
- /**
21
- * Given source code of a model (as produced by the compiler), this evaluates
22
- * it!
23
- *
24
- * That way, you can determine if the source code was syntactically-valid,
25
- * whether it raise an exception during construction, and you can even inspect
26
- * the resultant LexicalModel for yourself!
27
- *
28
- * @param code
29
- */
30
- export function compileModelSourceCode(code) {
31
- assert.typeOf(code, 'string');
32
- let error = null;
33
- let exportedModel = null;
34
- let hasSyntaxError = false;
35
- let modelConstructorName = null;
36
- let module = null;
37
- try {
38
- module = new Function('LMLayerWorker', 'models', 'wordBreakers', code);
39
- }
40
- catch (err) {
41
- if (err instanceof SyntaxError) {
42
- hasSyntaxError = true;
43
- }
44
- else {
45
- throw err;
46
- }
47
- }
48
- // Module had some sort of syntax error:
49
- if (module === null) {
50
- return {
51
- error, exportedModel, hasSyntaxError, modelConstructorName
52
- };
53
- }
54
- let fakeLMLayerWorker = {
55
- loadModel(model) {
56
- exportedModel = model;
57
- }
58
- };
59
- // We expect the compiled model to reach into the `models` namespace,
60
- // and get some sort of model constructor. Problem is, we don't know
61
- // what model constructors are defined!
62
- // This proxy allows us to intercept
63
- // models.*
64
- // meaning that when the compiled code tries to do this:
65
- //
66
- // new models.WhateverModel('foo', 'bar')
67
- //
68
- // ...we can intercept the name "WhateverModel" and assign it to
69
- // `modelConstructorName`.
70
- let modelsNamespace = new Proxy({}, {
71
- get(_target, property) {
72
- if (typeof property !== 'string')
73
- throw new Error(`Don't know how to handle non-string property: ${String(property)}`);
74
- return class DummyModel {
75
- constructor() {
76
- modelConstructorName = property;
77
- }
78
- };
79
- }
80
- });
81
- // We expect the compiled model to reach into the `wordBreaker` namespace,
82
- // and maybe get a function. Problem is, we don't know
83
- // what functions are available!
84
- // This proxy allows us to intercept
85
- // wordBreakers.*
86
- // meaning that when the compiled code tries to do this:
87
- //
88
- // wordBreaker["someWordBreaker"]
89
- //
90
- // ...we can intercept the name "someWordBreaker".
91
- let wordBreakerNamespace = new Proxy({}, {
92
- get(_target, property) {
93
- if (typeof property !== 'string')
94
- throw new Error(`Don't know how to handle non-string property: ${String(property)}`);
95
- return function dummyWordBreaker() {
96
- };
97
- }
98
- });
99
- try {
100
- module(fakeLMLayerWorker, modelsNamespace, wordBreakerNamespace);
101
- }
102
- catch (err) {
103
- error = err;
104
- }
105
- return {
106
- error, exportedModel, hasSyntaxError, modelConstructorName
107
- };
108
- }
109
- /**
110
- * Enables one to query log messages after they have been logged.
111
- */
112
- export class LogHoarder {
113
- messages = [];
114
- /**
115
- * Get rid of all log messages seen.
116
- */
117
- clear() {
118
- this.messages = [];
119
- }
120
- /**
121
- * Hoards a log message for later perusal.
122
- */
123
- handleLog(log) {
124
- this.messages.push(log);
125
- }
126
- /**
127
- * Has an error message with this code been witnessed?
128
- */
129
- hasSeenCode(code) {
130
- return Boolean(this.messages.find(log => log.code === code));
131
- }
132
- /**
133
- * Have any warnings been logged?
134
- */
135
- hasSeenWarnings() {
136
- return this.messages
137
- .filter(log => log.level === LogLevel.CERR_WARNING)
138
- .length > 0;
139
- }
140
- /**
141
- * Overrides the global log handler, allowing one to browse log messages
142
- * later.
143
- *
144
- * Remember to uninstall the log handler afterwards!
145
- */
146
- install() {
147
- redirectLogMessagesTo(this.handleLog.bind(this));
148
- return this;
149
- }
150
- /**
151
- * Return the log message handler to its default.
152
- *
153
- * Note: You MUST uninstall the hoarder after use!
154
- * It's recommended you put this in an afterEach() callback.
155
- */
156
- uninstall() {
157
- resetLogMessageHandler();
158
- }
159
- }
160
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceR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KAC3D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,GAAiB,EAAE,CAAC;IAEpC;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,GAAe;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAyB;QACnC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,QAAQ;aACjB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,YAAY,CAAC;aAClD,MAAM,GAAG,CAAC,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,SAAS;QACP,sBAAsB,EAAE,CAAA;IAC1B,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- import 'mocha';
2
- //# sourceMappingURL=test-compile-model-with-pseudoclosure.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-compile-model-with-pseudoclosure.d.ts","sourceRoot":"","sources":["../../test/test-compile-model-with-pseudoclosure.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,CAAC"}
@@ -1,200 +0,0 @@
1
- import LexicalModelCompiler from '../src/lexical-model-compiler.js';
2
- import { assert } from 'chai';
3
- import 'mocha';
4
- import { makePathToFixture, compileModelSourceCode } from './helpers/index.js';
5
- describe('LexicalModelCompiler - pseudoclosure compilation + use', function () {
6
- const MODEL_ID = 'example.qaa.trivial';
7
- const PATH = makePathToFixture(MODEL_ID);
8
- describe('specifying custom methods: applyCasing and searchTermToKey', function () {
9
- let casingWithPrependedSymbols = function (casingName, text, defaultApplyCasing) {
10
- switch (casingName) {
11
- // Use of symbols, and of the `casingName` name, exist to serve as regex targets.
12
- case 'lower':
13
- return '-' + defaultApplyCasing(casingName, text);
14
- case 'upper':
15
- return '+' + defaultApplyCasing(casingName, text);
16
- case 'initial':
17
- return '^' + defaultApplyCasing(casingName, text);
18
- default:
19
- return defaultApplyCasing(casingName, text);
20
- }
21
- };
22
- it('variant 1: applyCasing prepends symbols, searchTermToKey removes them', function () {
23
- let compiler = new LexicalModelCompiler;
24
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
25
- format: 'trie-1.0',
26
- sources: ['wordlist.tsv'],
27
- languageUsesCasing: true,
28
- applyCasing: casingWithPrependedSymbols,
29
- // Parameter name `rawSearchTerm` selected for uniqueness, regex matching test target.
30
- searchTermToKey: function (rawSearchTerm, applyCasing) {
31
- // Strips any applyCasing symbols ('-', '+', '^') out of the compiled Trie.
32
- // We should be able to test that they do _not_ occur within internal nodes of the Trie.
33
- return applyCasing('lower', rawSearchTerm)
34
- // We replace all prepended applyCasing symbols with a separate symbol not
35
- // otherwise seen within the model.
36
- .replace(/^-/, '§')
37
- .replace(/^\+/, '§')
38
- .replace(/^\^/, '§');
39
- }
40
- }, PATH);
41
- // Check that pseudoclosure forwarding is set up correctly.
42
- assert.match(code, /\.model\.searchTermToKey/);
43
- assert.match(code, /\.model\.applyCasing/);
44
- // Check that the methods actually made into the code; use our custom parameter names:
45
- assert.match(code, /casingName/);
46
- assert.match(code, /rawSearchTerm/);
47
- // Check that the prepended symbols from applyCasing also appear in the code:
48
- assert.match(code, /'-'/);
49
- assert.match(code, /'\+'/);
50
- assert.match(code, /'\^'/);
51
- assert.match(code, /§/);
52
- let modelInitIndex = code.indexOf('LMLayerWorker.loadModel');
53
- let modelInitCode = code.substring(modelInitIndex);
54
- // Chop off the IIFE terminator. Not strictly necessary, but whatever.
55
- modelInitCode = modelInitCode.substring(0, modelInitCode.lastIndexOf('\n})();'));
56
- // Check that the prepended symbols from applyCasing do not appear in the Trie.
57
- assert.notMatch(modelInitCode, /['"]-['"]/);
58
- assert.notMatch(modelInitCode, /['"]\+['"]/);
59
- assert.notMatch(modelInitCode, /['"]\^['"]/);
60
- // Instead, our custom keyer should ensure that the following symbol DOES appear.
61
- // Verifies that the compiler uses the custom searchTermToKey definition.
62
- assert.match(modelInitCode, /['"]§['"]/);
63
- // Make sure it compiles!
64
- let compilation = compileModelSourceCode(code);
65
- assert.isFalse(compilation.hasSyntaxError);
66
- assert.isNotNull(compilation.exportedModel);
67
- });
68
- it('variant 2: applyCasing prepends symbols, searchTermToKey keeps them', function () {
69
- let compiler = new LexicalModelCompiler;
70
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
71
- format: 'trie-1.0',
72
- sources: ['wordlist.tsv'],
73
- languageUsesCasing: true,
74
- applyCasing: casingWithPrependedSymbols,
75
- // Parameter name `rawSearchTerm` selected for uniqueness, regex matching test target.
76
- searchTermToKey: function (rawSearchTerm, applyCasing) {
77
- // Strips any applyCasing symbols ('-', '+', '^') out of the compiled Trie.
78
- // We should be able to test that they do _not_ occur within internal nodes of the Trie.
79
- return applyCasing('lower', rawSearchTerm);
80
- }
81
- }, PATH);
82
- // Check that pseudoclosure forwarding is set up correctly.
83
- assert.match(code, /\.model\.searchTermToKey/);
84
- assert.match(code, /\.model\.applyCasing/);
85
- // Check that the methods actually made into the code; use our custom parameter names:
86
- assert.match(code, /casingName/);
87
- assert.match(code, /rawSearchTerm/);
88
- // Check that the prepended symbols from applyCasing also appear in the code:
89
- assert.match(code, /'-'/);
90
- assert.match(code, /'\+'/);
91
- assert.match(code, /'\^'/);
92
- let modelInitIndex = code.indexOf('LMLayerWorker.loadModel');
93
- let modelInitCode = code.substring(modelInitIndex);
94
- // Chop off the IIFE terminator. Not strictly necessary, but whatever.
95
- modelInitCode = modelInitCode.substring(0, modelInitCode.lastIndexOf('\n})();'));
96
- // Check that the prepended lowercase "-" DOES appear within the Trie, as keying
97
- // does not remove it in this variant. Verifies that the compiler actually
98
- // used the custom applyCasing definition!
99
- assert.match(modelInitCode, /['"]-['"]/);
100
- // Make sure it compiles!
101
- let compilation = compileModelSourceCode(code);
102
- assert.isFalse(compilation.hasSyntaxError);
103
- assert.isNotNull(compilation.exportedModel);
104
- });
105
- it('variant 3: applyCasing prepends symbols, default searchTermToKey', function () {
106
- let compiler = new LexicalModelCompiler;
107
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
108
- format: 'trie-1.0',
109
- sources: ['wordlist.tsv'],
110
- languageUsesCasing: true,
111
- applyCasing: casingWithPrependedSymbols
112
- }, PATH);
113
- // Check that pseudoclosure forwarding is set up correctly.
114
- assert.match(code, /\.model\.searchTermToKey/);
115
- assert.match(code, /\.model\.applyCasing/);
116
- // Check that the methods actually made into the code; use our custom parameter names:
117
- assert.match(code, /casingName/);
118
- assert.match(code, /function defaultCasedSearchTermToKey/);
119
- // Check that the prepended symbols from applyCasing also appear in the code:
120
- assert.match(code, /'-'/);
121
- assert.match(code, /'\+'/);
122
- assert.match(code, /'\^'/);
123
- let modelInitIndex = code.indexOf('LMLayerWorker.loadModel');
124
- let modelInitCode = code.substring(modelInitIndex);
125
- // Chop off the IIFE terminator. Not strictly necessary, but whatever.
126
- modelInitCode = modelInitCode.substring(0, modelInitCode.lastIndexOf('\n})();'));
127
- // Check that the prepended lowercase "-" DOES appear within the Trie, as keying
128
- // does not remove it in this variant. Verifies that the compiler actually
129
- // used the custom applyCasing definition!
130
- assert.match(modelInitCode, /['"]-['"]/);
131
- // Make sure it compiles!
132
- let compilation = compileModelSourceCode(code);
133
- assert.isFalse(compilation.hasSyntaxError);
134
- assert.isNotNull(compilation.exportedModel);
135
- });
136
- });
137
- describe('relying on default applyCasing + searchTermToKey', function () {
138
- it('languageUsesCasing: true', function () {
139
- let compiler = new LexicalModelCompiler;
140
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
141
- format: 'trie-1.0',
142
- sources: ['wordlist.tsv'],
143
- languageUsesCasing: true, // applyCasing should appear!
144
- }, PATH);
145
- // Does the cased version of the search-term default appear?
146
- assert.match(code, /function defaultCasedSearchTermToKey/);
147
- assert.match(code, /\.model\.searchTermToKey/);
148
- // Does the default casing function appear?
149
- assert.match(code, /function defaultApplyCasing/);
150
- assert.match(code, /\.defaults\.applyCasing/);
151
- assert.match(code, /languageUsesCasing/);
152
- // Make sure it compiles!
153
- let compilation = compileModelSourceCode(code);
154
- assert.isFalse(compilation.hasSyntaxError);
155
- assert.isNotNull(compilation.exportedModel);
156
- });
157
- it('languageUsesCasing: false', function () {
158
- let compiler = new LexicalModelCompiler;
159
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
160
- format: 'trie-1.0',
161
- sources: ['wordlist.tsv'],
162
- languageUsesCasing: false, // applyCasing should not appear!
163
- }, PATH);
164
- // Does the cased version of the search-term default appear?
165
- assert.match(code, /function defaultSearchTermToKey/);
166
- assert.match(code, /\.model\.searchTermToKey/);
167
- // Does the default casing function appear?
168
- // Since `languageUsesCasing` is explicitly `false`, there should be no usage.
169
- assert.notMatch(code, /function defaultApplyCasing/);
170
- assert.notMatch(code, /\.defaults\.applyCasing/);
171
- assert.match(code, /languageUsesCasing/);
172
- // Make sure it compiles!
173
- let compilation = compileModelSourceCode(code);
174
- assert.isFalse(compilation.hasSyntaxError);
175
- assert.isNotNull(compilation.exportedModel);
176
- });
177
- it('languageUsesCasing: undefined', function () {
178
- let compiler = new LexicalModelCompiler;
179
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
180
- format: 'trie-1.0',
181
- sources: ['wordlist.tsv']
182
- // languageUsesCasing: undefined
183
- }, PATH);
184
- // Does the cased version of the search-term default appear?
185
- // Needed to match 14.0 defaults.
186
- assert.match(code, /function defaultCasedSearchTermToKey/);
187
- assert.match(code, /\.model\.searchTermToKey/);
188
- // Does the default casing function appear?
189
- assert.match(code, /function defaultApplyCasing/);
190
- assert.match(code, /\.defaults\.applyCasing/);
191
- // Did the compilation process explictly leave `languageUsesCasing` undefined?
192
- assert.notMatch(code, /languageUsesCasing/);
193
- // Make sure it compiles!
194
- let compilation = compileModelSourceCode(code);
195
- assert.isFalse(compilation.hasSyntaxError);
196
- assert.isNotNull(compilation.exportedModel);
197
- });
198
- });
199
- });
200
- //# sourceMappingURL=test-compile-model-with-pseudoclosure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-compile-model-with-pseudoclosure.js","sourceRoot":"","sources":["../../test/test-compile-model-with-pseudoclosure.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AAC5B,OAAO,OAAO,CAAC;AAEf,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,QAAQ,CAAC,wDAAwD,EAAE;IACjE,MAAM,QAAQ,GAAG,qBAAqB,CAAC;IACvC,MAAM,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAEzC,QAAQ,CAAC,4DAA4D,EAAE;QACrE,IAAI,0BAA0B,GAAmB,UAAS,UAAsB,EAAE,IAAY,EAAE,kBAAkC;YAChI,QAAO,UAAU,EAAE;gBACjB,iFAAiF;gBACjF,KAAK,OAAO;oBACV,OAAO,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gBACpD,KAAK,OAAO;oBACV,OAAO,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gBACpD,KAAK,SAAS;oBACZ,OAAO,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gBACpD;oBACE,OAAO,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;aAC/C;QACH,CAA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,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import 'mocha';
2
- //# sourceMappingURL=test-compile-model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-compile-model.d.ts","sourceRoot":"","sources":["../../test/test-compile-model.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC"}
@@ -1,30 +0,0 @@
1
- import 'mocha';
2
- import { assert } from 'chai';
3
- import { compileModel } from '../src/main.js';
4
- import { makePathToFixture, compileModelSourceCode } from './helpers/index.js';
5
- describe('compileModel', function () {
6
- // Try to compile ALL of the correct models.
7
- const MODELS = [
8
- 'example.qaa.sencoten',
9
- 'example.qaa.trivial',
10
- 'example.qaa.utf16le',
11
- 'example.qaa.wordbreaker',
12
- 'example.qaa.joinwordbreaker',
13
- 'example.qaa.scriptusesspaces',
14
- ];
15
- for (let modelID of MODELS) {
16
- let modelPath = makePathToFixture(modelID, `${modelID}.model.ts`);
17
- it(`should compile ${modelID}`, function () {
18
- let code = compileModel(modelPath);
19
- let r;
20
- assert.doesNotThrow(() => {
21
- r = compileModelSourceCode(code);
22
- });
23
- let compilation = r;
24
- assert.isFalse(compilation.hasSyntaxError, 'model code had syntax error');
25
- assert.isNull(compilation.error, `compilation error: ${compilation.error}`);
26
- assert.equal(compilation.modelConstructorName, 'TrieModel');
27
- });
28
- }
29
- });
30
- //# sourceMappingURL=test-compile-model.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-compile-model.js","sourceRoot":"","sources":["../../test/test-compile-model.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC;AACf,OAAO,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,iBAAiB,EAAE,sBAAsB,EAAoB,MAAM,oBAAoB,CAAC;AAEhG,QAAQ,CAAC,cAAc,EAAE;IACvB,4CAA4C;IAC5C,MAAM,MAAM,GAAG;QACb,sBAAsB;QACtB,qBAAqB;QACrB,qBAAqB;QACrB,yBAAyB;QACzB,6BAA6B;QAC7B,8BAA8B;KAC/B,CAAC;IAEF,KAAK,IAAI,OAAO,IAAI,MAAM,EAAE;QAC1B,IAAI,SAAS,GAAG,iBAAiB,CAAC,OAAO,EAAE,GAAG,OAAO,WAAW,CAAC,CAAC;QAElE,EAAE,CAAC,kBAAkB,OAAO,EAAE,EAAE;YAC9B,IAAI,IAAI,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;YACnC,IAAI,CAAU,CAAC;YACf,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;gBACvB,CAAC,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YACH,IAAI,WAAW,GAAG,CAAsB,CAAC;YAEzC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,6BAA6B,CAAC,CAAC;YAC1E,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,sBAAsB,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;YAC5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;KACJ;AACH,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import 'mocha';
2
- //# sourceMappingURL=test-compile-trie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-compile-trie.d.ts","sourceRoot":"","sources":["../../test/test-compile-trie.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,CAAC"}
@@ -1,125 +0,0 @@
1
- import LexicalModelCompiler from '../src/lexical-model-compiler.js';
2
- import { assert } from 'chai';
3
- import 'mocha';
4
- import { makePathToFixture, compileModelSourceCode } from './helpers/index.js';
5
- import { createTrieDataStructure } from '../src/build-trie.js';
6
- describe('LexicalModelCompiler', function () {
7
- describe('#generateLexicalModelCode', function () {
8
- it('should compile a trivial word list', function () {
9
- const MODEL_ID = 'example.qaa.trivial';
10
- const PATH = makePathToFixture(MODEL_ID);
11
- let compiler = new LexicalModelCompiler;
12
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
13
- format: 'trie-1.0',
14
- sources: ['wordlist.tsv']
15
- }, PATH);
16
- let result = compileModelSourceCode(code);
17
- assert.isFalse(result.hasSyntaxError);
18
- assert.isNotNull(result.exportedModel);
19
- assert.equal(result.modelConstructorName, 'TrieModel');
20
- // Sanity check: the word list has three total unweighted words, with a
21
- // total weight of 3!
22
- assert.match(code, /\btotalWeight\b["']?:\s*3\b/);
23
- // Sanity check: the word breaker is a property of the object.
24
- assert.match(code, /\bwordBreaker\b["']?:\s*wordBreakers\b/);
25
- });
26
- it('should compile a word list exported by Microsoft Excel', function () {
27
- const MODEL_ID = 'example.qaa.utf16le';
28
- const PATH = makePathToFixture(MODEL_ID);
29
- let compiler = new LexicalModelCompiler;
30
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
31
- format: 'trie-1.0',
32
- sources: ['wordlist.txt']
33
- }, PATH);
34
- let result = compileModelSourceCode(code);
35
- assert.isFalse(result.hasSyntaxError);
36
- assert.isNotNull(result.exportedModel);
37
- assert.equal(result.modelConstructorName, 'TrieModel');
38
- // Sanity check: the word list has three total unweighted words, with a
39
- // total weight of 44,103!
40
- assert.match(code, /\btotalWeight\b["']?:\s*44103\b/);
41
- });
42
- });
43
- it('should compile a word list with a custom word breaking function', function () {
44
- const MODEL_ID = 'example.qaa.trivial';
45
- const PATH = makePathToFixture(MODEL_ID);
46
- let compiler = new LexicalModelCompiler;
47
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
48
- format: 'trie-1.0',
49
- sources: ['wordlist.tsv'],
50
- // This is a possible word breaking function:
51
- wordBreaker(phrase) {
52
- return [];
53
- }
54
- }, PATH);
55
- let result = compileModelSourceCode(code);
56
- assert.isFalse(result.hasSyntaxError, `Syntax error in ${code}`);
57
- assert.isNotNull(result.exportedModel);
58
- assert.equal(result.modelConstructorName, 'TrieModel');
59
- // Sanity check: the word breaker is a property of the object.
60
- assert.match(code, /\bwordBreaker\b["']?:\s+function\b/);
61
- });
62
- it('should not generate unpaired surrogate code units', function () {
63
- const MODEL_ID = 'example.qaa.smp';
64
- const PATH = makePathToFixture(MODEL_ID);
65
- let compiler = new LexicalModelCompiler;
66
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
67
- format: 'trie-1.0',
68
- sources: ['wordlist.tsv']
69
- }, PATH);
70
- let result = compileModelSourceCode(code);
71
- assert.isFalse(result.hasSyntaxError);
72
- assert.isNotNull(result.exportedModel);
73
- assert.equal(result.modelConstructorName, 'TrieModel');
74
- // Test every character in the string to make sure we don't have
75
- // unpaired surrogates which destroy everything.
76
- // We can assume that the first and last chars are not SMP
77
- for (var i = 1; i < code.length - 1; i++) {
78
- assert.notEqual(0xFFFD, code.charCodeAt(i));
79
- if (code.charCodeAt(i) >= 0xD800 && code.charCodeAt(i) < 0xDC00) {
80
- assert.isTrue((code.charCodeAt(i + 1) >= 0xDC00 && code.charCodeAt(i + 1) < 0xE000), 'Unpaired lead surrogate U+' + code.charCodeAt(i).toString(16) + ' at position ' + i + ' of \'' + code + '\'');
81
- }
82
- else if (code.charCodeAt(i) >= 0xDC00 && code.charCodeAt(i) < 0xE000) {
83
- assert.isTrue((code.charCodeAt(i - 1) >= 0xD800 && code.charCodeAt(i - 1) < 0xDC00), 'Unpaired trail surrogate U+' + code.charCodeAt(i).toString(16) + ' at position ' + i + ' of \'' + code + '\'');
84
- }
85
- }
86
- // Sanity check: the word list has three total unweighted words, with a
87
- // total weight of 27,596!
88
- assert.match(code, /\btotalWeight\b["']?:\s*27596\b/);
89
- });
90
- it('should include the source code of its search term to key function', function () {
91
- const MODEL_ID = 'example.qaa.trivial';
92
- const PATH = makePathToFixture(MODEL_ID);
93
- let compiler = new LexicalModelCompiler;
94
- let code = compiler.generateLexicalModelCode(MODEL_ID, {
95
- format: 'trie-1.0',
96
- sources: ['wordlist.tsv']
97
- // NOTE: we intentionally OMIT the searchTermToKey function
98
- // so that the default can be provided.
99
- }, PATH);
100
- assert.match(code, /(["']|)searchTermToKey\1:\s*function\b/, 'expected to find searchTermToKey specified as a function');
101
- });
102
- });
103
- describe('createTrieDataStructure()', function () {
104
- const WORDLIST_FILENAME = makePathToFixture('example.qaa.trivial', 'wordlist.tsv');
105
- it('must be given an explicit searchTermToKey function', function () {
106
- assert.throws(function () {
107
- createTrieDataStructure([WORDLIST_FILENAME]);
108
- }, TypeError);
109
- });
110
- it('uses the provided searchTermToKey function', function () {
111
- // check if the expected key is in the resultant data structure.
112
- // N.B., we assume the wordlist contains the wordform "turtles"
113
- let lowercaseSourceCode = createTrieDataStructure([WORDLIST_FILENAME], (wf) => {
114
- return wf.toLowerCase();
115
- });
116
- assert.match(lowercaseSourceCode, /"key":\s*"turtles"/);
117
- assert.notMatch(lowercaseSourceCode, /"key":\s*"TURTLES"/);
118
- let uppercaseSourceCode = createTrieDataStructure([WORDLIST_FILENAME], (wf) => {
119
- return wf.toUpperCase();
120
- });
121
- assert.match(uppercaseSourceCode, /"key":\s*"TURTLES"/);
122
- assert.notMatch(uppercaseSourceCode, /"key":\s*"turtles"/);
123
- });
124
- });
125
- //# sourceMappingURL=test-compile-trie.js.map