@chaffjs/lang-en 0.34.0 → 0.35.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/dist/citation.d.ts +5 -0
- package/dist/citation.d.ts.map +1 -1
- package/dist/citation.js +21 -1
- package/dist/citation.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/initial-stop.d.ts +27 -0
- package/dist/initial-stop.d.ts.map +1 -0
- package/dist/initial-stop.js +47 -0
- package/dist/initial-stop.js.map +1 -0
- package/dist/item-style.d.ts +5 -2
- package/dist/item-style.d.ts.map +1 -1
- package/dist/item-style.js +31 -6
- package/dist/item-style.js.map +1 -1
- package/dist/law-citation.d.ts +14 -0
- package/dist/law-citation.d.ts.map +1 -0
- package/dist/law-citation.js +58 -0
- package/dist/law-citation.js.map +1 -0
- package/dist/lead-initial.d.ts +5 -0
- package/dist/lead-initial.d.ts.map +1 -0
- package/dist/lead-initial.js +24 -0
- package/dist/lead-initial.js.map +1 -0
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +54 -9
- package/dist/structure.js.map +1 -1
- package/lexicons/abbreviated-label.yaml +2 -0
- package/lexicons/alternative-clause-label.yaml +6 -0
- package/lexicons/capital-phrase.yaml +3 -1
- package/lexicons/case-party-joiner.yaml +7 -0
- package/lexicons/citation-name-connector.yaml +28 -0
- package/lexicons/citation-series.yaml +4 -1
- package/lexicons/common-acronym.yaml +6 -1
- package/lexicons/comparative-baseline.yaml +13 -0
- package/lexicons/conjunction-lookalike.yaml +13 -0
- package/lexicons/definition-scope-lead.yaml +11 -0
- package/lexicons/determiner-after-article.yaml +14 -0
- package/lexicons/enclosing-unit.yaml +14 -0
- package/lexicons/extra-word.yaml +13 -0
- package/lexicons/figure-label-plural.yaml +19 -0
- package/lexicons/figure-number-joiner.yaml +20 -0
- package/lexicons/headnote-heading.yaml +8 -0
- package/lexicons/initial-lead-word.yaml +7 -0
- package/lexicons/link-label-ending.yaml +6 -0
- package/lexicons/list-conjunction.yaml +7 -0
- package/lexicons/name-abbreviation.yaml +21 -0
- package/lexicons/newsletter-issue.yaml +9 -0
- package/lexicons/numbered-division.yaml +4 -1
- package/lexicons/over-general-claim.yaml +11 -0
- package/lexicons/placeholder-division.yaml +7 -0
- package/lexicons/prepositive-abbreviation.yaml +10 -0
- package/lexicons/question-wording-lead.yaml +7 -0
- package/lexicons/rejected-wording.yaml +8 -0
- package/lexicons/request-deadline-section.yaml +11 -0
- package/lexicons/request-prohibition.yaml +8 -0
- package/lexicons/sentence-start-word.yaml +64 -0
- package/lexicons/session-law.yaml +19 -0
- package/lexicons/superlative-phrase.yaml +13 -0
- package/lexicons/telling-cue.yaml +6 -0
- package/lexicons/word-suffix.yaml +5 -0
- package/lexicons/wordy-phrase.yaml +2 -2
- package/lexicons/year-reference.yaml +12 -0
- package/package.json +1 -1
- package/src/citation.ts +24 -1
- package/src/index.ts +13 -1
- package/src/initial-stop.ts +80 -0
- package/src/item-style.ts +33 -7
- package/src/law-citation.ts +68 -0
- package/src/lead-initial.ts +28 -0
- package/src/structure.ts +59 -9
package/src/structure.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Mention, NumberedLine, NumberingContext, StructurePatterns } from "chaffjs/plugin";
|
|
2
|
-
import { citedDocumentAfter, citedDocumentBefore, listedTagAround } from "./citation.ts";
|
|
2
|
+
import { citedDocumentAfter, citedDocumentBefore, enclosingUnitAfter, listedTagAround } from "./citation.ts";
|
|
3
3
|
import { citedCodeBefore, codeVocabulary, titledCodeAt } from "./code-citation.ts";
|
|
4
|
+
import { citedLawAround, lawVocabulary } from "./law-citation.ts";
|
|
4
5
|
import { loadLexicons } from "./lexicons.ts";
|
|
5
6
|
import { membersAfter } from "./reference-list.ts";
|
|
6
7
|
import { parseRoman } from "./roman.ts";
|
|
@@ -33,15 +34,48 @@ const titleOf = (rest: string): string | undefined => {
|
|
|
33
34
|
|
|
34
35
|
const ARTICLE = /^\s{0,3}(?:ARTICLE|Article)\s+(?<n>\d{1,3}|[IVXLC]{1,7})\b(?<rest>.*)$/u;
|
|
35
36
|
const SECTION = /^\s{0,3}(?:SECTION|Section|§)\s*(?<n>\d{1,3}(?:\.\d{1,3}){0,5})\b(?<rest>.*)$/u;
|
|
36
|
-
/**
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* "Sec. 3. (a) For confidential…", '#### "SEC. 3. REQUIREMENT OF DISCLOSURE.': an Act or an Executive order set out in a
|
|
39
|
+
* statute's notes numbers its sections with the abbreviation, the number ending in a full stop; an Act quoted in the notes
|
|
40
|
+
* opens each paragraph with a quotation mark. "Sec. 552 - Public information" (a citation header) has no full stop.
|
|
41
|
+
*/
|
|
42
|
+
const ABBREVIATED_SECTION = /^\s{0,3}["“]?(?:SECTION|Section|SEC\.|Sec\.)\s*(?<n>\d{1,3}(?:\.\d{1,3}){0,5})\.(?=\s|$)(?<rest>.*)$/u;
|
|
43
|
+
/**
|
|
44
|
+
* "(a) text", "(ii) text", "(B) text", or the label alone on its line with the text below it. A US statute joins a
|
|
45
|
+
* subsection's label to its first paragraph's ("(c)(1) Whenever…"): the rest then starts with the next label. A
|
|
46
|
+
* repealed item keeps its place in brackets ("[(D) Repealed. …]").
|
|
47
|
+
*/
|
|
48
|
+
const LETTERED = new RegExp(
|
|
49
|
+
`^\\s{0,6}\\[?\\((?<n>[a-z]{1,4}|[A-Z]{1,4}|\\d{1,3}|${INSERTED})\\)(?:\\s+(?<rest>\\S.*)|(?<joined>\\([^()\\s]{1,5}\\)\\s*\\S.*))?\\s*$`,
|
|
50
|
+
"u",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* "Sec. 4. General Provisions. (a) Nothing in this order…": a title run in before the first item of the section's own list.
|
|
55
|
+
* The rest then starts with that label, which opens the item as a joined label does. A title is a few words spaced as
|
|
56
|
+
* words are, with no sentence in it: a wider gap is a page flattened into one line ("ARTICLE II EFFECT… Section 2.1
|
|
57
|
+
* Effect… (a)"), and "At the Effective Time, … thereof: (a) Each share" is the section's text, not its title.
|
|
58
|
+
*/
|
|
59
|
+
const RUN_IN_FIRST_ITEM = /^(?<title>\S+(?: \S+){0,11}?[.:]) (?<item>\([a1]\)\s+\p{Lu}.*)$/u;
|
|
60
|
+
/** A lowercase word ending a sentence or a clause: "thereof: ", "Time. ". "U.S.C. " and "No. " end in capitals. */
|
|
61
|
+
const SENTENCE_END = /\p{Ll}[.:;] /u;
|
|
62
|
+
/** "(a) Prior to… (b) Each…": the next item on the same line is a list flattened into one paragraph, not one item. */
|
|
63
|
+
const NEXT_RUN_IN = /[.;:] \([b2]\) \p{Lu}/u;
|
|
64
|
+
|
|
65
|
+
const titleAndRest = (heading: string): { readonly heading: string; readonly rest: string } => {
|
|
66
|
+
const title = RUN_IN_FIRST_ITEM.exec(heading)?.groups?.["title"];
|
|
67
|
+
const item = title === undefined ? undefined : heading.slice(title.length + 1);
|
|
68
|
+
if (title === undefined || item === undefined || SENTENCE_END.test(title) || NEXT_RUN_IN.test(item)) return { heading, rest: heading };
|
|
69
|
+
return { heading: title, rest: item };
|
|
70
|
+
};
|
|
38
71
|
|
|
39
72
|
const headed = (pattern: RegExp, line: string, numbering: string, label: (n: string) => string): NumberedLine | undefined => {
|
|
40
73
|
const groups = pattern.exec(line)?.groups;
|
|
41
74
|
const number = numberOf(groups?.["n"]);
|
|
42
|
-
const
|
|
43
|
-
if (groups === undefined || number === undefined ||
|
|
75
|
+
const title = titleOf(groups?.["rest"] ?? "");
|
|
76
|
+
if (groups === undefined || number === undefined || title === undefined) return undefined;
|
|
44
77
|
const parts = number.split(".");
|
|
78
|
+
const { heading, rest } = titleAndRest(title);
|
|
45
79
|
return {
|
|
46
80
|
kind: "article",
|
|
47
81
|
depth: parts.length,
|
|
@@ -49,7 +83,7 @@ const headed = (pattern: RegExp, line: string, numbering: string, label: (n: str
|
|
|
49
83
|
absolute: true,
|
|
50
84
|
label: label(groups["n"] ?? ""),
|
|
51
85
|
heading,
|
|
52
|
-
rest
|
|
86
|
+
rest,
|
|
53
87
|
ordinal: Number(parts.at(-1)),
|
|
54
88
|
numbering,
|
|
55
89
|
};
|
|
@@ -59,9 +93,12 @@ const lettered = (line: string, context: NumberingContext): NumberedLine | undef
|
|
|
59
93
|
const groups = LETTERED.exec(line)?.groups;
|
|
60
94
|
const raw = groups?.["n"];
|
|
61
95
|
if (groups === undefined || raw === undefined) return undefined;
|
|
96
|
+
// "(a)(i) …", "(a)(ii) …": a list that writes its parent's label on every line repeats the open (a), and is its (ii).
|
|
97
|
+
const joined = groups["joined"];
|
|
98
|
+
if (joined !== undefined && context.open.some((open) => open.kind === "item" && open.label === `(${raw})`)) return lettered(joined, context);
|
|
62
99
|
const style = styleOf(raw, context);
|
|
63
100
|
const ordinal = style === undefined ? undefined : ordinalOf(raw, style);
|
|
64
|
-
const rest = groups["rest"];
|
|
101
|
+
const rest = groups["rest"] ?? groups["joined"];
|
|
65
102
|
if (style === undefined || (rest === undefined && !continuesOpen(style, ordinal, context))) return undefined;
|
|
66
103
|
// 番地は書かれたままの "ii" を使う。参照「Section 4.2(a)(ii)」も同じ形で書かれるので、そのまま引ける。
|
|
67
104
|
return {
|
|
@@ -94,6 +131,7 @@ const numbered = (line: string, context: NumberingContext): NumberedLine | undef
|
|
|
94
131
|
chapter(CHAPTER, line, CHAPTER_DEPTH, "ch", "Chapter") ??
|
|
95
132
|
headed(ARTICLE, line, "article", (n) => `Article ${n}`) ??
|
|
96
133
|
headed(SECTION, line, "section", (n) => `Section ${n}`) ??
|
|
134
|
+
headed(ABBREVIATED_SECTION, line, "section", (n) => `Section ${n}`) ??
|
|
97
135
|
lettered(line, context);
|
|
98
136
|
|
|
99
137
|
const REFERENCE = /(?<word>\b[Ss]ections?|\b[Aa]rticles?|§) ?(?<n>\d{1,3}(?:\.\d{1,3}){0,5}|[IVXLC]{1,7})\b/gu;
|
|
@@ -146,6 +184,8 @@ const glossedDocument = (gloss: Gloss): string | undefined => {
|
|
|
146
184
|
|
|
147
185
|
const LEXICONS = loadLexicons();
|
|
148
186
|
const CODES = codeVocabulary(LEXICONS);
|
|
187
|
+
const LAWS = lawVocabulary(LEXICONS);
|
|
188
|
+
const ENCLOSING_UNITS: ReadonlySet<string> = new Set((LEXICONS["enclosing-unit"] ?? []).map((entry) => entry.pattern.toLowerCase()));
|
|
149
189
|
|
|
150
190
|
/** The other document a reference names, or else a bracketed tag that the core checks against the document's list. */
|
|
151
191
|
const citation = (text: string, start: number, end: number, document: string | undefined): Readonly<Record<string, string>> => {
|
|
@@ -154,6 +194,12 @@ const citation = (text: string, start: number, end: number, document: string | u
|
|
|
154
194
|
return citedTag === undefined ? {} : { citedTag };
|
|
155
195
|
};
|
|
156
196
|
|
|
197
|
+
/** "section 552 of this title": the unit of a code the reference says it is in, which the core checks against the tree. */
|
|
198
|
+
const enclosing = (text: string, end: number): Readonly<Record<string, string>> => {
|
|
199
|
+
const withinUnit = enclosingUnitAfter(text, end, ENCLOSING_UNITS);
|
|
200
|
+
return withinUnit === undefined ? {} : { withinUnit };
|
|
201
|
+
};
|
|
202
|
+
|
|
157
203
|
/**
|
|
158
204
|
* "Section 4.2(a)" → 4.2.a, "Article III" → 3. The same addresses the tree gives.
|
|
159
205
|
* "Section 9 of the Master Agreement" and "35 CFR §122" carry the other document's name, and are not looked up in this tree.
|
|
@@ -165,12 +211,16 @@ const references = (text: string): Mention[] => {
|
|
|
165
211
|
if (main === undefined) return [];
|
|
166
212
|
const { parts, end } = subdivisions(text, match.index + match[0].length);
|
|
167
213
|
advance(gloss, text, match.index);
|
|
168
|
-
const cited =
|
|
214
|
+
const cited =
|
|
215
|
+
citedDocumentAfter(text, end) ??
|
|
216
|
+
citedDocumentBefore(text, match.index) ??
|
|
217
|
+
citedCodeBefore(text, match.index, CODES) ??
|
|
218
|
+
citedLawAround(text, match.index, end, LAWS);
|
|
169
219
|
const document = cited ?? glossedDocument(gloss);
|
|
170
220
|
gloss.scanned = Math.max(gloss.scanned, end);
|
|
171
221
|
if (cited !== undefined) gloss.anchors.push({ document: cited, depth: gloss.depth });
|
|
172
222
|
const numbering = /^[Aa]/u.test(match.groups?.["word"] ?? "") ? "article" : "section";
|
|
173
|
-
const shared = { numbering, ...citation(text, match.index, end, document) };
|
|
223
|
+
const shared = { numbering, ...enclosing(text, end), ...citation(text, match.index, end, document) };
|
|
174
224
|
const first = { start: match.index, end, attrs: { target: [main, ...parts].join("."), label: text.slice(match.index, end), ...shared } };
|
|
175
225
|
const [plural, roman] = [(match.groups?.["word"] ?? "").endsWith("s"), /^[IVXLC]+$/u.test(match.groups?.["n"] ?? "")];
|
|
176
226
|
return [first, ...membersAfter(text, end, [main, ...parts], shared, plural, roman)];
|