@chaffjs/lang-en 0.5.0 → 0.7.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.
- package/README.md +1 -1
- package/dist/citation.d.ts +15 -0
- package/dist/citation.d.ts.map +1 -0
- package/dist/citation.js +79 -0
- package/dist/citation.js.map +1 -0
- package/dist/definitions.d.ts +5 -0
- package/dist/definitions.d.ts.map +1 -0
- package/dist/definitions.js +33 -0
- package/dist/definitions.js.map +1 -0
- package/dist/depth.d.ts +4 -0
- package/dist/depth.d.ts.map +1 -0
- package/dist/depth.js +4 -0
- package/dist/depth.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reference-list.d.ts +7 -0
- package/dist/reference-list.d.ts.map +1 -0
- package/dist/reference-list.js +56 -0
- package/dist/reference-list.js.map +1 -0
- package/dist/roman.d.ts +3 -0
- package/dist/roman.d.ts.map +1 -0
- package/dist/roman.js +10 -0
- package/dist/roman.js.map +1 -0
- package/dist/structure.d.ts +3 -0
- package/dist/structure.d.ts.map +1 -0
- package/dist/structure.js +359 -0
- package/dist/structure.js.map +1 -0
- package/package.json +1 -1
- package/src/citation.ts +85 -0
- package/src/definitions.ts +43 -0
- package/src/depth.ts +3 -0
- package/src/index.ts +2 -0
- package/src/reference-list.ts +66 -0
- package/src/roman.ts +9 -0
- package/src/structure.ts +393 -0
package/README.md
CHANGED
|
@@ -7,6 +7,6 @@ It provides:
|
|
|
7
7
|
- Sentence splitting (handles `Dr.`, `e.g.`, `U.S.`, `$3.50` without breaking the sentence)
|
|
8
8
|
- L2 lexicons (empty intensifiers, padded openings, cliched closings)
|
|
9
9
|
|
|
10
|
-
To add a language: official adapters are `@chaffjs
|
|
10
|
+
To add a language: official adapters are `@chaffjs/lang-<lang>`, third-party ones are `chaff-lang-<lang>` — the same split as `@typescript-eslint/*` and `eslint-plugin-*`.
|
|
11
11
|
|
|
12
12
|
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ListMember = {
|
|
2
|
+
readonly start: number;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The members after a reference, "2" and "9" in "Sections 1, 2 and 9". After a plural ("Sections") every listed number
|
|
7
|
+
* is one; after a singular ("Section 3 and 4 days") only one where the list goes on or ends.
|
|
8
|
+
*/
|
|
9
|
+
export declare const listMembers: (rest: string, plural: boolean) => ListMember[];
|
|
10
|
+
/**
|
|
11
|
+
* The document named right after a reference, or undefined when the reference is into this document.
|
|
12
|
+
* "of this Agreement" and "of the Agreement" are this document; "of the Master Agreement" is another.
|
|
13
|
+
*/
|
|
14
|
+
export declare const citedDocumentAfter: (text: string, end: number) => string | undefined;
|
|
15
|
+
//# sourceMappingURL=citation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation.d.ts","sourceRoot":"","sources":["../src/citation.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAmB3E;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,QAAQ,OAAO,KAAG,UAAU,EAGtB,CAAC;AA2BjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,GAAG,SAUvE,CAAC"}
|
package/dist/citation.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// A reference into another document: "Section 9 of the Master Agreement" is not this document's Section 9.
|
|
2
|
+
const OF = /^,? of (?:the |that |those )?/u;
|
|
3
|
+
/** "section 4(2)(a) (exception to liability …) of the Damages (Scotland) Act 2011": the gloss sits between the number and the name. */
|
|
4
|
+
const GLOSS = /^ \([^()]{1,100}\)/u;
|
|
5
|
+
const CONNECTOR = /^(?:,? (?:to|and|or)|,) /u;
|
|
6
|
+
/** "9", "29(2)", "(g)", and a roman "V" for a list of Articles. The roman numeral must end the word: "VIII", not "Vendor". */
|
|
7
|
+
const LISTED_NUMBERS = [/^\d{1,3}[A-Z]{0,2}(?:\([a-z0-9]{1,4}\))*/u, /^(?:\([a-z0-9]{1,4}\))+/u, /^[IVXLC]{1,7}\b/u];
|
|
8
|
+
const listedNumber = (text) => LISTED_NUMBERS.map((pattern) => pattern.exec(text)?.[0]).find((found) => found !== undefined);
|
|
9
|
+
/**
|
|
10
|
+
* A listed number is a reference only where the list goes on or ends: "Sections 1, 2 and 9 of" or "Section 3 and 4." —
|
|
11
|
+
* not "Section 3 and 4 days", where the 4 counts days.
|
|
12
|
+
*/
|
|
13
|
+
const MEMBER_END = /^(?:$|[,;.:)]|\s(?:to|and|or|of)\b|\s\()/u;
|
|
14
|
+
/** Every number listed after a reference, with where it ends. `start` is from the start of `rest`. */
|
|
15
|
+
const listed = (rest) => {
|
|
16
|
+
const found = [];
|
|
17
|
+
let end = 0;
|
|
18
|
+
for (;;) {
|
|
19
|
+
const connector = CONNECTOR.exec(rest.slice(end))?.[0];
|
|
20
|
+
const number = connector === undefined ? undefined : listedNumber(rest.slice(end + connector.length));
|
|
21
|
+
if (connector === undefined || number === undefined)
|
|
22
|
+
return found;
|
|
23
|
+
const start = end + connector.length;
|
|
24
|
+
end = start + number.length;
|
|
25
|
+
found.push({ start, text: number, end });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/** "Article 58(2)(c) to (g) and (j) of the UK GDPR": the list runs on to the name that governs all of it. */
|
|
29
|
+
const listEnd = (rest) => listed(rest).at(-1)?.end ?? 0;
|
|
30
|
+
/**
|
|
31
|
+
* The members after a reference, "2" and "9" in "Sections 1, 2 and 9". After a plural ("Sections") every listed number
|
|
32
|
+
* is one; after a singular ("Section 3 and 4 days") only one where the list goes on or ends.
|
|
33
|
+
*/
|
|
34
|
+
export const listMembers = (rest, plural) => listed(rest)
|
|
35
|
+
.filter((member) => plural || MEMBER_END.test(rest.slice(member.end)))
|
|
36
|
+
.map(({ start, text }) => ({ start, text }));
|
|
37
|
+
const CAPITALISED = /^[A-Z][\w'’-]*/u;
|
|
38
|
+
/**
|
|
39
|
+
* How a document names itself. "Section 3 of the Agreement" in an agreement means this one.
|
|
40
|
+
* "the Act" and "the Code" are left out: a statute calls itself "this Act", and a contract's "the Act" is a law it cites.
|
|
41
|
+
*/
|
|
42
|
+
const SELF = new Set(["Agreement", "Contract", "Terms", "Policy"]);
|
|
43
|
+
/** Words that may sit inside a title: "Code of Federal Regulations". */
|
|
44
|
+
const JOINERS = new Set(["of", "and", "for", "on"]);
|
|
45
|
+
const MAX_WORDS = 8;
|
|
46
|
+
/** Capitalised words from the start of `rest`, allowing a joiner between two of them. Punctuation ends the title. */
|
|
47
|
+
const titleWords = (rest) => {
|
|
48
|
+
const tokens = rest.split(" ");
|
|
49
|
+
const words = [];
|
|
50
|
+
for (let index = 0; index < tokens.length && words.length < MAX_WORDS; index += 1) {
|
|
51
|
+
const token = tokens[index] ?? "";
|
|
52
|
+
const word = CAPITALISED.exec(token)?.[0];
|
|
53
|
+
const joins = word === undefined && words.length > 0 && JOINERS.has(token) && CAPITALISED.test(tokens[index + 1] ?? "");
|
|
54
|
+
if (word === undefined && !joins)
|
|
55
|
+
break;
|
|
56
|
+
words.push(word ?? token);
|
|
57
|
+
if (word !== undefined && word.length < token.length)
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
return words;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The document named right after a reference, or undefined when the reference is into this document.
|
|
64
|
+
* "of this Agreement" and "of the Agreement" are this document; "of the Master Agreement" is another.
|
|
65
|
+
*/
|
|
66
|
+
export const citedDocumentAfter = (text, end) => {
|
|
67
|
+
const rest = text.slice(end, end + 200);
|
|
68
|
+
const afterList = listEnd(rest);
|
|
69
|
+
const listed = afterList + (GLOSS.exec(rest.slice(afterList))?.[0].length ?? 0);
|
|
70
|
+
const of = OF.exec(rest.slice(listed));
|
|
71
|
+
if (of === null)
|
|
72
|
+
return undefined;
|
|
73
|
+
const words = titleWords(rest.slice(listed + of[0].length));
|
|
74
|
+
if (words.length === 0)
|
|
75
|
+
return undefined;
|
|
76
|
+
const name = words.join(" ");
|
|
77
|
+
return words.length === 1 && SELF.has(name) ? undefined : name;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=citation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation.js","sourceRoot":"","sources":["../src/citation.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAE3G,MAAM,EAAE,GAAG,gCAAgC,CAAC;AAC5C,uIAAuI;AACvI,MAAM,KAAK,GAAG,qBAAqB,CAAC;AACpC,MAAM,SAAS,GAAG,2BAA2B,CAAC;AAC9C,8HAA8H;AAC9H,MAAM,cAAc,GAAG,CAAC,2CAA2C,EAAE,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;AAErH,MAAM,YAAY,GAAG,CAAC,IAAY,EAAsB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;AAEzJ;;;GAGG;AACH,MAAM,UAAU,GAAG,2CAA2C,CAAC;AAI/D,sGAAsG;AACtG,MAAM,MAAM,GAAG,CAAC,IAAY,EAA6C,EAAE;IACzE,MAAM,KAAK,GAAqC,EAAE,CAAC;IACnD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,SAAS,CAAC;QACR,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACvD,MAAM,MAAM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;IACxC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,MAAM,GAAG,SAAS,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAChF,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACvC,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Mention } from "chaffjs/plugin";
|
|
2
|
+
export declare const opensDefinitionScope: (text: string) => boolean;
|
|
3
|
+
export declare const definitionScopeDepth: (text: string) => number | undefined;
|
|
4
|
+
export declare const definitions: (text: string) => Mention[];
|
|
5
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAwB9C,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,OAAsC,CAAC;AAE3F,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SACuC,CAAC;AAMrG,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,OAAO,EAS/C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CHAPTER_DEPTH, PART_DEPTH } from "./depth.js";
|
|
2
|
+
// Definitions in English documents, and how far a definition holds.
|
|
3
|
+
const DEFINITIONS = [
|
|
4
|
+
/["“](?<term>[^"”\n]{1,60})["”] (?:means|shall mean|refers to|has the meaning)\b/gu,
|
|
5
|
+
/\((?:the |hereinafter )?["“](?<term>[^"”\n]{1,60})["”]\)/gu,
|
|
6
|
+
/\(hereinafter referred to as ["“](?<term>[^"”\n]{1,60})["”]\)/gu,
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* "In this Part—" and "This section applies where a person ("the seller")…": a statute defines the same word again
|
|
10
|
+
* in the next Part. A Part's definitions are compared within the Part, a section's within the section.
|
|
11
|
+
*/
|
|
12
|
+
const DEFINITION_SCOPE = /\b(?:In this (?:section|subsection|Part|Chapter|Schedule|Article)\b|This (?:section|Part|Chapter) defines\b)/u;
|
|
13
|
+
/** "This section applies where a person ("the seller") …" names a party in parentheses for this section only. */
|
|
14
|
+
const APPLIES = /\bThis section applies\b/u;
|
|
15
|
+
/** "In this Part" and "This Part defines" hold in the Part; "In this Chapter" in the Chapter; the rest in the section. */
|
|
16
|
+
const WIDER_SCOPE = [
|
|
17
|
+
[/\b(?:In this|This) Part\b/u, PART_DEPTH],
|
|
18
|
+
[/\b(?:In this|This) Chapter\b/u, CHAPTER_DEPTH],
|
|
19
|
+
];
|
|
20
|
+
export const opensDefinitionScope = (text) => DEFINITION_SCOPE.test(text);
|
|
21
|
+
export const definitionScopeDepth = (text) => DEFINITION_SCOPE.test(text) ? WIDER_SCOPE.find(([pattern]) => pattern.test(text))?.[1] : undefined;
|
|
22
|
+
/** "has the meaning given in section 3" points at a definition elsewhere instead of making one. */
|
|
23
|
+
const POINTER = /^ has the meaning given (?:in|by)\b/u;
|
|
24
|
+
const isPointer = (text, end) => POINTER.test(text.slice(end - " has the meaning".length));
|
|
25
|
+
export const definitions = (text) => DEFINITIONS.flatMap((pattern) => [...text.matchAll(pattern)].flatMap((match) => {
|
|
26
|
+
const term = match.groups?.["term"];
|
|
27
|
+
if (term === undefined)
|
|
28
|
+
return [];
|
|
29
|
+
const end = match.index + match[0].length;
|
|
30
|
+
const namesAParty = match[0].startsWith("(") && APPLIES.test(text);
|
|
31
|
+
return [{ start: match.index, end, attrs: { term, ...(isPointer(text, end) || namesAParty ? { scope: "local" } : {}) } }];
|
|
32
|
+
}));
|
|
33
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEvD,oEAAoE;AAEpE,MAAM,WAAW,GAAG;IAClB,mFAAmF;IACnF,4DAA4D;IAC5D,iEAAiE;CAClE,CAAC;AAEF;;;GAGG;AACH,MAAM,gBAAgB,GAAG,+GAA+G,CAAC;AACzI,iHAAiH;AACjH,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,0HAA0H;AAC1H,MAAM,WAAW,GAA2C;IAC1D,CAAC,4BAA4B,EAAE,UAAU,CAAC;IAC1C,CAAC,+BAA+B,EAAE,aAAa,CAAC;CACjD,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAsB,EAAE,CACvE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAA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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../src/depth.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,aAAa,KAAK,CAAC"}
|
package/dist/depth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depth.js","sourceRoot":"","sources":["../src/depth.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,eAAe,EAA0B,MAAM,gBAAgB,CAAC;AAoB5F;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,eA8BrB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { split, SentenceSplitterSyntax } from "sentence-splitter";
|
|
2
2
|
import { loadLexicons } from "./lexicons.js";
|
|
3
|
+
import { structure } from "./structure.js";
|
|
3
4
|
import { isReady, prepare, tokenize } from "./pos.js";
|
|
4
5
|
// chaff からは型だけを取る。実行時の値依存を作らない。アダプタは単体で動く。
|
|
5
6
|
const LATIN_LETTER = /[a-z]/giu;
|
|
@@ -46,6 +47,7 @@ export const adapter = {
|
|
|
46
47
|
return [...source.matchAll(LATIN_LETTER)].length / total;
|
|
47
48
|
},
|
|
48
49
|
lexicons: loadLexicons(),
|
|
50
|
+
structure,
|
|
49
51
|
segment: (text) => {
|
|
50
52
|
const sentences = split(text)
|
|
51
53
|
.filter((node) => node.type === SentenceSplitterSyntax.Sentence)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGtD,2CAA2C;AAE3C,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAY,EAAE;IAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC1C,OAAO;QACL,GAAG,QAAQ;QACX,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;KAClJ,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAoB;IACtC,IAAI,EAAE,UAAU;IAChB,EAAE,EAAE,IAAI;IACR,UAAU,EAAE,CAAC;IACb,YAAY,EAAE;QACZ,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,IAAI;QACf,6CAA6C;QAC7C,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,IAAI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+
import type { Mention } from "chaffjs/plugin";
|
|
2
|
+
/**
|
|
3
|
+
* "Sections 1, 2 and 9" → 2 and 9 as references too, with the list's numbering and document (`shared`).
|
|
4
|
+
* `first` is the address of the reference that opens the list, and `end` where it ends in `text`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const membersAfter: (text: string, end: number, first: readonly string[], shared: Readonly<Record<string, string>>, plural: boolean, romanList: boolean) => Mention[];
|
|
7
|
+
//# sourceMappingURL=reference-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-list.d.ts","sourceRoot":"","sources":["../src/reference-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA4C9C;;;GAGG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,KAAK,MAAM,EACX,OAAO,SAAS,MAAM,EAAE,EACxB,QAAQ,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACxC,QAAQ,OAAO,EACf,WAAW,OAAO,KACjB,OAAO,EAUT,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { listMembers } from "./citation.js";
|
|
2
|
+
import { parseRoman } from "./roman.js";
|
|
3
|
+
// The later members of a reference list: "Sections 1, 2 and 9" names Section 9 too.
|
|
4
|
+
/**
|
|
5
|
+
* A member is a number, as in the reference itself ("45A" is not read there either), a roman numeral in a list that
|
|
6
|
+
* began with one ("Articles IV, V and VI"), or only parentheses.
|
|
7
|
+
*/
|
|
8
|
+
const MEMBER = /^(?:(?<main>\d{1,3})|(?<roman>[IVXLC]{1,7}))?(?<parens>(?:\([a-z0-9]{1,4}\))*)$/u;
|
|
9
|
+
const PAREN = /\(([a-z0-9]{1,4})\)/gu;
|
|
10
|
+
const isDigits = (part) => /^\d+$/u.test(part);
|
|
11
|
+
/**
|
|
12
|
+
* The part of the address before that a parenthesised member stands beside: the last one written the same way
|
|
13
|
+
* (digits with digits, letters with letters). 45.3.b and (5) → 45.5; 58.2.c and (g) → 58.2.g. The main number stays.
|
|
14
|
+
*/
|
|
15
|
+
const replaceLast = (previous, parens) => {
|
|
16
|
+
const first = parens[0];
|
|
17
|
+
if (previous === undefined || first === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
const at = previous.findLastIndex((part, index) => index > 0 && isDigits(part) === isDigits(first));
|
|
20
|
+
return at === -1 ? undefined : [...previous.slice(0, at), ...parens];
|
|
21
|
+
};
|
|
22
|
+
/** The main number of a member: digits as written, a roman numeral as its value, but only in a roman list. */
|
|
23
|
+
const mainOf = (groups, romanList) => {
|
|
24
|
+
const roman = groups["roman"];
|
|
25
|
+
if (roman === undefined)
|
|
26
|
+
return groups["main"];
|
|
27
|
+
const value = romanList ? parseRoman(roman) : undefined;
|
|
28
|
+
return value === undefined ? undefined : String(value);
|
|
29
|
+
};
|
|
30
|
+
/** A member's address, from the member before it when it is only parentheses. */
|
|
31
|
+
const addressOf = (member, previous, romanList) => {
|
|
32
|
+
const groups = MEMBER.exec(member)?.groups ?? {};
|
|
33
|
+
const parens = [...(groups["parens"] ?? "").matchAll(PAREN)].map((part) => part[1] ?? "");
|
|
34
|
+
const written = groups["main"] ?? groups["roman"];
|
|
35
|
+
if (written === undefined)
|
|
36
|
+
return replaceLast(previous, parens);
|
|
37
|
+
const main = mainOf(groups, romanList);
|
|
38
|
+
return main === undefined ? undefined : [main, ...parens];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* "Sections 1, 2 and 9" → 2 and 9 as references too, with the list's numbering and document (`shared`).
|
|
42
|
+
* `first` is the address of the reference that opens the list, and `end` where it ends in `text`.
|
|
43
|
+
*/
|
|
44
|
+
export const membersAfter = (text, end, first, shared, plural, romanList) => {
|
|
45
|
+
const mentions = [];
|
|
46
|
+
let previous = first;
|
|
47
|
+
listMembers(text.slice(end), plural).forEach((member) => {
|
|
48
|
+
previous = addressOf(member.text, previous, romanList);
|
|
49
|
+
if (previous === undefined)
|
|
50
|
+
return;
|
|
51
|
+
const start = end + member.start;
|
|
52
|
+
mentions.push({ start, end: start + member.text.length, attrs: { target: previous.join("."), label: member.text, ...shared } });
|
|
53
|
+
});
|
|
54
|
+
return mentions;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=reference-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-list.js","sourceRoot":"","sources":["../src/reference-list.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,oFAAoF;AAEpF;;;GAGG;AACH,MAAM,MAAM,GAAG,kFAAkF,CAAC;AAClG,MAAM,KAAK,GAAG,uBAAuB,CAAC;AAEtC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,GAAG,CAAC,QAAuC,EAAE,MAAyB,EAAwB,EAAE;IAC/G,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACpG,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,8GAA8G;AAC9G,MAAM,MAAM,GAAG,C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AW,EACX,KAAwB,EACxB,MAAwC,EACxC,MAAe,EACf,SAAkB,EACP,EAAE;IACb,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,IAAI,QAAQ,GAAkC,KAAK,CAAC;IACpD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACtD,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACvD,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO;QACnC,MAAM,KAAK,GAAG,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;IAClI,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
package/dist/roman.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roman.d.ts","sourceRoot":"","sources":["../src/roman.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAKlD,CAAC"}
|
package/dist/roman.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const ROMAN = { i: 1, v: 5, x: 10, l: 50, c: 100 };
|
|
2
|
+
/** "IV" → 4, "xii" → 12. Undefined for anything that is not a roman numeral. */
|
|
3
|
+
export const parseRoman = (text) => {
|
|
4
|
+
const values = [...text.toLowerCase()].map((char) => ROMAN[char]);
|
|
5
|
+
if (values.length === 0 || values.some((value) => value === undefined))
|
|
6
|
+
return undefined;
|
|
7
|
+
const known = values.filter((value) => value !== undefined);
|
|
8
|
+
return known.reduce((total, value, index) => ((known[index + 1] ?? 0) > value ? total - value : total + value), 0);
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=roman.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roman.js","sourceRoot":"","sources":["../src/roman.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAqC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAErF,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAsB,EAAE;IAC7D,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACzF,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACrH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2C,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA8XjG,eAAO,MAAM,SAAS,EAAE,iBAUvB,CAAC"}
|