@keymanapp/kmc-model 17.0.85-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 (180) hide show
  1. package/.nyc_output/coverage-10524-1681239236645-0.json +1 -0
  2. package/Makefile +38 -0
  3. package/build/cjs-src/lexical-model-compiler.cjs +152688 -0
  4. package/build/src/build-trie.d.ts +40 -0
  5. package/build/src/build-trie.d.ts.map +1 -0
  6. package/build/src/build-trie.js +362 -0
  7. package/build/src/build-trie.js.map +1 -0
  8. package/build/src/join-word-breaker-decorator.d.ts +10 -0
  9. package/build/src/join-word-breaker-decorator.d.ts.map +1 -0
  10. package/build/src/join-word-breaker-decorator.js +121 -0
  11. package/build/src/join-word-breaker-decorator.js.map +1 -0
  12. package/build/src/lexical-model-compiler.d.ts +19 -0
  13. package/build/src/lexical-model-compiler.d.ts.map +1 -0
  14. package/build/src/lexical-model-compiler.js +155 -0
  15. package/build/src/lexical-model-compiler.js.map +1 -0
  16. package/build/src/lexical-model.d.ts +135 -0
  17. package/build/src/lexical-model.d.ts.map +1 -0
  18. package/build/src/lexical-model.js +6 -0
  19. package/build/src/lexical-model.js.map +1 -0
  20. package/build/src/main.d.ts +15 -0
  21. package/build/src/main.d.ts.map +1 -0
  22. package/build/src/main.js +46 -0
  23. package/build/src/main.js.map +1 -0
  24. package/build/src/model-compiler-errors.d.ts +77 -0
  25. package/build/src/model-compiler-errors.d.ts.map +1 -0
  26. package/build/src/model-compiler-errors.js +156 -0
  27. package/build/src/model-compiler-errors.js.map +1 -0
  28. package/build/src/model-defaults.d.ts +56 -0
  29. package/build/src/model-defaults.d.ts.map +1 -0
  30. package/build/src/model-defaults.js +106 -0
  31. package/build/src/model-defaults.js.map +1 -0
  32. package/build/src/model-definitions.d.ts +71 -0
  33. package/build/src/model-definitions.d.ts.map +1 -0
  34. package/build/src/model-definitions.js +189 -0
  35. package/build/src/model-definitions.js.map +1 -0
  36. package/build/src/script-overrides-decorator.d.ts +4 -0
  37. package/build/src/script-overrides-decorator.d.ts.map +1 -0
  38. package/build/src/script-overrides-decorator.js +63 -0
  39. package/build/src/script-overrides-decorator.js.map +1 -0
  40. package/build/test/helpers/index.d.ts +69 -0
  41. package/build/test/helpers/index.d.ts.map +1 -0
  42. package/build/test/helpers/index.js +160 -0
  43. package/build/test/helpers/index.js.map +1 -0
  44. package/build/test/test-compile-model-with-pseudoclosure.d.ts +2 -0
  45. package/build/test/test-compile-model-with-pseudoclosure.d.ts.map +1 -0
  46. package/build/test/test-compile-model-with-pseudoclosure.js +200 -0
  47. package/build/test/test-compile-model-with-pseudoclosure.js.map +1 -0
  48. package/build/test/test-compile-model.d.ts +2 -0
  49. package/build/test/test-compile-model.d.ts.map +1 -0
  50. package/build/test/test-compile-model.js +30 -0
  51. package/build/test/test-compile-model.js.map +1 -0
  52. package/build/test/test-compile-trie.d.ts +2 -0
  53. package/build/test/test-compile-trie.d.ts.map +1 -0
  54. package/build/test/test-compile-trie.js +125 -0
  55. package/build/test/test-compile-trie.js.map +1 -0
  56. package/build/test/test-default-apply-case.d.ts +2 -0
  57. package/build/test/test-default-apply-case.d.ts.map +1 -0
  58. package/build/test/test-default-apply-case.js +105 -0
  59. package/build/test/test-default-apply-case.js.map +1 -0
  60. package/build/test/test-default-search-term-to-key.d.ts +2 -0
  61. package/build/test/test-default-search-term-to-key.d.ts.map +1 -0
  62. package/build/test/test-default-search-term-to-key.js +148 -0
  63. package/build/test/test-default-search-term-to-key.js.map +1 -0
  64. package/build/test/test-error-logger.d.ts +2 -0
  65. package/build/test/test-error-logger.d.ts.map +1 -0
  66. package/build/test/test-error-logger.js +26 -0
  67. package/build/test/test-error-logger.js.map +1 -0
  68. package/build/test/test-join-word-breaker.d.ts +2 -0
  69. package/build/test/test-join-word-breaker.d.ts.map +1 -0
  70. package/build/test/test-join-word-breaker.js +84 -0
  71. package/build/test/test-join-word-breaker.js.map +1 -0
  72. package/build/test/test-model-definitions.d.ts +2 -0
  73. package/build/test/test-model-definitions.d.ts.map +1 -0
  74. package/build/test/test-model-definitions.js +165 -0
  75. package/build/test/test-model-definitions.js.map +1 -0
  76. package/build/test/test-override-script-defaults.d.ts +2 -0
  77. package/build/test/test-override-script-defaults.d.ts.map +1 -0
  78. package/build/test/test-override-script-defaults.js +28 -0
  79. package/build/test/test-override-script-defaults.js.map +1 -0
  80. package/build/test/test-parse-wordlist.d.ts +2 -0
  81. package/build/test/test-parse-wordlist.d.ts.map +1 -0
  82. package/build/test/test-parse-wordlist.js +110 -0
  83. package/build/test/test-parse-wordlist.js.map +1 -0
  84. package/build/test/test-punctuation.d.ts +2 -0
  85. package/build/test/test-punctuation.d.ts.map +1 -0
  86. package/build/test/test-punctuation.js +31 -0
  87. package/build/test/test-punctuation.js.map +1 -0
  88. package/build/test/tsconfig.tsbuildinfo +1 -0
  89. package/build/test/wordbreakers/data.d.ts +35 -0
  90. package/build/test/wordbreakers/data.d.ts.map +1 -0
  91. package/build/test/wordbreakers/data.js +1778 -0
  92. package/build/test/wordbreakers/data.js.map +1 -0
  93. package/build/test/wordbreakers/default-wordbreaker-esm.d.ts +10 -0
  94. package/build/test/wordbreakers/default-wordbreaker-esm.d.ts.map +1 -0
  95. package/build/test/wordbreakers/default-wordbreaker-esm.js +354 -0
  96. package/build/test/wordbreakers/default-wordbreaker-esm.js.map +1 -0
  97. package/build/tsconfig.tsbuildinfo +1 -0
  98. package/build.sh +73 -0
  99. package/coverage/lcov-report/base.css +224 -0
  100. package/coverage/lcov-report/block-navigation.js +87 -0
  101. package/coverage/lcov-report/favicon.png +0 -0
  102. package/coverage/lcov-report/index.html +161 -0
  103. package/coverage/lcov-report/prettify.css +1 -0
  104. package/coverage/lcov-report/prettify.js +2 -0
  105. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  106. package/coverage/lcov-report/sorter.js +196 -0
  107. package/coverage/lcov-report/src/build-trie.ts.html +1618 -0
  108. package/coverage/lcov-report/src/index.html +221 -0
  109. package/coverage/lcov-report/src/join-word-breaker-decorator.ts.html +487 -0
  110. package/coverage/lcov-report/src/lexical-model-compiler.ts.html +622 -0
  111. package/coverage/lcov-report/src/main.ts.html +271 -0
  112. package/coverage/lcov-report/src/model-compiler-errors.ts.html +691 -0
  113. package/coverage/lcov-report/src/model-defaults.ts.html +415 -0
  114. package/coverage/lcov-report/src/model-definitions.ts.html +748 -0
  115. package/coverage/lcov-report/src/script-overrides-decorator.ts.html +310 -0
  116. package/coverage/lcov-report/test/helpers/index.html +116 -0
  117. package/coverage/lcov-report/test/helpers/index.ts.html +646 -0
  118. package/coverage/lcov-report/test/index.html +266 -0
  119. package/coverage/lcov-report/test/test-compile-model-with-pseudoclosure.ts.html +802 -0
  120. package/coverage/lcov-report/test/test-compile-model.ts.html +187 -0
  121. package/coverage/lcov-report/test/test-compile-trie.ts.html +541 -0
  122. package/coverage/lcov-report/test/test-default-apply-case.ts.html +466 -0
  123. package/coverage/lcov-report/test/test-default-search-term-to-key.ts.html +628 -0
  124. package/coverage/lcov-report/test/test-error-logger.ts.html +196 -0
  125. package/coverage/lcov-report/test/test-join-word-breaker.ts.html +376 -0
  126. package/coverage/lcov-report/test/test-model-definitions.ts.html +676 -0
  127. package/coverage/lcov-report/test/test-override-script-defaults.ts.html +184 -0
  128. package/coverage/lcov-report/test/test-parse-wordlist.ts.html +466 -0
  129. package/coverage/lcov-report/test/test-punctuation.ts.html +190 -0
  130. package/coverage/lcov-report/test/wordbreakers/data.ts.html +5413 -0
  131. package/coverage/lcov-report/test/wordbreakers/default-wordbreaker-esm.ts.html +1234 -0
  132. package/coverage/lcov-report/test/wordbreakers/index.html +131 -0
  133. package/coverage/lcov.info +5969 -0
  134. package/package.json +61 -0
  135. package/src/build-trie.ts +511 -0
  136. package/src/join-word-breaker-decorator.ts +134 -0
  137. package/src/lexical-model-compiler.ts +179 -0
  138. package/src/lexical-model.ts +150 -0
  139. package/src/main.ts +62 -0
  140. package/src/model-compiler-errors.ts +203 -0
  141. package/src/model-defaults.ts +111 -0
  142. package/src/model-definitions.ts +222 -0
  143. package/src/script-overrides-decorator.ts +75 -0
  144. package/test/README.md +15 -0
  145. package/test/fixtures/example.qaa.joinwordbreaker/example.qaa.joinwordbreaker.model.ts +10 -0
  146. package/test/fixtures/example.qaa.joinwordbreaker/wordlist.tsv +3 -0
  147. package/test/fixtures/example.qaa.scriptusesspaces/example.qaa.scriptusesspaces.model.ts +10 -0
  148. package/test/fixtures/example.qaa.scriptusesspaces/wordlist.tsv +8 -0
  149. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.kmp.json +45 -0
  150. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.kps +35 -0
  151. package/test/fixtures/example.qaa.sencoten/example.qaa.sencoten.model.ts +6 -0
  152. package/test/fixtures/example.qaa.sencoten/wordlist.tsv +10 -0
  153. package/test/fixtures/example.qaa.smp/example.qaa.smp.model.ts +6 -0
  154. package/test/fixtures/example.qaa.smp/wordlist.tsv +5 -0
  155. package/test/fixtures/example.qaa.trivial/example.qaa.trivial.model.ts +5 -0
  156. package/test/fixtures/example.qaa.trivial/wordlist.tsv +3 -0
  157. package/test/fixtures/example.qaa.utf16be/example.qaa.utf16be.model.ts +5 -0
  158. package/test/fixtures/example.qaa.utf16be/wordlist.txt +0 -0
  159. package/test/fixtures/example.qaa.utf16le/example.qaa.utf16le.model.ts +5 -0
  160. package/test/fixtures/example.qaa.utf16le/wordlist.txt +0 -0
  161. package/test/fixtures/example.qaa.wordbreaker/example.qaa.wordbreaker.model.ts +9 -0
  162. package/test/fixtures/example.qaa.wordbreaker/wordlist.tsv +3 -0
  163. package/test/helpers/index.ts +187 -0
  164. package/test/test-compile-model-with-pseudoclosure.ts +239 -0
  165. package/test/test-compile-model.ts +34 -0
  166. package/test/test-compile-trie.ts +152 -0
  167. package/test/test-default-apply-case.ts +128 -0
  168. package/test/test-default-search-term-to-key.ts +181 -0
  169. package/test/test-error-logger.ts +38 -0
  170. package/test/test-join-word-breaker.ts +97 -0
  171. package/test/test-model-definitions.ts +198 -0
  172. package/test/test-override-script-defaults.ts +33 -0
  173. package/test/test-parse-wordlist.ts +127 -0
  174. package/test/test-punctuation.ts +35 -0
  175. package/test/tsconfig.json +22 -0
  176. package/test/wordbreakers/README.md +3 -0
  177. package/test/wordbreakers/data.ts +1776 -0
  178. package/test/wordbreakers/default-wordbreaker-esm.ts +383 -0
  179. package/tools/create-override-script-regexp.ts +145 -0
  180. package/tsconfig.json +17 -0
@@ -0,0 +1,56 @@
1
+ /// <reference types="@keymanapp/models-types" />
2
+ /**
3
+ * Converts wordforms into an indexable form. It does this by
4
+ * normalizing the letter case of characters INDIVIDUALLY (to disregard
5
+ * context-sensitive case transformations), normalizing to NFKD form,
6
+ * and removing common diacritical marks.
7
+ *
8
+ * This is a very speculative implementation, that might work with
9
+ * your language. We don't guarantee that this will be perfect for your
10
+ * language, but it's a start.
11
+ *
12
+ * This uses String.prototype.normalize() to convert normalize into NFKD.
13
+ * NFKD neutralizes some funky distinctions, e.g., ꬲ, e, e should all be the
14
+ * same character; plus, it's an easy way to separate a Latin character from
15
+ * its diacritics; Even then, orthographies regularly use code points
16
+ * that, under NFKD normalization, do NOT decompose appropriately for your
17
+ * language (e.g., SENĆOŦEN, Plains Cree in syllabics).
18
+ *
19
+ * Use this in early iterations of the model. For a production lexical model,
20
+ * you will probably write/generate your own key function, tailored to your
21
+ * language. There is a chance the default will work properly out of the box.
22
+ */
23
+ export declare function defaultSearchTermToKey(wordform: string): string;
24
+ /**
25
+ * Converts wordforms into an indexable form. It does this by
26
+ * normalizing the letter case of characters INDIVIDUALLY (to disregard
27
+ * context-sensitive case transformations), normalizing to NFKD form,
28
+ * and removing common diacritical marks.
29
+ *
30
+ * This is a very speculative implementation, that might work with
31
+ * your language. We don't guarantee that this will be perfect for your
32
+ * language, but it's a start.
33
+ *
34
+ * This uses String.prototype.normalize() to convert normalize into NFKD.
35
+ * NFKD neutralizes some funky distinctions, e.g., ꬲ, e, e should all be the
36
+ * same character; plus, it's an easy way to separate a Latin character from
37
+ * its diacritics; Even then, orthographies regularly use code points
38
+ * that, under NFKD normalization, do NOT decompose appropriately for your
39
+ * language (e.g., SENĆOŦEN, Plains Cree in syllabics).
40
+ *
41
+ * Use this in early iterations of the model. For a production lexical model,
42
+ * you will probably write/generate your own key function, tailored to your
43
+ * language. There is a chance the default will work properly out of the box.
44
+ */
45
+ export declare function defaultCasedSearchTermToKey(wordform: string, applyCasing: CasingFunction): string;
46
+ /**
47
+ * Specifies default casing behavior for lexical models when `languageUsesCasing` is
48
+ * set to true.
49
+ * @param casing One of 'lower' (lowercased), 'upper' (uppercased), or 'initial'.
50
+ *
51
+ * 'initial' is designed to cover cases like sentence-initial & proper noun capitalization in English.
52
+ * This may be overwritten as appropriate in model-specific implementations.
53
+ * @param text The text to be modified.
54
+ */
55
+ export declare function defaultApplyCasing(casing: CasingForm, text: string): string;
56
+ //# sourceMappingURL=model-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-defaults.d.ts","sourceRoot":"","sources":["../../src/model-defaults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAW/D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,MAAM,CAiBjG;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2B3E"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Converts wordforms into an indexable form. It does this by
3
+ * normalizing the letter case of characters INDIVIDUALLY (to disregard
4
+ * context-sensitive case transformations), normalizing to NFKD form,
5
+ * and removing common diacritical marks.
6
+ *
7
+ * This is a very speculative implementation, that might work with
8
+ * your language. We don't guarantee that this will be perfect for your
9
+ * language, but it's a start.
10
+ *
11
+ * This uses String.prototype.normalize() to convert normalize into NFKD.
12
+ * NFKD neutralizes some funky distinctions, e.g., ꬲ, e, e should all be the
13
+ * same character; plus, it's an easy way to separate a Latin character from
14
+ * its diacritics; Even then, orthographies regularly use code points
15
+ * that, under NFKD normalization, do NOT decompose appropriately for your
16
+ * language (e.g., SENĆOŦEN, Plains Cree in syllabics).
17
+ *
18
+ * Use this in early iterations of the model. For a production lexical model,
19
+ * you will probably write/generate your own key function, tailored to your
20
+ * language. There is a chance the default will work properly out of the box.
21
+ */
22
+ export function defaultSearchTermToKey(wordform) {
23
+ return wordform
24
+ .normalize('NFKD')
25
+ // Remove any combining diacritics (if input is in NFKD)
26
+ .replace(/[\u0300-\u036F]/g, '')
27
+ // Replace directional quotation marks with plain apostrophes
28
+ .replace(/‘/, "'")
29
+ .replace(/’/, "'")
30
+ // Also double-quote marks.
31
+ .replace(/“/, '"')
32
+ .replace(/”/, '"');
33
+ }
34
+ /**
35
+ * Converts wordforms into an indexable form. It does this by
36
+ * normalizing the letter case of characters INDIVIDUALLY (to disregard
37
+ * context-sensitive case transformations), normalizing to NFKD form,
38
+ * and removing common diacritical marks.
39
+ *
40
+ * This is a very speculative implementation, that might work with
41
+ * your language. We don't guarantee that this will be perfect for your
42
+ * language, but it's a start.
43
+ *
44
+ * This uses String.prototype.normalize() to convert normalize into NFKD.
45
+ * NFKD neutralizes some funky distinctions, e.g., ꬲ, e, e should all be the
46
+ * same character; plus, it's an easy way to separate a Latin character from
47
+ * its diacritics; Even then, orthographies regularly use code points
48
+ * that, under NFKD normalization, do NOT decompose appropriately for your
49
+ * language (e.g., SENĆOŦEN, Plains Cree in syllabics).
50
+ *
51
+ * Use this in early iterations of the model. For a production lexical model,
52
+ * you will probably write/generate your own key function, tailored to your
53
+ * language. There is a chance the default will work properly out of the box.
54
+ */
55
+ export function defaultCasedSearchTermToKey(wordform, applyCasing) {
56
+ // While this is a bit WET, as the basic `defaultSearchTermToKey` exists and performs some of
57
+ // the same functions, repetition is the easiest way to allow the function to be safely compiled
58
+ // with ease by use of `.toString()`.
59
+ return Array.from(wordform
60
+ .normalize('NFKD')
61
+ // Remove any combining diacritics (if input is in NFKD)
62
+ .replace(/[\u0300-\u036F]/g, '')) // end of `Array.from`
63
+ .map(function (c) { return applyCasing('lower', c); })
64
+ .join('')
65
+ // Replace directional quotation marks with plain apostrophes
66
+ .replace(/‘/, "'")
67
+ .replace(/’/, "'")
68
+ // Also double-quote marks.
69
+ .replace(/“/, '"')
70
+ .replace(/”/, '"');
71
+ }
72
+ /**
73
+ * Specifies default casing behavior for lexical models when `languageUsesCasing` is
74
+ * set to true.
75
+ * @param casing One of 'lower' (lowercased), 'upper' (uppercased), or 'initial'.
76
+ *
77
+ * 'initial' is designed to cover cases like sentence-initial & proper noun capitalization in English.
78
+ * This may be overwritten as appropriate in model-specific implementations.
79
+ * @param text The text to be modified.
80
+ */
81
+ export function defaultApplyCasing(casing, text) {
82
+ switch (casing) {
83
+ case 'lower':
84
+ return text.toLowerCase();
85
+ case 'upper':
86
+ return text.toUpperCase();
87
+ case 'initial':
88
+ var headCode = text.charCodeAt(0);
89
+ // The length of the first code unit, as measured in code points.
90
+ var headUnitLength = 1;
91
+ // Is the first character a high surrogate, indicating possible use of UTF-16
92
+ // surrogate pairs? Also, is the string long enough for there to BE a pair?
93
+ if (text.length > 1 && headCode >= 0xD800 && headCode <= 0xDBFF) {
94
+ // It's possible, so now we check for low surrogates.
95
+ var lowSurrogateCode = text.charCodeAt(1);
96
+ if (lowSurrogateCode >= 0xDC00 && lowSurrogateCode <= 0xDFFF) {
97
+ // We have a surrogate pair; this pair is the 'first' character.
98
+ headUnitLength++;
99
+ }
100
+ }
101
+ // Capitalizes the first code unit of the string, leaving the rest intact.
102
+ return text.substring(0, headUnitLength).toUpperCase() // head - uppercased
103
+ .concat(text.substring(headUnitLength)); // tail - lowercased
104
+ }
105
+ }
106
+ //# sourceMappingURL=model-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3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,EAAE,CAAC;QAC5B,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,KAAK,SAAS;YACZ,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAClC,iEAAiE;YACjE,IAAI,cAAc,GAAG,CAAC,CAAC;YAEvB,6EAA6E;YAC7E,4EAA4E;YAC5E,IAAG,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,EAAE;gBAC9D,qDAAqD;gBACrD,IAAI,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAE1C,IAAG,gBAAgB,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,EAAE;oBAC3D,gEAAgE;oBAChE,cAAc,EAAE,CAAC;iBAClB;aACF;YAED,0EAA0E;YAC1E,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,WAAW,EAAE,CAAC,oBAAoB;iBACnE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAQ,oBAAoB;KAC9E;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ /// <reference types="@keymanapp/models-types" />
2
+ import { LexicalModelSource, WordformToKeySpec } from "./lexical-model.js";
3
+ /**
4
+ * Processes certain defined model behaviors in such a way that the needed closures
5
+ * may be safely compiled to a JS file and loaded within the LMLayer.
6
+ *
7
+ * This is accomplished by writing out a 'pseudoclosure' within the model's IIFE,
8
+ * then used to build _actual_ closures at LMLayer load time. This 'pseudoclosure'
9
+ * will very closely match the organizational patterns of this class in order to
10
+ * facilitate the maintenance of this approach.
11
+ */
12
+ export declare class ModelDefinitions {
13
+ static readonly COMPILED_NAME = "definitions";
14
+ /**
15
+ * A closure fully implementing the model's defined `applyCasing` behavior with
16
+ * the function parameter preset to the version-appropriate default.
17
+ * `defaults.applyCasing` is captured as part of the closure.
18
+ *
19
+ * During compilation of some models (such as Trie-based wordlist templated models),
20
+ * this closure will be directly used as part of searchTermToKey.
21
+ *
22
+ * In compiled code, this will instead be defined in-line as an autogenerated closure
23
+ * using the other properties of the pseudoclosure.
24
+ */
25
+ applyCasing?: CasingFunction;
26
+ /**
27
+ * A closure fully implementing the model's defined `searchTermToKey` behavior
28
+ * based upon the model's specified casing rules. The `applyCasing` closure is
29
+ * itself captured within this closure.
30
+ *
31
+ * During compilation of some models (such as Trie-based wordlist templated models),
32
+ * this closure will be directly utilized when compiling the lexicon.
33
+ *
34
+ * In compiled code, this will instead be defined in-line as an autogenerated closure
35
+ * using the other properties of the pseudoclosure.
36
+ */
37
+ searchTermToKey?: WordformToKeySpec;
38
+ /**
39
+ * Contains embedded 'default' implementations that may be needed for
40
+ * closures in the compiled version, annotated with the current version
41
+ * of Developer.
42
+ */
43
+ private defaults;
44
+ /**
45
+ * Contains the model-specific definitions specified in the model's source.
46
+ *
47
+ * These definitions may expect `defaults.applyCasing` as a parameter in
48
+ * their final closures.
49
+ */
50
+ private model;
51
+ constructor(modelSource: LexicalModelSource);
52
+ /**
53
+ * Writes out a compiled JS version of the pseudoclosure, preserving all function
54
+ * implementations.
55
+ *
56
+ * This should be written to the file within the same IIFE as the model but BEFORE
57
+ * the model itself, as the model will need to refer to the definitions herein.
58
+ */
59
+ compileDefinitions(): string;
60
+ /**
61
+ * Compiles the model-options entry for `searchTermToKey` in reference to the
62
+ * compiled pseudoclosure.
63
+ */
64
+ compileSearchTermToKey(): string;
65
+ /**
66
+ * Compiles the model-options entry for `applyCasing` in reference to the
67
+ * compiled pseudoclosure.
68
+ */
69
+ compileApplyCasing(): string;
70
+ }
71
+ //# sourceMappingURL=model-definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-definitions.d.ts","sourceRoot":"","sources":["../../src/model-definitions.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,QAAQ,CAAC,aAAa,iBAAiB;IAC9C;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC;IAE7B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,iBAAiB,CAAC;IAEpC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAKd;IAEF;;;;;OAKG;IACH,OAAO,CAAC,KAAK,CAGN;gBAEK,WAAW,EAAE,kBAAkB;IAsD3C;;;;;;OAMG;IACH,kBAAkB,IAAI,MAAM;IAuE5B;;;OAGG;IACH,sBAAsB,IAAI,MAAM;IAMhC;;;OAGG;IACH,kBAAkB,IAAI,MAAM;CAI7B"}
@@ -0,0 +1,189 @@
1
+ import { defaultApplyCasing, defaultCasedSearchTermToKey, defaultSearchTermToKey } from "./model-defaults.js";
2
+ import KEYMAN_VERSION from "@keymanapp/keyman-version";
3
+ /**
4
+ * Processes certain defined model behaviors in such a way that the needed closures
5
+ * may be safely compiled to a JS file and loaded within the LMLayer.
6
+ *
7
+ * This is accomplished by writing out a 'pseudoclosure' within the model's IIFE,
8
+ * then used to build _actual_ closures at LMLayer load time. This 'pseudoclosure'
9
+ * will very closely match the organizational patterns of this class in order to
10
+ * facilitate the maintenance of this approach.
11
+ */
12
+ export class ModelDefinitions {
13
+ static COMPILED_NAME = 'definitions';
14
+ /**
15
+ * A closure fully implementing the model's defined `applyCasing` behavior with
16
+ * the function parameter preset to the version-appropriate default.
17
+ * `defaults.applyCasing` is captured as part of the closure.
18
+ *
19
+ * During compilation of some models (such as Trie-based wordlist templated models),
20
+ * this closure will be directly used as part of searchTermToKey.
21
+ *
22
+ * In compiled code, this will instead be defined in-line as an autogenerated closure
23
+ * using the other properties of the pseudoclosure.
24
+ */
25
+ applyCasing;
26
+ /**
27
+ * A closure fully implementing the model's defined `searchTermToKey` behavior
28
+ * based upon the model's specified casing rules. The `applyCasing` closure is
29
+ * itself captured within this closure.
30
+ *
31
+ * During compilation of some models (such as Trie-based wordlist templated models),
32
+ * this closure will be directly utilized when compiling the lexicon.
33
+ *
34
+ * In compiled code, this will instead be defined in-line as an autogenerated closure
35
+ * using the other properties of the pseudoclosure.
36
+ */
37
+ searchTermToKey;
38
+ /**
39
+ * Contains embedded 'default' implementations that may be needed for
40
+ * closures in the compiled version, annotated with the current version
41
+ * of Developer.
42
+ */
43
+ defaults = {
44
+ version: KEYMAN_VERSION.VERSION_WITH_TAG
45
+ };
46
+ /**
47
+ * Contains the model-specific definitions specified in the model's source.
48
+ *
49
+ * These definitions may expect `defaults.applyCasing` as a parameter in
50
+ * their final closures.
51
+ */
52
+ model = {};
53
+ constructor(modelSource) {
54
+ // Determine the model's `applyCasing` function / implementation.
55
+ if (modelSource.languageUsesCasing) {
56
+ this.defaults.applyCasing = defaultApplyCasing;
57
+ if (modelSource.applyCasing) {
58
+ this.model.applyCasing = modelSource.applyCasing;
59
+ let _this = this;
60
+ // Since the defined casing function may expect to take our default implementation
61
+ // as a parameter, we can define the full implementation via closure capture.
62
+ this.applyCasing = function (casing, text) {
63
+ return _this.model.applyCasing(casing, text, _this.defaults.applyCasing);
64
+ };
65
+ }
66
+ else {
67
+ this.applyCasing = this.defaults.applyCasing;
68
+ }
69
+ }
70
+ // START: if(model type uses keying)...
71
+ // Use the default search term to key function, if left unspecified.
72
+ if (modelSource.searchTermToKey) {
73
+ this.model.searchTermToKey = modelSource.searchTermToKey;
74
+ }
75
+ else if (modelSource.languageUsesCasing) {
76
+ // applyCasing is defined here.
77
+ // Unfortunately, this only works conceptually. .toString on a closure
78
+ // does not result in proper compilation.
79
+ this.model.searchTermToKey = defaultCasedSearchTermToKey;
80
+ }
81
+ else if (modelSource.languageUsesCasing == false) {
82
+ this.model.searchTermToKey = defaultSearchTermToKey;
83
+ }
84
+ else {
85
+ // If languageUsesCasing is not defined, then we use pre-14.0 behavior,
86
+ // which expects a lowercased default.
87
+ this.model.searchTermToKey = defaultCasedSearchTermToKey;
88
+ // Needed to provide pre-14.0 default lowercasing as part of the
89
+ // search-term keying operation.
90
+ this.defaults.applyCasing = defaultApplyCasing;
91
+ // For compile-time use.
92
+ this.applyCasing = this.defaults.applyCasing;
93
+ }
94
+ let _this = this;
95
+ this.searchTermToKey = function (text) {
96
+ return _this.model.searchTermToKey(text, _this.applyCasing);
97
+ };
98
+ // END: if(model type uses keying)...
99
+ }
100
+ // ------------ end: common compile-time / run-time code ---------------
101
+ // START: handwritten compilation code (to accomplish the 'common' pattern defined above)
102
+ /**
103
+ * Writes out a compiled JS version of the pseudoclosure, preserving all function
104
+ * implementations.
105
+ *
106
+ * This should be written to the file within the same IIFE as the model but BEFORE
107
+ * the model itself, as the model will need to refer to the definitions herein.
108
+ */
109
+ compileDefinitions() {
110
+ let defn = '';
111
+ defn += `var ${PSEUDOCLOSURE} = {\n`;
112
+ // ----------------------
113
+ // START - the 'defaults', which are common within the same Developer version.
114
+ defn += ` defaults: {\n version: "${this.defaults.version}"`;
115
+ // Only write out `applyCasing` if and when it is needed.
116
+ if (this.defaults.applyCasing) {
117
+ defn += `,\n applyCasing: ${this.defaults.applyCasing.toString()}`;
118
+ }
119
+ // Finalizes `defaults`
120
+ defn += `\n },`;
121
+ // END - the 'defaults'
122
+ // ----------------------
123
+ // START - model-specific definitions (when defined)
124
+ defn += ` model: {\n`;
125
+ defn += ` searchTermToKey: ${this.model.searchTermToKey.toString()}`;
126
+ if (this.model.applyCasing) {
127
+ defn += `,\n applyCasing: ${this.model.applyCasing.toString()}`;
128
+ }
129
+ defn += `\n }`;
130
+ // END - model-specific definitions
131
+ // ----------------------
132
+ // START - compiled closures. Given those definitions, write out the
133
+ // pseudoclosure-referencing closures for the needed methods.
134
+ // We should be able to define these closures in-line with the object's
135
+ // initialization. Worst-case, we simply move the definitions outside
136
+ // of the pseudoclosure's init and THEN define/assign these closures to
137
+ // the object, as references will be available then for sure.
138
+ if (this.model.applyCasing) {
139
+ // A major potential issue: if the user wants to call extra custom functions that they've written.
140
+ //
141
+ // `applyCasing` recursion SHOULD be fine if they write `this.applyCasing() and forward all arguments
142
+ // appropriately, as it will be known as `applyCasing` on the runtime `this` (`model`) object.
143
+ //
144
+ // Similarly, as long as any helper functions are similarly compiled and stored as part of `model`,
145
+ // they should be accessible too. The issue would be to actually allow use of extra custom funcs
146
+ // and include them as part of this object as part of compilation.
147
+ defn += `,\n applyCasing: function(caseToApply, text) {
148
+ return ${PSEUDOCLOSURE}.model.applyCasing(caseToApply, text, ${PSEUDOCLOSURE}.defaults.applyCasing);
149
+ }`;
150
+ }
151
+ else if (this.defaults.applyCasing) {
152
+ // We can't directly assign from `.defaults`, as initialization-time field reads
153
+ // are not permitted within JS. Function references, however, are valid.
154
+ defn += `,\n applyCasing: function(caseToApply, text) {
155
+ return ${PSEUDOCLOSURE}.defaults.applyCasing(caseToApply, text);
156
+ }`;
157
+ }
158
+ // if(this.searchTermToKey) {
159
+ defn += `,\n searchTermToKey: function(text) {
160
+ return ${PSEUDOCLOSURE}.model.searchTermToKey(text, ${PSEUDOCLOSURE}.applyCasing);
161
+ }`;
162
+ // }
163
+ // END - compiled closures.
164
+ // ----------------------
165
+ // Finalize the definition of... `definitions`.
166
+ defn += `\n};\n`;
167
+ return defn;
168
+ }
169
+ /**
170
+ * Compiles the model-options entry for `searchTermToKey` in reference to the
171
+ * compiled pseudoclosure.
172
+ */
173
+ compileSearchTermToKey() {
174
+ // Simply point the model to the constructed closure defined by `compilePseudoclosure`.
175
+ // See "START - compiled closures" section.
176
+ return `${PSEUDOCLOSURE}.searchTermToKey`;
177
+ }
178
+ /**
179
+ * Compiles the model-options entry for `applyCasing` in reference to the
180
+ * compiled pseudoclosure.
181
+ */
182
+ compileApplyCasing() {
183
+ // See "START - compiled closures" section.
184
+ return `${PSEUDOCLOSURE}.applyCasing`;
185
+ }
186
+ }
187
+ // Because it references the class field, this line must come afterward.
188
+ const PSEUDOCLOSURE = ModelDefinitions.COMPILED_NAME;
189
+ //# sourceMappingURL=model-definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-definitions.js","sourceRoot":"","sources":["../../src/model-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAClB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAEpC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AAGvD;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAU,aAAa,GAAG,aAAa,CAAC;IAC9C;;;;;;;;;;OAUG;IACH,WAAW,CAAkB;IAE7B;;;;;;;;;;OAUG;IACH,eAAe,CAAqB;IAEpC;;;;OAIG;IACK,QAAQ,GAGZ;QACF,OAAO,EAAE,cAAc,CAAC,gBAAgB;KACzC,CAAC;IAEF;;;;;OAKG;IACK,KAAK,GAGT,EAAE,CAAC;IAEP,YAAY,WAA+B;QACzC,iEAAiE;QACjE,IAAG,WAAW,CAAC,kBAAkB,EAAE;YACjC,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,kBAAkB,CAAC;YAE/C,IAAG,WAAW,CAAC,WAAW,EAAE;gBAC1B,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC;gBACjD,IAAI,KAAK,GAAG,IAAI,CAAC;gBAEjB,kFAAkF;gBAClF,6EAA6E;gBAC7E,IAAI,CAAC,WAAW,GAAG,UAAS,MAAkB,EAAE,IAAY;oBAC1D,OAAO,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAC3E,CAAC,CAAC;aACH;iBAAM;gBACL,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;aAC9C;SACF;QAED,uCAAuC;QAEvC,oEAAoE;QACpE,IAAG,WAAW,CAAC,eAAe,EAAE;YAC9B,IAAI,CAAC,KAAK,CAAC,eA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AgB,CAAC,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="@keymanapp/models-types" />
2
+ import { OverrideScriptDefaults } from "./lexical-model.js";
3
+ export declare function decorateWithScriptOverrides(breaker: WordBreakingFunction, option: OverrideScriptDefaults): (phrase: string) => Span[];
4
+ //# sourceMappingURL=script-overrides-decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-overrides-decorator.d.ts","sourceRoot":"","sources":["../../src/script-overrides-decorator.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,sBAAsB,YAgB/D,MAAM,KAAG,IAAI,EAAE,CAwDxD"}
@@ -0,0 +1,63 @@
1
+ export function decorateWithScriptOverrides(breaker, option) {
2
+ if (option !== 'break-words-at-spaces') {
3
+ throw new Error(`Unsupported script override: ${option}`);
4
+ }
5
+ /**
6
+ * Matches if when a span contains a Southeast-Asian letter or mark anywhere.
7
+ * This makes it a candidate for joining.
8
+ *
9
+ * See: tools/create-override-script-regexp.ts for how this RegExp was
10
+ * generated.
11
+ *
12
+ * Last updated for Unicode 13.0.0.
13
+ */
14
+ const HAS_SOUTHEAST_ASIAN_LETTER = /[\u0E01-\u0E3A\u0E40-\u0E4E\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0EDC-\u0EDF\u1000-\u103F\u1050-\u108F\u109A-\u109D\u1780-\u17D3\u17D7\u17DC\u17DD\u30A1-\u30FA\u30FC-\u30FF]/;
15
+ return function enhancedBreaker(phrase) {
16
+ let originalSpans = breaker(phrase);
17
+ if (originalSpans.length === 0) {
18
+ return [];
19
+ }
20
+ let outputSpans = [originalSpans.shift()];
21
+ for (let currentSpan of originalSpans) {
22
+ let previousSpan = lastFrom(outputSpans);
23
+ if (spansAreBackToBack(previousSpan, currentSpan) &&
24
+ hasSouthEastAsianLetter(previousSpan) &&
25
+ hasSouthEastAsianLetter(currentSpan)) {
26
+ // previous span SHOULD be joined with current!
27
+ outputSpans[outputSpans.length - 1] = concatenateSpans(previousSpan, currentSpan);
28
+ }
29
+ else {
30
+ outputSpans.push(currentSpan);
31
+ }
32
+ }
33
+ return outputSpans;
34
+ };
35
+ function hasSouthEastAsianLetter(span) {
36
+ return HAS_SOUTHEAST_ASIAN_LETTER.test(span.text);
37
+ }
38
+ /**
39
+ * Returns true when the spans are contiguous.
40
+ * Order matters when calling this function!
41
+ */
42
+ function spansAreBackToBack(former, latter) {
43
+ return former.end === latter.start;
44
+ }
45
+ function concatenateSpans(former, latter) {
46
+ if (latter.start !== former.end) {
47
+ throw new Error(`Cannot concatenate non-contiguous spans: ${JSON.stringify(former)}/${JSON.stringify(latter)}`);
48
+ }
49
+ return {
50
+ start: former.start,
51
+ end: latter.end,
52
+ length: former.length + latter.length,
53
+ text: former.text + latter.text
54
+ };
55
+ }
56
+ /**
57
+ * Get the last element from the array.
58
+ */
59
+ function lastFrom(array) {
60
+ return array[array.length - 1];
61
+ }
62
+ }
63
+ //# sourceMappingURL=script-overrides-decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-overrides-decorator.js","sourceRoot":"","sources":["../../src/script-overrides-decorator.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,2BAA2B,CAAC,OAA6B,EAAE,MAA8B;IACvG,IAAI,MAAM,KAAK,uBAAuB,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAA;KAC1D;IAED;;;;;;;;OAQG;IACH,MAAM,0BAA0B,GAAG,0OAA0O,CAAC;IAE9Q,OAAO,SAAS,eAAe,CAAC,MAAc;QAC5C,IAAI,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpC,IAAI,aAAa,CAAC,MAAM,KAAK,CAA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,MAAM,CAAC,IAAI;SAChC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,SAAS,QAAQ,CAAI,KAAU;QAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
@@ -0,0 +1,69 @@
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
@@ -0,0 +1 @@
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"}