@chaffjs/lang-en 0.35.0 → 0.36.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/citation.d.ts.map +1 -1
  2. package/dist/citation.js +8 -2
  3. package/dist/citation.js.map +1 -1
  4. package/dist/names-read-as-verbs.d.ts +21 -0
  5. package/dist/names-read-as-verbs.d.ts.map +1 -0
  6. package/dist/names-read-as-verbs.js +40 -0
  7. package/dist/names-read-as-verbs.js.map +1 -0
  8. package/dist/pos.d.ts.map +1 -1
  9. package/dist/pos.js +30 -1
  10. package/dist/pos.js.map +1 -1
  11. package/dist/structure.d.ts.map +1 -1
  12. package/dist/structure.js +13 -0
  13. package/dist/structure.js.map +1 -1
  14. package/lexicons/ai-tell.yaml +61 -27
  15. package/lexicons/announcing-opener.yaml +7 -0
  16. package/lexicons/article-sound.yaml +1 -0
  17. package/lexicons/citation-series.yaml +1 -0
  18. package/lexicons/clause-conjunction.yaml +7 -0
  19. package/lexicons/closing-cliche.yaml +9 -0
  20. package/lexicons/closing-exhortation.yaml +11 -0
  21. package/lexicons/cold-open.yaml +30 -0
  22. package/lexicons/common-acronym.yaml +15 -0
  23. package/lexicons/comparative-baseline.yaml +14 -0
  24. package/lexicons/condition-heading.yaml +21 -0
  25. package/lexicons/connective-opener.yaml +23 -0
  26. package/lexicons/contraction-head.yaml +10 -0
  27. package/lexicons/contrast-amount.yaml +13 -0
  28. package/lexicons/contrast-lead.yaml +23 -0
  29. package/lexicons/contrast-turn.yaml +5 -0
  30. package/lexicons/drug-stem.yaml +48 -0
  31. package/lexicons/elision-mark.yaml +9 -0
  32. package/lexicons/email-closing.yaml +7 -1
  33. package/lexicons/email-salutation-end.yaml +7 -0
  34. package/lexicons/email-stock-courtesy.yaml +29 -0
  35. package/lexicons/everyday-name.yaml +24 -0
  36. package/lexicons/extra-word.yaml +15 -1
  37. package/lexicons/honorific.yaml +3 -0
  38. package/lexicons/indefinite-article.yaml +8 -0
  39. package/lexicons/intent-phrase.yaml +21 -0
  40. package/lexicons/interviewer-mark.yaml +10 -0
  41. package/lexicons/list-continues.yaml +9 -0
  42. package/lexicons/name-capitals-prefix.yaml +16 -0
  43. package/lexicons/name-direction-word.yaml +10 -0
  44. package/lexicons/name-title-head.yaml +23 -0
  45. package/lexicons/name-word-ending.yaml +10 -0
  46. package/lexicons/navigation-line.yaml +11 -0
  47. package/lexicons/open-list-end.yaml +10 -0
  48. package/lexicons/over-general-claim.yaml +57 -6
  49. package/lexicons/padded-intro.yaml +14 -0
  50. package/lexicons/product-name.yaml +9 -0
  51. package/lexicons/prohibition-opener.yaml +6 -0
  52. package/lexicons/superlative-goal.yaml +40 -0
  53. package/lexicons/superlative-part.yaml +22 -0
  54. package/lexicons/superlative-phrase.yaml +8 -0
  55. package/lexicons/superlative-purpose.yaml +7 -0
  56. package/lexicons/superlative-referent.yaml +15 -0
  57. package/lexicons/superlative-scope.yaml +5 -1
  58. package/lexicons/template-heading.yaml +35 -0
  59. package/lexicons/text-message-verb.yaml +11 -0
  60. package/lexicons/uninflected-word.yaml +22 -0
  61. package/lexicons/unprompted-denial.yaml +113 -0
  62. package/lexicons/word-suffix.yaml +29 -1
  63. package/package.json +1 -1
  64. package/src/citation.ts +9 -2
  65. package/src/names-read-as-verbs.ts +65 -0
  66. package/src/pos.ts +33 -1
  67. package/src/structure.ts +14 -0
@@ -0,0 +1,9 @@
1
+ # Product names that end in capitals (Adobe Acrobat Reader DC). The capitals are the edition's name inside the product's,
2
+ # not an acronym the writer spells out. Only the whole name is matched, as written: DC alone stays an acronym.
3
+ id: product-name
4
+ language: en
5
+ entries:
6
+ - pattern: Acrobat Reader DC
7
+ - pattern: Acrobat Pro DC
8
+ - pattern: Acrobat Standard DC
9
+ - pattern: Acrobat DC
@@ -0,0 +1,6 @@
1
+ # Words that open a prohibition before a noun (No calls, No food in the lab). list-item-form-mix reads a list item opening
2
+ # with one as neither a verb nor a noun phrase: it is a rule, as "Never feed animals" is. Matched in lower case.
3
+ id: prohibition-opener
4
+ language: en
5
+ entries:
6
+ - pattern: "no"
@@ -0,0 +1,40 @@
1
+ # Verbs that take a superlative as what is sought or chosen, not as what is claimed: "to achieve the best results",
2
+ # "before deciding the best way", "identify which font was the most legible", "start with the most important tasks". They stand before the superlative, at most
3
+ # a few words away in the same clause. unqualified-superlative does not report a superlative they govern.
4
+ id: superlative-goal
5
+ language: en
6
+ entries:
7
+ - pattern: achieve
8
+ position: before
9
+ - pattern: attain
10
+ position: before
11
+ - pattern: reach
12
+ position: before
13
+ - pattern: come to
14
+ position: before
15
+ - pattern: arrive at
16
+ position: before
17
+ - pattern: aim for
18
+ position: before
19
+ - pattern: strive for
20
+ position: before
21
+ - pattern: decide
22
+ position: before
23
+ - pattern: determine
24
+ position: before
25
+ - pattern: choose
26
+ position: before
27
+ - pattern: select
28
+ position: before
29
+ - pattern: pick
30
+ position: before
31
+ - pattern: identify
32
+ position: before
33
+ - pattern: start with
34
+ position: before
35
+ - pattern: begin with
36
+ position: before
37
+ - pattern: prioritize
38
+ position: before
39
+ - pattern: prioritise
40
+ position: before
@@ -0,0 +1,22 @@
1
+ # Nouns that name a part of something the text describes. A superlative whose noun is one of them ranks the parts of that
2
+ # whole ("the most important part of the formula", "the customer is the most important role" in a workshop), not the
3
+ # world: the set is the whole's parts. English only: the noun follows the superlative's modifiers.
4
+ id: superlative-part
5
+ language: en
6
+ entries:
7
+ - pattern: part
8
+ - pattern: parts
9
+ - pattern: role
10
+ - pattern: roles
11
+ - pattern: step
12
+ - pattern: steps
13
+ - pattern: aspect
14
+ - pattern: aspects
15
+ - pattern: element
16
+ - pattern: elements
17
+ - pattern: component
18
+ - pattern: components
19
+ - pattern: stage
20
+ - pattern: stages
21
+ - pattern: phase
22
+ - pattern: phases
@@ -1,5 +1,7 @@
1
1
  # Set phrases that hold a superlative but claim nothing is the best. A superlative inside one is not reported by
2
2
  # unqualified-superlative. "Even the best" concedes ("even the best teams slip"); "the best case" is a hypothetical.
3
+ # "Make the most of" and "do the most good" are idioms of effort; "the most recent" places in time; "the most common"
4
+ # reports how often something occurs; "the most important thing" orders the writer's own points.
3
5
  id: superlative-phrase
4
6
  language: en
5
7
  entries:
@@ -11,3 +13,9 @@ entries:
11
13
  - pattern: even with the best
12
14
  - pattern: the best case
13
15
  - pattern: the best-case
16
+ - pattern: make the most of
17
+ - pattern: get the most out of
18
+ - pattern: do the most good
19
+ - pattern: the most recent
20
+ - pattern: the most common
21
+ - pattern: the most important thing
@@ -0,0 +1,7 @@
1
+ # Words after a superlative's noun that name its set only when a gerund follows: "the most important tool for creating
2
+ # the culture" (tools for creating it), "the most prominent intervention for combating misinformation". "For" with a
3
+ # noun ("the best opportunity for government") names who gains, not a set.
4
+ id: superlative-purpose
5
+ language: en
6
+ entries:
7
+ - pattern: for
@@ -0,0 +1,15 @@
1
+ # Words that point at one member of a set, after a superlative subject and its verb: "The best plan is the one you will
2
+ # keep", "The most important divergence is the second". The sentence says which one is the most, not that something is.
3
+ id: superlative-referent
4
+ language: en
5
+ entries:
6
+ - pattern: one
7
+ - pattern: ones
8
+ - pattern: first
9
+ - pattern: second
10
+ - pattern: third
11
+ - pattern: last
12
+ - pattern: former
13
+ - pattern: latter
14
+ - pattern: whichever
15
+ - pattern: whatever
@@ -1,6 +1,6 @@
1
1
  # Words that say what a superlative is the most of. position is the side of the superlative they stand on.
2
2
  # English puts them after the superlative's noun phrase, with a noun phrase after them: "the best pizza in Chicago",
3
- # "the most famous of the sculptures".
3
+ # "the most famous of the sculptures", "the best thing about this gathering", "the best models at the frontier".
4
4
  id: superlative-scope
5
5
  language: en
6
6
  entries:
@@ -8,3 +8,7 @@ entries:
8
8
  position: after
9
9
  - pattern: of
10
10
  position: after
11
+ - pattern: about
12
+ position: after
13
+ - pattern: at
14
+ position: after
@@ -0,0 +1,35 @@
1
+ # The sections of a textbook proposal or report outline. A heading counts for its group when it starts with the pattern
2
+ # (case ignored). One or two are ordinary in a real proposal; ai-structure counts the outline when four groups appear.
3
+ id: template-heading
4
+ language: en
5
+ entries:
6
+ - { pattern: executive summary, group: summary }
7
+ - { pattern: summary, group: summary }
8
+ - { pattern: overview, group: summary }
9
+ - { pattern: background, group: background }
10
+ - { pattern: current situation, group: background }
11
+ - { pattern: current state, group: background }
12
+ - { pattern: problem statement, group: background }
13
+ - { pattern: the problem, group: background }
14
+ - { pattern: proposed solution, group: proposal }
15
+ - { pattern: proposal, group: proposal }
16
+ - { pattern: our proposal, group: proposal }
17
+ - { pattern: recommendation, group: proposal }
18
+ - { pattern: recommendations, group: proposal }
19
+ - { pattern: expected benefits, group: benefits }
20
+ - { pattern: benefits, group: benefits }
21
+ - { pattern: expected outcomes, group: benefits }
22
+ - { pattern: expected impact, group: benefits }
23
+ - { pattern: costs, group: costs }
24
+ - { pattern: cost, group: costs }
25
+ - { pattern: budget, group: costs }
26
+ - { pattern: implementation, group: implementation }
27
+ - { pattern: implementation plan, group: implementation }
28
+ - { pattern: timeline, group: implementation }
29
+ - { pattern: rollout, group: implementation }
30
+ - { pattern: risks, group: risks }
31
+ - { pattern: risk, group: risks }
32
+ - { pattern: risks and mitigation, group: risks }
33
+ - { pattern: next steps, group: next }
34
+ - { pattern: conclusion, group: next }
35
+ - { pattern: conclusions, group: next }
@@ -0,0 +1,11 @@
1
+ # Verbs that send a keyword by text message (text GNPCGS to 333111). The capitals between the verb and the short code are
2
+ # a keyword to type as it stands, not an acronym to spell out. Matched as written, in any case.
3
+ id: text-message-verb
4
+ language: en
5
+ entries:
6
+ - pattern: text
7
+ - pattern: texts
8
+ - pattern: texting
9
+ - pattern: txt
10
+ - pattern: reply
11
+ - pattern: replying
@@ -0,0 +1,22 @@
1
+ # Function words that take no ending (word-suffix): a determiner, a pronoun or a conjunction never has a plural or a
2
+ # past. unknown-word does not read "thoses" as "those" + s, so the slip is reported. Only closed-class words are listed;
3
+ # a word that does take an ending in some use (a noun, a verb) never belongs here.
4
+ id: uninflected-word
5
+ language: en
6
+ entries:
7
+ - pattern: although
8
+ - pattern: because
9
+ - pattern: these
10
+ - pattern: those
11
+ - pattern: their
12
+ - pattern: there
13
+ - pattern: thus
14
+ - pattern: unless
15
+ - pattern: where
16
+ - pattern: whether
17
+ - pattern: which
18
+ - pattern: whom
19
+ - pattern: whose
20
+ - pattern: would
21
+ - pattern: could
22
+ - pattern: should
@@ -0,0 +1,113 @@
1
+ # A sentence that denies a premise nobody stated ("This isn't about tooling.", "That's not the point."). Groups as
2
+ # unprompted-denial.ts reads them:
3
+ # open the sentence opens with it, and the next word is a follow word: a denial of what something is
4
+ # follow the word after open ("about", "a", "the", "what"); "It's not ready." negates a fact and is not counted
5
+ # basis a reason in the same sentence: the denial states a fact
6
+ # premise in the previous sentence: the denial answers something the text said ("You might think ...")
7
+ id: unprompted-denial
8
+ language: en
9
+ entries:
10
+ - pattern: this isn't
11
+ group: open
12
+ - pattern: this is not
13
+ group: open
14
+ - pattern: that's not
15
+ group: open
16
+ - pattern: that is not
17
+ group: open
18
+ - pattern: that isn't
19
+ group: open
20
+ - pattern: it's not
21
+ group: open
22
+ - pattern: it is not
23
+ group: open
24
+ - pattern: it isn't
25
+ group: open
26
+ - pattern: these aren't
27
+ group: open
28
+ - pattern: these are not
29
+ group: open
30
+ - pattern: those aren't
31
+ group: open
32
+ - pattern: those are not
33
+ group: open
34
+ - pattern: the point isn't
35
+ group: open
36
+ - pattern: the point is not
37
+ group: open
38
+ - pattern: the goal isn't
39
+ group: open
40
+ - pattern: the goal is not
41
+ group: open
42
+ - pattern: the problem isn't
43
+ group: open
44
+ - pattern: the problem is not
45
+ group: open
46
+ - pattern: the question isn't
47
+ group: open
48
+ - pattern: the question is not
49
+ group: open
50
+ - pattern: the answer isn't
51
+ group: open
52
+ - pattern: the answer is not
53
+ group: open
54
+ - pattern: about
55
+ group: follow
56
+ - pattern: a
57
+ group: follow
58
+ - pattern: an
59
+ group: follow
60
+ - pattern: the
61
+ group: follow
62
+ - pattern: just
63
+ group: follow
64
+ - pattern: only
65
+ group: follow
66
+ - pattern: what
67
+ group: follow
68
+ - pattern: why
69
+ group: follow
70
+ - pattern: how
71
+ group: follow
72
+ - pattern: where
73
+ group: follow
74
+ - pattern: who
75
+ group: follow
76
+ - pattern: my
77
+ group: follow
78
+ - pattern: your
79
+ group: follow
80
+ - pattern: our
81
+ group: follow
82
+ - pattern: their
83
+ group: follow
84
+ - pattern: something
85
+ group: follow
86
+ - pattern: really
87
+ group: follow
88
+ - pattern: simply
89
+ group: follow
90
+ - pattern: merely
91
+ group: follow
92
+ - pattern: because
93
+ group: basis
94
+ - pattern: since
95
+ group: basis
96
+ - pattern: due to
97
+ group: basis
98
+ - pattern: you might think
99
+ group: premise
100
+ - pattern: you may think
101
+ group: premise
102
+ - pattern: people think
103
+ group: premise
104
+ - pattern: some say
105
+ group: premise
106
+ - pattern: it's tempting
107
+ group: premise
108
+ - pattern: assume
109
+ group: premise
110
+ - pattern: myth
111
+ group: premise
112
+ - pattern: misconception
113
+ group: premise
@@ -1,45 +1,64 @@
1
1
  # Endings that make an inflected or derived form of a dictionary word: unknown-word strips the ending (pattern) and
2
2
  # puts the replacement (instead_of, empty when nothing goes back) before looking the stem up. "carried" is "carry",
3
3
  # "stopped" is "stop" (a doubled last consonant is undone too), "baking" is "bake". The dictionary itself is
4
- # dictionary.txt; this list only saves listing every inflected form there.
4
+ # dictionary.txt; this list only saves listing every inflected form there. An ending of group inflection (a plural, a
5
+ # past, a comparative) closes a word: unknown-word takes it on top of a derived word ("operationalises" is
6
+ # "operationalise" + s), never a derived ending on top of it, and never two of them ("oversers" is not "overs" + ers).
5
7
  id: word-suffix
6
8
  language: en
7
9
  entries:
8
10
  - pattern: s
9
11
  instead_of: ""
12
+ group: inflection
10
13
  - pattern: es
11
14
  instead_of: ""
15
+ group: inflection
12
16
  - pattern: ies
13
17
  instead_of: "y"
18
+ group: inflection
14
19
  # The Greek plural: "pneumoconioses" is "pneumoconiosis".
15
20
  - pattern: ses
16
21
  instead_of: "sis"
22
+ group: inflection
17
23
  - pattern: ied
18
24
  instead_of: "y"
25
+ group: inflection
19
26
  - pattern: ed
20
27
  instead_of: ""
28
+ group: inflection
21
29
  - pattern: ed
22
30
  instead_of: "e"
31
+ group: inflection
23
32
  - pattern: ing
24
33
  instead_of: ""
34
+ group: inflection
25
35
  - pattern: ing
26
36
  instead_of: "e"
37
+ group: inflection
27
38
  - pattern: er
28
39
  instead_of: ""
40
+ group: inflection
29
41
  - pattern: er
30
42
  instead_of: "e"
43
+ group: inflection
31
44
  - pattern: ers
32
45
  instead_of: ""
46
+ group: inflection
33
47
  - pattern: ers
34
48
  instead_of: "e"
49
+ group: inflection
35
50
  - pattern: ier
36
51
  instead_of: "y"
52
+ group: inflection
37
53
  - pattern: iest
38
54
  instead_of: "y"
55
+ group: inflection
39
56
  - pattern: est
40
57
  instead_of: ""
58
+ group: inflection
41
59
  - pattern: est
42
60
  instead_of: "e"
61
+ group: inflection
43
62
  # The adjective of a noun: "crunchy" is "crunch", "possessory" is "possessor", "stony" is "stone".
44
63
  - pattern: y
45
64
  instead_of: ""
@@ -87,3 +106,12 @@ entries:
87
106
  instead_of: "ible"
88
107
  - pattern: men
89
108
  instead_of: "man"
109
+ group: inflection
110
+ # The follower of a doctrine and the doctrine: "relativist" is "relativism", "generalism" is "generalist".
111
+ - pattern: ist
112
+ instead_of: "ism"
113
+ - pattern: ism
114
+ instead_of: "ist"
115
+ # The adjective of an -ion noun: "propositional" is "proposition".
116
+ - pattern: ional
117
+ instead_of: "ion"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaffjs/lang-en",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "English language adapter for chaff",
5
5
  "license": "MIT",
6
6
  "author": "isamu",
package/src/citation.ts CHANGED
@@ -100,14 +100,21 @@ const titleWords = (rest: string): string[] => {
100
100
  /** Labels the reference did not take into its address: the "(E)" of "section 552(a)(6)(E) of title 5". */
101
101
  const UNREAD_LABELS = /^(?:\([A-Za-z0-9]{1,4}\))+/u;
102
102
 
103
+ /**
104
+ * "chapter 15 (§401 et seq.) of Title 50": the sections from this one on, glossing the unit before the bracket, which the
105
+ * name after the bracket governs.
106
+ */
107
+ const RUN_ON = /^ et seq\.\)?/u;
108
+
103
109
  /** What follows the "of" after a reference and its list, or undefined when no "of" follows. */
104
110
  const afterOf = (text: string, end: number): string | undefined => {
105
111
  const rest = text.slice(end, end + 200);
106
112
  const unread = UNREAD_LABELS.exec(rest)?.[0].length ?? 0;
107
113
  const afterList = unread + listEnd(rest.slice(unread));
108
114
  const afterGloss = afterList + (GLOSS.exec(rest.slice(afterList))?.[0].length ?? 0);
109
- const of = OF.exec(rest.slice(afterGloss));
110
- return of === null ? undefined : rest.slice(afterGloss + of[0].length);
115
+ const afterRun = afterGloss + (RUN_ON.exec(rest.slice(afterGloss))?.[0].length ?? 0);
116
+ const of = OF.exec(rest.slice(afterRun));
117
+ return of === null ? undefined : rest.slice(afterRun + of[0].length);
111
118
  };
112
119
 
113
120
  /**
@@ -0,0 +1,65 @@
1
+ // A name the tagger reads as a verb or a pronoun because its lower-case spelling is one: AI as the "ai" of ain't, CA as the
2
+ // "ca" of can't, the US as "us", the IS department as "is". The tagger's vocabulary is keyed by the lower-case word, so it
3
+ // cannot tell the two apart; the sentence can.
4
+
5
+ type TaggedWord = { readonly value: string; readonly pos: string; readonly lemma?: string };
6
+
7
+ const CAPITALS = /^\p{Lu}{2,}$/u;
8
+
9
+ /** Penn tags a name is never given: the verb forms, the modal and the personal pronoun. */
10
+ const VERB_OR_PRONOUN = /^(?:VB[DGNPZ]?|MD|PRP)$/u;
11
+
12
+ /** The second half of a negative contraction, as the tagger splits it off (ca|n't). */
13
+ const NEGATION = "n't";
14
+
15
+ export type NameReadings = {
16
+ /** The first halves of a negative contraction, lower case (ai, ca, wo, sha). */
17
+ readonly contractionHeads: ReadonlySet<string>;
18
+ /** Whether a word opens a noun phrase that a verb or a pronoun cannot follow: an article or a possessive. */
19
+ readonly opensNounPhrase: (word: TaggedWord) => boolean;
20
+ };
21
+
22
+ /** A contraction's first half with no n't after it is not the contraction (AI is changing, lives in CA). */
23
+ const isUnpairedContractionHead = (tagged: readonly TaggedWord[], at: number, heads: ReadonlySet<string>): boolean =>
24
+ heads.has((tagged[at]?.value ?? "").toLowerCase()) && tagged[at + 1]?.value.toLowerCase() !== NEGATION;
25
+
26
+ /**
27
+ * Capitals right after an article or a possessive (the US office, our IT team, the company's IS staff) stand where a noun
28
+ * stands. Capitals elsewhere stay as the tagger read them: "I AM here", "it IS done" and "a hurricane DID form" are emphasis,
29
+ * and "That IS correct" opens with a demonstrative, not an article.
30
+ */
31
+ const isCapitalsAfterOpener = (tagged: readonly TaggedWord[], at: number, opensNounPhrase: NameReadings["opensNounPhrase"]): boolean => {
32
+ const previous = tagged[at - 1];
33
+ return CAPITALS.test(tagged[at]?.value ?? "") && previous !== undefined && opensNounPhrase(previous);
34
+ };
35
+
36
+ /** The positions of words the tagger read as a verb or a pronoun that the sentence shows to be names. */
37
+ export const namesReadAsVerbs = (tagged: readonly TaggedWord[], readings: NameReadings): readonly number[] =>
38
+ tagged.flatMap((word, at) =>
39
+ VERB_OR_PRONOUN.test(word.pos) &&
40
+ (isUnpairedContractionHead(tagged, at, readings.contractionHeads) || isCapitalsAfterOpener(tagged, at, readings.opensNounPhrase))
41
+ ? [at]
42
+ : [],
43
+ );
44
+
45
+ const asName = (word: TaggedWord): TaggedWord => ({ value: word.value, pos: "NNP", lemma: word.value.toLowerCase() });
46
+
47
+ /**
48
+ * The sentence read again with each name at `positions` replaced by `placeholder`, a word the tagger does not know: the names
49
+ * become proper nouns, and their neighbours take the tagger's reading of a sentence with a name there (the US team: team is a
50
+ * noun, not a verb after "us"). When the two readings do not line up word for word, only the names change.
51
+ */
52
+ export const rereadAsNames = (
53
+ entries: readonly TaggedWord[],
54
+ again: readonly TaggedWord[],
55
+ positions: readonly number[],
56
+ placeholder: string,
57
+ ): readonly TaggedWord[] => {
58
+ const names = new Set(positions);
59
+ const aligned = again.length === entries.length && again.every((word, at) => word.value === (names.has(at) ? placeholder : entries[at]?.value));
60
+ const source = aligned ? again : entries;
61
+ return source.map((word, at) => {
62
+ const original = entries[at] ?? word;
63
+ return names.has(at) ? asName(original) : { ...word, value: original.value };
64
+ });
65
+ };
package/src/pos.ts CHANGED
@@ -6,6 +6,7 @@ import { capitalisedGuessedVerbsAsNames, isOrdinaryWord, lowercasedAt, properNou
6
6
  import { isStativeParticiple, stativeVocabulary } from "./stative-participle.ts";
7
7
  import { isCapitalisedOrdinaryWord, isEmphasisedAdverb, isEmphasisedWord, isHyphenated, standsAlone } from "./emphasis.ts";
8
8
  import { gerundFeatures } from "./gerund.ts";
9
+ import { namesReadAsVerbs, rereadAsNames, type NameReadings } from "./names-read-as-verbs.ts";
9
10
  import { winkLexiconWords, winkPosTagger, winkWordNet } from "./wink-modules.ts";
10
11
 
11
12
  /** wink は CommonJS で、辞書を同期に持つ。初期化は 130 ms ほど。 */
@@ -164,6 +165,12 @@ const OBJECT_OR_POSSESSIVE = wordsOf("object-or-possessive");
164
165
 
165
166
  const POSSESSIVE_TAG = new Set(["PRP$", "WP$"]);
166
167
 
168
+ const NAME_READINGS: NameReadings = {
169
+ contractionHeads: wordsOf("contraction-head"),
170
+ opensNounPhrase: (word) =>
171
+ ARTICLES.has(word.value.toLowerCase()) || word.pos === "POS" || (word.pos === "PRP$" && !OBJECT_OR_POSSESSIVE.has(word.value.toLowerCase())),
172
+ };
173
+
167
174
  type Features = { features?: Readonly<Record<string, string>> };
168
175
 
169
176
  /** 冠詞(PronType=Art)と所有の語(Poss=Yes)は、名詞の前に一つしか立たない。二つ並ぶ our the platform は書き損じ。 */
@@ -306,10 +313,35 @@ const withSentenceInitialCase = (tagger: Tagger, text: string, entries: readonly
306
313
  return lowered === undefined ? entries : rereadAt(entries, at, tagged(tagger, lowered));
307
314
  };
308
315
 
316
+ /** A word the tagger's vocabulary does not hold. The tagger reads such capitals as a name, as it reads UN. */
317
+ const UNKNOWN_NAME = "XQZ";
318
+
319
+ /** text with each word at positions replaced by UNKNOWN_NAME, found in order as locate finds them. */
320
+ const withUnknownNamesAt = (text: string, entries: readonly Tagged[], positions: readonly number[]): string => {
321
+ const parts: string[] = [];
322
+ let cursor = 0;
323
+ entries.forEach((entry, at) => {
324
+ const start = text.indexOf(entry.value, cursor);
325
+ if (start === -1) return;
326
+ parts.push(text.slice(cursor, start), positions.includes(at) ? UNKNOWN_NAME : entry.value);
327
+ cursor = start + entry.value.length;
328
+ });
329
+ parts.push(text.slice(cursor));
330
+ return parts.join("");
331
+ };
332
+
333
+ /** Names the tagger read as a verb or a pronoun (AI, the US): the sentence is read again with a name the tagger does not know in their place. */
334
+ const withNamesReread = (tagger: Tagger, text: string, entries: readonly Tagged[]): readonly Tagged[] => {
335
+ const positions = namesReadAsVerbs(entries, NAME_READINGS);
336
+ if (positions.length === 0) return entries;
337
+ return rereadAsNames(entries, tagged(tagger, withUnknownNamesAt(text, entries, positions)), positions, UNKNOWN_NAME);
338
+ };
339
+
309
340
  export const tokenize = (text: string): Token[] | undefined => {
310
341
  const tagger = state.ready;
311
342
  if (tagger === undefined) return undefined;
312
343
  // 語は解析させた字(don't)で返す。語彙表の語と同じ字で比べられる。span は本文を指したまま。
313
344
  const words = straightApostrophes(blankLongRuns(text, RUN_LIMIT));
314
- return locate(words, capitalisedGuessedVerbsAsNames(withSentenceInitialCase(tagger, words, tagged(tagger, words)), state.vocabulary, state.senses));
345
+ const read = withNamesReread(tagger, words, tagged(tagger, words));
346
+ return locate(words, capitalisedGuessedVerbsAsNames(withSentenceInitialCase(tagger, words, read), state.vocabulary, state.senses));
315
347
  };
package/src/structure.ts CHANGED
@@ -29,9 +29,23 @@ const numberOf = (text: string | undefined): string | undefined => {
29
29
  const titleOf = (rest: string): string | undefined => {
30
30
  const trimmed = rest.replace(/^[.:\-–—\s]+/u, "").trim();
31
31
  if (trimmed !== "" && /^\p{Ll}/u.test(trimmed)) return undefined;
32
+ if (citesInSentence(rest)) return undefined;
32
33
  return trimmed;
33
34
  };
34
35
 
36
+ /** "(c) is brief", "(a) of the Act, 50 U.S.C.", "(15 USCA § 46), among other things": subdivisions or a bracketed citation. */
37
+ const LEADING_BRACKETS = /^(?:\s*\([^()]{1,40}\))+/u;
38
+
39
+ /**
40
+ * An opinion's paragraph or footnote that opens with a citation ("§ 331, 7 U.S.C. § 1331.", "Section 9(c) is brief…")
41
+ * cites another Act's section: a comma, or a lowercase word, right after the number and its bracketed parts. A heading's
42
+ * title follows its number without one ("Section 5 (Reserved).", "§ 3(a) Definitions").
43
+ */
44
+ const citesInSentence = (rest: string): boolean => {
45
+ const after = rest.replace(LEADING_BRACKETS, "").trimStart();
46
+ return after.startsWith(",") || (after !== rest.trimStart() && /^\p{Ll}/u.test(after));
47
+ };
48
+
35
49
  const ARTICLE = /^\s{0,3}(?:ARTICLE|Article)\s+(?<n>\d{1,3}|[IVXLC]{1,7})\b(?<rest>.*)$/u;
36
50
  const SECTION = /^\s{0,3}(?:SECTION|Section|§)\s*(?<n>\d{1,3}(?:\.\d{1,3}){0,5})\b(?<rest>.*)$/u;
37
51
  /**