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
@@ -1,104 +0,0 @@
1
- // tagfix.ts — Pre-parse POS-tag correction layer.
2
- //
3
- // FinNLP's en-pos tagger is structurally sound but carries a small tail of
4
- // SYSTEMATIC tag errors that matter enormously for verse analysis, because a
5
- // wrong tag flips a word's content/function status (→ its stress tier) and
6
- // derails the en-parse dependency tree built from the tags. This pass runs
7
- // BETWEEN en-pos and en-parse (see parseDocument in parser.ts), so corrected
8
- // tags repair both the tagging AND the resulting dependency structure — a
9
- // post-hoc fix of the parse could never do that.
10
- //
11
- // Every rule below targets an error class actually observed in this repo's
12
- // trials; rules are deliberately narrow (anti-gaming: each must be justified
13
- // by the error it fixes, not by benchmark deltas).
14
-
15
- /** Zero-derived irregular past participles that en-pos tags NN/VBP after a
16
- * have-auxiliary ("had quit", "has put", "have read"). Only forms whose
17
- * participle is identical to the base/noun spelling — the -en/-ed forms tag
18
- * fine on their own. */
19
- const ZERO_PARTICIPLES = new Set([
20
- 'quit', 'put', 'set', 'cut', 'hit', 'let', 'shut', 'cast', 'cost', 'hurt',
21
- 'burst', 'split', 'spread', 'bet', 'wed', 'read', 'rid', 'shed', 'thrust',
22
- 'slit', 'bid', 'broadcast', 'upset', 'sunburst',
23
- ]);
24
-
25
- const HAVE_FORMS = new Set(['have', 'has', 'had', 'having', "'ve", "'d"]);
26
-
27
- /** Archaic / Early-Modern-English forms en-pos has no lexicon entries for —
28
- * ubiquitous in the verse this toolkit exists to scan. */
29
- const ARCHAIC_TAGS: Record<string, string> = {
30
- thou: 'PRP', thee: 'PRP', ye: 'PRP',
31
- thy: 'PRP$', thine: 'PRP$',
32
- art: 'VBP', wert: 'VBD', wast: 'VBD',
33
- doth: 'VBZ', hath: 'VBZ', dost: 'VBZ', hast: 'VBZ', saith: 'VBZ',
34
- didst: 'VBD', hadst: 'VBD', wouldst: 'MD', couldst: 'MD', shouldst: 'MD',
35
- shalt: 'MD', wilt: 'MD', canst: 'MD', mayst: 'MD', 'mightst': 'MD',
36
- wherefore: 'WRB', whither: 'WRB', whence: 'WRB',
37
- hither: 'RB', thither: 'RB', yon: 'JJ', yonder: 'RB',
38
- ere: 'IN', oft: 'RB', anon: 'RB',
39
- };
40
-
41
- /**
42
- * Correct a sentence's tags in place-safe fashion (returns a new array).
43
- * `tokens` and `tags` are the en-pos outputs, index-aligned.
44
- */
45
- export function correctTags(tokens: string[], tags: string[]): string[] {
46
- const out = tags.slice();
47
- for (let i = 0; i < tokens.length; i++) {
48
- const w = tokens[i].toLowerCase();
49
-
50
- // 1. The pronoun "I". en-norm lowercases sentence-initial "I" → "i",
51
- // which en-pos then reads as a foreign word / letter name (FW).
52
- if (w === 'i' && out[i] === 'FW') out[i] = 'PRP';
53
-
54
- // 2. Archaic forms (thou/thy/doth/shalt/wherefore…): en-pos guesses
55
- // NN/JJ/FW for these, wrecking both stress class and the parse.
56
- // Guard "art": only when a pronoun precedes ("thou art"), since the
57
- // noun reading ("the art of…") is the modern default.
58
- const archaic = ARCHAIC_TAGS[w];
59
- if (archaic && !/^(NNP|NNPS)$/.test(out[i])) {
60
- if (w === 'art') {
61
- const prev = i > 0 ? tokens[i - 1].toLowerCase() : '';
62
- if (prev === 'thou' || prev === 'ye' || prev === 'you') out[i] = 'VBP';
63
- } else {
64
- out[i] = archaic;
65
- }
66
- }
67
-
68
- // 3. Perfect-tense zero participles: have-form + ("quit"/"put"/"read"…)
69
- // tagged as NN/VBP/VBD → VBN, so en-parse builds the verb chain
70
- // instead of treating the participle as a direct-object noun
71
- // ("I had quit the programming paradigm"). An intervening adverb
72
- // ("had just quit") is allowed.
73
- if (ZERO_PARTICIPLES.has(w) && /^(NN|NNS|VBP|VBD|VB)$/.test(out[i])) {
74
- const prev1 = i > 0 ? tokens[i - 1].toLowerCase() : '';
75
- const prev2 = i > 1 ? tokens[i - 2].toLowerCase() : '';
76
- const prev1IsAdv = i > 0 && /^RB/.test(out[i - 1]);
77
- if (HAVE_FORMS.has(prev1) || (prev1IsAdv && HAVE_FORMS.has(prev2))) {
78
- out[i] = 'VBN';
79
- }
80
- }
81
-
82
- // 4. Impossible gerunds: a VBG tag on a token that does not end in
83
- // -ing/-in' cannot be a gerund/present participle — it is an en-pos
84
- // lexicon glitch. The right tag depends on context: before a noun it
85
- // is a noun modifier ("wisdom"/VBG teeth → NN); after a subject
86
- // pronoun it is a finite verb ("as they bicycle/VBG through" → VBP,
87
- // which keeps "through" a phrasal particle in the parse). With no
88
- // deciding context, leave the tag alone (en-parse treats VBG
89
- // verb-ishly, the safer default).
90
- if (out[i] === 'VBG' && !/in[g'’]?$/.test(w)) {
91
- const prevTag = i > 0 ? out[i - 1] : '';
92
- const nextTag = i + 1 < tokens.length ? out[i + 1] : '';
93
- if (/^NNS?$/.test(nextTag)) out[i] = 'NN';
94
- else if (prevTag === 'PRP') out[i] = 'VBP';
95
- }
96
-
97
- // 5. Vocative "O" ("O wild West Wind"): en-pos gives NNP/JJ; it is an
98
- // interjection (and must not become a content word with a beat by
99
- // default). Only the bare capital O — "o'er" etc. are handled by the
100
- // aphaeresis lexicon in stress.ts.
101
- if (tokens[i] === 'O' && i + 1 < tokens.length && out[i] !== 'UH') out[i] = 'UH';
102
- }
103
- return out;
104
- }
package/src/depfix.ts DELETED
@@ -1,88 +0,0 @@
1
- // depfix.ts — Post-parse dependency repair via DepEdit rules (the `depedits`
2
- // npm package, the maintainer's TypeScript port of DepEdit).
3
- //
4
- // Runs AFTER en-parse, complementing the pre-parse tag corrections in
5
- // tagfix.ts: tagfix repairs what the tagger got wrong before the tree is
6
- // built; this pass repairs systematic attachment errors en-parse makes even
7
- // with correct tags. Rules are written in DepEdit's declarative format
8
- // (definitions ⟶ relations ⟶ actions, tab-separated) over en-parse's own
9
- // label space (DOBJ/NSUBJ/DEP/…), so the round-trip is lossless and every
10
- // rule is independently testable.
11
- //
12
- // The rule set is deliberately small and evidence-based — each rule cites the
13
- // observed failure it corrects. `depedits` is ESM-only; it is loaded lazily
14
- // and failures degrade gracefully (the unrepaired parse is still a parse).
15
-
16
- import { createRequire } from 'module';
17
-
18
- interface FinDepNode {
19
- label: string; // dependency label, e.g. "NSUBJ", "ROOT"
20
- type: string; // phrase type, e.g. "NP", "VP"
21
- parent: number; // 0-based index of governor token; -1 for root
22
- }
23
-
24
- // Observed failure (probe: "I had quit the programming paradigm"): en-parse
25
- // attaches BOTH nouns of a noun compound to the verb as parallel objects
26
- // ("programming ←DOBJ← quit", "paradigm ←DOBJ← quit"), and leaves the
27
- // determiner dangling on the first noun as generic DEP. The repairs:
28
- // 1. Two adjacent common nouns sharing a governor with the same object
29
- // relation → the first is a compound modifier (AMOD) of the second.
30
- // 2. A determiner left as DEP on a noun that has become a modifier →
31
- // re-attach it as DET to that noun's head (the true NP head).
32
- const CALLIOPE_DEP_FIXES = [
33
- 'xpos=/NNS?/&func=/DOBJ|IOBJ/;xpos=/NNS?/&func=/DOBJ|IOBJ/;xpos=/VB.*/\t#3>#1;#3>#2;#1.#2\t#2>#1;#1:func=AMOD',
34
- 'xpos=/DT/&func=/DEP|EXT/;xpos=/NNS?/&func=/AMOD/;xpos=/NNS?.*/\t#2>#1;#3>#2\t#3>#1;#1:func=DET',
35
- ].join('\n');
36
-
37
- let engine: { process(conllu: string): string } | null | undefined;
38
-
39
- function loadEngine(): typeof engine {
40
- if (engine !== undefined) return engine;
41
- try {
42
- // This package compiles to ESM, where bare `require` does not exist, and
43
- // the parse path is synchronous, so dynamic import() is not an option:
44
- // createRequire gives a sync loader, and since `depedits` is itself
45
- // ESM-only this resolves via Node's require(esm) (≥20.17 / ≥22.12). On
46
- // older runtimes it throws and the repair pass degrades to a no-op (the
47
- // unrepaired parse is still a parse).
48
- const req = createRequire(import.meta.url);
49
- const { DepEditEngine } = req('depedits');
50
- const e = new DepEditEngine();
51
- e.loadIniString(CALLIOPE_DEP_FIXES);
52
- engine = e;
53
- } catch {
54
- engine = null;
55
- }
56
- return engine;
57
- }
58
-
59
- /**
60
- * Repair systematic en-parse attachment errors. Returns a new deps array
61
- * (same shape as en-parse's `toArray` output); on any failure returns the
62
- * input unchanged.
63
- */
64
- export function applyDepFixes(tokens: string[], tags: string[], deps: FinDepNode[]): FinDepNode[] {
65
- const e = loadEngine();
66
- if (!e || tokens.length === 0 || deps.length !== tokens.length) return deps;
67
- try {
68
- const conllu = tokens.map((tok, i) => {
69
- const head = deps[i].parent >= 0 ? deps[i].parent + 1 : 0;
70
- const safe = tok.replace(/\s/g, '_') || '_';
71
- return `${i + 1}\t${safe}\t${safe}\t_\t${tags[i] || '_'}\t_\t${head}\t${deps[i].label || 'DEP'}\t_\t_`;
72
- }).join('\n') + '\n\n';
73
- const out = e.process(conllu);
74
- const fixed: FinDepNode[] = deps.map(d => ({ ...d }));
75
- for (const row of out.split('\n')) {
76
- const cols = row.split('\t');
77
- if (cols.length < 10) continue;
78
- const idx = parseInt(cols[0], 10) - 1;
79
- if (!(idx >= 0 && idx < fixed.length)) continue;
80
- const head = parseInt(cols[6], 10);
81
- fixed[idx].parent = Number.isFinite(head) ? head - 1 : fixed[idx].parent;
82
- if (cols[7] && cols[7] !== '_') fixed[idx].label = cols[7];
83
- }
84
- return fixed;
85
- } catch {
86
- return deps;
87
- }
88
- }