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,104 @@
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
+ }