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.
- package/README.md +32 -20
- package/dist/caesura.d.ts +33 -0
- package/dist/caesura.d.ts.map +1 -0
- package/dist/caesura.js +202 -0
- package/dist/calliope/boundaries.d.ts +19 -0
- package/dist/calliope/boundaries.d.ts.map +1 -0
- package/dist/calliope/boundaries.js +182 -0
- package/dist/calliope/bracketing.d.ts +11 -0
- package/dist/calliope/bracketing.d.ts.map +1 -0
- package/dist/calliope/bracketing.js +416 -0
- package/dist/calliope/deps.d.ts +4 -0
- package/dist/calliope/deps.d.ts.map +1 -0
- package/dist/calliope/deps.js +181 -0
- package/dist/calliope/engine.d.ts +3 -0
- package/dist/calliope/engine.d.ts.map +1 -0
- package/dist/calliope/engine.js +71 -0
- package/dist/calliope/feats.d.ts +9 -0
- package/dist/calliope/feats.d.ts.map +1 -0
- package/dist/calliope/feats.js +45 -0
- package/dist/calliope/names.d.ts +7 -0
- package/dist/calliope/names.d.ts.map +1 -0
- package/dist/calliope/names.js +42 -0
- package/dist/calliope/postag.d.ts +8 -0
- package/dist/calliope/postag.d.ts.map +1 -0
- package/dist/calliope/postag.js +250 -0
- package/dist/calliope/prosodic.d.ts +3 -0
- package/dist/calliope/prosodic.d.ts.map +1 -0
- package/dist/calliope/prosodic.js +275 -0
- package/dist/calliope/relstress.d.ts +4 -0
- package/dist/calliope/relstress.d.ts.map +1 -0
- package/dist/calliope/relstress.js +688 -0
- package/dist/calliope/stressrules.d.ts +28 -0
- package/dist/calliope/stressrules.d.ts.map +1 -0
- package/dist/calliope/stressrules.js +147 -0
- package/dist/calliope/syntax.d.ts +38 -0
- package/dist/calliope/syntax.d.ts.map +1 -0
- package/dist/calliope/syntax.js +234 -0
- package/dist/calliope/udpos.d.ts +13 -0
- package/dist/calliope/udpos.d.ts.map +1 -0
- package/dist/calliope/udpos.js +156 -0
- package/dist/clio/caesura.d.ts +27 -0
- package/dist/clio/caesura.d.ts.map +1 -0
- package/dist/clio/caesura.js +148 -0
- package/dist/clio/depfix.d.ts +13 -0
- package/dist/clio/depfix.d.ts.map +1 -0
- package/dist/clio/depfix.js +84 -0
- package/dist/clio/display.d.ts +32 -0
- package/dist/clio/display.d.ts.map +1 -0
- package/dist/clio/display.js +976 -0
- package/dist/clio/engine.d.ts +3 -0
- package/dist/clio/engine.d.ts.map +1 -0
- package/dist/clio/engine.js +28 -0
- package/dist/clio/parser.d.ts +10 -0
- package/dist/clio/parser.d.ts.map +1 -0
- package/dist/clio/parser.js +696 -0
- package/dist/clio/phonological.d.ts +41 -0
- package/dist/clio/phonological.d.ts.map +1 -0
- package/dist/clio/phonological.js +788 -0
- package/dist/clio/phrasestress.d.ts +6 -0
- package/dist/clio/phrasestress.d.ts.map +1 -0
- package/dist/clio/phrasestress.js +106 -0
- package/dist/clio/pipeline.d.ts +11 -0
- package/dist/clio/pipeline.d.ts.map +1 -0
- package/dist/clio/pipeline.js +147 -0
- package/dist/clio/rhyme.d.ts +65 -0
- package/dist/clio/rhyme.d.ts.map +1 -0
- package/dist/clio/rhyme.js +761 -0
- package/dist/clio/scandroid.d.ts +17 -0
- package/dist/clio/scandroid.d.ts.map +1 -0
- package/dist/clio/scandroid.js +435 -0
- package/dist/clio/scansion.d.ts +46 -0
- package/dist/clio/scansion.d.ts.map +1 -0
- package/dist/clio/scansion.js +1086 -0
- package/dist/clio/semantics.d.ts +44 -0
- package/dist/clio/semantics.d.ts.map +1 -0
- package/dist/clio/semantics.js +139 -0
- package/dist/clio/stress.d.ts +83 -0
- package/dist/clio/stress.d.ts.map +1 -0
- package/dist/clio/stress.js +1737 -0
- package/dist/clio/tagfix.d.ts +6 -0
- package/dist/clio/tagfix.d.ts.map +1 -0
- package/dist/clio/tagfix.js +101 -0
- package/dist/display.d.ts +0 -6
- package/dist/display.d.ts.map +1 -1
- package/dist/display.js +322 -141
- package/dist/engine.d.ts +9 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +12 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -26
- package/dist/parser.d.ts +3 -3
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +320 -563
- package/dist/phonological.d.ts +1 -1
- package/dist/phonological.d.ts.map +1 -1
- package/dist/phonological.js +73 -4
- package/dist/phrasestress.d.ts +6 -0
- package/dist/phrasestress.d.ts.map +1 -0
- package/dist/phrasestress.js +106 -0
- package/dist/rhyme.d.ts +40 -1
- package/dist/rhyme.d.ts.map +1 -1
- package/dist/rhyme.js +435 -7
- package/dist/scansion.d.ts +9 -0
- package/dist/scansion.d.ts.map +1 -1
- package/dist/scansion.js +145 -18
- package/dist/semantics.d.ts +44 -0
- package/dist/semantics.d.ts.map +1 -0
- package/dist/semantics.js +139 -0
- package/dist/stress.d.ts +127 -4
- package/dist/stress.d.ts.map +1 -1
- package/dist/stress.js +834 -61
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/caesura.ts +201 -0
- package/src/calliope/boundaries.ts +190 -0
- package/src/calliope/bracketing.ts +390 -0
- package/src/calliope/deps.ts +160 -0
- package/src/calliope/engine.ts +77 -0
- package/src/calliope/feats.ts +46 -0
- package/src/calliope/names.ts +44 -0
- package/src/calliope/postag.ts +253 -0
- package/src/calliope/prosodic.ts +262 -0
- package/src/calliope/relstress.ts +645 -0
- package/src/calliope/stressrules.ts +147 -0
- package/src/calliope/syntax.ts +218 -0
- package/src/calliope/udpos.ts +152 -0
- package/src/calliope_src_contents.md +19049 -0
- package/src/clio/caesura.ts +145 -0
- package/src/clio/depfix.ts +88 -0
- package/src/clio/display.ts +1042 -0
- package/src/clio/engine.ts +38 -0
- package/src/clio/parser.ts +845 -0
- package/src/clio/phonological.ts +849 -0
- package/src/clio/phrasestress.ts +108 -0
- package/src/clio/pipeline.ts +154 -0
- package/src/clio/rhyme.ts +740 -0
- package/src/clio/scandroid.ts +434 -0
- package/src/clio/scansion.ts +1130 -0
- package/src/clio/semantics.ts +134 -0
- package/src/clio/stress.ts +1731 -0
- package/src/clio/tagfix.ts +104 -0
- package/src/display.ts +321 -137
- package/src/engine.ts +22 -0
- package/src/index.ts +176 -32
- package/src/parser.ts +346 -682
- package/src/phonological.ts +72 -4
- package/src/phrasestress.ts +108 -0
- package/src/rhyme.ts +428 -8
- package/src/scansion.ts +136 -15
- package/src/semantics.ts +134 -0
- package/src/stress.ts +794 -64
- package/src/types.ts +39 -4
- package/tests/DataForHayesLinesOnly.txt +364 -0
- package/tests/DataForHayesStressSymbolsRevised.txt +728 -0
- package/tests/basic.test.ts +443 -37
- package/tests/bench-hayes.mjs +72 -0
- package/tests/wagner-stress.test.ts +188 -0
- 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
|
+
}
|