calliope-ts 0.0.2 → 0.0.3
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 +3 -13
- 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/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,88 @@
|
|
|
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
|
+
}
|