@chaffjs/lang-en 0.22.0 → 0.24.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.
Files changed (67) hide show
  1. package/dist/browser/package-files.d.ts +6 -0
  2. package/dist/browser/package-files.d.ts.map +1 -0
  3. package/dist/browser/package-files.js +10 -0
  4. package/dist/browser/package-files.js.map +1 -0
  5. package/dist/browser/wink-modules.d.ts +3 -0
  6. package/dist/browser/wink-modules.d.ts.map +1 -0
  7. package/dist/browser/wink-modules.js +7 -0
  8. package/dist/browser/wink-modules.js.map +1 -0
  9. package/dist/dates.d.ts.map +1 -1
  10. package/dist/dates.js +54 -2
  11. package/dist/dates.js.map +1 -1
  12. package/dist/definitions.d.ts.map +1 -1
  13. package/dist/definitions.js +42 -2
  14. package/dist/definitions.js.map +1 -1
  15. package/dist/dictionary.d.ts.map +1 -1
  16. package/dist/dictionary.js +3 -5
  17. package/dist/dictionary.js.map +1 -1
  18. package/dist/lexicons.d.ts.map +1 -1
  19. package/dist/lexicons.js +4 -6
  20. package/dist/lexicons.js.map +1 -1
  21. package/dist/package-files.d.ts +7 -0
  22. package/dist/package-files.d.ts.map +1 -0
  23. package/dist/package-files.js +12 -0
  24. package/dist/package-files.js.map +1 -0
  25. package/dist/pos.d.ts.map +1 -1
  26. package/dist/pos.js +3 -4
  27. package/dist/pos.js.map +1 -1
  28. package/dist/wink-modules.d.ts +5 -0
  29. package/dist/wink-modules.d.ts.map +1 -0
  30. package/dist/wink-modules.js +8 -0
  31. package/dist/wink-modules.js.map +1 -0
  32. package/lexicons/article-sound.yaml +7 -1
  33. package/lexicons/breakdown-gap-joiner.yaml +8 -0
  34. package/lexicons/breakdown-phrase.yaml +11 -0
  35. package/lexicons/change-base.yaml +9 -0
  36. package/lexicons/change-direction-not.yaml +5 -0
  37. package/lexicons/change-direction.yaml +27 -0
  38. package/lexicons/change-target.yaml +6 -0
  39. package/lexicons/company-form.yaml +15 -0
  40. package/lexicons/concrete-deadline.yaml +19 -0
  41. package/lexicons/deadline-permission.yaml +7 -0
  42. package/lexicons/demonstrative-not-opener.yaml +125 -0
  43. package/lexicons/demonstrative-opener.yaml +10 -0
  44. package/lexicons/discount-word.yaml +10 -0
  45. package/lexicons/message-date-field.yaml +8 -0
  46. package/lexicons/party-role.yaml +23 -0
  47. package/lexicons/party-short-name.yaml +7 -0
  48. package/lexicons/quote-attribution.yaml +21 -0
  49. package/lexicons/relative-day.yaml +7 -0
  50. package/lexicons/relative-week.yaml +8 -0
  51. package/lexicons/share-label.yaml +7 -0
  52. package/lexicons/total-phrase.yaml +11 -0
  53. package/lexicons/vague-deadline.yaml +16 -0
  54. package/lexicons/version-lead.yaml +14 -0
  55. package/lexicons/version-range.yaml +20 -0
  56. package/lexicons/year-reference.yaml +52 -0
  57. package/package.json +7 -1
  58. package/src/browser/package-files.ts +15 -0
  59. package/src/browser/wink-modules.ts +9 -0
  60. package/src/browser/wink.d.ts +10 -0
  61. package/src/dates.ts +56 -2
  62. package/src/definitions.ts +49 -2
  63. package/src/dictionary.ts +3 -5
  64. package/src/lexicons.ts +4 -6
  65. package/src/package-files.ts +16 -0
  66. package/src/pos.ts +3 -5
  67. package/src/wink-modules.ts +11 -0
@@ -0,0 +1,19 @@
1
+ # How a time limit stated as a number is written. A sentence holding one has a deadline, and vague-deadline leaves it; the
2
+ # document's count of these sentences is what its vague limits are compared with. "within … days" is a frame: "days" within
3
+ # a few words after "within". A bare unit ("24 hours a day", "on business days") is not a deadline, so units stand only in frames.
4
+ id: concrete-deadline
5
+ language: en
6
+ entries:
7
+ - pattern: within … day
8
+ - pattern: within … hours
9
+ - pattern: within … week
10
+ - pattern: within … month
11
+ - pattern: no later than
12
+ - pattern: business day of
13
+ - pattern: days of
14
+ - pattern: days after
15
+ - pattern: days before
16
+ - pattern: days prior
17
+ - pattern: days following
18
+ - pattern: days from
19
+ - pattern: days' notice
@@ -0,0 +1,7 @@
1
+ # Words that make a sentence a right rather than a duty ("We may promptly suspend your account"). A vague limit in such a
2
+ # sentence sets no deadline anyone must meet, so vague-deadline leaves it.
3
+ id: deadline-permission
4
+ language: en
5
+ entries:
6
+ - pattern: may
7
+ - pattern: can
@@ -0,0 +1,125 @@
1
+ # Openings with This, That or It that do not point back at the sentence before: the document itself ("This Agreement
2
+ # may be modified…", "This section explains…"), an "it" that stands for what follows ("It is worth noting that…"), and a
3
+ # "that" that opens a clause ("That the plan failed is clear"). An "it" before an adjective listed here is read as standing
4
+ # for what follows; one that points back there is missed, never misreported. demonstrative-opener-run does not count a
5
+ # sentence that opens with one.
6
+ id: demonstrative-not-opener
7
+ language: en
8
+ entries:
9
+ - pattern: this agreement
10
+ - pattern: these terms
11
+ - pattern: this document
12
+ - pattern: this section
13
+ - pattern: this subsection
14
+ - pattern: this chapter
15
+ - pattern: this part
16
+ - pattern: this article
17
+ - pattern: this policy
18
+ - pattern: this statement
19
+ - pattern: this notice
20
+ - pattern: this report
21
+ - pattern: this paper
22
+ - pattern: this page
23
+ - pattern: this guide
24
+ - pattern: this memo
25
+ - pattern: this specification
26
+ - pattern: this rfc
27
+ - pattern: this act
28
+ - pattern: this appendix
29
+ - pattern: it should be noted
30
+ - pattern: it seems
31
+ - pattern: it appears
32
+ - pattern: it turns out
33
+ - pattern: it is worth
34
+ - pattern: it was worth
35
+ - pattern: it is important
36
+ - pattern: it was important
37
+ - pattern: it is possible
38
+ - pattern: it was possible
39
+ - pattern: it is impossible
40
+ - pattern: it was impossible
41
+ - pattern: it is necessary
42
+ - pattern: it was necessary
43
+ - pattern: it is likely
44
+ - pattern: it was likely
45
+ - pattern: it is unlikely
46
+ - pattern: it was unlikely
47
+ - pattern: it is clear
48
+ - pattern: it was clear
49
+ - pattern: it is unclear
50
+ - pattern: it was unclear
51
+ - pattern: it is obvious
52
+ - pattern: it was obvious
53
+ - pattern: it is evident
54
+ - pattern: it was evident
55
+ - pattern: it is recommended
56
+ - pattern: it was recommended
57
+ - pattern: it is reasonable
58
+ - pattern: it was reasonable
59
+ - pattern: it is helpful
60
+ - pattern: it was helpful
61
+ - pattern: it is useful
62
+ - pattern: it was useful
63
+ - pattern: it is essential
64
+ - pattern: it was essential
65
+ - pattern: it is difficult
66
+ - pattern: it was difficult
67
+ - pattern: it is easy
68
+ - pattern: it was easy
69
+ - pattern: it is hard
70
+ - pattern: it was hard
71
+ - pattern: it is true
72
+ - pattern: it was true
73
+ - pattern: it is natural
74
+ - pattern: it was natural
75
+ - pattern: it is common
76
+ - pattern: it was common
77
+ - pattern: it is rare
78
+ - pattern: it was rare
79
+ - pattern: it is advisable
80
+ - pattern: it was advisable
81
+ - pattern: it is better
82
+ - pattern: it was better
83
+ - pattern: it is best
84
+ - pattern: it was best
85
+ - pattern: it is enough
86
+ - pattern: it was enough
87
+ - pattern: it is fair
88
+ - pattern: it was fair
89
+ - pattern: it is safe
90
+ - pattern: it was safe
91
+ - pattern: it is tempting
92
+ - pattern: it was tempting
93
+ - pattern: it is interesting
94
+ - pattern: it was interesting
95
+ - pattern: it is surprising
96
+ - pattern: it was surprising
97
+ - pattern: it is known
98
+ - pattern: it was known
99
+ - pattern: it is expected
100
+ - pattern: it was expected
101
+ - pattern: it is assumed
102
+ - pattern: it was assumed
103
+ - pattern: it is noted
104
+ - pattern: it was noted
105
+ - pattern: it's worth
106
+ - pattern: that the
107
+ - pattern: that a
108
+ - pattern: that an
109
+ - pattern: that it
110
+ - pattern: that this
111
+ - pattern: that these
112
+ - pattern: that there
113
+ - pattern: that we
114
+ - pattern: that they
115
+ - pattern: that he
116
+ - pattern: that she
117
+ - pattern: that i
118
+ - pattern: that you
119
+ - pattern: that our
120
+ - pattern: that their
121
+ - pattern: that such
122
+ - pattern: that no
123
+ - pattern: that any
124
+ - pattern: that some
125
+ - pattern: that all
@@ -0,0 +1,10 @@
1
+ # Sentence-opening words that point back (This, That, These, Those, It). demonstrative-opener-run counts the sentences in
2
+ # a row, in one paragraph, that open with one of these.
3
+ id: demonstrative-opener
4
+ language: en
5
+ entries:
6
+ - pattern: This
7
+ - pattern: That
8
+ - pattern: These
9
+ - pattern: Those
10
+ - pattern: It
@@ -0,0 +1,10 @@
1
+ # Words just before an amount that take it off a total ("a discount of $10"). total-mismatch subtracts it when it adds the items of a total in a sentence.
2
+ id: discount-word
3
+ language: en
4
+ entries:
5
+ - pattern: discount
6
+ - pattern: credit
7
+ - pattern: less
8
+ - pattern: minus
9
+ - pattern: deduction
10
+ - pattern: rebate
@@ -0,0 +1,8 @@
1
+ # The field at the head of an email or minutes that gives its date (relative-date-mismatch): "Date: Tuesday, October 6, 2026".
2
+ # "next Monday" and "tomorrow" are counted from that date.
3
+ id: message-date-field
4
+ language: en
5
+ entries:
6
+ - pattern: Date
7
+ - pattern: Sent
8
+ - pattern: When
@@ -0,0 +1,23 @@
1
+ # Role words for a party to a contract. In a document that gave its parties short names, party-role-name points at one of
2
+ # these written instead, unless the document defines it. Words for people who are not parties (subcontractor) are left out.
3
+ id: party-role
4
+ language: en
5
+ entries:
6
+ - pattern: Service Provider
7
+ - pattern: Provider
8
+ - pattern: Supplier
9
+ - pattern: Vendor
10
+ - pattern: Contractor
11
+ - pattern: Customer
12
+ - pattern: Client
13
+ - pattern: Company
14
+ - pattern: Licensor
15
+ - pattern: Licensee
16
+ - pattern: Discloser
17
+ - pattern: Recipient
18
+ - pattern: Disclosing Party
19
+ - pattern: Receiving Party
20
+ - pattern: Buyer
21
+ - pattern: Seller
22
+ - pattern: Purchaser
23
+ - pattern: Operator
@@ -0,0 +1,7 @@
1
+ # Short names a contract gives its parties. A definition of one of these in brackets ("we") is read as naming a party (party-role-name).
2
+ id: party-short-name
3
+ language: en
4
+ entries:
5
+ - pattern: we
6
+ - pattern: us
7
+ - pattern: you
@@ -0,0 +1,21 @@
1
+ # Words that give a quotation to someone. A quotation in the same sentence is then someone's words, not the writer's own
2
+ # or a title (quote-without-source). position: before is a cue that stands before the quotation (according to X, "…"); the others
3
+ # stand on either side (X said, "…" / "…," X said).
4
+ id: quote-attribution
5
+ language: en
6
+ entries:
7
+ - pattern: said
8
+ - pattern: says
9
+ - pattern: once said
10
+ - pattern: wrote
11
+ - pattern: writes
12
+ - pattern: put it
13
+ - pattern: puts it
14
+ - { pattern: according to, position: before }
15
+ - pattern: stated
16
+ - pattern: remarked
17
+ - pattern: famously
18
+ - { pattern: in the words of, position: before }
19
+ - pattern: quoted
20
+ - pattern: argued
21
+ - pattern: observed
@@ -0,0 +1,7 @@
1
+ # Words that count days from the base date (relative-date-mismatch): "tomorrow (October 7)". group is how many days later.
2
+ id: relative-day
3
+ language: en
4
+ entries:
5
+ - { pattern: tomorrow, group: "1" }
6
+ - { pattern: today, group: "0" }
7
+ - { pattern: yesterday, group: "-1" }
@@ -0,0 +1,8 @@
1
+ # Words that count weeks from the week of the base date (relative-date-mismatch): "next Monday". group is how many weeks
2
+ # later (last is -1). Read only right before a weekday (lexicon weekday).
3
+ id: relative-week
4
+ language: en
5
+ entries:
6
+ - { pattern: next, group: "1" }
7
+ - { pattern: this, group: "0" }
8
+ - { pattern: last, group: "-1" }
@@ -1,5 +1,6 @@
1
1
  # Words that name the parts of one whole (they add up to 100%). When a table's header, or the sentence or heading right
2
2
  # above a list or a table, has one of these, its percentages are added and compared with 100%.
3
+ # "made up" and "accounted for" say the same of each part ("A made up 50% of sales, B 30% and C 20%").
3
4
  # "rate" and "percentage" are left out: they also name a rate per row. So is a bare "share" ("share price return").
4
5
  id: share-label
5
6
  language: en
@@ -10,3 +11,9 @@ entries:
10
11
  - pattern: composition
11
12
  - pattern: split
12
13
  - pattern: allocation
14
+ - pattern: made up
15
+ - pattern: make up
16
+ - pattern: makes up
17
+ - pattern: accounted for
18
+ - pattern: account for
19
+ - pattern: accounts for
@@ -0,0 +1,11 @@
1
+ # Words a total amount follows directly in a sentence ("for a total of $9,000"). total-mismatch compares the amount with the
2
+ # sum of the items listed before the words. A total at the start of a list or table line is total-label.
3
+ id: total-phrase
4
+ language: en
5
+ entries:
6
+ - pattern: a total of
7
+ - pattern: total of
8
+ - pattern: totaling
9
+ - pattern: totalling
10
+ - pattern: "in total:"
11
+ - pattern: "total:"
@@ -0,0 +1,16 @@
1
+ # Time limits that leave the deadline to the reader. An obligation written with one of these alone cannot be shown to be met or
2
+ # missed (vague-deadline). "Immediately" means at once and leaves no period, so it is not here.
3
+ id: vague-deadline
4
+ language: en
5
+ entries:
6
+ - pattern: promptly
7
+ - pattern: as soon as practicable
8
+ - pattern: as soon as reasonably practicable
9
+ - pattern: as soon as possible
10
+ - pattern: within a reasonable time
11
+ - pattern: within a reasonable period
12
+ - pattern: without undue delay
13
+ - pattern: in a timely manner
14
+ - pattern: forthwith
15
+ - pattern: without delay
16
+ - pattern: without unreasonable delay
@@ -0,0 +1,14 @@
1
+ # Latin words that, right before a version, say it is the version installed (version-mismatch): "Install version 2.4.0",
2
+ # "release 2.4.0", "install 2.4.0". Any other Latin word there names another program ("Requires Node.js 18.17.0").
3
+ id: version-lead
4
+ language: en
5
+ entries:
6
+ - pattern: version
7
+ - pattern: release
8
+ - pattern: v
9
+ - pattern: install
10
+ - pattern: installs
11
+ - pattern: use
12
+ - pattern: pin
13
+ - pattern: download
14
+ - pattern: get
@@ -0,0 +1,20 @@
1
+ # Words that make a version a bound or a starting point rather than the version installed (version-mismatch): "from 2.3.0",
2
+ # "20.0.0 or later". position is the side of the version the word stands on.
3
+ id: version-range
4
+ language: en
5
+ entries:
6
+ - { pattern: from, position: before }
7
+ - { pattern: before, position: before }
8
+ - { pattern: prior to, position: before }
9
+ - { pattern: until, position: before }
10
+ - { pattern: below, position: before }
11
+ - { pattern: above, position: before }
12
+ - { pattern: at least, position: before }
13
+ - { pattern: or later, position: after }
14
+ - { pattern: or newer, position: after }
15
+ - { pattern: or higher, position: after }
16
+ - { pattern: or above, position: after }
17
+ - { pattern: and later, position: after }
18
+ - { pattern: and above, position: after }
19
+ - { pattern: or earlier, position: after }
20
+ - { pattern: or older, position: after }
@@ -0,0 +1,52 @@
1
+ # Words beside a date that give its year in words. date-without-year does not report a yearless date with one of these
2
+ # next to it: "June 30 of that year" has a year, and "by April 15 each year" or "annually, by October 30" is every year's.
3
+ # An entry stands after the date unless it says before; one before may end a few characters short of the date.
4
+ id: year-reference
5
+ language: en
6
+ entries:
7
+ - pattern: of each year
8
+ position: after
9
+ - pattern: of every year
10
+ position: after
11
+ - pattern: each year
12
+ position: after
13
+ - pattern: every year
14
+ position: after
15
+ - pattern: annually
16
+ position: after
17
+ - pattern: of that year
18
+ position: after
19
+ - pattern: of the same year
20
+ position: after
21
+ - pattern: of the following year
22
+ position: after
23
+ - pattern: of the next year
24
+ position: after
25
+ - pattern: of the previous year
26
+ position: after
27
+ - pattern: of the preceding year
28
+ position: after
29
+ - pattern: of this year
30
+ position: after
31
+ - pattern: of next year
32
+ position: after
33
+ - pattern: of last year
34
+ position: after
35
+ - pattern: of the fiscal year
36
+ position: after
37
+ - pattern: annually
38
+ position: before
39
+ - pattern: each year
40
+ position: before
41
+ - pattern: every year
42
+ position: before
43
+ - pattern: that year
44
+ position: before
45
+ - pattern: the same year
46
+ position: before
47
+ - pattern: this year
48
+ position: before
49
+ - pattern: next year
50
+ position: before
51
+ - pattern: last year
52
+ position: before
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaffjs/lang-en",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "English language adapter for chaff",
5
5
  "license": "MIT",
6
6
  "author": "isamu",
@@ -11,6 +11,12 @@
11
11
  "import": "./dist/index.js"
12
12
  }
13
13
  },
14
+ "browser": {
15
+ "./src/package-files.ts": "./src/browser/package-files.ts",
16
+ "./src/wink-modules.ts": "./src/browser/wink-modules.ts",
17
+ "./dist/package-files.js": "./dist/browser/package-files.js",
18
+ "./dist/wink-modules.js": "./dist/browser/wink-modules.js"
19
+ },
14
20
  "files": [
15
21
  "LICENSE",
16
22
  "README.md",
@@ -0,0 +1,15 @@
1
+ import { packageFiles } from "chaffjs/browser-files";
2
+
3
+ // package-files.ts in a build without a file system: this package's lexicons and word list from memory, rooted at
4
+ // /@chaffjs/lang-en.
5
+
6
+ const files = packageFiles("@chaffjs/lang-en");
7
+
8
+ export const PACKAGE_DIR = files.root;
9
+
10
+ /** Paths here are made only from PACKAGE_DIR and file names, so joining them needs no normalising. */
11
+ export const joinPath = (...parts: readonly string[]): string => parts.join("/");
12
+
13
+ export const readText = (path: string): string => files.readText(path);
14
+
15
+ export const readDir = (path: string): string[] => files.readDir(path);
@@ -0,0 +1,9 @@
1
+ import winkPosTaggerModule from "wink-pos-tagger";
2
+ import winkLexicon from "wink-lexicon/src/lexicon.js";
3
+
4
+ // wink-modules.ts in a bundle: the tagger and its vocabulary bundled. The vocabulary is the module the tagger itself
5
+ // imports, so the bundle holds it once.
6
+
7
+ export const winkPosTagger = (): unknown => winkPosTaggerModule;
8
+
9
+ export const winkLexiconWords = (): unknown => winkLexicon;
@@ -0,0 +1,10 @@
1
+ // wink ships no types. The browser build imports these two CommonJS modules and reads them as unknown.
2
+ declare module "wink-pos-tagger" {
3
+ const factory: unknown;
4
+ export default factory;
5
+ }
6
+
7
+ declare module "wink-lexicon/src/lexicon.js" {
8
+ const words: unknown;
9
+ export default words;
10
+ }
package/src/dates.ts CHANGED
@@ -41,8 +41,61 @@ const monthYear = (text: string, at: number, end: number, month: number): Mentio
41
41
  return { start: before?.start ?? at, end: end + found[0].length, attrs: { value } };
42
42
  };
43
43
 
44
+ /** "March 5", not "March 5.5", "March 5:30" or "March 50". */
45
+ const DAY_AFTER = /^ (?<d>\d{1,2})(?:st|nd|rd|th)?(?![\w%]|[.,:]\d)/u;
46
+ const LAST_DAY = 31;
47
+ /** "Rule 3 May Apply", a title-case heading: "May" before a capitalised word may be the modal, not the month after a day. */
48
+ const MODAL_AFTER = /^May [A-Z]/u;
49
+ /** "SEP 2 form", "MAY 2 servers": a capitalised month with a day and no year is more often a code or a shout than a date. */
50
+ const ALL_CAPS = /^[A-Z]+$/u;
51
+ /** The days listed after the first, "March 5, 6 and 7, 2026": ", 6". */
52
+ const LISTED_DAYS = /^(?:,\s*\d{1,2}(?:st|nd|rd|th)?)*/u;
53
+ const LINK = /^,?\s*(?:[-–—]|to|through|until|till|and|or|&)\s*/u;
54
+ const LEADING_MONTH = /^[A-Z][a-z]{2,8}\.?\s+/u;
55
+ const LATER_DAY = /^\d{1,2}(?:st|nd|rd|th)?/u;
56
+ const TRAILING_MONTH = /^\s+[A-Z][a-z]{2,8}\.?/u;
57
+ const YEAR_NEXT = /^,?\s+\d{4}\b/u;
58
+ const YEAR_LATER_REACH = 60;
59
+
60
+ /** What follows a match of `pattern` at the start of `text`, or `text` itself when `pattern` is optional and absent. */
61
+ const after = (text: string | undefined, pattern: RegExp, optional = false): string | undefined => {
62
+ if (text === undefined) return undefined;
63
+ const found = pattern.exec(text);
64
+ if (found === null) return optional ? text : undefined;
65
+ return text.slice(found[0].length);
66
+ };
67
+
68
+ /**
69
+ * "March 5 – 7, 2026", "5 March to 7 April 2026", "March 5, 6 and 7, 2026": the year written once, at the end of the
70
+ * range or the list, belongs to this date too, so it is not read as one without a year.
71
+ */
72
+ const yearLater = (text: string): boolean => {
73
+ const linked = after(after(text, LISTED_DAYS, true), LINK);
74
+ const day = after(after(linked, LEADING_MONTH, true), LATER_DAY);
75
+ const rest = after(day, TRAILING_MONTH, true);
76
+ return rest !== undefined && YEAR_NEXT.test(rest);
77
+ };
78
+
79
+ /** "2025 Dec 18" and "1872 February 4" (a citation's or an astronomer's order) carry their year in front; "Figure 3 5 May" is no date. */
80
+ const YEAR_OR_NUMBER_BEFORE = /\d,?\s*$/u;
81
+
82
+ const isDay = (day: string): boolean => Number(day) >= 1 && Number(day) <= LAST_DAY;
83
+
84
+ /** "March 5" or "5 March" with no year → 03-05. */
85
+ const monthDay = (text: string, at: number, end: number, month: number): Mention | undefined => {
86
+ const after = DAY_AFTER.exec(text.slice(end, end + 8));
87
+ const afterDay = after?.groups?.["d"];
88
+ const before = afterDay === undefined && !MODAL_AFTER.test(text.slice(at, end + 2)) ? dayBefore(text, at) : undefined;
89
+ const day = afterDay ?? before?.day;
90
+ const start = before?.start ?? at;
91
+ if (day === undefined || !isDay(day) || YEAR_OR_NUMBER_BEFORE.test(text.slice(Math.max(0, start - 6), start))) return undefined;
92
+ const dateEnd = after === null ? end : end + after[0].length;
93
+ if (yearLater(text.slice(dateEnd, dateEnd + YEAR_LATER_REACH))) return undefined;
94
+ return { start, end: dateEnd, attrs: { value: `${pad(String(month))}-${pad(day)}` } };
95
+ };
96
+
44
97
  /**
45
- * A month name alone is not a date: "May" is also the modal verb, so it counts only with a year beside it.
98
+ * A month name alone is not a date: "May" is also the modal verb, so it counts only with a year beside it, or a day.
46
99
  * The month is found first and its neighbours read with anchored patterns, never one long alternation.
47
100
  */
48
101
  const namedDate = (text: string, match: RegExpExecArray): Mention | undefined => {
@@ -51,7 +104,8 @@ const namedDate = (text: string, match: RegExpExecArray): Mention | undefined =>
51
104
  const month = full === 0 ? (ABBREVIATED.get(word) ?? 0) : full;
52
105
  if (month === 0) return undefined;
53
106
  const end = match.index + match[0].length + (full === 0 && text.charAt(match.index + match[0].length) === "." ? 1 : 0);
54
- return monthDayYear(text, match.index, end, month) ?? monthYear(text, match.index, end, month);
107
+ const dated = monthDayYear(text, match.index, end, month) ?? monthYear(text, match.index, end, month);
108
+ return dated ?? (ALL_CAPS.test(match[0]) ? undefined : monthDay(text, match.index, end, month));
55
109
  };
56
110
 
57
111
  const hyphenatedDate = (match: RegExpExecArray): Mention[] => {
@@ -5,7 +5,7 @@ import { CHAPTER_DEPTH, PART_DEPTH } from "./depth.ts";
5
5
 
6
6
  const DEFINITIONS = [
7
7
  /["“](?<term>[^"”\n]{1,60})["”] (?:means|shall mean|refers to|has the meaning)\b/gu,
8
- /\((?:the |hereinafter )?["“](?<term>[^"”\n]{1,60})["”]\)/gu,
8
+ /\((?:the |these |this |hereinafter |each,? an? |collectively,? the )?["“](?<term>[^"”\n]{1,60})["”]\)/gu,
9
9
  /\(hereinafter referred to as ["“](?<term>[^"”\n]{1,60})["”]\)/gu,
10
10
  ];
11
11
 
@@ -34,7 +34,51 @@ const isPointer = (text: string, end: number): boolean => POINTER.test(text.slic
34
34
  /** ("Seller") has no word that says it defines: the same parentheses quote an example ("silently fails"). */
35
35
  const BARE = /^\(["“]/u;
36
36
 
37
- export const definitions = (text: string): Mention[] =>
37
+ /**
38
+ * A bracket that gives one thing several names: ("Pinecone", "we" or "us"), (the "Company", "we", "us", or "our"). The
39
+ * first name is the inline definition (it follows the long name); the others are defined there too.
40
+ */
41
+ const BRACKET = /\((?<inside>[^()\n]{1,300})\)/gu;
42
+ const QUOTED_NAME = /["“](?<term>[^"”\n]{1,60})["”]/gu;
43
+ /** What may come before the first name: (the "Company", (each, a "Party", (collectively, the "Parties". */
44
+ const LIST_LEAD = /^(?:the |collectively,? the |each,? an? )?$/u;
45
+ /** What may come between two names: a comma, and or or, and the. */
46
+ const LIST_JOINT = /^(?:, (?:and |or )?| and | or )(?:the )?$/u;
47
+ /** A list of names starts with a capitalised one ("Pinecone"); ("mine", "not mine", "yours") quotes examples. */
48
+ const CAPITALISED = /^\p{Lu}/u;
49
+
50
+ type QuotedName = { readonly term: string; readonly start: number; readonly end: number };
51
+
52
+ /** The quoted names of a bracket that holds nothing but two or more names, joined as a list; otherwise none. */
53
+ const namesInList = (inside: string): QuotedName[] => {
54
+ const names = [...inside.matchAll(QUOTED_NAME)].map((match) => ({
55
+ term: match.groups?.["term"] ?? "",
56
+ start: match.index,
57
+ end: match.index + match[0].length,
58
+ }));
59
+ const [first] = names;
60
+ if (first === undefined || names.length < 2 || !CAPITALISED.test(first.term) || !LIST_LEAD.test(inside.slice(0, first.start))) return [];
61
+ const joined = names.slice(1).every((name, index) => LIST_JOINT.test(inside.slice(names[index]?.end ?? 0, name.start)));
62
+ return joined && inside.slice(names.at(-1)?.end ?? 0) === "" ? names : [];
63
+ };
64
+
65
+ /**
66
+ * A bracket that gives one thing several names: ("Pinecone", "we" or "us"), (the "Company", "we", "us", or "our"). The
67
+ * first name is the inline definition (it follows the long name); the others are defined there too.
68
+ */
69
+ const nameListDefinitions = (text: string): Mention[] =>
70
+ [...text.matchAll(BRACKET)].flatMap((match) => {
71
+ const inside = match.groups?.["inside"] ?? "";
72
+ const bare = BARE.test(match[0]) ? { form: "bare" } : {};
73
+ const scope = APPLIES.test(text) ? { scope: "local" } : {};
74
+ return namesInList(inside).map((name, index) => {
75
+ const start = index === 0 ? match.index : match.index + 1 + name.start;
76
+ const end = index === 0 ? match.index + match[0].length : match.index + 1 + name.end;
77
+ return { start, end, attrs: { term: name.term, ...scope, ...(index === 0 ? { placement: "inline" } : {}), ...bare } };
78
+ });
79
+ });
80
+
81
+ const patternDefinitions = (text: string): Mention[] =>
38
82
  DEFINITIONS.flatMap((pattern) =>
39
83
  [...text.matchAll(pattern)].flatMap((match) => {
40
84
  const term = match.groups?.["term"];
@@ -47,3 +91,6 @@ export const definitions = (text: string): Mention[] =>
47
91
  return [{ start: match.index, end, attrs: { term, ...scope, ...(inline ? { placement: "inline" } : {}), ...bare } }];
48
92
  }),
49
93
  );
94
+
95
+ export const definitions = (text: string): Mention[] =>
96
+ [...patternDefinitions(text), ...nameListDefinitions(text)].toSorted((left, right) => left.start - right.start);
package/src/dictionary.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { readFileSync } from "node:fs";
2
- import { fileURLToPath } from "node:url";
3
- import { dirname, join } from "node:path";
1
+ import { PACKAGE_DIR, joinPath, readText } from "./package-files.ts";
4
2
 
5
3
  // The English word list (lexicons/dictionary.txt, built by scripts/en-dictionary.ts). It is large, so it is read only
6
4
  // when a rule asks for it, and once.
7
5
 
8
- const FILE = join(dirname(fileURLToPath(import.meta.url)), "..", "lexicons", "dictionary.txt");
6
+ const FILE = joinPath(PACKAGE_DIR, "lexicons", "dictionary.txt");
9
7
 
10
8
  const loaded: { words: ReadonlySet<string> | undefined } = { words: undefined };
11
9
 
@@ -14,7 +12,7 @@ const wordsIn = (text: string): ReadonlySet<string> => new Set(text.split("\n").
14
12
  export const dictionary = (): ReadonlySet<string> => {
15
13
  if (loaded.words !== undefined) return loaded.words;
16
14
  try {
17
- loaded.words = wordsIn(readFileSync(FILE, "utf8"));
15
+ loaded.words = wordsIn(readText(FILE));
18
16
  } catch (error) {
19
17
  throw new Error(`${FILE}: cannot read the English word list`, { cause: error });
20
18
  }
package/src/lexicons.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { readFileSync, readdirSync } from "node:fs";
2
- import { fileURLToPath } from "node:url";
3
- import { dirname, join } from "node:path";
4
1
  import { parse } from "yaml";
5
2
  import type { Lexicon, LexiconEntry } from "chaffjs/plugin";
3
+ import { PACKAGE_DIR, joinPath, readDir, readText } from "./package-files.ts";
6
4
 
7
- const DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "lexicons");
5
+ const DIR = joinPath(PACKAGE_DIR, "lexicons");
8
6
 
9
7
  const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value);
10
8
 
@@ -32,10 +30,10 @@ const toEntry = (raw: unknown): LexiconEntry | undefined => {
32
30
  */
33
31
  export const loadLexicons = (dir: string = DIR): Record<string, Lexicon> =>
34
32
  Object.fromEntries(
35
- readdirSync(dir)
33
+ readDir(dir)
36
34
  .filter((file) => file.endsWith(".yaml"))
37
35
  .flatMap((file): [string, Lexicon][] => {
38
- const raw: unknown = parse(readFileSync(join(dir, file), "utf8"));
36
+ const raw: unknown = parse(readText(joinPath(dir, file)));
39
37
  if (!isRecord(raw) || typeof raw["id"] !== "string" || !Array.isArray(raw["entries"])) return [];
40
38
  return [[raw["id"], raw["entries"].map(toEntry).filter((entry) => entry !== undefined)]];
41
39
  }),