@kensio/pinyinjs 1.7.4 → 1.7.5

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 (695) hide show
  1. package/dist/accuracy/score-case.d.ts +23 -0
  2. package/dist/accuracy/score-case.d.ts.map +1 -0
  3. package/dist/accuracy/score-case.js +63 -0
  4. package/dist/accuracy/score-case.js.map +1 -0
  5. package/dist/accuracy/score.d.ts +1 -8
  6. package/dist/accuracy/score.d.ts.map +1 -1
  7. package/dist/accuracy/score.js +1 -55
  8. package/dist/accuracy/score.js.map +1 -1
  9. package/dist/cli/arguments.d.ts +4 -290
  10. package/dist/cli/arguments.d.ts.map +1 -1
  11. package/dist/cli/arguments.js +5 -357
  12. package/dist/cli/arguments.js.map +1 -1
  13. package/dist/cli/check-command.d.ts +9 -0
  14. package/dist/cli/check-command.d.ts.map +1 -0
  15. package/dist/cli/check-command.js +95 -0
  16. package/dist/cli/check-command.js.map +1 -0
  17. package/dist/cli/cli-input.d.ts +49 -0
  18. package/dist/cli/cli-input.d.ts.map +1 -0
  19. package/dist/cli/cli-input.js +31 -0
  20. package/dist/cli/cli-input.js.map +1 -0
  21. package/dist/cli/command.d.ts +97 -0
  22. package/dist/cli/command.d.ts.map +1 -0
  23. package/dist/cli/command.js +40 -0
  24. package/dist/cli/command.js.map +1 -0
  25. package/dist/cli/commands.d.ts +7 -110
  26. package/dist/cli/commands.d.ts.map +1 -1
  27. package/dist/cli/commands.js +14 -991
  28. package/dist/cli/commands.js.map +1 -1
  29. package/dist/cli/convert-command.d.ts +6 -0
  30. package/dist/cli/convert-command.d.ts.map +1 -0
  31. package/dist/cli/convert-command.js +52 -0
  32. package/dist/cli/convert-command.js.map +1 -0
  33. package/dist/cli/environment.d.ts +1 -1
  34. package/dist/cli/environment.d.ts.map +1 -1
  35. package/dist/cli/explain-command.d.ts +6 -0
  36. package/dist/cli/explain-command.d.ts.map +1 -0
  37. package/dist/cli/explain-command.js +40 -0
  38. package/dist/cli/explain-command.js.map +1 -0
  39. package/dist/cli/explain-syllable.d.ts +10 -0
  40. package/dist/cli/explain-syllable.d.ts.map +1 -0
  41. package/dist/cli/explain-syllable.js +70 -0
  42. package/dist/cli/explain-syllable.js.map +1 -0
  43. package/dist/cli/flag-help.d.ts +18 -0
  44. package/dist/cli/flag-help.d.ts.map +1 -0
  45. package/dist/cli/flag-help.js +78 -0
  46. package/dist/cli/flag-help.js.map +1 -0
  47. package/dist/cli/flag-lists.d.ts +49 -0
  48. package/dist/cli/flag-lists.d.ts.map +1 -0
  49. package/dist/cli/flag-lists.js +58 -0
  50. package/dist/cli/flag-lists.js.map +1 -0
  51. package/dist/cli/flag-values.d.ts +44 -0
  52. package/dist/cli/flag-values.d.ts.map +1 -0
  53. package/dist/cli/flag-values.js +56 -0
  54. package/dist/cli/flag-values.js.map +1 -0
  55. package/dist/cli/flags.d.ts +193 -0
  56. package/dist/cli/flags.d.ts.map +1 -0
  57. package/dist/cli/flags.js +133 -0
  58. package/dist/cli/flags.js.map +1 -0
  59. package/dist/cli/format-options.d.ts +29 -0
  60. package/dist/cli/format-options.d.ts.map +1 -0
  61. package/dist/cli/format-options.js +72 -0
  62. package/dist/cli/format-options.js.map +1 -0
  63. package/dist/cli/global-help.d.ts +23 -0
  64. package/dist/cli/global-help.d.ts.map +1 -0
  65. package/dist/cli/global-help.js +40 -0
  66. package/dist/cli/global-help.js.map +1 -0
  67. package/dist/cli/help.d.ts +1 -1
  68. package/dist/cli/help.d.ts.map +1 -1
  69. package/dist/cli/help.js +5 -99
  70. package/dist/cli/help.js.map +1 -1
  71. package/dist/cli/html-commands.d.ts +13 -0
  72. package/dist/cli/html-commands.d.ts.map +1 -0
  73. package/dist/cli/html-commands.js +49 -0
  74. package/dist/cli/html-commands.js.map +1 -0
  75. package/dist/cli/info-command.d.ts +7 -0
  76. package/dist/cli/info-command.d.ts.map +1 -0
  77. package/dist/cli/info-command.js +39 -0
  78. package/dist/cli/info-command.js.map +1 -0
  79. package/dist/cli/lookup-commands.d.ts +10 -0
  80. package/dist/cli/lookup-commands.d.ts.map +1 -0
  81. package/dist/cli/lookup-commands.js +101 -0
  82. package/dist/cli/lookup-commands.js.map +1 -0
  83. package/dist/cli/match-command.d.ts +11 -0
  84. package/dist/cli/match-command.d.ts.map +1 -0
  85. package/dist/cli/match-command.js +76 -0
  86. package/dist/cli/match-command.js.map +1 -0
  87. package/dist/cli/number-command.d.ts +12 -0
  88. package/dist/cli/number-command.d.ts.map +1 -0
  89. package/dist/cli/number-command.js +89 -0
  90. package/dist/cli/number-command.js.map +1 -0
  91. package/dist/cli/options.d.ts +30 -0
  92. package/dist/cli/options.d.ts.map +1 -0
  93. package/dist/cli/options.js +54 -0
  94. package/dist/cli/options.js.map +1 -0
  95. package/dist/cli/run-command.d.ts +24 -0
  96. package/dist/cli/run-command.d.ts.map +1 -0
  97. package/dist/cli/run-command.js +40 -0
  98. package/dist/cli/run-command.js.map +1 -0
  99. package/dist/cli/run.d.ts +4 -42
  100. package/dist/cli/run.d.ts.map +1 -1
  101. package/dist/cli/run.js +6 -61
  102. package/dist/cli/run.js.map +1 -1
  103. package/dist/cli/script-command.d.ts +10 -0
  104. package/dist/cli/script-command.d.ts.map +1 -0
  105. package/dist/cli/script-command.js +58 -0
  106. package/dist/cli/script-command.js.map +1 -0
  107. package/dist/cli/segment-command.d.ts +11 -0
  108. package/dist/cli/segment-command.d.ts.map +1 -0
  109. package/dist/cli/segment-command.js +53 -0
  110. package/dist/cli/segment-command.js.map +1 -0
  111. package/dist/cli/slug-command.d.ts +10 -0
  112. package/dist/cli/slug-command.d.ts.map +1 -0
  113. package/dist/cli/slug-command.js +28 -0
  114. package/dist/cli/slug-command.js.map +1 -0
  115. package/dist/cli/syllable-command.d.ts +14 -0
  116. package/dist/cli/syllable-command.d.ts.map +1 -0
  117. package/dist/cli/syllable-command.js +82 -0
  118. package/dist/cli/syllable-command.js.map +1 -0
  119. package/dist/cli/system-table.d.ts +12 -0
  120. package/dist/cli/system-table.d.ts.map +1 -0
  121. package/dist/cli/system-table.js +48 -0
  122. package/dist/cli/system-table.js.map +1 -0
  123. package/dist/cli/systems.d.ts +57 -0
  124. package/dist/cli/systems.d.ts.map +1 -0
  125. package/dist/cli/systems.js +27 -0
  126. package/dist/cli/systems.js.map +1 -0
  127. package/dist/cli/transcribe-command.d.ts +18 -0
  128. package/dist/cli/transcribe-command.d.ts.map +1 -0
  129. package/dist/cli/transcribe-command.js +86 -0
  130. package/dist/cli/transcribe-command.js.map +1 -0
  131. package/dist/cli/transcribe-reading.d.ts +15 -0
  132. package/dist/cli/transcribe-reading.d.ts.map +1 -0
  133. package/dist/cli/transcribe-reading.js +90 -0
  134. package/dist/cli/transcribe-reading.js.map +1 -0
  135. package/dist/cli/transcribe-rows.d.ts +26 -0
  136. package/dist/cli/transcribe-rows.d.ts.map +1 -0
  137. package/dist/cli/transcribe-rows.js +30 -0
  138. package/dist/cli/transcribe-rows.js.map +1 -0
  139. package/dist/cli/usage-error.d.ts +9 -0
  140. package/dist/cli/usage-error.d.ts.map +1 -0
  141. package/dist/cli/usage-error.js +9 -0
  142. package/dist/cli/usage-error.js.map +1 -0
  143. package/dist/decode/alternatives.d.ts +16 -0
  144. package/dist/decode/alternatives.d.ts.map +1 -0
  145. package/dist/decode/alternatives.js +31 -0
  146. package/dist/decode/alternatives.js.map +1 -0
  147. package/dist/decode/confidence.d.ts.map +1 -1
  148. package/dist/decode/confidence.js +3 -118
  149. package/dist/decode/confidence.js.map +1 -1
  150. package/dist/decode/convert-options.d.ts +116 -0
  151. package/dist/decode/convert-options.d.ts.map +1 -0
  152. package/dist/decode/convert-options.js +2 -0
  153. package/dist/decode/convert-options.js.map +1 -0
  154. package/dist/decode/convert-pipeline.d.ts +18 -0
  155. package/dist/decode/convert-pipeline.d.ts.map +1 -0
  156. package/dist/decode/convert-pipeline.js +66 -0
  157. package/dist/decode/convert-pipeline.js.map +1 -0
  158. package/dist/decode/convert.d.ts +9 -118
  159. package/dist/decode/convert.d.ts.map +1 -1
  160. package/dist/decode/convert.js +5 -453
  161. package/dist/decode/convert.js.map +1 -1
  162. package/dist/decode/decode.d.ts +2 -15
  163. package/dist/decode/decode.d.ts.map +1 -1
  164. package/dist/decode/decode.js +2 -121
  165. package/dist/decode/decode.js.map +1 -1
  166. package/dist/decode/decoders.d.ts +32 -0
  167. package/dist/decode/decoders.d.ts.map +1 -0
  168. package/dist/decode/decoders.js +29 -0
  169. package/dist/decode/decoders.js.map +1 -0
  170. package/dist/decode/edge-context.d.ts +38 -0
  171. package/dist/decode/edge-context.d.ts.map +1 -0
  172. package/dist/decode/edge-context.js +57 -0
  173. package/dist/decode/edge-context.js.map +1 -0
  174. package/dist/decode/hint-lattice.d.ts +45 -0
  175. package/dist/decode/hint-lattice.d.ts.map +1 -0
  176. package/dist/decode/hint-lattice.js +140 -0
  177. package/dist/decode/hint-lattice.js.map +1 -0
  178. package/dist/decode/hints.d.ts +2 -45
  179. package/dist/decode/hints.d.ts.map +1 -1
  180. package/dist/decode/hints.js +1 -139
  181. package/dist/decode/hints.js.map +1 -1
  182. package/dist/decode/jiao-rule.d.ts +58 -0
  183. package/dist/decode/jiao-rule.d.ts.map +1 -0
  184. package/dist/decode/jiao-rule.js +76 -0
  185. package/dist/decode/jiao-rule.js.map +1 -0
  186. package/dist/decode/lattice-costs.d.ts +55 -0
  187. package/dist/decode/lattice-costs.d.ts.map +1 -0
  188. package/dist/decode/lattice-costs.js +90 -0
  189. package/dist/decode/lattice-costs.js.map +1 -0
  190. package/dist/decode/lattice-edges.d.ts +29 -0
  191. package/dist/decode/lattice-edges.d.ts.map +1 -0
  192. package/dist/decode/lattice-edges.js +78 -0
  193. package/dist/decode/lattice-edges.js.map +1 -0
  194. package/dist/decode/lattice-slice.d.ts +37 -0
  195. package/dist/decode/lattice-slice.d.ts.map +1 -0
  196. package/dist/decode/lattice-slice.js +43 -0
  197. package/dist/decode/lattice-slice.js.map +1 -0
  198. package/dist/decode/lattice-types.d.ts +82 -0
  199. package/dist/decode/lattice-types.d.ts.map +1 -0
  200. package/dist/decode/lattice-types.js +44 -0
  201. package/dist/decode/lattice-types.js.map +1 -0
  202. package/dist/decode/lattice.d.ts +2 -59
  203. package/dist/decode/lattice.d.ts.map +1 -1
  204. package/dist/decode/lattice.js +2 -118
  205. package/dist/decode/lattice.js.map +1 -1
  206. package/dist/decode/number-pieces.d.ts +62 -0
  207. package/dist/decode/number-pieces.d.ts.map +1 -0
  208. package/dist/decode/number-pieces.js +106 -0
  209. package/dist/decode/number-pieces.js.map +1 -0
  210. package/dist/decode/numbers.d.ts +53 -0
  211. package/dist/decode/numbers.d.ts.map +1 -0
  212. package/dist/decode/numbers.js +69 -0
  213. package/dist/decode/numbers.js.map +1 -0
  214. package/dist/decode/pieces.d.ts +78 -0
  215. package/dist/decode/pieces.d.ts.map +1 -0
  216. package/dist/decode/pieces.js +136 -0
  217. package/dist/decode/pieces.js.map +1 -0
  218. package/dist/decode/polyphone-rules.d.ts +31 -0
  219. package/dist/decode/polyphone-rules.d.ts.map +1 -0
  220. package/dist/decode/polyphone-rules.js +159 -0
  221. package/dist/decode/polyphone-rules.js.map +1 -0
  222. package/dist/decode/reading-rules.d.ts +2 -97
  223. package/dist/decode/reading-rules.d.ts.map +1 -1
  224. package/dist/decode/reading-rules.js +4 -365
  225. package/dist/decode/reading-rules.js.map +1 -1
  226. package/dist/decode/rules.d.ts +1 -17
  227. package/dist/decode/rules.d.ts.map +1 -1
  228. package/dist/decode/rules.js +1 -43
  229. package/dist/decode/rules.js.map +1 -1
  230. package/dist/decode/run-lattice.d.ts +52 -0
  231. package/dist/decode/run-lattice.d.ts.map +1 -0
  232. package/dist/decode/run-lattice.js +91 -0
  233. package/dist/decode/run-lattice.js.map +1 -0
  234. package/dist/decode/sandhi-tones.d.ts +69 -0
  235. package/dist/decode/sandhi-tones.d.ts.map +1 -0
  236. package/dist/decode/sandhi-tones.js +88 -0
  237. package/dist/decode/sandhi-tones.js.map +1 -0
  238. package/dist/decode/sandhi.d.ts +1 -1
  239. package/dist/decode/sandhi.d.ts.map +1 -1
  240. package/dist/decode/sandhi.js +1 -81
  241. package/dist/decode/sandhi.js.map +1 -1
  242. package/dist/decode/script-types.d.ts +76 -0
  243. package/dist/decode/script-types.d.ts.map +1 -0
  244. package/dist/decode/script-types.js +35 -0
  245. package/dist/decode/script-types.js.map +1 -0
  246. package/dist/decode/script-words.d.ts +32 -0
  247. package/dist/decode/script-words.d.ts.map +1 -0
  248. package/dist/decode/script-words.js +77 -0
  249. package/dist/decode/script-words.js.map +1 -0
  250. package/dist/decode/script.d.ts +3 -73
  251. package/dist/decode/script.d.ts.map +1 -1
  252. package/dist/decode/script.js +3 -109
  253. package/dist/decode/script.js.map +1 -1
  254. package/dist/decode/tan-rule.d.ts +68 -0
  255. package/dist/decode/tan-rule.d.ts.map +1 -0
  256. package/dist/decode/tan-rule.js +131 -0
  257. package/dist/decode/tan-rule.js.map +1 -0
  258. package/dist/decode/write-run.d.ts +28 -0
  259. package/dist/decode/write-run.d.ts.map +1 -0
  260. package/dist/decode/write-run.js +77 -0
  261. package/dist/decode/write-run.js.map +1 -0
  262. package/dist/dictionary/artifact-claims.d.ts +25 -0
  263. package/dist/dictionary/artifact-claims.d.ts.map +1 -0
  264. package/dist/dictionary/artifact-claims.js +47 -0
  265. package/dist/dictionary/artifact-claims.js.map +1 -0
  266. package/dist/dictionary/artifact-format.d.ts +86 -0
  267. package/dist/dictionary/artifact-format.d.ts.map +1 -0
  268. package/dist/dictionary/artifact-format.js +91 -0
  269. package/dist/dictionary/artifact-format.js.map +1 -0
  270. package/dist/dictionary/artifact-read.d.ts +34 -0
  271. package/dist/dictionary/artifact-read.d.ts.map +1 -0
  272. package/dist/dictionary/artifact-read.js +114 -0
  273. package/dist/dictionary/artifact-read.js.map +1 -0
  274. package/dist/dictionary/artifact.d.ts +4 -63
  275. package/dist/dictionary/artifact.d.ts.map +1 -1
  276. package/dist/dictionary/artifact.js +12 -229
  277. package/dist/dictionary/artifact.js.map +1 -1
  278. package/dist/dictionary/assertions.d.ts +5 -57
  279. package/dist/dictionary/assertions.d.ts.map +1 -1
  280. package/dist/dictionary/assertions.js +4 -317
  281. package/dist/dictionary/assertions.js.map +1 -1
  282. package/dist/dictionary/build-assertions.d.ts +12 -0
  283. package/dist/dictionary/build-assertions.d.ts.map +1 -0
  284. package/dist/dictionary/build-assertions.js +13 -0
  285. package/dist/dictionary/build-assertions.js.map +1 -0
  286. package/dist/dictionary/built-dictionary.d.ts +46 -0
  287. package/dist/dictionary/built-dictionary.d.ts.map +1 -0
  288. package/dist/dictionary/built-dictionary.js +97 -0
  289. package/dist/dictionary/built-dictionary.js.map +1 -0
  290. package/dist/dictionary/cedict-senses.d.ts +80 -0
  291. package/dist/dictionary/cedict-senses.d.ts.map +1 -0
  292. package/dist/dictionary/cedict-senses.js +114 -0
  293. package/dist/dictionary/cedict-senses.js.map +1 -0
  294. package/dist/dictionary/character-defaults.d.ts +26 -0
  295. package/dist/dictionary/character-defaults.d.ts.map +1 -0
  296. package/dist/dictionary/character-defaults.js +67 -0
  297. package/dist/dictionary/character-defaults.js.map +1 -0
  298. package/dist/dictionary/character-readings.d.ts +10 -0
  299. package/dist/dictionary/character-readings.d.ts.map +1 -0
  300. package/dist/dictionary/character-readings.js +25 -0
  301. package/dist/dictionary/character-readings.js.map +1 -0
  302. package/dist/dictionary/dictionary-entry.d.ts +37 -0
  303. package/dist/dictionary/dictionary-entry.d.ts.map +1 -0
  304. package/dist/dictionary/dictionary-entry.js +41 -0
  305. package/dist/dictionary/dictionary-entry.js.map +1 -0
  306. package/dist/dictionary/dictionary-readings.d.ts +56 -0
  307. package/dist/dictionary/dictionary-readings.d.ts.map +1 -0
  308. package/dist/dictionary/dictionary-readings.js +93 -0
  309. package/dist/dictionary/dictionary-readings.js.map +1 -0
  310. package/dist/dictionary/dictionary.d.ts +6 -60
  311. package/dist/dictionary/dictionary.d.ts.map +1 -1
  312. package/dist/dictionary/dictionary.js +9 -169
  313. package/dist/dictionary/dictionary.js.map +1 -1
  314. package/dist/dictionary/entry-invariants.d.ts +3 -0
  315. package/dist/dictionary/entry-invariants.d.ts.map +1 -0
  316. package/dist/dictionary/entry-invariants.js +67 -0
  317. package/dist/dictionary/entry-invariants.js.map +1 -0
  318. package/dist/dictionary/entry-lines.d.ts +35 -0
  319. package/dist/dictionary/entry-lines.d.ts.map +1 -0
  320. package/dist/dictionary/entry-lines.js +70 -0
  321. package/dist/dictionary/entry-lines.js.map +1 -0
  322. package/dist/dictionary/erhua-repair.d.ts +26 -0
  323. package/dist/dictionary/erhua-repair.d.ts.map +1 -0
  324. package/dist/dictionary/erhua-repair.js +49 -0
  325. package/dist/dictionary/erhua-repair.js.map +1 -0
  326. package/dist/dictionary/frequency-tones.d.ts +74 -0
  327. package/dist/dictionary/frequency-tones.d.ts.map +1 -0
  328. package/dist/dictionary/frequency-tones.js +128 -0
  329. package/dist/dictionary/frequency-tones.js.map +1 -0
  330. package/dist/dictionary/inventory-invariants.d.ts +3 -0
  331. package/dist/dictionary/inventory-invariants.d.ts.map +1 -0
  332. package/dist/dictionary/inventory-invariants.js +54 -0
  333. package/dist/dictionary/inventory-invariants.js.map +1 -0
  334. package/dist/dictionary/locale-candidates.d.ts +40 -0
  335. package/dist/dictionary/locale-candidates.d.ts.map +1 -0
  336. package/dist/dictionary/locale-candidates.js +77 -0
  337. package/dist/dictionary/locale-candidates.js.map +1 -0
  338. package/dist/dictionary/locale-segments.d.ts +47 -0
  339. package/dist/dictionary/locale-segments.d.ts.map +1 -0
  340. package/dist/dictionary/locale-segments.js +141 -0
  341. package/dist/dictionary/locale-segments.js.map +1 -0
  342. package/dist/dictionary/locale.d.ts +1 -21
  343. package/dist/dictionary/locale.d.ts.map +1 -1
  344. package/dist/dictionary/locale.js +9 -198
  345. package/dist/dictionary/locale.js.map +1 -1
  346. package/dist/dictionary/merge-types.d.ts +121 -0
  347. package/dist/dictionary/merge-types.d.ts.map +1 -0
  348. package/dist/dictionary/merge-types.js +35 -0
  349. package/dist/dictionary/merge-types.js.map +1 -0
  350. package/dist/dictionary/merge-word.d.ts +7 -0
  351. package/dist/dictionary/merge-word.d.ts.map +1 -0
  352. package/dist/dictionary/merge-word.js +91 -0
  353. package/dist/dictionary/merge-word.js.map +1 -0
  354. package/dist/dictionary/merge.d.ts +5 -62
  355. package/dist/dictionary/merge.d.ts.map +1 -1
  356. package/dist/dictionary/merge.js +30 -713
  357. package/dist/dictionary/merge.js.map +1 -1
  358. package/dist/dictionary/proper-noun.d.ts +28 -0
  359. package/dist/dictionary/proper-noun.d.ts.map +1 -0
  360. package/dist/dictionary/proper-noun.js +43 -0
  361. package/dist/dictionary/proper-noun.js.map +1 -0
  362. package/dist/dictionary/reading-agreement.d.ts +71 -0
  363. package/dist/dictionary/reading-agreement.d.ts.map +1 -0
  364. package/dist/dictionary/reading-agreement.js +156 -0
  365. package/dist/dictionary/reading-agreement.js.map +1 -0
  366. package/dist/dictionary/script-conversion.d.ts +28 -0
  367. package/dist/dictionary/script-conversion.d.ts.map +1 -0
  368. package/dist/dictionary/script-conversion.js +58 -0
  369. package/dist/dictionary/script-conversion.js.map +1 -0
  370. package/dist/dictionary/script-pairings.d.ts +74 -0
  371. package/dist/dictionary/script-pairings.d.ts.map +1 -0
  372. package/dist/dictionary/script-pairings.js +120 -0
  373. package/dist/dictionary/script-pairings.js.map +1 -0
  374. package/dist/dictionary/script-tables.d.ts.map +1 -1
  375. package/dist/dictionary/script-tables.js +2 -165
  376. package/dist/dictionary/script-tables.js.map +1 -1
  377. package/dist/dictionary/taiwan-reading.d.ts +8 -0
  378. package/dist/dictionary/taiwan-reading.d.ts.map +1 -0
  379. package/dist/dictionary/taiwan-reading.js +38 -0
  380. package/dist/dictionary/taiwan-reading.js.map +1 -0
  381. package/dist/dictionary/tone-invariants.d.ts +3 -0
  382. package/dist/dictionary/tone-invariants.d.ts.map +1 -0
  383. package/dist/dictionary/tone-invariants.js +64 -0
  384. package/dist/dictionary/tone-invariants.js.map +1 -0
  385. package/dist/dictionary/traditional-form.d.ts +21 -0
  386. package/dist/dictionary/traditional-form.d.ts.map +1 -0
  387. package/dist/dictionary/traditional-form.js +59 -0
  388. package/dist/dictionary/traditional-form.js.map +1 -0
  389. package/dist/dictionary/traditional-ranking.d.ts +22 -0
  390. package/dist/dictionary/traditional-ranking.d.ts.map +1 -0
  391. package/dist/dictionary/traditional-ranking.js +74 -0
  392. package/dist/dictionary/traditional-ranking.js.map +1 -0
  393. package/dist/dictionary/traditional-table.d.ts +51 -0
  394. package/dist/dictionary/traditional-table.d.ts.map +1 -0
  395. package/dist/dictionary/traditional-table.js +98 -0
  396. package/dist/dictionary/traditional-table.js.map +1 -0
  397. package/dist/dictionary/traditional.d.ts +3 -56
  398. package/dist/dictionary/traditional.d.ts.map +1 -1
  399. package/dist/dictionary/traditional.js +3 -186
  400. package/dist/dictionary/traditional.js.map +1 -1
  401. package/dist/dictionary/variant-counts.d.ts +39 -0
  402. package/dist/dictionary/variant-counts.d.ts.map +1 -0
  403. package/dist/dictionary/variant-counts.js +38 -0
  404. package/dist/dictionary/variant-counts.js.map +1 -0
  405. package/dist/dictionary/word-reading.d.ts +26 -0
  406. package/dist/dictionary/word-reading.d.ts.map +1 -0
  407. package/dist/dictionary/word-reading.js +76 -0
  408. package/dist/dictionary/word-reading.js.map +1 -0
  409. package/dist/dictionary/word-readings.d.ts +15 -0
  410. package/dist/dictionary/word-readings.d.ts.map +1 -0
  411. package/dist/dictionary/word-readings.js +38 -0
  412. package/dist/dictionary/word-readings.js.map +1 -0
  413. package/dist/format/annotate.d.ts +90 -0
  414. package/dist/format/annotate.d.ts.map +1 -0
  415. package/dist/format/annotate.js +168 -0
  416. package/dist/format/annotate.js.map +1 -0
  417. package/dist/format/html.d.ts +15 -46
  418. package/dist/format/html.d.ts.map +1 -1
  419. package/dist/format/html.js +3 -162
  420. package/dist/format/html.js.map +1 -1
  421. package/dist/format/slug-hash.d.ts +51 -0
  422. package/dist/format/slug-hash.d.ts.map +1 -0
  423. package/dist/format/slug-hash.js +74 -0
  424. package/dist/format/slug-hash.js.map +1 -0
  425. package/dist/format/slug-options.d.ts +98 -0
  426. package/dist/format/slug-options.d.ts.map +1 -0
  427. package/dist/format/slug-options.js +2 -0
  428. package/dist/format/slug-options.js.map +1 -0
  429. package/dist/format/slug-words.d.ts +27 -0
  430. package/dist/format/slug-words.d.ts.map +1 -0
  431. package/dist/format/slug-words.js +0 -0
  432. package/dist/format/slug-words.js.map +1 -0
  433. package/dist/format/slug.d.ts +3 -128
  434. package/dist/format/slug.d.ts.map +1 -1
  435. package/dist/format/slug.js +0 -0
  436. package/dist/format/slug.js.map +1 -1
  437. package/dist/grade/check-readings.d.ts +41 -0
  438. package/dist/grade/check-readings.d.ts.map +1 -0
  439. package/dist/grade/check-readings.js +36 -0
  440. package/dist/grade/check-readings.js.map +1 -0
  441. package/dist/grade/check.d.ts +4 -4
  442. package/dist/grade/check.d.ts.map +1 -1
  443. package/dist/grade/check.js +5 -270
  444. package/dist/grade/check.js.map +1 -1
  445. package/dist/grade/pair-syllables.d.ts +48 -0
  446. package/dist/grade/pair-syllables.d.ts.map +1 -0
  447. package/dist/grade/pair-syllables.js +71 -0
  448. package/dist/grade/pair-syllables.js.map +1 -0
  449. package/dist/grade/reading-syllables.d.ts +62 -0
  450. package/dist/grade/reading-syllables.d.ts.map +1 -0
  451. package/dist/grade/reading-syllables.js +58 -0
  452. package/dist/grade/reading-syllables.js.map +1 -0
  453. package/dist/grade/reading-tolerance.d.ts +72 -0
  454. package/dist/grade/reading-tolerance.d.ts.map +1 -0
  455. package/dist/grade/reading-tolerance.js +107 -0
  456. package/dist/grade/reading-tolerance.js.map +1 -0
  457. package/dist/grade/typed-reading.d.ts +28 -0
  458. package/dist/grade/typed-reading.d.ts.map +1 -0
  459. package/dist/grade/typed-reading.js +36 -0
  460. package/dist/grade/typed-reading.js.map +1 -0
  461. package/dist/numerals/numeral-parse.d.ts +32 -0
  462. package/dist/numerals/numeral-parse.d.ts.map +1 -0
  463. package/dist/numerals/numeral-parse.js +44 -0
  464. package/dist/numerals/numeral-parse.js.map +1 -0
  465. package/dist/numerals/numeral-shapes.d.ts +89 -0
  466. package/dist/numerals/numeral-shapes.d.ts.map +1 -0
  467. package/dist/numerals/numeral-shapes.js +99 -0
  468. package/dist/numerals/numeral-shapes.js.map +1 -0
  469. package/dist/numerals/numerals.d.ts.map +1 -1
  470. package/dist/numerals/numerals.js +2 -36
  471. package/dist/numerals/numerals.js.map +1 -1
  472. package/dist/numerals/read-numeral.d.ts +76 -0
  473. package/dist/numerals/read-numeral.d.ts.map +1 -0
  474. package/dist/numerals/read-numeral.js +88 -0
  475. package/dist/numerals/read-numeral.js.map +1 -0
  476. package/dist/numerals/text.d.ts +3 -37
  477. package/dist/numerals/text.d.ts.map +1 -1
  478. package/dist/numerals/text.js +3 -254
  479. package/dist/numerals/text.js.map +1 -1
  480. package/dist/numerals/time.d.ts +34 -0
  481. package/dist/numerals/time.d.ts.map +1 -0
  482. package/dist/numerals/time.js +93 -0
  483. package/dist/numerals/time.js.map +1 -0
  484. package/dist/orthography/address-grouping.d.ts +34 -0
  485. package/dist/orthography/address-grouping.d.ts.map +1 -0
  486. package/dist/orthography/address-grouping.js +52 -0
  487. package/dist/orthography/address-grouping.js.map +1 -0
  488. package/dist/orthography/grouping.d.ts +3 -87
  489. package/dist/orthography/grouping.d.ts.map +1 -1
  490. package/dist/orthography/grouping.js +4 -270
  491. package/dist/orthography/grouping.js.map +1 -1
  492. package/dist/orthography/place-grouping.d.ts +39 -0
  493. package/dist/orthography/place-grouping.d.ts.map +1 -0
  494. package/dist/orthography/place-grouping.js +83 -0
  495. package/dist/orthography/place-grouping.js.map +1 -0
  496. package/dist/orthography/word-grouping.d.ts +48 -0
  497. package/dist/orthography/word-grouping.d.ts.map +1 -0
  498. package/dist/orthography/word-grouping.js +147 -0
  499. package/dist/orthography/word-grouping.js.map +1 -0
  500. package/dist/script/conversion-format.d.ts +22 -0
  501. package/dist/script/conversion-format.d.ts.map +1 -0
  502. package/dist/script/conversion-format.js +22 -0
  503. package/dist/script/conversion-format.js.map +1 -0
  504. package/dist/script/conversion-read.d.ts +9 -0
  505. package/dist/script/conversion-read.d.ts.map +1 -0
  506. package/dist/script/conversion-read.js +69 -0
  507. package/dist/script/conversion-read.js.map +1 -0
  508. package/dist/script/conversion-write.d.ts +14 -0
  509. package/dist/script/conversion-write.d.ts.map +1 -0
  510. package/dist/script/conversion-write.js +34 -0
  511. package/dist/script/conversion-write.js.map +1 -0
  512. package/dist/script/conversion.d.ts +10 -16
  513. package/dist/script/conversion.d.ts.map +1 -1
  514. package/dist/script/conversion.js +2 -115
  515. package/dist/script/conversion.js.map +1 -1
  516. package/dist/search/candidate-narrowing.d.ts +56 -0
  517. package/dist/search/candidate-narrowing.d.ts.map +1 -0
  518. package/dist/search/candidate-narrowing.js +55 -0
  519. package/dist/search/candidate-narrowing.js.map +1 -0
  520. package/dist/search/candidate-query.d.ts +25 -0
  521. package/dist/search/candidate-query.d.ts.map +1 -0
  522. package/dist/search/candidate-query.js +28 -0
  523. package/dist/search/candidate-query.js.map +1 -0
  524. package/dist/search/candidate-writings.d.ts +24 -0
  525. package/dist/search/candidate-writings.d.ts.map +1 -0
  526. package/dist/search/candidate-writings.js +114 -0
  527. package/dist/search/candidate-writings.js.map +1 -0
  528. package/dist/search/candidates.d.ts +7 -41
  529. package/dist/search/candidates.d.ts.map +1 -1
  530. package/dist/search/candidates.js +10 -164
  531. package/dist/search/candidates.js.map +1 -1
  532. package/dist/search/match-chunks.d.ts +19 -0
  533. package/dist/search/match-chunks.d.ts.map +1 -0
  534. package/dist/search/match-chunks.js +30 -0
  535. package/dist/search/match-chunks.js.map +1 -0
  536. package/dist/search/match-ranking.d.ts +39 -0
  537. package/dist/search/match-ranking.d.ts.map +1 -0
  538. package/dist/search/match-ranking.js +51 -0
  539. package/dist/search/match-ranking.js.map +1 -0
  540. package/dist/search/match-readings.d.ts +43 -0
  541. package/dist/search/match-readings.d.ts.map +1 -0
  542. package/dist/search/match-readings.js +83 -0
  543. package/dist/search/match-readings.js.map +1 -0
  544. package/dist/search/match-scoring.d.ts +146 -0
  545. package/dist/search/match-scoring.d.ts.map +1 -0
  546. package/dist/search/match-scoring.js +114 -0
  547. package/dist/search/match-scoring.js.map +1 -0
  548. package/dist/search/match-search.d.ts +28 -0
  549. package/dist/search/match-search.d.ts.map +1 -0
  550. package/dist/search/match-search.js +128 -0
  551. package/dist/search/match-search.js.map +1 -0
  552. package/dist/search/match.d.ts +5 -36
  553. package/dist/search/match.d.ts.map +1 -1
  554. package/dist/search/match.js +2 -379
  555. package/dist/search/match.js.map +1 -1
  556. package/dist/search/reverse-index-build.d.ts +30 -0
  557. package/dist/search/reverse-index-build.d.ts.map +1 -0
  558. package/dist/search/reverse-index-build.js +72 -0
  559. package/dist/search/reverse-index-build.js.map +1 -0
  560. package/dist/search/reverse-index-format.d.ts +60 -0
  561. package/dist/search/reverse-index-format.d.ts.map +1 -0
  562. package/dist/search/reverse-index-format.js +54 -0
  563. package/dist/search/reverse-index-format.js.map +1 -0
  564. package/dist/search/reverse-index-groups.d.ts +37 -0
  565. package/dist/search/reverse-index-groups.d.ts.map +1 -0
  566. package/dist/search/reverse-index-groups.js +71 -0
  567. package/dist/search/reverse-index-groups.js.map +1 -0
  568. package/dist/search/reverse-index-passes.d.ts +78 -0
  569. package/dist/search/reverse-index-passes.d.ts.map +1 -0
  570. package/dist/search/reverse-index-passes.js +59 -0
  571. package/dist/search/reverse-index-passes.js.map +1 -0
  572. package/dist/search/reverse-index-state.d.ts +36 -0
  573. package/dist/search/reverse-index-state.d.ts.map +1 -0
  574. package/dist/search/reverse-index-state.js +95 -0
  575. package/dist/search/reverse-index-state.js.map +1 -0
  576. package/dist/search/reverse-index.d.ts +8 -67
  577. package/dist/search/reverse-index.d.ts.map +1 -1
  578. package/dist/search/reverse-index.js +4 -255
  579. package/dist/search/reverse-index.js.map +1 -1
  580. package/dist/sources/unihan-readings.d.ts +58 -0
  581. package/dist/sources/unihan-readings.d.ts.map +1 -0
  582. package/dist/sources/unihan-readings.js +95 -0
  583. package/dist/sources/unihan-readings.js.map +1 -0
  584. package/dist/sources/unihan.d.ts +6 -9
  585. package/dist/sources/unihan.d.ts.map +1 -1
  586. package/dist/sources/unihan.js +2 -85
  587. package/dist/sources/unihan.js.map +1 -1
  588. package/dist/syllable/final-tables.d.ts +23 -0
  589. package/dist/syllable/final-tables.d.ts.map +1 -0
  590. package/dist/syllable/final-tables.js +50 -0
  591. package/dist/syllable/final-tables.js.map +1 -0
  592. package/dist/syllable/inventory.d.ts +8 -42
  593. package/dist/syllable/inventory.d.ts.map +1 -1
  594. package/dist/syllable/inventory.js +9 -918
  595. package/dist/syllable/inventory.js.map +1 -1
  596. package/dist/syllable/spellings.d.ts +40 -0
  597. package/dist/syllable/spellings.d.ts.map +1 -0
  598. package/dist/syllable/spellings.js +469 -0
  599. package/dist/syllable/spellings.js.map +1 -0
  600. package/dist/syllable/syllable-parts.d.ts +31 -0
  601. package/dist/syllable/syllable-parts.d.ts.map +1 -0
  602. package/dist/syllable/syllable-parts.js +105 -0
  603. package/dist/syllable/syllable-parts.js.map +1 -0
  604. package/dist/syllable/syllable.d.ts +1 -14
  605. package/dist/syllable/syllable.d.ts.map +1 -1
  606. package/dist/syllable/syllable.js +3 -144
  607. package/dist/syllable/syllable.js.map +1 -1
  608. package/dist/syllable/written-tones.d.ts +6 -0
  609. package/dist/syllable/written-tones.d.ts.map +1 -0
  610. package/dist/syllable/written-tones.js +453 -0
  611. package/dist/syllable/written-tones.js.map +1 -0
  612. package/dist/transcription/bopomofo-parse.d.ts +42 -0
  613. package/dist/transcription/bopomofo-parse.d.ts.map +1 -0
  614. package/dist/transcription/bopomofo-parse.js +92 -0
  615. package/dist/transcription/bopomofo-parse.js.map +1 -0
  616. package/dist/transcription/bopomofo-reverse.d.ts +31 -0
  617. package/dist/transcription/bopomofo-reverse.d.ts.map +1 -0
  618. package/dist/transcription/bopomofo-reverse.js +48 -0
  619. package/dist/transcription/bopomofo-reverse.js.map +1 -0
  620. package/dist/transcription/bopomofo-symbols.d.ts +36 -0
  621. package/dist/transcription/bopomofo-symbols.d.ts.map +1 -0
  622. package/dist/transcription/bopomofo-symbols.js +41 -0
  623. package/dist/transcription/bopomofo-symbols.js.map +1 -0
  624. package/dist/transcription/bopomofo-tables.d.ts +87 -0
  625. package/dist/transcription/bopomofo-tables.d.ts.map +1 -0
  626. package/dist/transcription/bopomofo-tables.js +180 -0
  627. package/dist/transcription/bopomofo-tables.js.map +1 -0
  628. package/dist/transcription/bopomofo.d.ts +14 -32
  629. package/dist/transcription/bopomofo.d.ts.map +1 -1
  630. package/dist/transcription/bopomofo.js +5 -343
  631. package/dist/transcription/bopomofo.js.map +1 -1
  632. package/dist/transcription/gwoyeu-first-second.d.ts +36 -0
  633. package/dist/transcription/gwoyeu-first-second.d.ts.map +1 -0
  634. package/dist/transcription/gwoyeu-first-second.js +75 -0
  635. package/dist/transcription/gwoyeu-first-second.js.map +1 -0
  636. package/dist/transcription/gwoyeu-spelling.d.ts +38 -0
  637. package/dist/transcription/gwoyeu-spelling.d.ts.map +1 -0
  638. package/dist/transcription/gwoyeu-spelling.js +124 -0
  639. package/dist/transcription/gwoyeu-spelling.js.map +1 -0
  640. package/dist/transcription/gwoyeu-tables.d.ts +93 -0
  641. package/dist/transcription/gwoyeu-tables.d.ts.map +1 -0
  642. package/dist/transcription/gwoyeu-tables.js +205 -0
  643. package/dist/transcription/gwoyeu-tables.js.map +1 -0
  644. package/dist/transcription/gwoyeu-tonal-forms.d.ts +49 -0
  645. package/dist/transcription/gwoyeu-tonal-forms.d.ts.map +1 -0
  646. package/dist/transcription/gwoyeu-tonal-forms.js +89 -0
  647. package/dist/transcription/gwoyeu-tonal-forms.js.map +1 -0
  648. package/dist/transcription/gwoyeu-vowels.d.ts +51 -0
  649. package/dist/transcription/gwoyeu-vowels.d.ts.map +1 -0
  650. package/dist/transcription/gwoyeu-vowels.js +58 -0
  651. package/dist/transcription/gwoyeu-vowels.js.map +1 -0
  652. package/dist/transcription/gwoyeu.d.ts +1 -26
  653. package/dist/transcription/gwoyeu.d.ts.map +1 -1
  654. package/dist/transcription/gwoyeu.js +2 -540
  655. package/dist/transcription/gwoyeu.js.map +1 -1
  656. package/dist/transcription/ipa-symbols.d.ts +67 -0
  657. package/dist/transcription/ipa-symbols.d.ts.map +1 -0
  658. package/dist/transcription/ipa-symbols.js +135 -0
  659. package/dist/transcription/ipa-symbols.js.map +1 -0
  660. package/dist/transcription/ipa.d.ts +2 -10
  661. package/dist/transcription/ipa.d.ts.map +1 -1
  662. package/dist/transcription/ipa.js +2 -134
  663. package/dist/transcription/ipa.js.map +1 -1
  664. package/dist/transcription/wade-giles-index.d.ts +35 -0
  665. package/dist/transcription/wade-giles-index.d.ts.map +1 -0
  666. package/dist/transcription/wade-giles-index.js +110 -0
  667. package/dist/transcription/wade-giles-index.js.map +1 -0
  668. package/dist/transcription/wade-giles-parse.d.ts +36 -0
  669. package/dist/transcription/wade-giles-parse.d.ts.map +1 -0
  670. package/dist/transcription/wade-giles-parse.js +84 -0
  671. package/dist/transcription/wade-giles-parse.js.map +1 -0
  672. package/dist/transcription/wade-giles-spelling.d.ts +61 -0
  673. package/dist/transcription/wade-giles-spelling.d.ts.map +1 -0
  674. package/dist/transcription/wade-giles-spelling.js +107 -0
  675. package/dist/transcription/wade-giles-spelling.js.map +1 -0
  676. package/dist/transcription/wade-giles-syllable.d.ts +29 -0
  677. package/dist/transcription/wade-giles-syllable.d.ts.map +1 -0
  678. package/dist/transcription/wade-giles-syllable.js +90 -0
  679. package/dist/transcription/wade-giles-syllable.js.map +1 -0
  680. package/dist/transcription/wade-giles-tables.d.ts +80 -0
  681. package/dist/transcription/wade-giles-tables.d.ts.map +1 -0
  682. package/dist/transcription/wade-giles-tables.js +178 -0
  683. package/dist/transcription/wade-giles-tables.js.map +1 -0
  684. package/dist/transcription/wade-giles.d.ts +9 -60
  685. package/dist/transcription/wade-giles.d.ts.map +1 -1
  686. package/dist/transcription/wade-giles.js +6 -543
  687. package/dist/transcription/wade-giles.js.map +1 -1
  688. package/dist/transcription/yale-tables.d.ts +54 -0
  689. package/dist/transcription/yale-tables.d.ts.map +1 -0
  690. package/dist/transcription/yale-tables.js +125 -0
  691. package/dist/transcription/yale-tables.js.map +1 -0
  692. package/dist/transcription/yale.d.ts.map +1 -1
  693. package/dist/transcription/yale.js +1 -124
  694. package/dist/transcription/yale.js.map +1 -1
  695. package/package.json +1 -1
@@ -1,382 +1,5 @@
1
- import { isSameReading } from "../dictionary/entry.js";
2
- import { isErCharacter, withErhua } from "../dictionary/erhua.js";
3
- import { sourcesOf } from "../decode/convert.js";
4
- import { segment } from "../decode/segment.js";
5
- import { toCharacters } from "../script/characters.js";
6
- import { toCanonicalGlyphs } from "../script/glyphs.js";
7
- import { normaliseQuery, readQueryChunks, skipSeparators, } from "./query.js";
8
- /**
9
- * What a match scores for reading its characters the way the text reads them.
10
- *
11
- * The one thing this has that a reverse index cannot: every reading a character
12
- * takes is matchable, so 行 is found by both `xing` and `hang` — and the decoder
13
- * has already settled which of them the text in front of it means. So 银行 ranks
14
- * `yh` above `yx`, and 长江 ranks `cj` above `zj`, without either being refused.
15
- *
16
- * Weighted by the share of the matched characters that agree, rather than by how
17
- * many, so that a long match and a short one are scored on the same scale.
18
- */
19
- const CONTEXT_READING = 4;
20
- /**
21
- * What a match scores for starting where a word starts.
22
- *
23
- * 大学 in 北京大学 is the second half of a word a reader thinks of as one thing;
24
- * 大学 in 大学生 starts it. Both are matches and the second is the better one.
25
- */
26
- const WORD_START = 2;
27
- /**
28
- * What a match at the very start of the haystack scores, decaying with position.
29
- *
30
- * A tie-break rather than a judgement, and deliberately smaller than
31
- * {@link WORD_START}: it settles two matches that are otherwise alike, and never
32
- * outranks starting a word.
33
- */
34
- const EARLINESS = 1;
35
- /**
36
- * What one character scores for being written out in full rather than initialled.
37
- *
38
- * Only used to choose between the ways one query can be read over one haystack,
39
- * never in the score a caller sees: `beij` over 北京大学 is 北 spelled out and 京
40
- * initialled, and no other reading of it is on offer. Where two are — `xian` is
41
- * both 西安 and 县 — the fuller spelling is the one the typist meant.
42
- *
43
- * Per character, which is what settles 这儿 against `zher`: read as 这 `zhèr` it
44
- * spells two characters out at once, where 这 abbreviated to `zh` and 儿 as `er`
45
- * spells one of them and initials the other.
46
- */
47
- const SPELLED_OUT = 1;
48
- /**
49
- * What one step down a character's reading list costs, likeliest reading first.
50
- *
51
- * The dictionary's own order, applied before the decoder has been asked
52
- * anything: it is what separates 行 `xíng` from 行 `hàng` when the query could
53
- * be either and the surrounding text says nothing.
54
- */
55
- const RARE_READING = 2;
56
- /**
57
- * What crossing one character with no reading costs.
58
- *
59
- * A separator inside a name is worth stepping over — 北京·大学 is one thing
60
- * with a mark in the middle of it — and a query that steps over half a line of
61
- * Latin to reach its second half has found something more tenuous.
62
- */
63
- const CROSSED = 0.5;
64
- /**
65
- * The query having been read to its end, with nothing left to account for.
66
- */
67
- const COMPLETE = { steps: [], score: 0 };
68
- /**
69
- * The steps of a match, gathered into the stretches they cover.
70
- */
71
- function rangesOf(steps) {
72
- const ranges = [];
73
- for (const step of steps) {
74
- if (!step.isRead) {
75
- continue;
76
- }
77
- const last = ranges.at(-1);
78
- if (last !== undefined && last.at + last.length === step.at) {
79
- ranges[ranges.length - 1] = { at: last.at, length: last.length + 1 };
80
- continue;
81
- }
82
- ranges.push({ at: step.at, length: 1 });
83
- }
84
- return ranges;
85
- }
86
- /**
87
- * Ask the decoder what the haystack says, for the two things ranking needs.
88
- *
89
- * Worked out once a match is known to exist rather than before, because this is
90
- * a decode of the whole text and matching is not: a search box filtering a list
91
- * asks the cheap question of every item and pays for this on the few that hit.
92
- */
93
- function contextOf(dictionary, haystack) {
94
- const preferred = [];
95
- const wordStarts = new Set();
96
- for (const word of segment(dictionary, haystack)) {
97
- if (word.reading.length === 0) {
98
- continue;
99
- }
100
- wordStarts.add(word.at);
101
- // `sourcesOf` is the decoder's own answer to which characters a syllable
102
- // reads, 儿化 included. It names the whole word and then nothing where it
103
- // cannot say, which is not an alignment and is dropped rather than guessed.
104
- const sources = sourcesOf(word.text, word.reading).filter((source) => source !== undefined);
105
- if (sources.length !== word.reading.length) {
106
- continue;
107
- }
108
- let at = word.at;
109
- for (const [index, source] of sources.entries()) {
110
- for (const _ of toCharacters(source)) {
111
- preferred[at] = word.reading[index];
112
- at++;
113
- }
114
- }
115
- }
116
- return { preferred, wordStarts };
117
- }
118
- /**
119
- * How much of a match was written the way the text is actually read.
120
- *
121
- * Asked of what the query wrote rather than of the reading the search happened
122
- * to take it by: 西 is stored with a neutral-toned `xi` and a first-tone `xī`,
123
- * and a query writing `xi` has picked neither of them over the other. What it
124
- * has done is write something the settled reading can account for, which is the
125
- * question — and the one `yx` over 银行 answers differently from `yh`.
126
- */
127
- function agreementOf(query, steps, preferred) {
128
- let comparable = 0;
129
- let agreeing = 0;
130
- for (const step of steps) {
131
- const settled = preferred[step.at];
132
- if (!step.isRead || settled === undefined) {
133
- continue;
134
- }
135
- comparable++;
136
- const written = readQueryChunks(query, step.from, settled);
137
- if (written.some((chunk) => chunk.next === step.next)) {
138
- agreeing++;
139
- }
140
- }
141
- return comparable === 0 ? 0 : agreeing / comparable;
142
- }
143
- /**
144
- * One query being read over one haystack.
145
- *
146
- * The search is a walk over two sequences at once — the haystack's characters
147
- * and the query's letters — where each character may account for some of the
148
- * query in more than one way, since it may have more than one reading and each
149
- * reading may be written out or abbreviated. Memoised on the pair of positions,
150
- * which is what stops the ways of splitting a long query multiplying out.
151
- */
152
- class Search {
153
- #dictionary;
154
- #haystack;
155
- #characters;
156
- #query;
157
- #readings = [];
158
- #paths = new Map();
159
- constructor(dictionary, haystack, query) {
160
- this.#dictionary = dictionary;
161
- this.#haystack = haystack;
162
- this.#characters = toCharacters(haystack);
163
- this.#query = query;
164
- }
165
- /**
166
- * Every reading a character offers, likeliest first, asked for once.
167
- *
168
- * Canonicalised here rather than left to the dictionary, so that a Hong Kong
169
- * glyph form is matched by the readings of the Taiwan-standard key it folds
170
- * to rather than by nothing.
171
- *
172
- * The 國語 reading goes on the end where it differs, so that 圾 answers to
173
- * `se` as well as to `ji`. A search box is not the place to insist on one
174
- * standard: somebody typing what they say is not typing it wrongly, and the
175
- * decoder's own reading is what ranks the two afterwards.
176
- */
177
- #readingsAt(at) {
178
- const held = this.#readings[at];
179
- if (held !== undefined) {
180
- return held;
181
- }
182
- /* c8 ignore next -- only ever asked about a character that is there */
183
- const character = toCanonicalGlyphs(this.#characters[at] ?? "");
184
- const found = this.#dictionary.readingsOf(character);
185
- const taiwan = this.#dictionary.lookup(character)?.taiwanReading;
186
- const readings = taiwan === undefined ||
187
- found.some((reading) => isSameReading(reading, taiwan))
188
- ? found
189
- : [...found, taiwan];
190
- this.#readings[at] = readings;
191
- return readings;
192
- }
193
- /**
194
- * Every reading the query could be accounting for at a character.
195
- *
196
- * One per reading the character has — and one more for each of them where an
197
- * 儿 follows, carrying the r suffix that character stands for. 玩儿 is
198
- * `wánr`, one syllable over two characters, and somebody looking for it types
199
- * `wanr`: the r is part of how the word is said, so it is part of how the
200
- * word is searched for.
201
- *
202
- * Offered wherever an 儿 follows rather than only where the dictionary
203
- * attests the 儿化, because the query is what decides which of them was
204
- * meant. 女儿 is `nǚ'ér` and not `nǚr`, and typing `nvr` still finds it —
205
- * below `nver`, since the reading the text takes is what ranks them.
206
- */
207
- #candidatesAt(at) {
208
- const readings = this.#readingsAt(at);
209
- const plain = readings.map((reading, rank) => ({
210
- reading,
211
- rank,
212
- characters: 1,
213
- }));
214
- if (!isErCharacter(this.#characters[at + 1] ?? "")) {
215
- return plain;
216
- }
217
- return [
218
- ...plain,
219
- ...readings.flatMap((reading, rank) => {
220
- const last = reading.at(-1);
221
- /* c8 ignore next 3 -- a stored reading is never empty or already r-ed */
222
- if (last === undefined || last.erhua === true) {
223
- return [];
224
- }
225
- return [
226
- {
227
- reading: [...reading.slice(0, -1), withErhua(last)],
228
- rank,
229
- characters: 2,
230
- },
231
- ];
232
- }),
233
- ];
234
- }
235
- /**
236
- * Every position the query can be read up to by one whole reading.
237
- *
238
- * A reading is usually one syllable, and is not always: 瓩 is `qiānwǎ`, one
239
- * character read as two. The query accounts for them in order, and may run
240
- * out partway through, which is a query still being typed.
241
- */
242
- #chunksFor(from, reading) {
243
- let reached = [{ next: from, isFull: true }];
244
- for (const syllable of reading) {
245
- const found = [];
246
- for (const chunk of reached) {
247
- const start = skipSeparators(this.#query, chunk.next);
248
- if (start === this.#query.length) {
249
- found.push({ next: start, isFull: chunk.isFull });
250
- continue;
251
- }
252
- for (const one of readQueryChunks(this.#query, start, syllable)) {
253
- found.push({
254
- next: one.next,
255
- isFull: chunk.isFull && one.isFull,
256
- });
257
- }
258
- }
259
- reached = found;
260
- }
261
- return reached;
262
- }
263
- /**
264
- * The best way of reading the rest of the query from a character, or nothing.
265
- */
266
- #from(at, offset) {
267
- const start = skipSeparators(this.#query, offset);
268
- if (start === this.#query.length) {
269
- return COMPLETE;
270
- }
271
- if (at >= this.#characters.length) {
272
- return undefined;
273
- }
274
- const key = `${String(at)}:${String(start)}`;
275
- const held = this.#paths.get(key);
276
- if (held !== undefined || this.#paths.has(key)) {
277
- return held;
278
- }
279
- const found = this.#read(at, start);
280
- this.#paths.set(key, found);
281
- return found;
282
- }
283
- /**
284
- * Read one character, every way it can be read, and keep the best.
285
- */
286
- #read(at, start) {
287
- const candidates = this.#candidatesAt(at);
288
- if (candidates.length === 0) {
289
- return this.#cross(at, start);
290
- }
291
- let best;
292
- for (const candidate of candidates) {
293
- for (const chunk of this.#chunksFor(start, candidate.reading)) {
294
- const rest = this.#from(at + candidate.characters, chunk.next);
295
- if (rest === undefined) {
296
- continue;
297
- }
298
- const score = rest.score +
299
- (chunk.isFull ? SPELLED_OUT * candidate.characters : 0) -
300
- candidate.rank * RARE_READING;
301
- if (best === undefined || score > best.score) {
302
- best = {
303
- steps: [
304
- ...Array.from({ length: candidate.characters }, (_, covered) => ({
305
- at: at + covered,
306
- isRead: true,
307
- from: start,
308
- next: chunk.next,
309
- })),
310
- ...rest.steps,
311
- ],
312
- score,
313
- };
314
- }
315
- }
316
- }
317
- return best;
318
- }
319
- /**
320
- * Step over a character with no reading, which a match may span but not end
321
- * on: the query is checked for having been read to its end first.
322
- */
323
- #cross(at, start) {
324
- const rest = this.#from(at + 1, start);
325
- return rest === undefined
326
- ? undefined
327
- : {
328
- steps: [
329
- { at, isRead: false, from: start, next: start },
330
- ...rest.steps,
331
- ],
332
- score: rest.score - CROSSED,
333
- };
334
- }
335
- /**
336
- * Where the query matches at all, and how it reads at each of those places.
337
- */
338
- #everyMatch() {
339
- const found = [];
340
- for (const [at] of this.#characters.entries()) {
341
- if (this.#readingsAt(at).length === 0) {
342
- continue;
343
- }
344
- const path = this.#from(at, 0);
345
- if (path !== undefined) {
346
- found.push(path);
347
- }
348
- }
349
- return found;
350
- }
351
- /**
352
- * The best match, or undefined where the query matches nowhere.
353
- */
354
- best() {
355
- const found = this.#everyMatch();
356
- if (found.length === 0) {
357
- return undefined;
358
- }
359
- const context = contextOf(this.#dictionary, this.#haystack);
360
- let best;
361
- for (const path of found) {
362
- const ranges = rangesOf(path.steps);
363
- /* c8 ignore next 3 -- a match always starts on a character it read */
364
- if (ranges[0] === undefined) {
365
- continue;
366
- }
367
- const start = ranges[0].at;
368
- const score = CONTEXT_READING *
369
- agreementOf(this.#query, path.steps, context.preferred) +
370
- (context.wordStarts.has(start) ? WORD_START : 0) +
371
- EARLINESS / (1 + start);
372
- // Strictly better, so that two matches worth the same keep the earlier.
373
- if (best === undefined || score > best.score) {
374
- best = { ranges, score };
375
- }
376
- }
377
- return best;
378
- }
379
- }
1
+ import { normaliseQuery } from "./query.js";
2
+ import { Search } from "./match-search.js";
380
3
  /**
381
4
  * Find where a pinyin query matches a Chinese text, for filtering and
382
5
  * highlighting.
@@ -1 +1 @@
1
- {"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/search/match.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAA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AAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAoB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAK7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,KAAK,CACnB,UAAsB,EACtB,QAAgB,EAChB,KAAa;IAEb,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,UAAU,KAAK,EAAE,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Deriving the reverse index a slice at a time.
3
+ *
4
+ * The full tier costs about half a second to derive, so the build is handed
5
+ * back as a stepper a caller can drive from an idle callback rather than a
6
+ * function that blocks. What each pass does is `reverse-index-state.ts`; what
7
+ * is here is how much of it one step is worth.
8
+ */
9
+ import type { Dictionary } from "../dictionary/dictionary.js";
10
+ import { ReverseIndex } from "./reverse-index.js";
11
+ import { type ReverseIndexBuild } from "./reverse-index-passes.js";
12
+ export { readingKey, type ReverseIndexData } from "./reverse-index-format.js";
13
+ /**
14
+ * The streaming build, which never holds every reading at once.
15
+ *
16
+ * Three passes over the dictionary — count the groups, fill them, rank them —
17
+ * with a fourth between the first two that lays the groups out. The only things
18
+ * about them that need the dictionary are the two functions they are driven by:
19
+ * what a position is read as, and how common the word there is.
20
+ */
21
+ export declare function startBuild(dictionary: Dictionary): ReverseIndexBuild;
22
+ /**
23
+ * Derive the whole index in one go, which is {@link ReverseIndex.of}.
24
+ *
25
+ * Stepped without a bound rather than built by a separate path, so there is one
26
+ * implementation of the build and the two entry points differ only in how much
27
+ * of it they ask for at a time.
28
+ */
29
+ export declare function buildAll(dictionary: Dictionary): ReverseIndex;
30
+ //# sourceMappingURL=reverse-index-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-index-build.d.ts","sourceRoot":"","sources":["../../src/search/reverse-index-build.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAS/E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE9E;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,iBAAiB,CAmDpE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,YAAY,CAO7D"}
@@ -0,0 +1,72 @@
1
+ import { FREQUENCY_BUCKETS } from "../dictionary/frequency-table.js";
2
+ import { ReverseIndex } from "./reverse-index.js";
3
+ import { LINE, readingKey, STEP } from "./reverse-index-format.js";
4
+ import { progressOf } from "./reverse-index-passes.js";
5
+ import { countPass, fillPass, orderPass, rankPass, startState, } from "./reverse-index-state.js";
6
+ export { readingKey } from "./reverse-index-format.js";
7
+ /**
8
+ * The streaming build, which never holds every reading at once.
9
+ *
10
+ * Three passes over the dictionary — count the groups, fill them, rank them —
11
+ * with a fourth between the first two that lays the groups out. The only things
12
+ * about them that need the dictionary are the two functions they are driven by:
13
+ * what a position is read as, and how common the word there is.
14
+ */
15
+ export function startBuild(dictionary) {
16
+ const readings = dictionary.readingsInOrder();
17
+ const state = startState();
18
+ /** The reading key at a position, or the empty string where there is none. */
19
+ const keyAt = (position) => readingKey(readings.readingAt(position));
20
+ /** Where a position sorts, commonest first: the bucket, counted downwards. */
21
+ const rankOf = (position) => FREQUENCY_BUCKETS - 1 - dictionary.frequencyAt(position);
22
+ return {
23
+ get progress() {
24
+ return progressOf(state.pass, state.at, readings.size, state.layout.keys.length);
25
+ },
26
+ step(positions = STEP) {
27
+ switch (state.pass) {
28
+ case "counting": {
29
+ countPass(state, readings.size, keyAt, positions);
30
+ return undefined;
31
+ }
32
+ case "ordering": {
33
+ orderPass(state);
34
+ return undefined;
35
+ }
36
+ case "filling": {
37
+ fillPass(state, readings.size, keyAt, positions);
38
+ return undefined;
39
+ }
40
+ case "ranking": {
41
+ return rankPass(state, positions, rankOf)
42
+ ? ReverseIndex.from(dictionary, {
43
+ keys: state.layout.keys.join(LINE),
44
+ postings: state.layout.postings,
45
+ starts: state.layout.starts,
46
+ })
47
+ : undefined;
48
+ }
49
+ /* c8 ignore next 3 -- a finished build is not stepped again */
50
+ case "done": {
51
+ return undefined;
52
+ }
53
+ }
54
+ },
55
+ };
56
+ }
57
+ /**
58
+ * Derive the whole index in one go, which is {@link ReverseIndex.of}.
59
+ *
60
+ * Stepped without a bound rather than built by a separate path, so there is one
61
+ * implementation of the build and the two entry points differ only in how much
62
+ * of it they ask for at a time.
63
+ */
64
+ export function buildAll(dictionary) {
65
+ const build = startBuild(dictionary);
66
+ let index = build.step(Number.POSITIVE_INFINITY);
67
+ while (index === undefined) {
68
+ index = build.step(Number.POSITIVE_INFINITY);
69
+ }
70
+ return index;
71
+ }
72
+ //# sourceMappingURL=reverse-index-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-index-build.js","sourceRoot":"","sources":["../../src/search/reverse-index-build.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,UAAU,EAA0B,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EACL,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,GACX,MAAM,0BAA0B,CAAC;AAElC,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,SAAS,EAAE,MAAM,CAAC;wBACvC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE;4BAC5B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;4BAClC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;4BAC/B,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;yBAC5B,CAAC;wBACJ,CAAC,CAAC,SAAS,CAAC;gBAChB,CAAC;gBACD,+DAA+D;gBAC/D,KAAK,MAAM,EAAE,CAAC;oBACZ,OAAO,SAAS,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAsB;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACjD,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3B,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * How the reverse index is laid out on disk.
3
+ *
4
+ * The key a reading is stored under and the packed arrays behind it.
5
+ * `reverse-index.ts` is the index built on top of both.
6
+ */
7
+ /**
8
+ * The separator between reading keys, matching what {@link KeyIndex} expects.
9
+ */
10
+ export declare const LINE = "\n";
11
+ export declare const SPACE = 32;
12
+ export declare const ZERO = 48;
13
+ export declare const FIVE = 53;
14
+ export declare const UMLAUT_U = "\u00FC";
15
+ export declare const PLAIN_U = "u";
16
+ /**
17
+ * How many positions one {@link ReverseIndexBuild.step} covers by default.
18
+ *
19
+ * Sized so that a step is a frame rather than several: the full tier's build is
20
+ * about 510 ms of work over 723,147 keys, so 20,000 keys is roughly 14 ms of it.
21
+ * A caller with a frame budget of its own should pass its own number rather than
22
+ * trust this one.
23
+ */
24
+ export declare const STEP = 20000;
25
+ /**
26
+ * Fold a stored reading into the key a typist's spelling reaches it by.
27
+ *
28
+ * `yin2 hang2` becomes `yinhang` and `lü4 se4` becomes `luse`. Three things go:
29
+ * the spaces, because nobody types them; the tone digits, because a typist
30
+ * mostly does not write tones and a toned query is answered by filtering a
31
+ * toneless list rather than by a second index; and the umlaut, because `lu` and
32
+ * `lv` both have to reach 绿 and the only spelling both of them fold to is `lu`.
33
+ *
34
+ * The 儿化 r **stays**, so 玩儿 is keyed `wanr` and not `wan`. It is a letter a
35
+ * typist writes, and the query side reaches the key from both directions by
36
+ * searching `wan` and `wanr` alike — see `candidates`.
37
+ *
38
+ * Nothing here parses a syllable, which is what keeps a pass over every key in
39
+ * the dictionary affordable.
40
+ */
41
+ export declare function readingKey(reading: string): string;
42
+ /**
43
+ * A reverse index in the form it can be handed between threads.
44
+ *
45
+ * Three pieces, the same shape the forward index has: the reading keys as one
46
+ * sorted newline-joined blob, the dictionary positions grouped under them, and
47
+ * where each group begins. The two arrays are transferable and the blob is a
48
+ * string, so a worker can build this and post it back with no copy of the
49
+ * postings — which is the point, since the full tier's build is over half a
50
+ * second and does not belong on the main thread.
51
+ */
52
+ export interface ReverseIndexData {
53
+ /** Sorted reading keys, newline-joined: a {@link KeyIndex} blob. */
54
+ readonly keys: string;
55
+ /** Dictionary positions, grouped by reading key, likeliest first. */
56
+ readonly postings: Uint32Array;
57
+ /** Where each key's postings begin, with one past the end on the tail. */
58
+ readonly starts: Uint32Array;
59
+ }
60
+ //# sourceMappingURL=reverse-index-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-index-format.d.ts","sourceRoot":"","sources":["../../src/search/reverse-index-format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,IAAI,OAAO,CAAC;AAEzB,eAAO,MAAM,KAAK,KAAK,CAAC;AAExB,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB,eAAO,MAAM,QAAQ,WAAM,CAAC;AAE5B,eAAO,MAAM,OAAO,MAAM,CAAC;AAE3B;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,QAAS,CAAC;AAE3B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYlD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * How the reverse index is laid out on disk.
3
+ *
4
+ * The key a reading is stored under and the packed arrays behind it.
5
+ * `reverse-index.ts` is the index built on top of both.
6
+ */
7
+ /**
8
+ * The separator between reading keys, matching what {@link KeyIndex} expects.
9
+ */
10
+ export const LINE = "\n";
11
+ export const SPACE = 32;
12
+ export const ZERO = 48;
13
+ export const FIVE = 53;
14
+ export const UMLAUT_U = "ü";
15
+ export const PLAIN_U = "u";
16
+ /**
17
+ * How many positions one {@link ReverseIndexBuild.step} covers by default.
18
+ *
19
+ * Sized so that a step is a frame rather than several: the full tier's build is
20
+ * about 510 ms of work over 723,147 keys, so 20,000 keys is roughly 14 ms of it.
21
+ * A caller with a frame budget of its own should pass its own number rather than
22
+ * trust this one.
23
+ */
24
+ export const STEP = 20_000;
25
+ /**
26
+ * Fold a stored reading into the key a typist's spelling reaches it by.
27
+ *
28
+ * `yin2 hang2` becomes `yinhang` and `lü4 se4` becomes `luse`. Three things go:
29
+ * the spaces, because nobody types them; the tone digits, because a typist
30
+ * mostly does not write tones and a toned query is answered by filtering a
31
+ * toneless list rather than by a second index; and the umlaut, because `lu` and
32
+ * `lv` both have to reach 绿 and the only spelling both of them fold to is `lu`.
33
+ *
34
+ * The 儿化 r **stays**, so 玩儿 is keyed `wanr` and not `wan`. It is a letter a
35
+ * typist writes, and the query side reaches the key from both directions by
36
+ * searching `wan` and `wanr` alike — see `candidates`.
37
+ *
38
+ * Nothing here parses a syllable, which is what keeps a pass over every key in
39
+ * the dictionary affordable.
40
+ */
41
+ export function readingKey(reading) {
42
+ let key = "";
43
+ for (let at = 0; at < reading.length; at++) {
44
+ /* c8 ignore next -- `at` is inside the string, so the fallback cannot fire */
45
+ const code = reading.codePointAt(at) ?? 0;
46
+ if (code === SPACE || (code >= ZERO && code <= FIVE)) {
47
+ continue;
48
+ }
49
+ const character = reading.charAt(at);
50
+ key += character === UMLAUT_U ? PLAIN_U : character;
51
+ }
52
+ return key;
53
+ }
54
+ //# sourceMappingURL=reverse-index-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-index-format.js","sourceRoot":"","sources":["../../src/search/reverse-index-format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;AAEzB,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;AAExB,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;AAEvB,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;AAEvB,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAE5B,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAE3B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAE3B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;QAC3C,8EAA8E;QAC9E,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YACrD,SAAS;QACX,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACrC,GAAG,IAAI,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}