calliope-ts 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +69 -3
  2. package/dist/calliope/bracketing.d.ts.map +1 -1
  3. package/dist/calliope/bracketing.js +59 -5
  4. package/dist/calliope/deps.d.ts +5 -1
  5. package/dist/calliope/deps.d.ts.map +1 -1
  6. package/dist/calliope/deps.js +53 -3
  7. package/dist/calliope/engine.d.ts.map +1 -1
  8. package/dist/calliope/engine.js +6 -1
  9. package/dist/calliope/relstress.d.ts.map +1 -1
  10. package/dist/calliope/relstress.js +411 -15
  11. package/dist/calliope/syntax.d.ts +33 -0
  12. package/dist/calliope/syntax.d.ts.map +1 -1
  13. package/dist/calliope/syntax.js +199 -0
  14. package/dist/data/en_common_words.json +1 -0
  15. package/dist/display.d.ts +15 -1
  16. package/dist/display.d.ts.map +1 -1
  17. package/dist/display.js +112 -10
  18. package/dist/fabbhalle.d.ts +54 -0
  19. package/dist/fabbhalle.d.ts.map +1 -0
  20. package/dist/fabbhalle.js +404 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +86 -33
  23. package/dist/phonological.d.ts.map +1 -1
  24. package/dist/phonological.js +7 -1
  25. package/dist/rewriteEn.d.ts +14 -0
  26. package/dist/rewriteEn.d.ts.map +1 -0
  27. package/dist/rewriteEn.js +392 -0
  28. package/dist/rhyme.d.ts +35 -3
  29. package/dist/rhyme.d.ts.map +1 -1
  30. package/dist/rhyme.js +176 -11
  31. package/dist/russian/accentuator.d.ts +31 -0
  32. package/dist/russian/accentuator.d.ts.map +1 -0
  33. package/dist/russian/accentuator.js +546 -0
  34. package/dist/russian/collocations.d.ts +7 -0
  35. package/dist/russian/collocations.d.ts.map +1 -0
  36. package/dist/russian/collocations.js +38 -0
  37. package/dist/russian/compounds.d.ts +6 -0
  38. package/dist/russian/compounds.d.ts.map +1 -0
  39. package/dist/russian/compounds.js +81 -0
  40. package/dist/russian/download.d.ts +23 -0
  41. package/dist/russian/download.d.ts.map +1 -0
  42. package/dist/russian/download.js +117 -0
  43. package/dist/russian/engine.d.ts +6 -0
  44. package/dist/russian/engine.d.ts.map +1 -0
  45. package/dist/russian/engine.js +1424 -0
  46. package/dist/russian/parser.d.ts +8 -0
  47. package/dist/russian/parser.d.ts.map +1 -0
  48. package/dist/russian/parser.js +92 -0
  49. package/dist/russian/paths.d.ts +55 -0
  50. package/dist/russian/paths.d.ts.map +1 -0
  51. package/dist/russian/paths.js +114 -0
  52. package/dist/russian/rewrite.d.ts +6 -0
  53. package/dist/russian/rewrite.d.ts.map +1 -0
  54. package/dist/russian/rewrite.js +400 -0
  55. package/dist/russian/rhyme.d.ts +18 -0
  56. package/dist/russian/rhyme.d.ts.map +1 -0
  57. package/dist/russian/rhyme.js +230 -0
  58. package/dist/russian/syllabifier.d.ts +14 -0
  59. package/dist/russian/syllabifier.d.ts.map +1 -0
  60. package/dist/russian/syllabifier.js +475 -0
  61. package/dist/russian/types.d.ts +94 -0
  62. package/dist/russian/types.d.ts.map +1 -0
  63. package/dist/russian/types.js +27 -0
  64. package/dist/scandroidNative/constants.d.ts +16 -0
  65. package/dist/scandroidNative/constants.d.ts.map +1 -0
  66. package/dist/scandroidNative/constants.js +60 -0
  67. package/dist/scandroidNative/deduceParameters.d.ts +16 -0
  68. package/dist/scandroidNative/deduceParameters.d.ts.map +1 -0
  69. package/dist/scandroidNative/deduceParameters.js +69 -0
  70. package/dist/scandroidNative/dictionary-data.d.ts +2 -0
  71. package/dist/scandroidNative/dictionary-data.d.ts.map +1 -0
  72. package/dist/scandroidNative/dictionary-data.js +744 -0
  73. package/dist/scandroidNative/dictionary.d.ts +12 -0
  74. package/dist/scandroidNative/dictionary.d.ts.map +1 -0
  75. package/dist/scandroidNative/dictionary.js +50 -0
  76. package/dist/scandroidNative/engine.d.ts +41 -0
  77. package/dist/scandroidNative/engine.d.ts.map +1 -0
  78. package/dist/scandroidNative/engine.js +119 -0
  79. package/dist/scandroidNative/machine.d.ts +93 -0
  80. package/dist/scandroidNative/machine.d.ts.map +1 -0
  81. package/dist/scandroidNative/machine.js +795 -0
  82. package/dist/scandroidNative/positioner.d.ts +32 -0
  83. package/dist/scandroidNative/positioner.d.ts.map +1 -0
  84. package/dist/scandroidNative/positioner.js +208 -0
  85. package/dist/scandroidNative/syllabizer.d.ts +3 -0
  86. package/dist/scandroidNative/syllabizer.d.ts.map +1 -0
  87. package/dist/scandroidNative/syllabizer.js +215 -0
  88. package/dist/scandroidNative/utilities.d.ts +37 -0
  89. package/dist/scandroidNative/utilities.d.ts.map +1 -0
  90. package/dist/scandroidNative/utilities.js +86 -0
  91. package/dist/scansion.d.ts.map +1 -1
  92. package/dist/scansion.js +118 -14
  93. package/dist/stress.d.ts +1 -0
  94. package/dist/stress.d.ts.map +1 -1
  95. package/dist/stress.js +502 -42
  96. package/dist/types.d.ts +3 -0
  97. package/dist/types.d.ts.map +1 -1
  98. package/package.json +27 -6
  99. package/tools/fetch-russian-data.mjs +30 -0
  100. package/webapp/public/app.js +2418 -0
  101. package/webapp/public/assets/GithubLogo.png +0 -0
  102. package/webapp/public/assets/NPM2.png +0 -0
  103. package/webapp/public/assets/fonts/MurenaBold-webfont.woff2 +0 -0
  104. package/webapp/public/assets/fonts/MurenaItalic-webfont.woff2 +0 -0
  105. package/webapp/public/assets/fonts/MurenaRegular-webfont.woff2 +0 -0
  106. package/webapp/public/assets/fonts/Myra_4F_Caps_Bold-webfont.woff2 +0 -0
  107. package/webapp/public/assets/fonts/SinkinSans-700Bold.otf +0 -0
  108. package/webapp/public/assets/fonts/butterflies.ttf +0 -0
  109. package/webapp/public/assets/fonts/midcase_blackline-webfont.woff2 +0 -0
  110. package/webapp/public/assets/fonts/neueral-bold-webfont.woff2 +0 -0
  111. package/webapp/public/assets/fonts/neueral-regular-webfont.woff2 +0 -0
  112. package/webapp/public/assets/fonts/popelka-webfont.woff2 +0 -0
  113. package/webapp/public/assets/fonts/vremenagrotesk-webfont.woff +0 -0
  114. package/webapp/public/assets/fonts/wicky_javick_bold-webfont.woff2 +0 -0
  115. package/webapp/public/assets/logos/Logo_Var_10_Celtic_Knot_SVG.svg +116 -0
  116. package/webapp/public/assets/logos/Logo_Var_11_Graph_SVG.svg +313 -0
  117. package/webapp/public/assets/logos/Logo_Var_12_Limacon_Knot_SVG.svg +3942 -0
  118. package/webapp/public/assets/logos/Logo_Var_13_Crescents_SVG.svg +1030 -0
  119. package/webapp/public/assets/logos/Logo_Var_1_Spiral_SVG.svg +1491 -0
  120. package/webapp/public/assets/logos/Logo_Var_2_Tunnel_SVG.svg +12 -0
  121. package/webapp/public/assets/logos/Logo_Var_3_Triskelion_SVG.svg +10 -0
  122. package/webapp/public/assets/logos/Logo_Var_4_Quinquetra_PNG.png +0 -0
  123. package/webapp/public/assets/logos/Logo_Var_5_Penrose_Pentagram_SVG.svg +37 -0
  124. package/webapp/public/assets/logos/Logo_Var_6_Triskelion2_SVG.svg +10 -0
  125. package/webapp/public/assets/logos/Logo_Var_7_SixfoldSpirals_SVG.svg +20 -0
  126. package/webapp/public/assets/logos/Logo_Var_8_Radial_Labyrinth_SVG.svg +163 -0
  127. package/webapp/public/assets/logos/Logo_Var_9_Radial_Labyrinth_2_SVG.svg +106 -0
  128. package/webapp/public/index.html +316 -0
  129. package/webapp/public/styles.css +1114 -0
  130. package/webapp/server.mjs +680 -0
  131. package/src/caesura.ts +0 -201
  132. package/src/calliope/boundaries.ts +0 -190
  133. package/src/calliope/bracketing.ts +0 -390
  134. package/src/calliope/deps.ts +0 -160
  135. package/src/calliope/engine.ts +0 -77
  136. package/src/calliope/feats.ts +0 -46
  137. package/src/calliope/names.ts +0 -44
  138. package/src/calliope/postag.ts +0 -253
  139. package/src/calliope/prosodic.ts +0 -262
  140. package/src/calliope/relstress.ts +0 -645
  141. package/src/calliope/stressrules.ts +0 -147
  142. package/src/calliope/syntax.ts +0 -218
  143. package/src/calliope/udpos.ts +0 -152
  144. package/src/calliope_src_contents.md +0 -19049
  145. package/src/clio/caesura.ts +0 -145
  146. package/src/clio/depfix.ts +0 -88
  147. package/src/clio/display.ts +0 -1042
  148. package/src/clio/engine.ts +0 -38
  149. package/src/clio/parser.ts +0 -845
  150. package/src/clio/phonological.ts +0 -849
  151. package/src/clio/phrasestress.ts +0 -108
  152. package/src/clio/pipeline.ts +0 -154
  153. package/src/clio/rhyme.ts +0 -740
  154. package/src/clio/scandroid.ts +0 -434
  155. package/src/clio/scansion.ts +0 -1130
  156. package/src/clio/semantics.ts +0 -134
  157. package/src/clio/stress.ts +0 -1731
  158. package/src/clio/tagfix.ts +0 -104
  159. package/src/depfix.ts +0 -88
  160. package/src/display.ts +0 -1138
  161. package/src/engine.ts +0 -22
  162. package/src/index.ts +0 -690
  163. package/src/parser.ts +0 -501
  164. package/src/phonological.ts +0 -917
  165. package/src/phrasestress.ts +0 -108
  166. package/src/rhyme.ts +0 -748
  167. package/src/scandroid.ts +0 -434
  168. package/src/scansion.ts +0 -1174
  169. package/src/semantics.ts +0 -134
  170. package/src/stress.ts +0 -2111
  171. package/src/tagfix.ts +0 -104
  172. package/src/types.ts +0 -265
  173. package/tests/DataForHayesLinesOnly.txt +0 -364
  174. package/tests/DataForHayesStressSymbolsRevised.txt +0 -728
  175. package/tests/basic.test.ts +0 -1102
  176. package/tests/bench-hayes.mjs +0 -72
  177. package/tests/epg64.meter.train.txt +0 -8139
  178. package/tests/litlab-sample-2016.txt +0 -1738
  179. package/tests/prosodic.meter.train.txt +0 -13192
  180. package/tests/wagner-stress.test.ts +0 -188
  181. package/tsconfig.json +0 -29
  182. package/vitest.config.d.ts +0 -2
  183. package/vitest.config.js +0 -14
@@ -0,0 +1,23 @@
1
+ /** Static manifest: every file the Russian pipeline needs, with its exact byte size. */
2
+ export declare const RUSSIAN_DATA_FILES: {
3
+ name: string;
4
+ size: number;
5
+ }[];
6
+ export declare const RUSSIAN_DATA_BASE_URL: string;
7
+ /**
8
+ * Ensure the Russian data assets are present in russianDataWriteDir(),
9
+ * downloading any missing or incorrectly-sized files from
10
+ * RUSSIAN_DATA_BASE_URL. Safe to call repeatedly — once the files are
11
+ * present and correctly sized, this is a cheap no-op. Concurrent callers
12
+ * share the same in-flight run.
13
+ */
14
+ export declare function ensureRussianData(opts?: {
15
+ force?: boolean;
16
+ onlyFiles?: string[];
17
+ log?: (m: string) => void;
18
+ }): Promise<{
19
+ downloaded: string[];
20
+ skipped: string[];
21
+ dir: string;
22
+ }>;
23
+ //# sourceMappingURL=download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/russian/download.ts"],"names":[],"mappings":"AAYA,wFAAwF;AACxF,eAAO,MAAM,kBAAkB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAmB9D,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAE+C,CAAC;AAyDlF;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,CAAC,EAAE;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3B,GAAG,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAmCpE"}
@@ -0,0 +1,117 @@
1
+ // download.ts — on-first-use downloader for the Russian data assets.
2
+ //
3
+ // The Russian pipeline needs ~122 MB of data (SynTagRus UDPipe model +
4
+ // dictionaries) that are NOT bundled in the npm package. This module fetches
5
+ // them from a HuggingFace space into russianDataWriteDir() on first use, then
6
+ // every later call is a cheap no-op once the files are present and correctly
7
+ // sized. Dependency-free: only node: builtins + global fetch (Node 20+).
8
+ import { mkdir, rename, stat, writeFile } from 'node:fs/promises';
9
+ import { resolve } from 'node:path';
10
+ import { russianDataFile, russianDataWriteDir } from './paths.js';
11
+ /** Static manifest: every file the Russian pipeline needs, with its exact byte size. */
12
+ export const RUSSIAN_DATA_FILES = [
13
+ { name: 'LICENSE.txt', size: 1094 },
14
+ { name: 'LICENSE_UDpipe_SynTagRus.txt', size: 187 },
15
+ { name: 'accentuator.bin', size: 31960084 },
16
+ { name: 'accentuator.json', size: 811 },
17
+ { name: 'ambiguous_accents.json', size: 3111298 },
18
+ { name: 'ambiguous_accents2.json', size: 373565 },
19
+ { name: 'collocations.json', size: 29085 },
20
+ { name: 'derivation_data.json', size: 4059886 },
21
+ { name: 'fuzzy_rhymes.json', size: 306 },
22
+ { name: 'rhymed_words.json', size: 77945 },
23
+ { name: 'rhyming_dict.json', size: 8651588 },
24
+ { name: 'russian-syntagrus-ud-2.0-170801.udpipe', size: 45014943 },
25
+ { name: 'secondary_stress.json', size: 10260274 },
26
+ { name: 'word_accents.tsv.gz', size: 11107564 },
27
+ { name: 'word_freq.json', size: 1002126 },
28
+ { name: 'word_segmentation.json', size: 5087512 },
29
+ { name: 'yo_by_gram.json', size: 677879 },
30
+ { name: 'yo_words.json', size: 5988934 },
31
+ ];
32
+ export const RUSSIAN_DATA_BASE_URL = process.env.CALLIOPE_RUSSIAN_DATA_URL ??
33
+ 'https://huggingface.co/spaces/AlekseyCalvin/cts/resolve/main/src/russian/data';
34
+ const LOG_PREFIX = '[Calliope Russian]';
35
+ function formatBytes(n) {
36
+ return `${(n / (1024 * 1024)).toFixed(1)} MB`;
37
+ }
38
+ /** True if `name` already resolves to a file whose size matches the manifest. */
39
+ async function isPresentAndCorrect(name, expectedSize) {
40
+ const existing = russianDataFile(name);
41
+ if (!existing)
42
+ return false;
43
+ try {
44
+ const st = await stat(existing);
45
+ return st.size === expectedSize;
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }
51
+ async function downloadOne(name, expectedSize, targetDir, log) {
52
+ const url = `${RUSSIAN_DATA_BASE_URL}/${name}`;
53
+ log(`${LOG_PREFIX} downloading ${name} (${formatBytes(expectedSize)})…`);
54
+ let buf;
55
+ try {
56
+ const res = await fetch(url);
57
+ if (!res.ok) {
58
+ throw new Error(`HTTP ${res.status} ${res.statusText}`);
59
+ }
60
+ const ab = await res.arrayBuffer();
61
+ buf = Buffer.from(ab);
62
+ }
63
+ catch (err) {
64
+ throw new Error(`${LOG_PREFIX} failed to download "${name}" from ${url}: ${err instanceof Error ? err.message : String(err)}\n` +
65
+ `Fix options:\n` +
66
+ ` - Check network access to huggingface.co and retry.\n` +
67
+ ` - Set CALLIOPE_RUSSIAN_DATA to a directory that already has the Russian data/ files.\n` +
68
+ ` - Set CALLIOPE_RUSSIAN_DATA_URL to an alternate mirror hosting the same file set.`);
69
+ }
70
+ if (buf.length !== expectedSize) {
71
+ throw new Error(`${LOG_PREFIX} downloaded "${name}" has the wrong size: expected ${expectedSize} bytes, got ${buf.length} bytes. ` +
72
+ `The remote file may have changed or the transfer was truncated. URL: ${url}`);
73
+ }
74
+ const finalPath = resolve(targetDir, name);
75
+ const tmpPath = `${finalPath}.download-tmp`;
76
+ await writeFile(tmpPath, buf);
77
+ await rename(tmpPath, finalPath);
78
+ }
79
+ let _inFlight = null;
80
+ /**
81
+ * Ensure the Russian data assets are present in russianDataWriteDir(),
82
+ * downloading any missing or incorrectly-sized files from
83
+ * RUSSIAN_DATA_BASE_URL. Safe to call repeatedly — once the files are
84
+ * present and correctly sized, this is a cheap no-op. Concurrent callers
85
+ * share the same in-flight run.
86
+ */
87
+ export async function ensureRussianData(opts) {
88
+ const force = opts?.force ?? false;
89
+ const log = opts?.log ?? ((m) => console.error(m));
90
+ if (_inFlight && !force)
91
+ return _inFlight;
92
+ const run = (async () => {
93
+ const targetDir = russianDataWriteDir();
94
+ await mkdir(targetDir, { recursive: true });
95
+ const manifest = opts?.onlyFiles
96
+ ? RUSSIAN_DATA_FILES.filter(f => opts.onlyFiles.includes(f.name))
97
+ : RUSSIAN_DATA_FILES;
98
+ const downloaded = [];
99
+ const skipped = [];
100
+ for (const { name, size } of manifest) {
101
+ if (!force && (await isPresentAndCorrect(name, size))) {
102
+ skipped.push(name);
103
+ continue;
104
+ }
105
+ await downloadOne(name, size, targetDir, log);
106
+ downloaded.push(name);
107
+ }
108
+ return { downloaded, skipped, dir: targetDir };
109
+ })();
110
+ _inFlight = run;
111
+ try {
112
+ return await run;
113
+ }
114
+ finally {
115
+ _inFlight = null;
116
+ }
117
+ }
@@ -0,0 +1,6 @@
1
+ import type { RuScansionResult } from './types.js';
2
+ /** Analyze a Russian poem and return the full scansion result. */
3
+ export declare function analyzeRussianPoem(text: string): Promise<RuScansionResult>;
4
+ /** Quick check: is this text Russian? */
5
+ export declare function isRussian(text: string): boolean;
6
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/russian/engine.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAqsCpB,kEAAkE;AAClE,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAuQhF;AAED,yCAAyC;AACzC,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI/C"}