@chaffjs/lang-en 0.32.0 → 0.33.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 (50) hide show
  1. package/dist/dates.d.ts.map +1 -1
  2. package/dist/dates.js +35 -3
  3. package/dist/dates.js.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +14 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/list-line.d.ts +12 -0
  9. package/dist/list-line.d.ts.map +1 -0
  10. package/dist/list-line.js +118 -0
  11. package/dist/list-line.js.map +1 -0
  12. package/lexicons/any-year-marker.yaml +6 -1
  13. package/lexicons/article-sound.yaml +3 -0
  14. package/lexicons/attached-instrument-label.yaml +12 -0
  15. package/lexicons/breakdown-partial-word.yaml +8 -0
  16. package/lexicons/caps-convention.yaml +8 -2
  17. package/lexicons/common-acronym.yaml +7 -0
  18. package/lexicons/comparative-baseline.yaml +5 -0
  19. package/lexicons/count-title.yaml +10 -0
  20. package/lexicons/date-stamp-label.yaml +1 -0
  21. package/lexicons/defined-term-pointer.yaml +26 -0
  22. package/lexicons/definition-alternative.yaml +6 -0
  23. package/lexicons/demonstrative-not-opener.yaml +3 -0
  24. package/lexicons/duration-per-period.yaml +18 -0
  25. package/lexicons/extra-word.yaml +37 -1
  26. package/lexicons/figure-scale-joiner.yaml +6 -0
  27. package/lexicons/figure-scale-word.yaml +9 -0
  28. package/lexicons/instruction-verb.yaml +1 -0
  29. package/lexicons/known-misspelling.yaml +8 -0
  30. package/lexicons/list-note-lead.yaml +9 -0
  31. package/lexicons/literal-quote-cue.yaml +16 -0
  32. package/lexicons/memo-header-label.yaml +16 -0
  33. package/lexicons/mention-cue.yaml +15 -0
  34. package/lexicons/named-deadline.yaml +12 -0
  35. package/lexicons/negation-word.yaml +13 -0
  36. package/lexicons/placeholder-word.yaml +5 -0
  37. package/lexicons/requirement-open-condition.yaml +9 -0
  38. package/lexicons/requirement-open-question.yaml +6 -0
  39. package/lexicons/rounded-amount-unit.yaml +9 -0
  40. package/lexicons/self-prefix.yaml +6 -0
  41. package/lexicons/sequence-opener.yaml +17 -0
  42. package/lexicons/side-step-label.yaml +7 -0
  43. package/lexicons/term-mention-cue.yaml +15 -0
  44. package/lexicons/title-cue.yaml +9 -0
  45. package/lexicons/verb-or-adjective.yaml +14 -0
  46. package/lexicons/wordy-phrase.yaml +3 -3
  47. package/package.json +1 -1
  48. package/src/dates.ts +39 -3
  49. package/src/index.ts +16 -3
  50. package/src/list-line.ts +136 -0
@@ -1,11 +1,14 @@
1
1
  # Words in everyday technical and business writing that WordNet does not list. unknown-word reads them as known, with
2
2
  # their endings: function words WordNet leaves out (cannot, wherein, albeit, whilst), Latin phrases in English text
3
- # (a priori, in forma pauperis) and newer coinages (onboard, roadmap, phishing). A team adds its own words under names in chaff.yaml; this list is only for words any document may use.
3
+ # (a priori, in forma pauperis, de minimis), the legal words of contracts (thereunder, herefrom, monies, pendency,
4
+ # cedent, telecopy) and newer coinages (onboard, roadmap, phishing, vishing, ransomware). A team adds its own words
5
+ # under names in chaff.yaml; this list is only for words any document may use.
4
6
  id: extra-word
5
7
  language: en
6
8
  entries:
7
9
  - pattern: accessibility
8
10
  - pattern: admin
11
+ - pattern: adware
9
12
  - pattern: albeit
10
13
  - pattern: alia
11
14
  - pattern: api
@@ -20,9 +23,12 @@ entries:
20
23
  - pattern: bona
21
24
  - pattern: bool
22
25
  - pattern: boolean
26
+ - pattern: botnet
23
27
  - pattern: browser
28
+ - pattern: burnout
24
29
  - pattern: callout
25
30
  - pattern: cannot
31
+ - pattern: cedent
26
32
  - pattern: changelog
27
33
  - pattern: checkbox
28
34
  - pattern: checkout
@@ -31,6 +37,7 @@ entries:
31
37
  - pattern: codebase
32
38
  - pattern: codec
33
39
  - pattern: config
40
+ - pattern: conveniens
34
41
  - pattern: counterparty
35
42
  - pattern: covid
36
43
  - pattern: cron
@@ -42,6 +49,7 @@ entries:
42
49
  - pattern: dedup
43
50
  - pattern: dedupe
44
51
  - pattern: deploy
52
+ - pattern: designee
45
53
  - pattern: dev
46
54
  - pattern: devops
47
55
  - pattern: dialog
@@ -67,6 +75,9 @@ entries:
67
75
  - pattern: hardcode
68
76
  - pattern: hardcoded
69
77
  - pattern: hashtag
78
+ - pattern: hereat
79
+ - pattern: herefrom
80
+ - pattern: hereon
70
81
  - pattern: hostname
71
82
  - pattern: html
72
83
  - pattern: http
@@ -76,12 +87,15 @@ entries:
76
87
  - pattern: inbox
77
88
  - pattern: incentivise
78
89
  - pattern: incentivize
90
+ - pattern: indemnitee
79
91
  - pattern: init
80
92
  - pattern: inline
81
93
  - pattern: interoperability
82
94
  - pattern: interoperable
83
95
  - pattern: json
96
+ - pattern: keylogger
84
97
  - pattern: lest
98
+ - pattern: licensor
85
99
  - pattern: lifecycle
86
100
  - pattern: linter
87
101
  - pattern: localhost
@@ -92,12 +106,16 @@ entries:
92
106
  - pattern: meta
93
107
  - pattern: metadata
94
108
  - pattern: middleware
109
+ - pattern: minimis
95
110
  - pattern: modulo
111
+ - pattern: monies
96
112
  - pattern: multi
97
113
  - pattern: multiplet
98
114
  - pattern: mutex
99
115
  - pattern: namespace
100
116
  - pattern: npm
117
+ - pattern: obligee
118
+ - pattern: obligor
101
119
  - pattern: offline
102
120
  - pattern: offsite
103
121
  - pattern: onboard
@@ -108,8 +126,11 @@ entries:
108
126
  - pattern: params
109
127
  - pattern: parser
110
128
  - pattern: pauperis
129
+ - pattern: payor
111
130
  - pattern: payout
112
131
  - pattern: pdf
132
+ - pattern: pendency
133
+ - pattern: pharming
113
134
  - pattern: phishing
114
135
  - pattern: plaintext
115
136
  - pattern: plugin
@@ -121,23 +142,29 @@ entries:
121
142
  - pattern: prepend
122
143
  - pattern: priori
123
144
  - pattern: quadrupole
145
+ - pattern: quishing
146
+ - pattern: ransomware
124
147
  - pattern: realtime
125
148
  - pattern: refactor
126
149
  - pattern: regex
127
150
  - pattern: regexp
128
151
  - pattern: repo
129
152
  - pattern: reputational
153
+ - pattern: requestor
130
154
  - pattern: roadmap
155
+ - pattern: rootkit
131
156
  - pattern: runtime
132
157
  - pattern: sandbox
133
158
  - pattern: sans
134
159
  - pattern: scalability
160
+ - pattern: scareware
135
161
  - pattern: screenshot
136
162
  - pattern: sdk
137
163
  - pattern: sectoral
138
164
  - pattern: serverless
139
165
  - pattern: signup
140
166
  - pattern: smartphone
167
+ - pattern: smishing
141
168
  - pattern: snowmelt
142
169
  - pattern: soever
143
170
  - pattern: spreadsheet
@@ -149,7 +176,10 @@ entries:
149
176
  - pattern: subproject
150
177
  - pattern: sustainably
151
178
  - pattern: syntax
179
+ - pattern: telecopy
152
180
  - pattern: thenceforward
181
+ - pattern: thereat
182
+ - pattern: thereunder
153
183
  - pattern: thereupon
154
184
  - pattern: timeline
155
185
  - pattern: timestamp
@@ -169,17 +199,23 @@ entries:
169
199
  - pattern: verbatim
170
200
  - pattern: versa
171
201
  - pattern: virtualize
202
+ - pattern: vishing
172
203
  - pattern: vitae
173
204
  - pattern: watersports
174
205
  - pattern: webhook
175
206
  - pattern: webinar
176
207
  - pattern: webpage
177
208
  - pattern: website
209
+ - pattern: whereat
178
210
  - pattern: whereby
211
+ - pattern: wherefrom
179
212
  - pattern: wherein
180
213
  - pattern: whereof
181
214
  - pattern: whereon
215
+ - pattern: whereto
216
+ - pattern: whereunder
182
217
  - pattern: whereupon
218
+ - pattern: wherewith
183
219
  - pattern: whilst
184
220
  - pattern: whitelist
185
221
  - pattern: whither
@@ -0,0 +1,6 @@
1
+ # Words between two numbers with a word of scale that let one unit serve both ("from $1.1 million to 1.3 million"),
2
+ # beyond range-connector and enumeration-joiner. number-without-unit does not read a number joined so as missing its unit.
3
+ id: figure-scale-joiner
4
+ language: en
5
+ entries:
6
+ - pattern: to
@@ -0,0 +1,9 @@
1
+ # Words of scale written right after a number ($83 million, 3 thousand cars). number-without-unit looks for the one
2
+ # number with such a word and no unit (83 million) where the other numbers with that word all carry one.
3
+ id: figure-scale-word
4
+ language: en
5
+ entries:
6
+ - pattern: thousand
7
+ - pattern: million
8
+ - pattern: billion
9
+ - pattern: trillion
@@ -5,6 +5,7 @@ id: instruction-verb
5
5
  language: en
6
6
  entries:
7
7
  - pattern: click
8
+ - pattern: partner
8
9
  - pattern: scroll
9
10
  - pattern: swipe
10
11
  - pattern: toggle
@@ -127,6 +127,11 @@ entries:
127
127
  instead_of: category
128
128
  - pattern: completly
129
129
  instead_of: completely
130
+ # complete + -ment: unknown-word takes it for a derived word, so only this list catches it.
131
+ - pattern: completement
132
+ instead_of: complement
133
+ - pattern: completements
134
+ instead_of: complements
130
135
  - pattern: compatability
131
136
  instead_of: compatibility
132
137
  - pattern: dissapoint
@@ -219,6 +224,9 @@ entries:
219
224
  instead_of: definitely
220
225
  - pattern: desparate
221
226
  instead_of: desperate
227
+ # Denger is a surname, so only the phrase
228
+ - pattern: denger zone
229
+ instead_of: danger zone
222
230
  - pattern: developement
223
231
  instead_of: development
224
232
  - pattern: dilemna
@@ -0,0 +1,9 @@
1
+ # What opens a note line written just under a list without indentation ("Note: documents are not returned."). Markdown
2
+ # reads that line as part of the last item; list-item-form-mix reads the item's form only up to it, since the note is
3
+ # about the whole list, not part of its last item.
4
+ id: list-note-lead
5
+ language: en
6
+ entries:
7
+ - pattern: "Note:"
8
+ - pattern: "NB:"
9
+ - pattern: "N.B."
@@ -0,0 +1,16 @@
1
+ # Words that say a quotation is a string to type as it stands (an e-mail subject, a file name, a title). Its brackets
2
+ # are the string's own and the writer cannot take them out. bracket-nesting counts such a quotation as one bracket when
3
+ # one of these stands right before it (position: before, as in with the subject line “…”) or right after it.
4
+ id: literal-quote-cue
5
+ language: en
6
+ entries:
7
+ - { pattern: subject line, position: before }
8
+ - { pattern: "subject:", position: before }
9
+ - { pattern: the subject, position: before }
10
+ - { pattern: file name, position: before }
11
+ - { pattern: filename, position: before }
12
+ - { pattern: "file name:", position: before }
13
+ - { pattern: named, position: before }
14
+ - { pattern: titled, position: before }
15
+ - pattern: as the subject
16
+ - pattern: as the file name
@@ -0,0 +1,16 @@
1
+ # The labels of a memorandum's header (TO:, FROM:, SUBJECT:), as a memo sets them: in capitals. A label in the header,
2
+ # before the first sentence, followed by a colon or the line's end, makes the document a memo, which takes no greeting
3
+ # and no closing. Matched with case, since a mail program's header writes "To:" and "Subject:".
4
+ id: memo-header-label
5
+ language: en
6
+ entries:
7
+ - pattern: MEMORANDUM
8
+ - pattern: MEMO
9
+ - pattern: TO
10
+ - pattern: FROM
11
+ - pattern: THROUGH
12
+ - pattern: THRU
13
+ - pattern: SUBJECT
14
+ - pattern: RE
15
+ - pattern: DATE
16
+ - pattern: CC
@@ -0,0 +1,15 @@
1
+ # Words that name a phrase as a term rather than use it: when saying "raise the bar", the phrase "low-hanging fruit".
2
+ # group before: right before the phrase (quote marks may stand between). Written forms only: "say" would also take
3
+ # "I'd say the bottom line is", which uses the phrase.
4
+ id: mention-cue
5
+ language: en
6
+ entries:
7
+ - { pattern: saying, group: before }
8
+ - { pattern: the phrase, group: before }
9
+ - { pattern: the term, group: before }
10
+ - { pattern: the expression, group: before }
11
+ - { pattern: the idiom, group: before }
12
+ - { pattern: the cliché, group: before }
13
+ - { pattern: the cliche, group: before }
14
+ - { pattern: the words, group: before }
15
+ - { pattern: so-called, group: before }
@@ -0,0 +1,12 @@
1
+ # Names of a dated deadline (the Due Date, the Payment Date) and the act whose time each sets (group: a timed-duty word). A
2
+ # duty to do that act in the same article (else the same list or paragraph) as its deadline's name is timed by that date, and
3
+ # obligation-without-deadline leaves it: "The Customer shall pay the Fees." beside "Fees not paid by the Due Date bear
4
+ # interest." A date for another act (a delivery date beside a duty to pay) times nothing.
5
+ id: named-deadline
6
+ language: en
7
+ entries:
8
+ - { pattern: due date, group: pay }
9
+ - { pattern: payment date, group: pay }
10
+ - { pattern: payment due date, group: pay }
11
+ - { pattern: delivery date, group: deliver }
12
+ - { pattern: return date, group: return }
@@ -0,0 +1,13 @@
1
+ # Negating words. modal-conflict reads them: a negation inside the act or its condition ("goods that do not conform")
2
+ # is part of what a sentence decides, so two sentences that differ only by it decide different things.
3
+ # Matched by the written form or the lemma, lower-cased. "n't" is the contracted not.
4
+ id: negation-word
5
+ language: en
6
+ entries:
7
+ - pattern: not
8
+ - pattern: n't
9
+ - pattern: no
10
+ - pattern: never
11
+ - pattern: neither
12
+ - pattern: nor
13
+ - pattern: without
@@ -25,6 +25,11 @@ entries:
25
25
  group: marker
26
26
  - pattern: FIXME
27
27
  group: marker
28
+ # group: label — a template's instruction label left in a filled document ("OPTIONAL: General conclusions (bullet
29
+ # points or narrative)"). It counts only written in capitals exactly as here, opening a line before a colon and some
30
+ # text: "Optional: bring a jacket" is a note to the reader, not a template's instruction.
31
+ - pattern: OPTIONAL
32
+ group: label
28
33
  # group: template — a word that, in a heading, says the section is a template ("## Template", "# Sample letter").
29
34
  # Blanks under that heading (to the next heading at its depth or above) are what the template is for, so they are not reported.
30
35
  - pattern: template
@@ -0,0 +1,9 @@
1
+ # Words that state a condition. An open list in brackets right after one ("in other cases (a single-table query, etc.)")
2
+ # gives examples of when the requirement applies, not what it covers. Read by requirement-smell.
3
+ id: requirement-open-condition
4
+ language: en
5
+ entries:
6
+ - pattern: case
7
+ - pattern: cases
8
+ - pattern: when
9
+ - pattern: where
@@ -0,0 +1,6 @@
1
+ # Words of a question that an open list gives example answers to (〜措置など、どのような措置を求めるのか in Japanese). English
2
+ # puts such a list after its question ("state which measures you seek, such as …"), where "such as" is no open-end word,
3
+ # so there are none; the list exists so both languages name the same lists.
4
+ id: requirement-open-question
5
+ language: en
6
+ entries: []
@@ -0,0 +1,9 @@
1
+ # Units of amounts written rounded to a digit ($6,655 million, $3.1 billion). When a total in a sentence and all its items
2
+ # are in one of these, total-mismatch reads a difference of up to (number of items − 1) last digits as rounding.
3
+ id: rounded-amount-unit
4
+ language: en
5
+ entries:
6
+ - pattern: thousand
7
+ - pattern: million
8
+ - pattern: billion
9
+ - pattern: trillion
@@ -0,0 +1,6 @@
1
+ # The word in front of a name that points at this document itself ("this Agreement", "this Policy"). A term the document
2
+ # defines as its own name (this "Agreement") may be written with it before the definition (use-before-definition).
3
+ id: self-prefix
4
+ language: en
5
+ entries:
6
+ - pattern: this
@@ -0,0 +1,17 @@
1
+ # One word that opens a sentence by giving its place in a sequence (First, …; Finally, …). Followed by a comma it is an
2
+ # introduction, not the first item of a list, though the tagger may read First as an adjective. Read by oxford-comma-consistency.
3
+ id: sequence-opener
4
+ language: en
5
+ entries:
6
+ - pattern: first
7
+ - pattern: firstly
8
+ - pattern: second
9
+ - pattern: secondly
10
+ - pattern: third
11
+ - pattern: thirdly
12
+ - pattern: fourth
13
+ - pattern: next
14
+ - pattern: then
15
+ - pattern: last
16
+ - pattern: lastly
17
+ - pattern: finally
@@ -0,0 +1,7 @@
1
+ # Words a step-by-step list writes in place of a step's number, for a step done alongside the one before it
2
+ # ("1 Check the rules", "and Book a courier", "3 Pack the parcel"). Such a step may have taken a number.
3
+ id: side-step-label
4
+ language: en
5
+ entries:
6
+ - pattern: and
7
+ - pattern: or
@@ -0,0 +1,15 @@
1
+ # Words right before an opening quote that name the quoted words as a term: the definition of "Material Adverse Effect",
2
+ # the term "Affiliate". The term is mentioned there, not used, so defined-term-form does not report it as quoted again.
3
+ # Matched without regard to case.
4
+ id: term-mention-cue
5
+ language: en
6
+ entries:
7
+ - pattern: definition of
8
+ - pattern: definitions of
9
+ - pattern: meaning of
10
+ - pattern: the term
11
+ - pattern: the terms
12
+ - pattern: the word
13
+ - pattern: the words
14
+ - pattern: the phrase
15
+ - pattern: defined term
@@ -0,0 +1,9 @@
1
+ # Words that introduce a cited title written without quotes ("whose full title is Protecting Tokens and Assertions from
2
+ # Forgery, Theft, and Misuse"). The run of Title Case words right after one is the title, and its commas are the title
3
+ # author's, so oxford-comma-consistency does not count them as the writer's choice.
4
+ id: title-cue
5
+ language: en
6
+ entries:
7
+ - pattern: title is
8
+ - pattern: titled
9
+ - pattern: entitled
@@ -0,0 +1,14 @@
1
+ # Words that open an instruction (Secure the server, Open the app) and also an adjective before a noun (Secure
2
+ # configuration, Open questions). list-item-form-mix reads a list item opening with one as opening with a verb only when
3
+ # "the", "a" or a possessive follows; otherwise it does not judge the item's first word. Matched in lower case.
4
+ id: verb-or-adjective
5
+ language: en
6
+ entries:
7
+ - pattern: secure
8
+ - pattern: open
9
+ - pattern: clean
10
+ - pattern: clear
11
+ - pattern: close
12
+ - pattern: complete
13
+ - pattern: empty
14
+ - pattern: free
@@ -1,6 +1,8 @@
1
1
  # Wordy phrases: several words where one or two say the same. Read by wordy-phrase; rewrite is the short form.
2
2
  # Only phrases whose short form says the same in every context. "with regard to", "prior to" and "in accordance with"
3
- # are left out: contracts and statutes use them on purpose. Matched as whole words, case aside.
3
+ # are left out: contracts and statutes use them on purpose. "a small number of" is left out too: "a few" names a
4
+ # different count, and minutes use both as separate points of one scale (a few, a small number, some, several, many).
5
+ # Matched as whole words, case aside.
4
6
  id: wordy-phrase
5
7
  language: en
6
8
  entries:
@@ -60,8 +62,6 @@ entries:
60
62
  rewrite: except
61
63
  - pattern: in the majority of cases
62
64
  rewrite: usually
63
- - pattern: a small number of
64
- rewrite: a few
65
65
  - pattern: at an early date
66
66
  rewrite: soon
67
67
  - pattern: by means of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaffjs/lang-en",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "English language adapter for chaff",
5
5
  "license": "MIT",
6
6
  "author": "isamu",
package/src/dates.ts CHANGED
@@ -13,6 +13,33 @@ const ISO_DATE = /\b(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})\b/gu;
13
13
  const DAY_BEFORE = /(?<d>\d{1,2})(?:st|nd|rd|th)? $/u;
14
14
  const DAY_YEAR_AFTER = /^ (?<d>\d{1,2})(?:st|nd|rd|th)?,? (?<y>\d{4})\b/u;
15
15
  const YEAR_AFTER = /^,? (?<y>\d{4})\b/u;
16
+ /** "Mar 28 14:02:11 UTC 2024", the form of `date` and C's ctime: the year comes after the time and its zone. */
17
+ const DAY_TIME_YEAR_AFTER = /^ (?<d>\d{1,2}) (?:[01]?\d|2[0-3]):[0-5]\d(?::[0-5]\d)?(?: (?!AM\b|PM\b)[A-Z]{2,5})? (?<y>\d{4})\b/u;
18
+ const TIME_YEAR_REACH = 32;
19
+ /** A time zone or "hrs" after four figures: "1300 UTC", "0930 PST", "1300 hrs". */
20
+ const ZONE_WORDS: ReadonlySet<string> = new Set(
21
+ ["UTC", "GMT", "Z", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", "BST", "IST", "JST", "KST"].concat([
22
+ "CET",
23
+ "CEST",
24
+ "EET",
25
+ "EEST",
26
+ "AEST",
27
+ "AEDT",
28
+ "hrs",
29
+ "hours",
30
+ ]),
31
+ );
32
+ /** The word after the figures, unless it runs on into "&" ("AT&T"). */
33
+ const WORD_AFTER = /^ ?(?<word>[A-Za-z]+)(?![\w&])/u;
34
+ const zoneAfter = (rest: string): boolean => ZONE_WORDS.has(WORD_AFTER.exec(rest)?.groups?.["word"] ?? "");
35
+ const HOURS_IN_DAY = 24;
36
+ const MINUTES_IN_HOUR = 60;
37
+ /** From here on, four figures before a zone may be a year as well as a time ("March 28 2024 UTC"), and stay a year. */
38
+ const MODERN_YEARS_FROM = 1900;
39
+
40
+ /** "Mar 28 1300 UTC": four figures that can only be a 24-hour clock, with a time zone after them, are the time, not the year. */
41
+ const clockTime = (figures: string, rest: string): boolean =>
42
+ Number(figures) < MODERN_YEARS_FROM && Number(figures.slice(0, 2)) < HOURS_IN_DAY && Number(figures.slice(2)) < MINUTES_IN_HOUR && zoneAfter(rest);
16
43
 
17
44
  const pad = (value: string): string => value.padStart(2, "0");
18
45
 
@@ -26,16 +53,25 @@ const dayBefore = (text: string, at: number): { readonly day: string; readonly s
26
53
  /** "April 1, 2024" → 2024-04-01. */
27
54
  const monthDayYear = (text: string, at: number, end: number, month: number): Mention | undefined => {
28
55
  const found = DAY_YEAR_AFTER.exec(text.slice(end, end + 16));
29
- if (found?.groups === undefined) return undefined;
56
+ if (found?.groups === undefined || clockTime(found.groups["y"] ?? "", text.slice(end + found[0].length))) return undefined;
30
57
  const value = `${found.groups["y"] ?? ""}-${pad(String(month))}-${pad(found.groups["d"] ?? "")}`;
31
58
  return { start: at, end: end + found[0].length, attrs: { value } };
32
59
  };
33
60
 
61
+ /** "Mar 28 14:02:11 UTC 2024" → 2024-03-28. The mention ends at the day, so the time stays a time of its own. */
62
+ const monthDayTimeYear = (text: string, at: number, end: number, month: number): Mention | undefined => {
63
+ const found = DAY_TIME_YEAR_AFTER.exec(text.slice(end, end + TIME_YEAR_REACH));
64
+ const day = found?.groups?.["d"];
65
+ if (found?.groups === undefined || day === undefined) return undefined;
66
+ const value = `${found.groups["y"] ?? ""}-${pad(String(month))}-${pad(day)}`;
67
+ return { start: at, end: end + 1 + day.length, attrs: { value } };
68
+ };
69
+
34
70
  /** "1 April 2024" → 2024-04-01, "April 2024" → 2024-04. */
35
71
  const monthYear = (text: string, at: number, end: number, month: number): Mention | undefined => {
36
72
  const found = YEAR_AFTER.exec(text.slice(end, end + 8));
37
73
  const year = found?.groups?.["y"];
38
- if (found === null || year === undefined) return undefined;
74
+ if (found === null || year === undefined || clockTime(year, text.slice(end + found[0].length))) return undefined;
39
75
  const before = dayBefore(text, at);
40
76
  const value = [year, pad(String(month)), ...(before === undefined ? [] : [pad(before.day)])].join("-");
41
77
  return { start: before?.start ?? at, end: end + found[0].length, attrs: { value } };
@@ -104,7 +140,7 @@ const namedDate = (text: string, match: RegExpExecArray): Mention | undefined =>
104
140
  const month = full === 0 ? (ABBREVIATED.get(word) ?? 0) : full;
105
141
  if (month === 0) return undefined;
106
142
  const end = match.index + match[0].length + (full === 0 && text.charAt(match.index + match[0].length) === "." ? 1 : 0);
107
- const dated = monthDayYear(text, match.index, end, month) ?? monthYear(text, match.index, end, month);
143
+ const dated = monthDayYear(text, match.index, end, month) ?? monthYear(text, match.index, end, month) ?? monthDayTimeYear(text, match.index, end, month);
108
144
  return dated ?? (ALL_CAPS.test(match[0]) ? undefined : monthDay(text, match.index, end, month));
109
145
  };
110
146
 
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import { structure } from "./structure.ts";
8
8
  import { dictionary } from "./dictionary.ts";
9
9
  import { isReady, prepare, tokenize } from "./pos.ts";
10
10
  import { isJapaneseRun } from "./japanese-run.ts";
11
+ import { cutAtBreaks, listItemHeads, listLineBreaks, startsListItem } from "./list-line.ts";
11
12
  import type { AdapterNeeds, EmbeddedLanguage, LanguageAdapter, Segmentation, Sentence, Span } from "chaffjs/plugin";
12
13
 
13
14
  // chaff からは型だけを取る。実行時の値依存を作らない。アダプタは単体で動く。
@@ -35,9 +36,22 @@ const JAPANESE: EmbeddedLanguage = { id: "ja", lengthUnit: "char" };
35
36
 
36
37
  const withLanguage = (text: string, span: Span): Sentence => (isJapaneseRun(text) ? { span, text, embeddedLanguage: JAPANESE } : { span, text });
37
38
 
39
+ const asListItem = (sentence: Sentence): Sentence => ({ ...sentence, listItem: true });
40
+
41
+ /** Spans of the splitter, cut again where a line break before a list item ends a sentence. */
42
+ const sentencesOf = (text: string): Sentence[] => {
43
+ const quotedStops = sentenceSpans(unmarkNumberStops(unmarkLabelStops(text, LABEL_STOPS))).flatMap((span) => splitAtQuotedStops(text, span));
44
+ const listBreaks = listLineBreaks(text);
45
+ const itemHeads = listItemHeads(text);
46
+ return reattachClosingQuotes(text, quotedStops)
47
+ .flatMap((span) => cutAtBreaks(span, listBreaks))
48
+ .map((span) => withLanguage(text.slice(span.start, span.end), span))
49
+ .map((sentence) => (startsListItem(itemHeads, sentence.span.start) ? asListItem(sentence) : sentence));
50
+ };
51
+
38
52
  /**
39
53
  * 英語は sentence-splitter の既定にほぼ任せる。"Dr." "e.g." "U.S." "$3.50" を
40
- * いずれも文末と誤認しない。前処理は行の途中の番号を箇条書きと読ませることと、番号の前の略した名前(FIG. 1、Vol. XLIII)の点で切らないこと、後処理は閉じ引用符の内側で閉じた文を切ることと、文頭に取り残された閉じ引用符を前の文へ戻すこと。spec §7.2。
54
+ * いずれも文末と誤認しない。前処理は行の途中の番号を箇条書きと読ませることと、番号の前の略した名前(FIG. 1、Vol. XLIII)の点で切らないこと、後処理は閉じ引用符の内側で閉じた文を切ることと、文頭に取り残された閉じ引用符を前の文へ戻すこと、1 行 1 項目の箇条書きを項目ごとの文に切ること。spec §7.2。
41
55
  */
42
56
  export const adapter: LanguageAdapter = {
43
57
  kind: "language",
@@ -65,8 +79,7 @@ export const adapter: LanguageAdapter = {
65
79
  structure,
66
80
  dictionary,
67
81
  segment: (text: string): Segmentation => {
68
- const quotedStops = sentenceSpans(unmarkNumberStops(unmarkLabelStops(text, LABEL_STOPS))).flatMap((span) => splitAtQuotedStops(text, span));
69
- const sentences: Sentence[] = reattachClosingQuotes(text, quotedStops).map((span) => withLanguage(text.slice(span.start, span.end), span));
82
+ const sentences = sentencesOf(text);
70
83
  return { sentences: isReady() ? sentences.map(withTokens) : sentences };
71
84
  },
72
85
  };