calliope-ts 0.0.2 → 0.0.4

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 (160) hide show
  1. package/README.md +32 -20
  2. package/dist/caesura.d.ts +33 -0
  3. package/dist/caesura.d.ts.map +1 -0
  4. package/dist/caesura.js +202 -0
  5. package/dist/calliope/boundaries.d.ts +19 -0
  6. package/dist/calliope/boundaries.d.ts.map +1 -0
  7. package/dist/calliope/boundaries.js +182 -0
  8. package/dist/calliope/bracketing.d.ts +11 -0
  9. package/dist/calliope/bracketing.d.ts.map +1 -0
  10. package/dist/calliope/bracketing.js +416 -0
  11. package/dist/calliope/deps.d.ts +4 -0
  12. package/dist/calliope/deps.d.ts.map +1 -0
  13. package/dist/calliope/deps.js +181 -0
  14. package/dist/calliope/engine.d.ts +3 -0
  15. package/dist/calliope/engine.d.ts.map +1 -0
  16. package/dist/calliope/engine.js +71 -0
  17. package/dist/calliope/feats.d.ts +9 -0
  18. package/dist/calliope/feats.d.ts.map +1 -0
  19. package/dist/calliope/feats.js +45 -0
  20. package/dist/calliope/names.d.ts +7 -0
  21. package/dist/calliope/names.d.ts.map +1 -0
  22. package/dist/calliope/names.js +42 -0
  23. package/dist/calliope/postag.d.ts +8 -0
  24. package/dist/calliope/postag.d.ts.map +1 -0
  25. package/dist/calliope/postag.js +250 -0
  26. package/dist/calliope/prosodic.d.ts +3 -0
  27. package/dist/calliope/prosodic.d.ts.map +1 -0
  28. package/dist/calliope/prosodic.js +275 -0
  29. package/dist/calliope/relstress.d.ts +4 -0
  30. package/dist/calliope/relstress.d.ts.map +1 -0
  31. package/dist/calliope/relstress.js +688 -0
  32. package/dist/calliope/stressrules.d.ts +28 -0
  33. package/dist/calliope/stressrules.d.ts.map +1 -0
  34. package/dist/calliope/stressrules.js +147 -0
  35. package/dist/calliope/syntax.d.ts +38 -0
  36. package/dist/calliope/syntax.d.ts.map +1 -0
  37. package/dist/calliope/syntax.js +234 -0
  38. package/dist/calliope/udpos.d.ts +13 -0
  39. package/dist/calliope/udpos.d.ts.map +1 -0
  40. package/dist/calliope/udpos.js +156 -0
  41. package/dist/clio/caesura.d.ts +27 -0
  42. package/dist/clio/caesura.d.ts.map +1 -0
  43. package/dist/clio/caesura.js +148 -0
  44. package/dist/clio/depfix.d.ts +13 -0
  45. package/dist/clio/depfix.d.ts.map +1 -0
  46. package/dist/clio/depfix.js +84 -0
  47. package/dist/clio/display.d.ts +32 -0
  48. package/dist/clio/display.d.ts.map +1 -0
  49. package/dist/clio/display.js +976 -0
  50. package/dist/clio/engine.d.ts +3 -0
  51. package/dist/clio/engine.d.ts.map +1 -0
  52. package/dist/clio/engine.js +28 -0
  53. package/dist/clio/parser.d.ts +10 -0
  54. package/dist/clio/parser.d.ts.map +1 -0
  55. package/dist/clio/parser.js +696 -0
  56. package/dist/clio/phonological.d.ts +41 -0
  57. package/dist/clio/phonological.d.ts.map +1 -0
  58. package/dist/clio/phonological.js +788 -0
  59. package/dist/clio/phrasestress.d.ts +6 -0
  60. package/dist/clio/phrasestress.d.ts.map +1 -0
  61. package/dist/clio/phrasestress.js +106 -0
  62. package/dist/clio/pipeline.d.ts +11 -0
  63. package/dist/clio/pipeline.d.ts.map +1 -0
  64. package/dist/clio/pipeline.js +147 -0
  65. package/dist/clio/rhyme.d.ts +65 -0
  66. package/dist/clio/rhyme.d.ts.map +1 -0
  67. package/dist/clio/rhyme.js +761 -0
  68. package/dist/clio/scandroid.d.ts +17 -0
  69. package/dist/clio/scandroid.d.ts.map +1 -0
  70. package/dist/clio/scandroid.js +435 -0
  71. package/dist/clio/scansion.d.ts +46 -0
  72. package/dist/clio/scansion.d.ts.map +1 -0
  73. package/dist/clio/scansion.js +1086 -0
  74. package/dist/clio/semantics.d.ts +44 -0
  75. package/dist/clio/semantics.d.ts.map +1 -0
  76. package/dist/clio/semantics.js +139 -0
  77. package/dist/clio/stress.d.ts +83 -0
  78. package/dist/clio/stress.d.ts.map +1 -0
  79. package/dist/clio/stress.js +1737 -0
  80. package/dist/clio/tagfix.d.ts +6 -0
  81. package/dist/clio/tagfix.d.ts.map +1 -0
  82. package/dist/clio/tagfix.js +101 -0
  83. package/dist/display.d.ts +0 -6
  84. package/dist/display.d.ts.map +1 -1
  85. package/dist/display.js +322 -141
  86. package/dist/engine.d.ts +9 -0
  87. package/dist/engine.d.ts.map +1 -0
  88. package/dist/engine.js +12 -0
  89. package/dist/index.d.ts +4 -3
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +169 -26
  92. package/dist/parser.d.ts +3 -3
  93. package/dist/parser.d.ts.map +1 -1
  94. package/dist/parser.js +320 -563
  95. package/dist/phonological.d.ts +1 -1
  96. package/dist/phonological.d.ts.map +1 -1
  97. package/dist/phonological.js +73 -4
  98. package/dist/phrasestress.d.ts +6 -0
  99. package/dist/phrasestress.d.ts.map +1 -0
  100. package/dist/phrasestress.js +106 -0
  101. package/dist/rhyme.d.ts +40 -1
  102. package/dist/rhyme.d.ts.map +1 -1
  103. package/dist/rhyme.js +435 -7
  104. package/dist/scansion.d.ts +9 -0
  105. package/dist/scansion.d.ts.map +1 -1
  106. package/dist/scansion.js +145 -18
  107. package/dist/semantics.d.ts +44 -0
  108. package/dist/semantics.d.ts.map +1 -0
  109. package/dist/semantics.js +139 -0
  110. package/dist/stress.d.ts +127 -4
  111. package/dist/stress.d.ts.map +1 -1
  112. package/dist/stress.js +834 -61
  113. package/dist/types.d.ts +15 -0
  114. package/dist/types.d.ts.map +1 -1
  115. package/package.json +5 -3
  116. package/src/caesura.ts +201 -0
  117. package/src/calliope/boundaries.ts +190 -0
  118. package/src/calliope/bracketing.ts +390 -0
  119. package/src/calliope/deps.ts +160 -0
  120. package/src/calliope/engine.ts +77 -0
  121. package/src/calliope/feats.ts +46 -0
  122. package/src/calliope/names.ts +44 -0
  123. package/src/calliope/postag.ts +253 -0
  124. package/src/calliope/prosodic.ts +262 -0
  125. package/src/calliope/relstress.ts +645 -0
  126. package/src/calliope/stressrules.ts +147 -0
  127. package/src/calliope/syntax.ts +218 -0
  128. package/src/calliope/udpos.ts +152 -0
  129. package/src/calliope_src_contents.md +19049 -0
  130. package/src/clio/caesura.ts +145 -0
  131. package/src/clio/depfix.ts +88 -0
  132. package/src/clio/display.ts +1042 -0
  133. package/src/clio/engine.ts +38 -0
  134. package/src/clio/parser.ts +845 -0
  135. package/src/clio/phonological.ts +849 -0
  136. package/src/clio/phrasestress.ts +108 -0
  137. package/src/clio/pipeline.ts +154 -0
  138. package/src/clio/rhyme.ts +740 -0
  139. package/src/clio/scandroid.ts +434 -0
  140. package/src/clio/scansion.ts +1130 -0
  141. package/src/clio/semantics.ts +134 -0
  142. package/src/clio/stress.ts +1731 -0
  143. package/src/clio/tagfix.ts +104 -0
  144. package/src/display.ts +321 -137
  145. package/src/engine.ts +22 -0
  146. package/src/index.ts +176 -32
  147. package/src/parser.ts +346 -682
  148. package/src/phonological.ts +72 -4
  149. package/src/phrasestress.ts +108 -0
  150. package/src/rhyme.ts +428 -8
  151. package/src/scansion.ts +136 -15
  152. package/src/semantics.ts +134 -0
  153. package/src/stress.ts +794 -64
  154. package/src/types.ts +39 -4
  155. package/tests/DataForHayesLinesOnly.txt +364 -0
  156. package/tests/DataForHayesStressSymbolsRevised.txt +728 -0
  157. package/tests/basic.test.ts +443 -37
  158. package/tests/bench-hayes.mjs +72 -0
  159. package/tests/wagner-stress.test.ts +188 -0
  160. package/vitest.config.ts +0 -15
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Correct a sentence's tags in place-safe fashion (returns a new array).
3
+ * `tokens` and `tags` are the en-pos outputs, index-aligned.
4
+ */
5
+ export declare function correctTags(tokens: string[], tags: string[]): string[];
6
+ //# sourceMappingURL=tagfix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tagfix.d.ts","sourceRoot":"","sources":["../../src/clio/tagfix.ts"],"names":[],"mappings":"AAwCA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA2DtE"}
@@ -0,0 +1,101 @@
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
+ /** Zero-derived irregular past participles that en-pos tags NN/VBP after a
15
+ * have-auxiliary ("had quit", "has put", "have read"). Only forms whose
16
+ * participle is identical to the base/noun spelling — the -en/-ed forms tag
17
+ * fine on their own. */
18
+ const ZERO_PARTICIPLES = new Set([
19
+ 'quit', 'put', 'set', 'cut', 'hit', 'let', 'shut', 'cast', 'cost', 'hurt',
20
+ 'burst', 'split', 'spread', 'bet', 'wed', 'read', 'rid', 'shed', 'thrust',
21
+ 'slit', 'bid', 'broadcast', 'upset', 'sunburst',
22
+ ]);
23
+ const HAVE_FORMS = new Set(['have', 'has', 'had', 'having', "'ve", "'d"]);
24
+ /** Archaic / Early-Modern-English forms en-pos has no lexicon entries for —
25
+ * ubiquitous in the verse this toolkit exists to scan. */
26
+ const ARCHAIC_TAGS = {
27
+ thou: 'PRP', thee: 'PRP', ye: 'PRP',
28
+ thy: 'PRP$', thine: 'PRP$',
29
+ art: 'VBP', wert: 'VBD', wast: 'VBD',
30
+ doth: 'VBZ', hath: 'VBZ', dost: 'VBZ', hast: 'VBZ', saith: 'VBZ',
31
+ didst: 'VBD', hadst: 'VBD', wouldst: 'MD', couldst: 'MD', shouldst: 'MD',
32
+ shalt: 'MD', wilt: 'MD', canst: 'MD', mayst: 'MD', 'mightst': 'MD',
33
+ wherefore: 'WRB', whither: 'WRB', whence: 'WRB',
34
+ hither: 'RB', thither: 'RB', yon: 'JJ', yonder: 'RB',
35
+ ere: 'IN', oft: 'RB', anon: 'RB',
36
+ };
37
+ /**
38
+ * Correct a sentence's tags in place-safe fashion (returns a new array).
39
+ * `tokens` and `tags` are the en-pos outputs, index-aligned.
40
+ */
41
+ export function correctTags(tokens, tags) {
42
+ const out = tags.slice();
43
+ for (let i = 0; i < tokens.length; i++) {
44
+ const w = tokens[i].toLowerCase();
45
+ // 1. The pronoun "I". en-norm lowercases sentence-initial "I" → "i",
46
+ // which en-pos then reads as a foreign word / letter name (FW).
47
+ if (w === 'i' && out[i] === 'FW')
48
+ out[i] = 'PRP';
49
+ // 2. Archaic forms (thou/thy/doth/shalt/wherefore…): en-pos guesses
50
+ // NN/JJ/FW for these, wrecking both stress class and the parse.
51
+ // Guard "art": only when a pronoun precedes ("thou art"), since the
52
+ // noun reading ("the art of…") is the modern default.
53
+ const archaic = ARCHAIC_TAGS[w];
54
+ if (archaic && !/^(NNP|NNPS)$/.test(out[i])) {
55
+ if (w === 'art') {
56
+ const prev = i > 0 ? tokens[i - 1].toLowerCase() : '';
57
+ if (prev === 'thou' || prev === 'ye' || prev === 'you')
58
+ out[i] = 'VBP';
59
+ }
60
+ else {
61
+ out[i] = archaic;
62
+ }
63
+ }
64
+ // 3. Perfect-tense zero participles: have-form + ("quit"/"put"/"read"…)
65
+ // tagged as NN/VBP/VBD → VBN, so en-parse builds the verb chain
66
+ // instead of treating the participle as a direct-object noun
67
+ // ("I had quit the programming paradigm"). An intervening adverb
68
+ // ("had just quit") is allowed.
69
+ if (ZERO_PARTICIPLES.has(w) && /^(NN|NNS|VBP|VBD|VB)$/.test(out[i])) {
70
+ const prev1 = i > 0 ? tokens[i - 1].toLowerCase() : '';
71
+ const prev2 = i > 1 ? tokens[i - 2].toLowerCase() : '';
72
+ const prev1IsAdv = i > 0 && /^RB/.test(out[i - 1]);
73
+ if (HAVE_FORMS.has(prev1) || (prev1IsAdv && HAVE_FORMS.has(prev2))) {
74
+ out[i] = 'VBN';
75
+ }
76
+ }
77
+ // 4. Impossible gerunds: a VBG tag on a token that does not end in
78
+ // -ing/-in' cannot be a gerund/present participle — it is an en-pos
79
+ // lexicon glitch. The right tag depends on context: before a noun it
80
+ // is a noun modifier ("wisdom"/VBG teeth → NN); after a subject
81
+ // pronoun it is a finite verb ("as they bicycle/VBG through" → VBP,
82
+ // which keeps "through" a phrasal particle in the parse). With no
83
+ // deciding context, leave the tag alone (en-parse treats VBG
84
+ // verb-ishly, the safer default).
85
+ if (out[i] === 'VBG' && !/in[g'’]?$/.test(w)) {
86
+ const prevTag = i > 0 ? out[i - 1] : '';
87
+ const nextTag = i + 1 < tokens.length ? out[i + 1] : '';
88
+ if (/^NNS?$/.test(nextTag))
89
+ out[i] = 'NN';
90
+ else if (prevTag === 'PRP')
91
+ out[i] = 'VBP';
92
+ }
93
+ // 5. Vocative "O" ("O wild West Wind"): en-pos gives NNP/JJ; it is an
94
+ // interjection (and must not become a content word with a beat by
95
+ // default). Only the bare capital O — "o'er" etc. are handled by the
96
+ // aphaeresis lexicon in stress.ts.
97
+ if (tokens[i] === 'O' && i + 1 < tokens.length && out[i] !== 'UH')
98
+ out[i] = 'UH';
99
+ }
100
+ return out;
101
+ }
package/dist/display.d.ts CHANGED
@@ -28,11 +28,5 @@ export interface ReadingStanza {
28
28
  * the rest of the line. No original character is ever dropped.
29
29
  */
30
30
  export declare function projectStressOntoLine(rawLine: string, words: ClsWord[]): string;
31
- /**
32
- * Reading view: the poem itself in its original formatting, each syllable
33
- * coloured by 4-tier relative stress, followed by a same-structure block of
34
- * per-line stress maps + meter (with top-3 fit scores). This is the whole
35
- * output for this mode — not the full per-line analytic dump.
36
- */
37
31
  export declare function renderReadingView(stanzas: ReadingStanza[]): string;
38
32
  //# sourceMappingURL=display.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EAMP,UAAU,EAGX,MAAM,YAAY,CAAC;AAqJpB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAkPjF;AAMD,wBAAgB,YAAY,IAAI,MAAM,CAUrC;AAuHD;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAsBzC;AAqCD,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAmCD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAuC/E;AAmMD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CAsDlE"}
1
+ {"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EAMP,UAAU,EAGX,MAAM,YAAY,CAAC;AAgNpB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAySjF;AAMD,wBAAgB,YAAY,IAAI,MAAM,CAUrC;AAuHD;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAsBzC;AAqCD,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAmCD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAuC/E;AA2OD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CA0FlE"}