chaffjs 0.43.0 → 0.44.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 (198) hide show
  1. package/dist/bound-word-particles.d.ts +9 -0
  2. package/dist/bound-word-particles.d.ts.map +1 -0
  3. package/dist/bound-word-particles.js +16 -0
  4. package/dist/bound-word-particles.js.map +1 -0
  5. package/dist/derived/stays.d.ts +0 -1
  6. package/dist/derived/stays.d.ts.map +1 -1
  7. package/dist/derived/stays.js +3 -1
  8. package/dist/derived/stays.js.map +1 -1
  9. package/dist/detectors/absolute-exception.d.ts.map +1 -1
  10. package/dist/detectors/absolute-exception.js +10 -4
  11. package/dist/detectors/absolute-exception.js.map +1 -1
  12. package/dist/detectors/agreement-slip.d.ts +2 -0
  13. package/dist/detectors/agreement-slip.d.ts.map +1 -1
  14. package/dist/detectors/agreement-slip.js +22 -8
  15. package/dist/detectors/agreement-slip.js.map +1 -1
  16. package/dist/detectors/bold-label.d.ts +5 -1
  17. package/dist/detectors/bold-label.d.ts.map +1 -1
  18. package/dist/detectors/bold-label.js +22 -3
  19. package/dist/detectors/bold-label.js.map +1 -1
  20. package/dist/detectors/bold-quoted.d.ts +4 -0
  21. package/dist/detectors/bold-quoted.d.ts.map +1 -0
  22. package/dist/detectors/bold-quoted.js +17 -0
  23. package/dist/detectors/bold-quoted.js.map +1 -0
  24. package/dist/detectors/caps-caption.d.ts +5 -0
  25. package/dist/detectors/caps-caption.d.ts.map +1 -1
  26. package/dist/detectors/caps-caption.js +7 -0
  27. package/dist/detectors/caps-caption.js.map +1 -1
  28. package/dist/detectors/count-per-section.d.ts.map +1 -1
  29. package/dist/detectors/count-per-section.js +7 -4
  30. package/dist/detectors/count-per-section.js.map +1 -1
  31. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  32. package/dist/detectors/defined-term-form.js +2 -1
  33. package/dist/detectors/defined-term-form.js.map +1 -1
  34. package/dist/detectors/emoticon.d.ts +6 -0
  35. package/dist/detectors/emoticon.d.ts.map +1 -0
  36. package/dist/detectors/emoticon.js +19 -0
  37. package/dist/detectors/emoticon.js.map +1 -0
  38. package/dist/detectors/en-shape.d.ts +6 -1
  39. package/dist/detectors/en-shape.d.ts.map +1 -1
  40. package/dist/detectors/en-shape.js +9 -1
  41. package/dist/detectors/en-shape.js.map +1 -1
  42. package/dist/detectors/katakana-density.d.ts +6 -1
  43. package/dist/detectors/katakana-density.d.ts.map +1 -1
  44. package/dist/detectors/katakana-density.js +14 -1
  45. package/dist/detectors/katakana-density.js.map +1 -1
  46. package/dist/detectors/lexicon.d.ts.map +1 -1
  47. package/dist/detectors/lexicon.js +2 -1
  48. package/dist/detectors/lexicon.js.map +1 -1
  49. package/dist/detectors/mark-shape.d.ts +2 -2
  50. package/dist/detectors/mark-shape.d.ts.map +1 -1
  51. package/dist/detectors/mark-shape.js +24 -5
  52. package/dist/detectors/mark-shape.js.map +1 -1
  53. package/dist/detectors/mentioned-phrase.d.ts +3 -1
  54. package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
  55. package/dist/detectors/mentioned-phrase.js +9 -0
  56. package/dist/detectors/mentioned-phrase.js.map +1 -1
  57. package/dist/detectors/number-style.d.ts.map +1 -1
  58. package/dist/detectors/number-style.js +13 -1
  59. package/dist/detectors/number-style.js.map +1 -1
  60. package/dist/detectors/obligation-without-deadline.d.ts +10 -2
  61. package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
  62. package/dist/detectors/obligation-without-deadline.js +47 -2
  63. package/dist/detectors/obligation-without-deadline.js.map +1 -1
  64. package/dist/detectors/open-end-names.d.ts +2 -0
  65. package/dist/detectors/open-end-names.d.ts.map +1 -1
  66. package/dist/detectors/open-end-names.js +8 -1
  67. package/dist/detectors/open-end-names.js.map +1 -1
  68. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  69. package/dist/detectors/orthographic-variant.js +5 -3
  70. package/dist/detectors/orthographic-variant.js.map +1 -1
  71. package/dist/detectors/paragraph-pointer.d.ts +4 -0
  72. package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
  73. package/dist/detectors/paragraph-pointer.js +22 -0
  74. package/dist/detectors/paragraph-pointer.js.map +1 -0
  75. package/dist/detectors/phrase-match.d.ts +4 -1
  76. package/dist/detectors/phrase-match.d.ts.map +1 -1
  77. package/dist/detectors/phrase-match.js +12 -5
  78. package/dist/detectors/phrase-match.js.map +1 -1
  79. package/dist/detectors/redundant-pair.d.ts +5 -0
  80. package/dist/detectors/redundant-pair.d.ts.map +1 -0
  81. package/dist/detectors/redundant-pair.js +18 -0
  82. package/dist/detectors/redundant-pair.js.map +1 -0
  83. package/dist/detectors/registry/redundant-pair.d.ts +3 -0
  84. package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
  85. package/dist/detectors/registry/redundant-pair.js +3 -0
  86. package/dist/detectors/registry/redundant-pair.js.map +1 -0
  87. package/dist/detectors/request-owner.d.ts +1 -0
  88. package/dist/detectors/request-owner.d.ts.map +1 -1
  89. package/dist/detectors/request-owner.js +6 -3
  90. package/dist/detectors/request-owner.js.map +1 -1
  91. package/dist/detectors/structure-tree.d.ts.map +1 -1
  92. package/dist/detectors/structure-tree.js +1 -0
  93. package/dist/detectors/structure-tree.js.map +1 -1
  94. package/dist/detectors/structure.js +3 -3
  95. package/dist/detectors/structure.js.map +1 -1
  96. package/dist/detectors/superlative-context.d.ts +7 -0
  97. package/dist/detectors/superlative-context.d.ts.map +1 -1
  98. package/dist/detectors/superlative-context.js +9 -0
  99. package/dist/detectors/superlative-context.js.map +1 -1
  100. package/dist/detectors/token-shape.d.ts.map +1 -1
  101. package/dist/detectors/token-shape.js +7 -5
  102. package/dist/detectors/token-shape.js.map +1 -1
  103. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  104. package/dist/detectors/unbalanced-bracket.js +2 -1
  105. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  106. package/dist/paragraph-length.d.ts +4 -0
  107. package/dist/paragraph-length.d.ts.map +1 -1
  108. package/dist/paragraph-length.js +6 -0
  109. package/dist/paragraph-length.js.map +1 -1
  110. package/dist/plugin.d.ts +2 -0
  111. package/dist/plugin.d.ts.map +1 -1
  112. package/dist/rule-of-three.d.ts +7 -0
  113. package/dist/rule-of-three.d.ts.map +1 -1
  114. package/dist/rule-of-three.js +22 -1
  115. package/dist/rule-of-three.js.map +1 -1
  116. package/dist/structure/build.d.ts.map +1 -1
  117. package/dist/structure/build.js +2 -1
  118. package/dist/structure/build.js.map +1 -1
  119. package/dist/structure/negated-act.d.ts +1 -0
  120. package/dist/structure/negated-act.d.ts.map +1 -1
  121. package/dist/structure/negated-act.js +1 -1
  122. package/dist/structure/negated-act.js.map +1 -1
  123. package/dist/structure/own-name.d.ts +4 -0
  124. package/dist/structure/own-name.d.ts.map +1 -0
  125. package/dist/structure/own-name.js +20 -0
  126. package/dist/structure/own-name.js.map +1 -0
  127. package/dist/structure/percent-sum-prose.d.ts.map +1 -1
  128. package/dist/structure/percent-sum-prose.js +9 -1
  129. package/dist/structure/percent-sum-prose.js.map +1 -1
  130. package/dist/structure/percent-sum.d.ts +2 -0
  131. package/dist/structure/percent-sum.d.ts.map +1 -1
  132. package/dist/structure/percent-sum.js.map +1 -1
  133. package/dist/structure/reference-text.d.ts.map +1 -1
  134. package/dist/structure/reference-text.js +3 -1
  135. package/dist/structure/reference-text.js.map +1 -1
  136. package/dist/te-form-helper.d.ts +22 -0
  137. package/dist/te-form-helper.d.ts.map +1 -0
  138. package/dist/te-form-helper.js +35 -0
  139. package/dist/te-form-helper.js.map +1 -0
  140. package/dist/word-use.d.ts +7 -0
  141. package/dist/word-use.d.ts.map +1 -1
  142. package/dist/word-use.js +11 -0
  143. package/dist/word-use.js.map +1 -1
  144. package/package.json +3 -3
  145. package/rules/absolute-exception.yaml +3 -3
  146. package/rules/all-caps-shouting.yaml +2 -2
  147. package/rules/bold-label-list.yaml +9 -2
  148. package/rules/duration-mismatch.yaml +2 -2
  149. package/rules/katakana-density.yaml +3 -3
  150. package/rules/no-doubled-joshi.yaml +2 -2
  151. package/rules/number-style-consistency.yaml +2 -2
  152. package/rules/obligation-without-deadline.yaml +2 -2
  153. package/rules/padded-intro.yaml +1 -1
  154. package/rules/redundant-expression.yaml +1 -1
  155. package/rules/request-without-deadline.yaml +2 -2
  156. package/rules/requirement-smell.yaml +2 -2
  157. package/rules/rule-of-three.yaml +2 -2
  158. package/src/bound-word-particles.ts +23 -0
  159. package/src/derived/stays.ts +4 -1
  160. package/src/detectors/absolute-exception.ts +11 -5
  161. package/src/detectors/agreement-slip.ts +35 -10
  162. package/src/detectors/bold-label.ts +25 -4
  163. package/src/detectors/bold-quoted.ts +21 -0
  164. package/src/detectors/caps-caption.ts +10 -0
  165. package/src/detectors/count-per-section.ts +9 -4
  166. package/src/detectors/defined-term-form.ts +2 -1
  167. package/src/detectors/emoticon.ts +21 -0
  168. package/src/detectors/en-shape.ts +10 -1
  169. package/src/detectors/katakana-density.ts +17 -2
  170. package/src/detectors/lexicon.ts +2 -1
  171. package/src/detectors/mark-shape.ts +28 -7
  172. package/src/detectors/mentioned-phrase.ts +13 -1
  173. package/src/detectors/number-style.ts +14 -1
  174. package/src/detectors/obligation-without-deadline.ts +69 -5
  175. package/src/detectors/open-end-names.ts +21 -2
  176. package/src/detectors/orthographic-variant.ts +20 -15
  177. package/src/detectors/paragraph-pointer.ts +28 -0
  178. package/src/detectors/phrase-match.ts +13 -5
  179. package/src/detectors/redundant-pair.ts +25 -0
  180. package/src/detectors/registry/redundant-pair.ts +4 -0
  181. package/src/detectors/request-owner.ts +6 -3
  182. package/src/detectors/structure-tree.ts +1 -0
  183. package/src/detectors/structure.ts +3 -3
  184. package/src/detectors/superlative-context.ts +12 -0
  185. package/src/detectors/token-shape.ts +10 -7
  186. package/src/detectors/unbalanced-bracket.ts +2 -1
  187. package/src/paragraph-length.ts +10 -0
  188. package/src/plugin.ts +2 -0
  189. package/src/rule-of-three.ts +27 -1
  190. package/src/structure/build.ts +2 -1
  191. package/src/structure/negated-act.ts +1 -1
  192. package/src/structure/own-name.ts +28 -0
  193. package/src/structure/percent-sum-prose.ts +12 -1
  194. package/src/structure/percent-sum.ts +2 -0
  195. package/src/structure/reference-text.ts +5 -1
  196. package/src/te-form-helper.ts +52 -0
  197. package/src/word-use.ts +13 -0
  198. package/src/honorific-group.ts +0 -22
@@ -24,6 +24,8 @@ export type AgreementLists = {
24
24
  readonly misnumbered: Lexicon;
25
25
  /** 冠詞の後ろに立たない限定詞(some / the)。 */
26
26
  readonly afterArticle: ReadonlySet<string>;
27
+ /** 名詞句を目的語に取る前置詞(on / of)。この後ろの this / these は主語にならない。 */
28
+ readonly prepositions?: ReadonlySet<string>;
27
29
  };
28
30
 
29
31
  export type Slip = { readonly variant: "number" | "possessive" | "determiner"; readonly first: Token; readonly last: Token; readonly word: string };
@@ -75,9 +77,15 @@ const isNamePart = (tokens: readonly Token[], at: number): boolean => UPPER_STAR
75
77
 
76
78
  const isModifier = (token: Token): boolean => token.pos === "ADJ" || token.pos === "ADV" || (token.pos === "VERB" && isParticiple(token));
77
79
 
78
- /** 限定詞の後ろの修飾語。数の形容詞(a few days)が挟まれば、単数の限定詞でも複数を数えるので undefined。 */
79
- const modifiersAfter = (tokens: readonly Token[], from: number, count: ReadonlySet<string>): readonly Token[] | undefined => {
80
- const end = tokens.findIndex((token, index) => index >= from && !isModifier(token));
80
+ /** 活用した動詞の形(flagged)。限定詞が主語になれない所では、名詞の前の分詞としか読めない。 */
81
+ const isInflectedVerb = (token: Token): boolean => token.pos === "VERB" && token.lemma !== undefined && token.lemma.toLowerCase() !== lower(token);
82
+
83
+ /**
84
+ * 限定詞の後ろの修飾語。数の形容詞(a few days)が挟まれば、単数の限定詞でも複数を数えるので undefined。
85
+ * bound は限定詞が前置詞の目的語の頭にあること。そこでは活用した動詞の形も修飾語(on these flagged post)。
86
+ */
87
+ const modifiersAfter = (tokens: readonly Token[], from: number, count: ReadonlySet<string>, bound: boolean): readonly Token[] | undefined => {
88
+ const end = tokens.findIndex((token, index) => index >= from && !isModifier(token) && !(bound && isInflectedVerb(token)));
81
89
  const modifiers = tokens.slice(from, end === -1 ? tokens.length : end);
82
90
  return modifiers.some((token) => count.has(lower(token))) ? undefined : modifiers;
83
91
  };
@@ -106,8 +114,14 @@ const determinerAt = (tokens: readonly Token[], at: number, lists: AgreementList
106
114
  */
107
115
  const standsAlone = (determiner: Determiner): boolean => determiner.length === 1 && !isArticle(determiner.head);
108
116
 
109
- const readsAsDeterminer = (determiner: Determiner, modifiers: readonly Token[]): boolean =>
110
- !standsAlone(determiner) || modifiers.some((token) => token.pos === "ADJ");
117
+ const readsAsDeterminer = (determiner: Determiner, modifiers: readonly Token[], bound: boolean): boolean =>
118
+ !standsAlone(determiner) || (bound && modifiers.length > 0) || modifiers.some((token) => token.pos === "ADJ");
119
+
120
+ /** 限定詞が前置詞のすぐ後ろにあるか(on these)。前置詞の目的語の頭は主語にならないので、後ろの語は動詞ではない。 */
121
+ const followsPreposition = (tokens: readonly Token[], at: number, prepositions: ReadonlySet<string> | undefined): boolean => {
122
+ const before = tokens[at - 1];
123
+ return before !== undefined && (prepositions?.has(lower(before)) ?? false);
124
+ };
111
125
 
112
126
  const mayBeNoun = (token: Token): boolean => token.features?.["AlsoNoun"] === "Yes" || isGuessed(token);
113
127
 
@@ -116,8 +130,17 @@ const mayBeNoun = (token: Token): boolean => token.features?.["AlsoNoun"] === "Y
116
130
  * an individual works(individual は名詞にもなる)/ Those responsible report to the board(those は代名詞にもなる)。
117
131
  * 後ろが is / has なら、名詞は動詞ではない(these key result is)。
118
132
  */
119
- const mayBeVerb = (determiner: Determiner, modifiers: readonly Token[], noun: Token, next: Token | undefined, finite: ReadonlySet<string>): boolean =>
120
- noun.features?.["AlsoVerb"] === "Yes" && !(next !== undefined && finite.has(lower(next))) && (standsAlone(determiner) || modifiers.some(mayBeNoun));
133
+ const mayBeVerb = (
134
+ determiner: Determiner,
135
+ modifiers: readonly Token[],
136
+ noun: Token,
137
+ next: Token | undefined,
138
+ finite: ReadonlySet<string>,
139
+ bound: boolean,
140
+ ): boolean =>
141
+ noun.features?.["AlsoVerb"] === "Yes" &&
142
+ !(next !== undefined && finite.has(lower(next))) &&
143
+ ((standsAlone(determiner) && !bound) || modifiers.some(mayBeNoun));
121
144
 
122
145
  /** 冠詞は名詞句の頭に立つ。形容詞や数の後ろの a は、記号の名前(the eight 3-hourly a indices)。 */
123
146
  const AFTER_MODIFIER = new Set(["ADJ", "NUM"]);
@@ -128,14 +151,15 @@ const isLetterName = (tokens: readonly Token[], at: number, determiner: Determin
128
151
  const numberSlipAt = (source: string, tokens: readonly Token[], at: number, lists: AgreementLists): Slip | undefined => {
129
152
  const determiner = determinerAt(tokens, at, lists);
130
153
  if (determiner === undefined || isNamePart(tokens, at) || isLetterName(tokens, at, determiner)) return undefined;
131
- const modifiers = modifiersAfter(tokens, at + determiner.length, lists.count);
132
- if (modifiers === undefined || !readsAsDeterminer(determiner, modifiers)) return undefined;
154
+ const bound = standsAlone(determiner) && followsPreposition(tokens, at, lists.prepositions);
155
+ const modifiers = modifiersAfter(tokens, at + determiner.length, lists.count, bound);
156
+ if (modifiers === undefined || !readsAsDeterminer(determiner, modifiers, bound)) return undefined;
133
157
  const nounAt = at + determiner.length + modifiers.length;
134
158
  const noun = tokens[nounAt];
135
159
  if (!isCommonNoun(noun) || !hasOneNumber(noun, lists.invariant) || isPlural(noun) === determiner.plural) return undefined;
136
160
  // A file name or a path (a quotes.json, a docs/ folder) is spelled as it must be, not counted.
137
161
  if (isPartOfAddress(source, noun.span.start, noun.span.end)) return undefined;
138
- if (mayBeVerb(determiner, modifiers, noun, tokens[nounAt + 1], lists.finite)) return undefined;
162
+ if (mayBeVerb(determiner, modifiers, noun, tokens[nounAt + 1], lists.finite, bound)) return undefined;
139
163
  const span = tokens.slice(at, nounAt + 1);
140
164
  if (!endsNounPhrase(tokens[nounAt + 1], lists.finite) || !joinedBySpace(source, span) || isPartOfLongerWord(source, determiner.head, noun)) return undefined;
141
165
  return slipOf("number", source, determiner.head, noun);
@@ -211,6 +235,7 @@ const listsOf = (lexicons: Readonly<Record<string, Lexicon>>): AgreementLists =>
211
235
  finite: setOf(lexicons["finite-auxiliary"]),
212
236
  misnumbered: lexicons["misnumbered-phrase"] ?? [],
213
237
  afterArticle: setOf(lexicons["determiner-after-article"]),
238
+ prepositions: setOf(lexicons["object-preposition"]),
214
239
  });
215
240
 
216
241
  export const agreementSlip: Detector = (doc): Finding[] => {
@@ -1,4 +1,4 @@
1
- import type { Detector, Finding, ProseDocument, Span } from "../plugin.ts";
1
+ import type { Detector, DetectorOptions, Finding, ProseDocument, Span } from "../plugin.ts";
2
2
 
3
3
  /** A bold run longer than this is a bold sentence, not a label. */
4
4
  const MAX_LABEL_CHARS = 40;
@@ -61,11 +61,32 @@ const unquotedItems = (doc: ProseDocument, opens: (item: string) => string | und
61
61
  /** The list items, in document order, that open with a bold label and are not quoted. */
62
62
  export const boldLabelItems = (doc: ProseDocument): Span[] => unquotedItems(doc, boldLabelOf);
63
63
 
64
- /** A count, not a density: a person writes one or two labels even in a long article. A bold lead sentence counts as a label. */
64
+ /** Bold lead sentences that report on their own (the rule's min_leads). */
65
+ const DEFAULT_MIN_LEADS = 3;
66
+
67
+ const minLeads = (options: DetectorOptions): number => {
68
+ const value = options.settings?.["min_leads"];
69
+ return typeof value === "number" ? value : DEFAULT_MIN_LEADS;
70
+ };
71
+
72
+ /** The count reported and the limit it reached: all the labelled items, or else the bold lead sentences alone, or undefined. */
73
+ const reached = (items: readonly Span[], leads: number, options: DetectorOptions): { count: number; limit: number } | undefined => {
74
+ if (items.length >= options.limit) return { count: items.length, limit: options.limit };
75
+ const least = minLeads(options);
76
+ return leads >= least ? { count: leads, limit: least } : undefined;
77
+ };
78
+
79
+ /**
80
+ * A count, not a density: a person writes one or two labels even in a long article. A bold lead sentence counts as a label.
81
+ * Bold lead sentences (- **Check one result by hand.** …) report at fewer items than colon labels: human documents write a few
82
+ * colon labels for steps or fields (- **Gather input**: …), but rarely make a list of bold lead sentences.
83
+ */
65
84
  export const boldLabelList: Detector = (doc, options): Finding[] => {
66
85
  const items = unquotedItems(doc, labelOrLeadOf);
67
86
  const first = items[0];
68
- if (first === undefined || items.length < options.limit) return [];
87
+ const leads = items.filter((span) => boldLabelOf(doc.source.slice(span.start, span.end)) === undefined).length;
88
+ const found = reached(items, leads, options);
89
+ if (first === undefined || found === undefined) return [];
69
90
  const written = doc.source.slice(first.start, first.end);
70
91
  return [
71
92
  {
@@ -74,7 +95,7 @@ export const boldLabelList: Detector = (doc, options): Finding[] => {
74
95
  line: 0,
75
96
  column: 0,
76
97
  quote: (written.split("\n")[0] ?? "").trim(),
77
- values: { label: labelOrLeadOf(written) ?? "", count: items.length, limit: options.limit, offset: first.start },
98
+ values: { label: labelOrLeadOf(written) ?? "", count: found.count, limit: found.limit, offset: first.start },
78
99
  },
79
100
  ];
80
101
  };
@@ -0,0 +1,21 @@
1
+ import type { Span } from "../plugin.ts";
2
+
3
+ /** The bold marks around a run. */
4
+ const BOLD_MARKS = /^(?:\*\*|__)(.*)(?:\*\*|__)$/su;
5
+
6
+ /** Each opening quote mark or backtick, with the mark that closes it. */
7
+ const CLOSING: Readonly<Record<string, string>> = { '"': '"', "“": "”", "'": "'", "‘": "’", "「": "」", "『": "』", "`": "`" };
8
+
9
+ /** A quotation or a code span that is the whole run: the writer names the words, as a README marks the part of an example it means. */
10
+ const isWhollyQuoted = (text: string): boolean => {
11
+ const chars = Array.from(text);
12
+ const close = CLOSING[chars[0] ?? ""];
13
+ const inside = chars.slice(1, -1);
14
+ return close !== undefined && chars.length > 2 && chars.at(-1) === close && !inside.includes(close) && !inside.includes(chars[0] ?? "");
15
+ };
16
+
17
+ /** Whether the bold run is nothing but a quoted phrase (**"であったが"**, **`strict`**): a mention of words, not emphasis. */
18
+ export const isQuotedMention = (source: string, span: Span): boolean => {
19
+ const inner = BOLD_MARKS.exec(source.slice(span.start, span.end))?.[1];
20
+ return inner !== undefined && isWhollyQuoted(inner.trim());
21
+ };
@@ -157,3 +157,13 @@ export const bracketPlaceholderSpans = (source: string): Span[] =>
157
157
  [...source.matchAll(BRACKETS)]
158
158
  .filter((hit) => isCapitalPlaceholder(hit[0], source.slice(hit.index + hit[0].length, hit.index + hit[0].length + 1)))
159
159
  .map((hit) => ({ start: hit.index, end: hit.index + hit[0].length }));
160
+
161
+ const OPENING_QUOTE = /["“‘']$/u;
162
+ const CLOSING_QUOTE = /^[.,;:!?]?["”’']/u;
163
+
164
+ /**
165
+ * A capital run that is a whole quotation (mark it “THIS DOCUMENT CONTAINS CONFIDENTIAL INFORMATION.”): the words a reader is to
166
+ * write or will see as they stand, quoted from a label or a sign, not the writer raising their voice.
167
+ */
168
+ export const isWholeQuotation = (source: string, start: number, end: number): boolean =>
169
+ OPENING_QUOTE.test(source.slice(Math.max(0, start - 1), start)) && CLOSING_QUOTE.test(source.slice(end, end + 2));
@@ -1,5 +1,6 @@
1
1
  import { charLength, proseText } from "../measure.ts";
2
2
  import type { Detector, Finding, Section } from "../plugin.ts";
3
+ import { isQuotedMention } from "./bold-quoted.ts";
3
4
 
4
5
  /** これより短い節では密度が暴れる。43 字に 1 箇所で「1000 字あたり 23」になる。 */
5
6
  const MIN_CHARS = 200;
@@ -8,6 +9,10 @@ const PER = 1000;
8
9
 
9
10
  const charsOf = (section: Section): number => section.sentences.reduce((sum, sentence) => sum + charLength(sentence), 0);
10
11
 
12
+ /** The section's bold runs, less those that only quote words: a README bolds the part of an example sentence it talks about. */
13
+ const boldsOf = (section: Section, source: string): number =>
14
+ section.strongs === undefined ? section.strongCount : section.strongs.filter((span) => !isQuotedMention(source, span)).length;
15
+
11
16
  /**
12
17
  * 節あたりの「密度」を見る。件数ではない。
13
18
  *
@@ -18,11 +23,11 @@ const charsOf = (section: Section): number => section.sentences.reduce((sum, sen
18
23
  */
19
24
  export const countPerSection: Detector = (doc, options): Finding[] =>
20
25
  doc.sections
21
- .map((section) => ({ section, chars: charsOf(section) }))
26
+ .map((section) => ({ section, chars: charsOf(section), bolds: boldsOf(section, doc.source) }))
22
27
  .filter(({ chars }) => chars >= MIN_CHARS)
23
- .map(({ section, chars }) => ({ section, chars, density: Math.round((section.strongCount / chars) * PER) }))
28
+ .map(({ section, chars, bolds }) => ({ section, chars, bolds, density: Math.round((bolds / chars) * PER) }))
24
29
  .filter(({ density }) => density > options.limit)
25
- .map(({ section, chars, density }) => ({
30
+ .map(({ section, chars, bolds, density }) => ({
26
31
  rule: "bold-density",
27
32
  severity: "warning",
28
33
  line: 0,
@@ -32,7 +37,7 @@ export const countPerSection: Detector = (doc, options): Finding[] =>
32
37
  values: {
33
38
  count: density,
34
39
  limit: options.limit,
35
- bolds: section.strongCount,
40
+ bolds,
36
41
  chars,
37
42
  offset: section.firstSentence?.span.start ?? section.span.start,
38
43
  },
@@ -186,7 +186,8 @@ const isOrdinaryPhraseAt = (doc: ProseDocument, offset: number, term: string, de
186
186
  /** The term written longer with a word of its definition (文書管理責任者, the Application), after the sentence that defines it. */
187
187
  const extendedFindings = (doc: ProseDocument, texts: readonly BodyText[], term: DefinedTerm, spans: readonly Span[], defined: readonly string[]): Finding[] => {
188
188
  const definition = definingSentence(doc, term.span)?.text ?? "";
189
- const pointers = patternsOf(doc, "defined-term-pointer");
189
+ // A pointer (当該管理責任者) points at the term, and the definition's own marker (以下本契約において同じ) is no word of its meaning.
190
+ const pointers = [...patternsOf(doc, "defined-term-pointer"), ...patternsOf(doc, "definition-marker")];
190
191
  // Every sentence that defines the term (a second definition too) holds the long words it is defined from.
191
192
  const defining = spans.map((span) => definingSentence(doc, span)?.span ?? span);
192
193
  const definingEnd = definingSentenceEnd(doc, term.span);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A round bracket written as the mouth of an emoticon (":-)", ";)", ":(" ). It opens and closes nothing.
3
+ * text is the section, offset the bracket's position.
4
+ */
5
+
6
+ /**
7
+ * The eyes and an optional nose right before the mouth, at the start of a word or after an opening quote: ":", ";" or "=",
8
+ * then "-" or "'". Not after an opening bracket: "(:)" names the colon.
9
+ */
10
+ const FACE_BEFORE = /(?:^|[\s"'“‘])[:;=][-']?$/u;
11
+
12
+ /** After the mouth: the end, a space, a closing quote or punctuation. A letter or digit would make it part of a word. */
13
+ const FACE_AFTER = /^(?:$|[\s"'”’),.;:!?])/u;
14
+
15
+ const LOOK_AROUND = 4;
16
+
17
+ export const isEmoticonMouth = (text: string, offset: number): boolean => {
18
+ const mark = text[offset];
19
+ if (mark !== "(" && mark !== ")") return false;
20
+ return FACE_BEFORE.test(text.slice(Math.max(0, offset - LOOK_AROUND), offset)) && FACE_AFTER.test(text.slice(offset + 1, offset + 2));
21
+ };
@@ -53,6 +53,15 @@ export const adverbDensity: Detector = (doc, options): Finding[] => {
53
53
 
54
54
  const BE = new Set(["be", "is", "are", "was", "were"]);
55
55
 
56
+ /**
57
+ * The words before ", but": "It's not fashionable these days, but my view is that …" is a concessive aside, and its
58
+ * that-clause belongs to the clause after but.
59
+ */
60
+ export const beforeConcession = (tokens: readonly Token[]): readonly Token[] => {
61
+ const at = tokens.findIndex((token, index) => token.surface === "," && tokens[index + 1]?.surface.toLowerCase() === "but");
62
+ return at === -1 ? tokens : tokens.slice(0, at);
63
+ };
64
+
56
65
  /**
57
66
  * There is / It is ... that は、主語を後ろへ押しやって誰が何をするのかを消す。
58
67
  * 「There is a need to review」は、誰が必要としているのかを言っていない。
@@ -65,7 +74,7 @@ const expletiveAt = (tokens: readonly Token[]): Token | undefined => {
65
74
  const next = tokens.find((token) => token.span.start >= head.span.end && token.pos !== "PUNCT");
66
75
  if (next === undefined || !BE.has(next.lemma ?? next.surface.toLowerCase())) return undefined;
67
76
  // "it is" は "it is raining" のような正当な用法があるので、that 節を伴うときだけ数える。
68
- if (lead === "it" && !tokens.some((token) => token.surface.toLowerCase() === "that")) return undefined;
77
+ if (lead === "it" && !beforeConcession(tokens).some((token) => token.surface.toLowerCase() === "that")) return undefined;
69
78
  return head;
70
79
  };
71
80
 
@@ -33,8 +33,23 @@ export const mostFrequent = (words: readonly string[], count: number): string[]
33
33
  .map(([word]) => word);
34
34
  };
35
35
 
36
- const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] =>
37
- doc.sentences.flatMap((sentence) => katakanaWordsIn(sentence.text, doc.names ?? []).map((word) => ({ sentence, word })));
36
+ /**
37
+ * The katakana words of the document's title: what the document is about (e-Govアカウントの登録方法). A manual on accounts
38
+ * cannot say アカウント another way, so the subject is not a loanword to trim.
39
+ */
40
+ export const subjectWords = (doc: ProseDocument): ReadonlySet<string> => {
41
+ const title = doc.markup?.headings.find((heading) => heading.depth === 1)?.text ?? "";
42
+ return new Set(katakanaWordsIn(title, doc.names ?? []));
43
+ };
44
+
45
+ const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] => {
46
+ const subject = subjectWords(doc);
47
+ return doc.sentences.flatMap((sentence) =>
48
+ katakanaWordsIn(sentence.text, doc.names ?? [])
49
+ .filter((word) => !subject.has(word))
50
+ .map((word) => ({ sentence, word })),
51
+ );
52
+ };
38
53
 
39
54
  /**
40
55
  * Katakana loanwords per 1000 characters, over the whole document. Reported once, at the first sentence holding one, with the
@@ -11,7 +11,7 @@ import { restricted, type Restrictors } from "./superlative-clause.ts";
11
11
  import { stackedHedges, type StackedHedge } from "./stacked-hedge.ts";
12
12
  import { comparisonMarkersOf, counterpartBefore, onlyQuoted, quotedRange, type ComparisonMarkers } from "./superlative-comparison.ts";
13
13
  import { inPhrase, ownedBefore } from "./superlative-phrase.ts";
14
- import { asked, contextOf, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
14
+ import { asked, contextOf, picksFromNamedSet, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
15
15
 
16
16
  const PER = 1000;
17
17
 
@@ -156,6 +156,7 @@ const qualifiedAt = (tokens: readonly Token[], range: TokenRange, qualifiers: Qu
156
156
  viewpointBefore(tokens, range, qualifiers.context.viewpoints) ||
157
157
  pointsAtReferent(tokens, range, qualifiers.context.referents) ||
158
158
  ranksParts(tokens, range, qualifiers.context.parts) ||
159
+ picksFromNamedSet(tokens, range, qualifiers.context.proForms) ||
159
160
  restricted(tokens, range, qualifiers.restrictors) ||
160
161
  namesQuantity(tokens, range, qualifiers.quantityNouns) ||
161
162
  makesWord(tokens, range, qualifiers.suffixes) ||
@@ -6,7 +6,7 @@ import { externalLinkTitleSpans } from "../link-title.ts";
6
6
  import { formulaBracketSpans } from "../formula-brackets.ts";
7
7
  import { ownTitleQuoteSpans } from "../own-title-quote.ts";
8
8
  import { isWithinAny, quotedSpans } from "../quoted-span.ts";
9
- import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
9
+ import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWholeQuotation, isWithinSorted } from "./caps-caption.ts";
10
10
  import { lineStarts } from "../position.ts";
11
11
  import { isTypewritten } from "./typewritten.ts";
12
12
  import { divisionLabelPattern, isDivisionSeparator } from "./division-label-separator.ts";
@@ -260,6 +260,20 @@ const reportFrom = (hits: readonly Hit[], limit: number): Finding[] => (hits.len
260
260
  /** A spaced hyphen or a double hyphen between words, standing for a dash ("late - very late", "late--very late"). */
261
261
  const HYPHEN_DASH = /(?<=[\p{L},;)]) -{1,2} (?=[\p{L}(])|(?<=\p{L})--(?=\p{L})/gu;
262
262
 
263
+ /** A spaced hyphen whose side is masked out of the sentence's text: a code span may stand there ("`float` - everything"). */
264
+ const MASKED_SIDE_HYPHEN = /(?<=\s) -{1,2} (?=[\p{L}(])|(?<=[\p{L},;)]) -{1,2} (?=\s)/gu;
265
+ const CODE_MARK = "`";
266
+
267
+ /**
268
+ * A spaced hyphen between a code span and a word, either way round ("`float` - everything", "two properties - `x`"). Code
269
+ * is masked out of the text, so the code side reads as spaces; the source shows the code mark right beside the hyphen.
270
+ * Code on both sides ("`query` - `form`") is a mapping, not a dash.
271
+ */
272
+ const besideCode = (source: string, hit: Hit): boolean => {
273
+ const end = hit.offset + hit.matched.length + 2;
274
+ return (source[hit.offset - 1] === CODE_MARK) !== (source[end] === CODE_MARK);
275
+ };
276
+
263
277
  /** A dash set as a character (an em dash, an en dash). */
264
278
  const TRUE_DASH = /[—–]/u;
265
279
  const DOUBLE_HYPHEN = "--";
@@ -276,10 +290,11 @@ export const hyphenDash: Detector = (doc, options): Finding[] => {
276
290
  const sentences = ownSentences(doc);
277
291
  const setsDashes = sentences.some((sentence) => TRUE_DASH.test(sentence.text));
278
292
  const divisionLabel = divisionLabelPattern((doc.lexicons["numbered-division"] ?? []).map((entry) => entry.pattern));
293
+ const codeHits = hitsOf(sentences, MASKED_SIDE_HYPHEN).filter((hit) => besideCode(doc.source, hit));
279
294
  return reportFrom(
280
- hitsOf(sentences, HYPHEN_DASH).filter(
281
- (hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset),
282
- ),
295
+ [...hitsOf(sentences, HYPHEN_DASH), ...codeHits]
296
+ .toSorted((left, right) => left.offset - right.offset)
297
+ .filter((hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset)),
283
298
  options.limit,
284
299
  );
285
300
  };
@@ -332,8 +347,8 @@ export const isShouting = (run: string, known: ReadonlySet<string>, conventional
332
347
 
333
348
  /**
334
349
  * Runs of three or more all-capital words that are ordinary words, not acronyms ("DO NOT DELETE THIS"), and not a
335
- * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, or a
336
- * placeholder in square brackets.
350
+ * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, a
351
+ * placeholder in square brackets, or a whole quotation.
337
352
  */
338
353
  export const capsShouting: Detector = (doc, options): Finding[] => {
339
354
  const known = lowerCaseWords(doc.prose ?? doc.source);
@@ -343,7 +358,13 @@ export const capsShouting: Detector = (doc, options): Finding[] => {
343
358
  const placeholders = bracketPlaceholderSpans(doc.source);
344
359
  const isCaptionOrLetterhead = (hit: Hit): boolean => {
345
360
  const span = { start: hit.offset, end: hit.offset + hit.matched.length };
346
- return captions.has(hit.matched) || isCaptionAt(doc.source, span.start, span.end) || isWithinSorted(capitalLines, span) || isWithinAny(placeholders, span);
361
+ return (
362
+ captions.has(hit.matched) ||
363
+ isCaptionAt(doc.source, span.start, span.end) ||
364
+ isWithinSorted(capitalLines, span) ||
365
+ isWithinAny(placeholders, span) ||
366
+ isWholeQuotation(doc.source, span.start, span.end)
367
+ );
347
368
  };
348
369
  const hits = hitsOf(ownSentences(doc), CAPS_RUN).filter((hit) => isShouting(hit.matched, known, conventional) && !isCaptionOrLetterhead(hit));
349
370
  return reportFrom(hits, options.limit);
@@ -1,7 +1,7 @@
1
1
  // A phrase that is mentioned rather than used: named as a term (when saying "raise the bar", the phrase "low-hanging
2
2
  // fruit", 「徹底解説」という言い方). The writer is talking about the words, not leaning on them. The cue words come from the
3
3
  // language's mention-cue word list: group before stands right before the phrase, group after right after it. Pure.
4
- import type { LexiconEntry, Sentence, Token } from "../plugin.ts";
4
+ import type { LexiconEntry, Sentence, Span, Token } from "../plugin.ts";
5
5
  import { entryEndsAt, entryRanges, type TokenRange } from "./lexicon-match.ts";
6
6
 
7
7
  const BEFORE = "before";
@@ -36,3 +36,15 @@ export const onlyMentioned = (sentence: Sentence, entry: LexiconEntry, cues: Men
36
36
  const ranges = entryRanges(sentence, entry);
37
37
  return tokens !== undefined && ranges.length > 0 && ranges.every((range) => isMention(tokens, range, cues));
38
38
  };
39
+
40
+ /** Whether every use of the entry in the sentence lies in a linked page's title: the other page's words, which the writer cites. */
41
+ export const onlyInTitles = (sentence: Sentence, entry: LexiconEntry, titles: readonly Span[]): boolean => {
42
+ const tokens = sentence.tokens ?? [];
43
+ const ranges = entryRanges(sentence, entry);
44
+ const inTitle = (start: number, end: number): boolean => titles.some((title) => start >= title.start && end <= title.end);
45
+ return (
46
+ titles.length > 0 &&
47
+ ranges.length > 0 &&
48
+ ranges.every((range) => inTitle(tokens[range.start]?.span.start ?? -1, tokens[range.end - 1]?.span.end ?? Number.POSITIVE_INFINITY))
49
+ );
50
+ };
@@ -63,12 +63,25 @@ const isBeforeLongerWord = (numeral: string, written: string, offset: number, to
63
63
  return word !== undefined && word.surface.length > counter.length;
64
64
  };
65
65
 
66
+ /** The ordinal suffix (三枚目): a word the tokenizer joins to a count that is still a number of things. */
67
+ const ORDINAL_SUFFIX = "目";
68
+
69
+ /**
70
+ * A kanji numeral and counter that open a longer word (二枚貝, 二枚舌, 三人称): the tokenizer reads the whole as one noun, a name
71
+ * for a thing rather than a count of it, and digits could not be written there.
72
+ */
73
+ const isInsideWord = (written: string, offset: number, tokens: readonly Token[]): boolean => {
74
+ const word = tokens.find((token) => token.span.start === offset);
75
+ if (word === undefined || word.surface.length <= written.length || !word.surface.startsWith(written)) return false;
76
+ return word.surface.slice(written.length) !== ORDINAL_SUFFIX;
77
+ };
78
+
66
79
  const countMarks = (text: string, base: number, words: NumberWords, tokens: readonly Token[]): NumberMark[] => {
67
80
  const pattern = countPattern(words);
68
81
  if (pattern === undefined) return [];
69
82
  return [...text.matchAll(pattern)].flatMap((match): NumberMark[] => {
70
83
  const [written, digits, kanji] = match;
71
- if (kanji !== undefined && isIdiomNumeral(kanji)) return [];
84
+ if (kanji !== undefined && (isIdiomNumeral(kanji) || isInsideWord(written, base + match.index, tokens))) return [];
72
85
  if (isBeforeLongerWord(digits ?? kanji ?? "", written, base + match.index, tokens)) return [];
73
86
  return [{ kind: "count", style: digits === undefined ? "kanji" : "digits", written, offset: base + match.index }];
74
87
  });
@@ -4,21 +4,31 @@
4
4
  // a vague limit (promptly) is vague-deadline's; one stating an amount (pays a fee of $9,000) sets a price, and its
5
5
  // timing is another clause's. The words come from the language package's word lists: timed-duty (the act),
6
6
  // duty-marker (shall, will), duty-ending (う, するものとする: what may follow a Japanese act at the sentence end),
7
- // stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission and currency-notation. Pure.
7
+ // stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission, currency-notation and paragraph-pointer (前項). Pure.
8
8
  import { quoteAt } from "./structure-tree.ts";
9
9
  import { actsTimedAt, type NamedDeadline, type Units } from "./deadline-unit.ts";
10
+ import { pointedParagraphs } from "./paragraph-pointer.ts";
10
11
  import { inDocumentOrder } from "../structure/issues.ts";
11
12
  import { escapeRegExp } from "../orthography.ts";
12
13
  import { grantsRight, statesConcrete, vagueIn } from "./vague-deadline.ts";
13
- import type { Detector, Finding, LexiconEntry, ProseDocument } from "../plugin.ts";
14
+ import type { Detector, Finding, LexiconEntry, ProseDocument, Span, StructureNode } from "../plugin.ts";
14
15
 
15
16
  export type UntimedDuty = { readonly offset: number; readonly act: string };
16
17
 
17
18
  /**
18
19
  * sameLine: the sentence goes on the line of the one before it (no line break between them). timedActs: the acts whose
19
- * dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed.
20
+ * dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed. place: its
21
+ * article (where it starts) and its paragraph's number in it.
20
22
  */
21
- type Text = { readonly start: number; readonly text: string; readonly sameLine?: boolean; readonly timedActs?: readonly string[] };
23
+ type Text = {
24
+ readonly start: number;
25
+ readonly text: string;
26
+ readonly sameLine?: boolean;
27
+ readonly timedActs?: readonly string[];
28
+ readonly place?: Place | undefined;
29
+ };
30
+
31
+ type Place = { readonly article: number; readonly paragraph: number };
22
32
 
23
33
  /** What the word lists give the decision. */
24
34
  export type DutyWords = {
@@ -36,6 +46,8 @@ export type DutyWords = {
36
46
  readonly deferrals: readonly string[];
37
47
  readonly permissions: readonly LexiconEntry[];
38
48
  readonly currencies: readonly LexiconEntry[];
49
+ /** Words that point at another paragraph of the article (前項, 本条1項). */
50
+ readonly paragraphPointers?: readonly LexiconEntry[];
39
51
  };
40
52
 
41
53
  const LATIN = /\p{Script=Latin}/u;
@@ -147,13 +159,41 @@ const lineEnds = (texts: readonly Text[]): number[] => {
147
159
  return ends;
148
160
  };
149
161
 
162
+ type Bound = { readonly place: Place; readonly act: string; readonly text: string };
163
+
164
+ /** The limited sentences of articles, with the act each binds. */
165
+ const limitedBounds = (texts: readonly Text[], words: DutyWords): Bound[] =>
166
+ texts.flatMap((text) => {
167
+ const act = text.place === undefined || !limited(text, words) ? undefined : actIn(text.text, words);
168
+ return act === undefined || text.place === undefined ? [] : [{ place: text.place, act: act.act.toLowerCase(), text: text.text }];
169
+ });
170
+
171
+ /**
172
+ * Whether another paragraph of the duty's article times the same act and one of the two points at the other: an article
173
+ * that says what is paid in its first paragraph and, in its third, pays 「本条1項に定める対価」 within ten days, or pays
174
+ * 「前項の対価」 by bank transfer after the paragraph that gives the time.
175
+ */
176
+ const timedInArticle = (text: Text, act: string, bounds: readonly Bound[], pointers: readonly LexiconEntry[]): boolean => {
177
+ const place = text.place;
178
+ if (place === undefined || pointers.length === 0) return false;
179
+ const pointed = pointedParagraphs(text.text, place.paragraph, pointers);
180
+ return bounds.some(
181
+ (bound) =>
182
+ bound.place.article === place.article &&
183
+ bound.place.paragraph !== place.paragraph &&
184
+ bound.act === act.toLowerCase() &&
185
+ (pointed.includes(bound.place.paragraph) || pointedParagraphs(bound.text, bound.place.paragraph, pointers).includes(place.paragraph)),
186
+ );
187
+ };
188
+
150
189
  /**
151
190
  * Each duty to act at a point in time whose sentence, and the rest of whose line, states no limit, holds no vague one, grants no right and states
152
- * no amount, when more sentences of the document state a limit than hold such a duty: these duties are then the
191
+ * no amount, and whose article times its act in a paragraph one of the two points at, when more sentences of the document state a limit than hold such a duty: these duties are then the
153
192
  * document's minority.
154
193
  */
155
194
  export const untimedDuties = (texts: readonly Text[], words: DutyWords): UntimedDuty[] => {
156
195
  const ends = lineEnds(texts);
196
+ const bounds = limitedBounds(texts, words);
157
197
  const found = texts.flatMap((text, index) => {
158
198
  const line = texts.slice(index, ends[index]);
159
199
  if (line.some((later) => limited(later, words) || words.deferrals.some((deferral) => phraseIn(later.text, deferral)))) return [];
@@ -161,6 +201,7 @@ export const untimedDuties = (texts: readonly Text[], words: DutyWords): Untimed
161
201
  const act = actIn(text.text, words);
162
202
  if (act === undefined || (LATIN.test(act.act) && !isWordStart(text.text, act.at))) return [];
163
203
  if (text.timedActs?.some((timed) => timed.toLowerCase() === act.act.toLowerCase()) === true) return [];
204
+ if (timedInArticle(text, act.act, bounds, words.paragraphPointers ?? [])) return [];
164
205
  return [{ offset: text.start + act.at, act: text.text.slice(act.at, act.at + act.act.length) }];
165
206
  });
166
207
  const limitedSentences = texts.filter((text) => statesLimit(text, words)).length;
@@ -185,14 +226,36 @@ const timedActsReader = (doc: ProseDocument): ((offset: number) => string[]) =>
185
226
  return (offset) => actsTimedAt(doc.source, units, offset, deadlines, phraseIn);
186
227
  };
187
228
 
229
+ const within = (span: Span, offset: number): boolean => offset >= span.start && offset < span.end;
230
+
231
+ /** The paragraph's number: its item's label among the article's own items (2, 2), or 1 for the article's first, unnumbered text. */
232
+ const paragraphOf = (article: StructureNode, offset: number): number | undefined => {
233
+ const item = article.children.find((child) => child.kind === "item" && within(child.span, offset));
234
+ if (item === undefined) return 1;
235
+ const label = Number(String(item.attrs["label"] ?? "").normalize("NFKC"));
236
+ return Number.isInteger(label) && label > 0 ? label : undefined;
237
+ };
238
+
239
+ /** Where a sentence stands: its innermost article and the paragraph in it. */
240
+ const placeReader = (doc: ProseDocument): ((offset: number) => Place | undefined) => {
241
+ const articles = doc.structure === undefined ? [] : inDocumentOrder(doc.structure).filter((node) => node.kind === "article");
242
+ return (offset) => {
243
+ const article = articles.filter((node) => within(node.span, offset)).at(-1);
244
+ const paragraph = article === undefined ? undefined : paragraphOf(article, offset);
245
+ return article === undefined || paragraph === undefined ? undefined : { article: article.span.start, paragraph };
246
+ };
247
+ };
248
+
188
249
  export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
189
250
  const timedActs = timedActsReader(doc);
251
+ const placeAt = placeReader(doc);
190
252
  return untimedDuties(
191
253
  doc.sentences.map((sentence, index) => ({
192
254
  start: sentence.span.start,
193
255
  text: sentence.text,
194
256
  sameLine: index > 0 && !doc.source.slice(doc.sentences[index - 1]?.span.end ?? 0, sentence.span.start).includes("\n"),
195
257
  timedActs: timedActs(sentence.span.start),
258
+ place: placeAt(sentence.span.start),
196
259
  })),
197
260
  {
198
261
  acts: patternsOf(doc, "timed-duty"),
@@ -205,6 +268,7 @@ export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
205
268
  deferrals: patternsOf(doc, "duty-terms-elsewhere"),
206
269
  permissions: doc.lexicons["deadline-permission"] ?? [],
207
270
  currencies: doc.lexicons["currency-notation"] ?? [],
271
+ paragraphPointers: doc.lexicons["paragraph-pointer"] ?? [],
208
272
  },
209
273
  ).map((duty) => ({
210
274
  rule: "obligation-without-deadline",