chaffjs 0.47.0 → 0.49.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 (208) hide show
  1. package/README.ja.md +1 -0
  2. package/README.md +1 -0
  3. package/dist/bound-word-particles.d.ts +1 -0
  4. package/dist/bound-word-particles.d.ts.map +1 -1
  5. package/dist/bound-word-particles.js +1 -1
  6. package/dist/bound-word-particles.js.map +1 -1
  7. package/dist/clause-particles.d.ts +11 -0
  8. package/dist/clause-particles.d.ts.map +1 -0
  9. package/dist/clause-particles.js +20 -0
  10. package/dist/clause-particles.js.map +1 -0
  11. package/dist/detectors/acronym-definition.d.ts.map +1 -1
  12. package/dist/detectors/acronym-definition.js +14 -6
  13. package/dist/detectors/acronym-definition.js.map +1 -1
  14. package/dist/detectors/acronym-expansion.d.ts +2 -0
  15. package/dist/detectors/acronym-expansion.d.ts.map +1 -1
  16. package/dist/detectors/acronym-expansion.js +18 -7
  17. package/dist/detectors/acronym-expansion.js.map +1 -1
  18. package/dist/detectors/acronym-mention.d.ts.map +1 -1
  19. package/dist/detectors/acronym-mention.js +3 -1
  20. package/dist/detectors/acronym-mention.js.map +1 -1
  21. package/dist/detectors/acronym-name.d.ts +2 -2
  22. package/dist/detectors/acronym-name.d.ts.map +1 -1
  23. package/dist/detectors/acronym-name.js +3 -3
  24. package/dist/detectors/acronym-name.js.map +1 -1
  25. package/dist/detectors/acronym-parent-item.d.ts +6 -0
  26. package/dist/detectors/acronym-parent-item.d.ts.map +1 -0
  27. package/dist/detectors/acronym-parent-item.js +50 -0
  28. package/dist/detectors/acronym-parent-item.js.map +1 -0
  29. package/dist/detectors/broken-link.d.ts.map +1 -1
  30. package/dist/detectors/broken-link.js +14 -0
  31. package/dist/detectors/broken-link.js.map +1 -1
  32. package/dist/detectors/char-shape.d.ts.map +1 -1
  33. package/dist/detectors/char-shape.js +11 -4
  34. package/dist/detectors/char-shape.js.map +1 -1
  35. package/dist/detectors/citation-sentence.d.ts +8 -0
  36. package/dist/detectors/citation-sentence.d.ts.map +1 -1
  37. package/dist/detectors/citation-sentence.js +24 -0
  38. package/dist/detectors/citation-sentence.js.map +1 -1
  39. package/dist/detectors/concrete-evidence-density.d.ts.map +1 -1
  40. package/dist/detectors/concrete-evidence-density.js +13 -6
  41. package/dist/detectors/concrete-evidence-density.js.map +1 -1
  42. package/dist/detectors/concrete-evidence.d.ts +14 -1
  43. package/dist/detectors/concrete-evidence.d.ts.map +1 -1
  44. package/dist/detectors/concrete-evidence.js +65 -0
  45. package/dist/detectors/concrete-evidence.js.map +1 -1
  46. package/dist/detectors/doubled-punctuation.d.ts.map +1 -1
  47. package/dist/detectors/doubled-punctuation.js +14 -4
  48. package/dist/detectors/doubled-punctuation.js.map +1 -1
  49. package/dist/detectors/en-shape.d.ts +1 -0
  50. package/dist/detectors/en-shape.d.ts.map +1 -1
  51. package/dist/detectors/en-shape.js +15 -6
  52. package/dist/detectors/en-shape.js.map +1 -1
  53. package/dist/detectors/kanji-name-edge.d.ts +10 -0
  54. package/dist/detectors/kanji-name-edge.d.ts.map +1 -1
  55. package/dist/detectors/kanji-name-edge.js +23 -0
  56. package/dist/detectors/kanji-name-edge.js.map +1 -1
  57. package/dist/detectors/law-governed.d.ts +10 -0
  58. package/dist/detectors/law-governed.d.ts.map +1 -0
  59. package/dist/detectors/law-governed.js +41 -0
  60. package/dist/detectors/law-governed.js.map +1 -0
  61. package/dist/detectors/name-variant-two-things.d.ts +2 -1
  62. package/dist/detectors/name-variant-two-things.d.ts.map +1 -1
  63. package/dist/detectors/name-variant-two-things.js +21 -3
  64. package/dist/detectors/name-variant-two-things.js.map +1 -1
  65. package/dist/detectors/open-end-names.d.ts +7 -2
  66. package/dist/detectors/open-end-names.d.ts.map +1 -1
  67. package/dist/detectors/open-end-names.js +14 -4
  68. package/dist/detectors/open-end-names.js.map +1 -1
  69. package/dist/detectors/reference-entry.d.ts.map +1 -1
  70. package/dist/detectors/reference-entry.js +35 -5
  71. package/dist/detectors/reference-entry.js.map +1 -1
  72. package/dist/detectors/register-set-apart.d.ts +1 -1
  73. package/dist/detectors/register-set-apart.js +4 -4
  74. package/dist/detectors/register-set-apart.js.map +1 -1
  75. package/dist/detectors/register-voice.d.ts +5 -0
  76. package/dist/detectors/register-voice.d.ts.map +1 -1
  77. package/dist/detectors/register-voice.js +17 -0
  78. package/dist/detectors/register-voice.js.map +1 -1
  79. package/dist/detectors/requirement-smell.d.ts.map +1 -1
  80. package/dist/detectors/requirement-smell.js +6 -2
  81. package/dist/detectors/requirement-smell.js.map +1 -1
  82. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  83. package/dist/detectors/sentence-counts.js +2 -1
  84. package/dist/detectors/sentence-counts.js.map +1 -1
  85. package/dist/detectors/sentence-ending.d.ts +2 -2
  86. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  87. package/dist/detectors/sentence-ending.js +3 -1
  88. package/dist/detectors/sentence-ending.js.map +1 -1
  89. package/dist/detectors/sentence-length.d.ts.map +1 -1
  90. package/dist/detectors/sentence-length.js +7 -6
  91. package/dist/detectors/sentence-length.js.map +1 -1
  92. package/dist/detectors/sentence-parts.d.ts +8 -3
  93. package/dist/detectors/sentence-parts.d.ts.map +1 -1
  94. package/dist/detectors/sentence-parts.js +25 -7
  95. package/dist/detectors/sentence-parts.js.map +1 -1
  96. package/dist/detectors/signals.d.ts.map +1 -1
  97. package/dist/detectors/signals.js +3 -0
  98. package/dist/detectors/signals.js.map +1 -1
  99. package/dist/detectors/space-before-punctuation.js +3 -3
  100. package/dist/detectors/space-before-punctuation.js.map +1 -1
  101. package/dist/detectors/speaker-turns.d.ts +4 -0
  102. package/dist/detectors/speaker-turns.d.ts.map +1 -0
  103. package/dist/detectors/speaker-turns.js +28 -0
  104. package/dist/detectors/speaker-turns.js.map +1 -0
  105. package/dist/detectors/token-shape.d.ts.map +1 -1
  106. package/dist/detectors/token-shape.js +21 -5
  107. package/dist/detectors/token-shape.js.map +1 -1
  108. package/dist/detectors/topic-predicate-distance.d.ts.map +1 -1
  109. package/dist/detectors/topic-predicate-distance.js +3 -1
  110. package/dist/detectors/topic-predicate-distance.js.map +1 -1
  111. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  112. package/dist/detectors/unbalanced-bracket.js +31 -6
  113. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  114. package/dist/detectors/vague-density.d.ts +4 -2
  115. package/dist/detectors/vague-density.d.ts.map +1 -1
  116. package/dist/detectors/vague-density.js +17 -9
  117. package/dist/detectors/vague-density.js.map +1 -1
  118. package/dist/document.js +2 -2
  119. package/dist/document.js.map +1 -1
  120. package/dist/name-variant-shapes.d.ts +32 -0
  121. package/dist/name-variant-shapes.d.ts.map +1 -1
  122. package/dist/name-variant-shapes.js +87 -0
  123. package/dist/name-variant-shapes.js.map +1 -1
  124. package/dist/paragraph-length.d.ts.map +1 -1
  125. package/dist/paragraph-length.js +5 -6
  126. package/dist/paragraph-length.js.map +1 -1
  127. package/dist/sentence-load.d.ts.map +1 -1
  128. package/dist/sentence-load.js +20 -6
  129. package/dist/sentence-load.js.map +1 -1
  130. package/dist/set-phrase-particles.js +2 -2
  131. package/dist/set-phrase-particles.js.map +1 -1
  132. package/dist/structure/definition-use.d.ts.map +1 -1
  133. package/dist/structure/definition-use.js +13 -0
  134. package/dist/structure/definition-use.js.map +1 -1
  135. package/dist/structure/universal.d.ts.map +1 -1
  136. package/dist/structure/universal.js +9 -1
  137. package/dist/structure/universal.js.map +1 -1
  138. package/dist/structure/unread-label.d.ts.map +1 -1
  139. package/dist/structure/unread-label.js +3 -1
  140. package/dist/structure/unread-label.js.map +1 -1
  141. package/dist/topic-clause.d.ts +2 -0
  142. package/dist/topic-clause.d.ts.map +1 -1
  143. package/dist/topic-clause.js +12 -5
  144. package/dist/topic-clause.js.map +1 -1
  145. package/package.json +3 -3
  146. package/rules/adverb-overuse.yaml +2 -2
  147. package/rules/bracket-nesting.yaml +2 -2
  148. package/rules/broken-link.yaml +2 -2
  149. package/rules/concrete-evidence-density.yaml +2 -2
  150. package/rules/doubled-punctuation.yaml +2 -2
  151. package/rules/expletive-construction.yaml +2 -2
  152. package/rules/max-kanji-continuous.yaml +5 -3
  153. package/rules/max-sentence-length.yaml +2 -2
  154. package/rules/name-variant.yaml +2 -2
  155. package/rules/ngram-repetition.yaml +2 -2
  156. package/rules/no-doubled-joshi.yaml +2 -2
  157. package/rules/no-mixed-desumasu.yaml +3 -2
  158. package/rules/orthographic-variant.yaml +2 -2
  159. package/rules/requirement-smell.yaml +2 -2
  160. package/rules/space-before-punctuation.yaml +4 -4
  161. package/rules/taigen-dome-in-prose.yaml +2 -2
  162. package/rules/topic-predicate-distance.yaml +3 -3
  163. package/rules/unbalanced-bracket.yaml +4 -4
  164. package/rules/undefined-acronym.yaml +4 -2
  165. package/rules/vague-word-density.yaml +2 -2
  166. package/skills/chaff/SKILL.md +3 -1
  167. package/src/bound-word-particles.ts +2 -1
  168. package/src/clause-particles.ts +35 -0
  169. package/src/detectors/acronym-definition.ts +14 -6
  170. package/src/detectors/acronym-expansion.ts +26 -7
  171. package/src/detectors/acronym-mention.ts +6 -1
  172. package/src/detectors/acronym-name.ts +6 -3
  173. package/src/detectors/acronym-parent-item.ts +60 -0
  174. package/src/detectors/broken-link.ts +16 -0
  175. package/src/detectors/char-shape.ts +18 -3
  176. package/src/detectors/citation-sentence.ts +30 -0
  177. package/src/detectors/concrete-evidence-density.ts +18 -7
  178. package/src/detectors/concrete-evidence.ts +83 -1
  179. package/src/detectors/doubled-punctuation.ts +20 -4
  180. package/src/detectors/en-shape.ts +18 -9
  181. package/src/detectors/kanji-name-edge.ts +27 -0
  182. package/src/detectors/law-governed.ts +50 -0
  183. package/src/detectors/name-variant-two-things.ts +43 -3
  184. package/src/detectors/open-end-names.ts +21 -4
  185. package/src/detectors/reference-entry.ts +36 -6
  186. package/src/detectors/register-set-apart.ts +4 -4
  187. package/src/detectors/register-voice.ts +19 -0
  188. package/src/detectors/requirement-smell.ts +6 -2
  189. package/src/detectors/sentence-counts.ts +2 -1
  190. package/src/detectors/sentence-ending.ts +8 -4
  191. package/src/detectors/sentence-length.ts +10 -8
  192. package/src/detectors/sentence-parts.ts +33 -9
  193. package/src/detectors/signals.ts +3 -0
  194. package/src/detectors/space-before-punctuation.ts +3 -3
  195. package/src/detectors/speaker-turns.ts +37 -0
  196. package/src/detectors/token-shape.ts +27 -7
  197. package/src/detectors/topic-predicate-distance.ts +3 -1
  198. package/src/detectors/unbalanced-bracket.ts +39 -7
  199. package/src/detectors/vague-density.ts +25 -10
  200. package/src/document.ts +2 -2
  201. package/src/name-variant-shapes.ts +103 -0
  202. package/src/paragraph-length.ts +8 -9
  203. package/src/sentence-load.ts +29 -6
  204. package/src/set-phrase-particles.ts +2 -2
  205. package/src/structure/definition-use.ts +15 -0
  206. package/src/structure/universal.ts +10 -1
  207. package/src/structure/unread-label.ts +3 -1
  208. package/src/topic-clause.ts +19 -5
@@ -3,12 +3,26 @@
3
3
  // [FETCH] WHATWG, "Fetch - Living Standard",
4
4
  // <https://fetch.spec.whatwg.org/>.
5
5
  //
6
+ // A label too long for its column leaves one space, or stands alone on its line, before the entry's indented lines:
7
+ //
8
+ // [CERT.CVD] Software Engineering Institute, "The CERT Guide to
9
+ // Coordinated Vulnerability Disclosure", August 2017.
10
+ //
11
+ // [ISO.29147.2018]
12
+ // ISO, "Information technology - Security techniques -
13
+ //
6
14
  // The entry is written in the cited work's words. Pure.
7
15
 
8
16
  type Span = { readonly start: number; readonly end: number };
9
17
 
18
+ const LABEL = String.raw`^(?<indent>[ \t]*)\[(?<label>[A-Za-z0-9][\w.:+-]*)\]`;
10
19
  /** A label in square brackets opening a line, then a wide gap: two spaces or a tab. A link definition ([x]: url) has a colon. */
11
- const ENTRY_START = /^(?<indent>[ \t]*)\[(?<label>[A-Za-z0-9][\w.:+-]*)\](?: {2,}|\t)\S/u;
20
+ const ENTRY_START = new RegExp(String.raw`${LABEL}(?: {2,}|\t)\S`, "u");
21
+ /**
22
+ * A label followed by one space or by the end of its line. Prose opens a line with a bracketed citation too ("[JSON] and XML
23
+ * [XML] document formats"), so this starts an entry only when the next line is indented deeper than the label.
24
+ */
25
+ const LONG_LABEL_START = new RegExp(String.raw`${LABEL}(?: \S|$)`, "u");
12
26
 
13
27
  type Line = { readonly text: string; readonly start: number };
14
28
 
@@ -31,12 +45,26 @@ const entryEnd = (lines: readonly Line[], at: number, indent: number): number =>
31
45
  return lines.length;
32
46
  };
33
47
 
48
+ type EntryStart = { readonly indent: number; readonly label: string };
49
+
50
+ /** The entry that opens at this line, if one does. */
51
+ const entryStartAt = (lines: readonly Line[], at: number): EntryStart | undefined => {
52
+ const text = lines[at]?.text ?? "";
53
+ const wide = ENTRY_START.exec(text)?.groups;
54
+ if (wide !== undefined) return { indent: (wide["indent"] ?? "").length, label: wide["label"] ?? "" };
55
+ const long = LONG_LABEL_START.exec(text)?.groups;
56
+ if (long === undefined) return undefined;
57
+ const indent = (long["indent"] ?? "").length;
58
+ const next = lines[at + 1]?.text ?? "";
59
+ return next.trim() !== "" && indentOf(next) > indent ? { indent, label: long["label"] ?? "" } : undefined;
60
+ };
61
+
34
62
  export const referenceEntrySpans = (source: string): Span[] => {
35
63
  const lines = linesOf(source);
36
64
  return lines.flatMap((line, at) => {
37
- const indent = ENTRY_START.exec(line.text)?.groups?.["indent"];
38
- if (indent === undefined) return [];
39
- const last = lines[entryEnd(lines, at, indent.length) - 1] ?? line;
65
+ const entry = entryStartAt(lines, at);
66
+ if (entry === undefined) return [];
67
+ const last = lines[entryEnd(lines, at, entry.indent) - 1] ?? line;
40
68
  return [{ start: line.start, end: last.start + last.text.length }];
41
69
  });
42
70
  };
@@ -45,5 +73,7 @@ export const referenceEntrySpans = (source: string): Span[] => {
45
73
  * The labels of the entries ([UNIX] The Open Group, "The Single UNIX Specification"). The entry says what the label names,
46
74
  * so the label written in prose (a UNIX timestamp) is explained by it.
47
75
  */
48
- export const referenceEntryLabels = (source: string): ReadonlySet<string> =>
49
- new Set(linesOf(source).flatMap((line) => ENTRY_START.exec(line.text)?.groups?.["label"] ?? []));
76
+ export const referenceEntryLabels = (source: string): ReadonlySet<string> => {
77
+ const lines = linesOf(source);
78
+ return new Set(lines.flatMap((_, at) => entryStartAt(lines, at)?.label ?? []));
79
+ };
@@ -3,7 +3,7 @@ import type { LexiconEntry, Paragraph, Sentence, Span } from "../plugin.ts";
3
3
 
4
4
  // Sentences that are not the writer's running prose and so are not compared for register: wording quoted under a label
5
5
  // (例:…, Q: …, a paragraph under a lone 用例), the value of a field set out under a marked label line (■ 調査目的\n…) and a contact
6
- // block (a paragraph with a 〒 or 電話: line). A note on a ※ line and a cell of a table laid out as lines are set apart too, but
6
+ // block (a paragraph with a 〒 or 電話: line). A note on a ※ or * line and a cell of a table laid out as lines are set apart too, but
7
7
  // stay counted: only some of a table's cells take the shape, and dropping those would leave the rest a smaller minority. Pure.
8
8
 
9
9
  /** A label, a number after it (Q1, 例2), then the mark that ends it. */
@@ -78,13 +78,13 @@ export const fieldValueSentences = (sentences: readonly Sentence[], source: stri
78
78
  return new Set(sentences.filter((sentence) => values.some((value) => sentence.span.start >= value.start && sentence.span.start < value.end)));
79
79
  };
80
80
 
81
- /** A line that opens with a reference mark (※PDFファイルが開けない…): a note set beside the text. */
82
- const NOTE_LINE = /^[ \t\u3000]*※/u;
81
+ /** A line that opens with a reference mark, ※ or the full-width asterisk * (※PDFファイルが開けない…, *図は圧縮しているため…): a note set beside the text. */
82
+ const NOTE_LINE = /^[ \t\u3000]*[※*]/u;
83
83
 
84
84
  const lineStartOf = (source: string, offset: number): number => source.lastIndexOf("\n", offset - 1) + 1;
85
85
 
86
86
  /**
87
- * The sentences on a line that opens with ※. A note (※…の場合はこちらをご覧ください。) is the page's aside to the reader, written in
87
+ * The sentences on a line that opens with ※ or *. A note (※…の場合はこちらをご覧ください。) is the page's aside to the reader, written in
88
88
  * its own register whatever the text around it uses.
89
89
  */
90
90
  export const referenceNoteSentences = (sentences: readonly Sentence[], source: string): Set<Sentence> =>
@@ -70,6 +70,25 @@ export const isTakenUp = (next: Sentence | undefined, between: string, openers:
70
70
  return openers.some((opener) => opening.has(opener.pattern));
71
71
  };
72
72
 
73
+ /** The particles a sentence closes with, joined (か/な → かな), after its last word and before its marks. */
74
+ const closingParticles = (tokens: readonly Token[]): string => {
75
+ const words = tokens.filter((token) => token.pos !== "PUNCT" && !TRAILING_MARKS.has(token.surface));
76
+ const start = words.findLastIndex((token) => token.pos !== "PART") + 1;
77
+ return words
78
+ .slice(start)
79
+ .map((token) => token.surface)
80
+ .join("");
81
+ };
82
+
83
+ /**
84
+ * A sentence that closes with a particle of address from address-particle (…含まれているよ。…違うんだよ。…のかな?): the writer speaks
85
+ * to the reader on purpose, in a voice a polite page sets among its sentences, not a slip into the plain register.
86
+ */
87
+ export const isAddressed = (sentence: Sentence, particles: readonly LexiconEntry[]): boolean => {
88
+ const closing = closingParticles(sentence.tokens ?? []);
89
+ return closing !== "" && particles.some((particle) => closing.endsWith(particle.pattern));
90
+ };
91
+
73
92
  const EXCLAMATION = /[!!][\s」』))]*$/u;
74
93
 
75
94
  /** A sentence closed by an exclamation mark (わかるかっ!!!): a cry in the writer's voice, said plainly in either register. */
@@ -20,6 +20,8 @@ const LOOPHOLE = "requirement-loophole";
20
20
  const OPEN_QUESTION = "requirement-open-question";
21
21
  /** The words of a condition whose bracketed examples an open list may give. */
22
22
  const OPEN_CONDITION = "requirement-open-condition";
23
+ /** The terms law or usage fixes with an open-end word (消費税等), which close their own list. The language may have none. */
24
+ const FIXED_TERMS = "requirement-open-end-fixed-term";
23
25
  const TIME = "time";
24
26
  const CONCRETE_DEADLINE = "concrete-deadline";
25
27
 
@@ -77,7 +79,8 @@ const smellWords = (doc: ProseDocument, lexicon: string, genre: string | undefin
77
79
  /**
78
80
  * Where the word stands as a smell. An open-end word inside a name the document gives (業務執行取締役等), giving examples
79
81
  * of a class named right after it (印刷等、二次的に利用), ending a list a condition, a permission or a prohibition holds
80
- * (転載等をしてはならない), or ending a list a pointing word opens (当該改良、改善等), is none; without tokens none of these can be told apart.
82
+ * (転載等をしてはならない), ending a list a pointing word opens (当該改良、改善等), or part of a term law fixes (消費税等), is
83
+ * none; without tokens none of these can be told apart.
81
84
  */
82
85
  const smellAt = (doc: ProseDocument, sentence: Sentence, entry: LexiconEntry, lexicon: string, names: () => OpenEndNames): number | undefined => {
83
86
  if (!entryIn(sentence, entry) || boundedInTime(doc, sentence, entry, lexicon)) return undefined;
@@ -126,7 +129,8 @@ export const requirementSmell: Detector = (doc, options): Finding[] => {
126
129
  const statements = (doc.lexicons[STATEMENTS] ?? []).map((entry) => entry.pattern);
127
130
  // Read once, and only when a requirement has an open-end word to tell apart from a name.
128
131
  const cache: { names?: OpenEndNames } = {};
129
- const names = (): OpenEndNames => (cache.names ??= openEndNames(doc, smellWords(doc, OPEN_END, options.genre), statements));
132
+ const fixed = (doc.lexicons[FIXED_TERMS] ?? []).map((entry) => entry.pattern);
133
+ const names = (): OpenEndNames => (cache.names ??= openEndNames(doc, smellWords(doc, OPEN_END, options.genre), statements, fixed));
130
134
  const onPurpose = scopeWordsOf(doc.lexicons[OPEN_END] ?? []).onPurpose;
131
135
  const openItems = itemsOpenOnPurpose(doc.source, doc.sentences, doc.lists, onPurpose);
132
136
  return doc.sentences.flatMap((sentence, index) => {
@@ -163,7 +163,8 @@ export const sentenceCommaCount: Detector = (doc, options): Finding[] => {
163
163
  return known;
164
164
  };
165
165
  const counts: TokenTest = (token, at, tokens) => isComma(token) && !separatesItems(at, tokens) && !listedIn(tokens).has(at);
166
- return sentencesOver({ ...doc, sentences: doc.sentences.filter((sentence) => !isFlattenedTable(sentence.text)) }, options.limit, counts);
166
+ const eras = (doc.lexicons["calendar-era"] ?? []).map((entry) => entry.pattern);
167
+ return sentencesOver({ ...doc, sentences: doc.sentences.filter((sentence) => !isFlattenedTable(sentence.text, eras)) }, options.limit, counts);
167
168
  };
168
169
 
169
170
  const CONJUNCTIVE = "SCONJ";
@@ -11,7 +11,7 @@ import { chronologyRows } from "../chronology-rows.ts";
11
11
  import { isNeutralPlainShape } from "./register-neutral-shape.ts";
12
12
  import { spokenAnswerSentences } from "./register-interview.ts";
13
13
  import { contactBlockSentences, fieldValueSentences, labelledQuoteSentences, referenceNoteSentences, tableCellSentences } from "./register-set-apart.ts";
14
- import { endsInSetGreeting, isDeclaration, isExclamation, isTakenUp } from "./register-voice.ts";
14
+ import { endsInSetGreeting, isAddressed, isDeclaration, isExclamation, isTakenUp } from "./register-voice.ts";
15
15
  import { entriesForGenre } from "../lexicon-genres.ts";
16
16
  import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
17
17
 
@@ -34,15 +34,16 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
34
34
  /**
35
35
  * quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
36
36
  * 丁寧な形でしか言わない挨拶(お疲れ様でした。)、演説の決意の言い切り(二度と繰り返さない。)、
37
- * 次の文が「そんな」「これだけ」で受ける場面の書き出し、「!」で終わる叫び(わかるかっ!)も quiet(register-voice.ts)。
38
- * ※で始まる行の注記と、行に並べ直した表のセル(制限なし。)は、どちらの調子でも quiet(register-set-apart.ts)。
37
+ * 次の文が「そんな」「これだけ」で受ける場面の書き出し、「!」で終わる叫び(わかるかっ!)、読み手に呼びかける終助詞で終わる文(…いるよ。)も quiet(register-voice.ts)。
38
+ * ※や*で始まる行の注記と、行に並べ直した表のセル(制限なし。)は、どちらの調子でも quiet(register-set-apart.ts)。
39
39
  * インタビューの答え(聞き手の「――」の後の段落)は話した言葉なので quiet(register-interview.ts)。
40
40
  * 数には入れる。数から外すと、常体を何度も使う文書(演説)で少数派が閾値を下回り、残りの常体の文が新たに指されてしまう。
41
41
  */
42
42
  type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined; readonly quiet: boolean };
43
43
 
44
44
  /** 文の調子と quiet を決める語彙表。polite は polite-ending、neutral は neutral-ending、requests は neutral-request、wishes は neutral-wish、
45
- * greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener。 */
45
+ * greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener、
46
+ * address は address-particle。 */
46
47
  type EndingWords = {
47
48
  readonly polite: readonly LexiconEntry[];
48
49
  readonly neutral: readonly LexiconEntry[];
@@ -52,6 +53,7 @@ type EndingWords = {
52
53
  readonly declaration: readonly LexiconEntry[];
53
54
  readonly resolves: readonly LexiconEntry[];
54
55
  readonly openers: readonly LexiconEntry[];
56
+ readonly address: readonly LexiconEntry[];
55
57
  };
56
58
 
57
59
  type Read = { readonly register: Register; readonly quiet: boolean };
@@ -65,6 +67,7 @@ const endingWords = (doc: ProseDocument, polite: readonly LexiconEntry[], genre:
65
67
  declaration: entriesForGenre(doc.lexicons["declaration-particle"] ?? [], genre),
66
68
  resolves: entriesForGenre(doc.lexicons["declaration-ending"] ?? [], genre),
67
69
  openers: doc.lexicons["takeup-opener"] ?? [],
70
+ address: doc.lexicons["address-particle"] ?? [],
68
71
  });
69
72
 
70
73
  /** 調子を持つ文のうち、指さない形か。next は同じ文書の次の文、between はその間の文字列。 */
@@ -74,6 +77,7 @@ const isQuiet = (sentence: Sentence, ending: readonly Token[], register: Registe
74
77
  : isNeutralPlainShape(sentence, ending, words.requests, words.wishes) ||
75
78
  isDeclaration(sentence, ending, words.declaration, words.resolves) ||
76
79
  isExclamation(sentence) ||
80
+ isAddressed(sentence, words.address) ||
77
81
  isTakenUp(next, between, words.openers);
78
82
 
79
83
  const registerOfSentence = (doc: ProseDocument, index: number, words: EndingWords): Read | undefined => {
@@ -1,20 +1,21 @@
1
1
  import { lengthOf, proseText } from "../measure.ts";
2
2
  import type { Detector, DetectorOptions, Finding, LengthUnit, Sentence } from "../plugin.ts";
3
- import { citationLead } from "./citation-sentence.ts";
3
+ import { authorListSaving, citationLead, withoutEarlierReference } from "./citation-sentence.ts";
4
4
  import { isCitationString, wordsAroundCitation } from "./citation-string.ts";
5
5
  import { isNameList } from "./name-list-sentence.ts";
6
6
  import { pageMarkerPattern, pageMarkerSize } from "./page-marker.ts";
7
7
  import { quotedSentenceParts } from "./quoted-sentences.ts";
8
8
  import { isReproduced, reproducedSpans } from "./reproduced-text.ts";
9
- import { colonQuotationParts, flattenedTableParts, isGrammarBlock, labelLineParts } from "./sentence-parts.ts";
9
+ import { colonQuotationParts, flattenedTableParts, isGrammarBlock, labelLineParts, parentheticalSentenceParts } from "./sentence-parts.ts";
10
10
  import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAfterTitle, termSeriesSaving } from "./sentence-title.ts";
11
11
 
12
12
  type Measure = { readonly size: number; readonly limit: number; readonly variant?: string };
13
13
 
14
- /** The page markers' pattern, the citation signals ("see") and the spans of the list items, read once per document. */
14
+ /** The page markers' pattern, the citation signals ("see"), the era names and the spans of the list items, read once per document. */
15
15
  type SentenceWords = {
16
16
  readonly markers: RegExp | undefined;
17
17
  readonly citationSignals: readonly string[];
18
+ readonly eras: readonly string[];
18
19
  readonly listItems: readonly { readonly start: number; readonly end: number }[];
19
20
  };
20
21
 
@@ -25,7 +26,7 @@ type SentenceWords = {
25
26
  * Only where words are the unit: the shapes are read from capitals and spaces.
26
27
  */
27
28
  const unwrittenWords = (sentence: Sentence, text: string, listItems: SentenceWords["listItems"]): number =>
28
- termSeriesSaving(text) + (isInListItem(sentence.span, listItems) || isReferenceLine(text) ? quotedTitleWords(text) : 0);
29
+ termSeriesSaving(text) + authorListSaving(text) + (isInListItem(sentence.span, listItems) || isReferenceLine(text) ? quotedTitleWords(text) : 0);
29
30
 
30
31
  const sizeOf = (text: string, unit: LengthUnit): number =>
31
32
  unit === "word" ? text.split(/\s+/u).filter((word) => word.length > 0).length : text.replace(/\s+/gu, "").length;
@@ -43,7 +44,7 @@ const longestQuotedPart = (text: string, size: number, markers: RegExp | undefin
43
44
  */
44
45
  const measureOf = (sentence: Sentence, unit: LengthUnit, options: DetectorOptions, words: SentenceWords): Measure => {
45
46
  const lead = citationLead(proseText(sentence), words.citationSignals);
46
- if (lead !== undefined) return { size: sizeOf(lead, unit), limit: options.limit };
47
+ if (lead !== undefined) return { size: sizeOf(withoutEarlierReference(lead), unit), limit: options.limit };
47
48
  const embedded = sentence.embeddedLanguage;
48
49
  const limit = embedded === undefined ? undefined : options.embeddedLimits?.[embedded.id];
49
50
  if (embedded === undefined || limit === undefined) return { size: ownSize(sentence, unit, words), limit: options.limit };
@@ -55,8 +56,8 @@ const isUnwritten = (sentence: Sentence, text: string, unit: LengthUnit, words:
55
56
  isGrammarBlock(sentence.text) || isCitationString(text, words.citationSignals) || (unit === "word" && isTitleLine(text));
56
57
 
57
58
  /** The parts measured one by one when the splitter ran several things into one sentence (label lines, table cells, a quotation). */
58
- const partsOf = (sentence: Sentence, text: string): readonly string[] | undefined =>
59
- labelLineParts(sentence.text) ?? flattenedTableParts(text) ?? colonQuotationParts(text);
59
+ const partsOf = (sentence: Sentence, text: string, eras: readonly string[]): readonly string[] | undefined =>
60
+ labelLineParts(sentence.text) ?? flattenedTableParts(text, eras) ?? colonQuotationParts(text) ?? parentheticalSentenceParts(text);
60
61
 
61
62
  /** The length of a sentence in the document's language, without what the writer did not write as one. */
62
63
  const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): number => {
@@ -64,7 +65,7 @@ const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): nu
64
65
  if (isUnwritten(sentence, text, unit, words)) return 0;
65
66
  const aroundCitation = unit === "word" ? wordsAroundCitation(text, words.citationSignals) : undefined;
66
67
  if (aroundCitation !== undefined) return sizeOf(aroundCitation, unit);
67
- const parts = partsOf(sentence, text);
68
+ const parts = partsOf(sentence, text, words.eras);
68
69
  if (parts !== undefined) return Math.max(0, ...parts.map((part) => sizeOf(part, unit) - pageMarkerSize(part, words.markers, unit)));
69
70
  const remark = unit === "word" ? remarkAfterTitle(text) : undefined;
70
71
  if (remark !== undefined) return sizeOf(remark, unit);
@@ -77,6 +78,7 @@ export const sentenceLength: Detector = (doc, options): Finding[] => {
77
78
  const words: SentenceWords = {
78
79
  markers: pageMarkerPattern((options.lexicon ?? []).map((entry) => entry.pattern)),
79
80
  citationSignals: (doc.lexicons["citation-signal"] ?? []).map((entry) => entry.pattern),
81
+ eras: (doc.lexicons["calendar-era"] ?? []).map((entry) => entry.pattern),
80
82
  listItems: doc.lists.flatMap((list) => list.itemSpans),
81
83
  };
82
84
  const long = doc.sentences
@@ -3,6 +3,7 @@
3
3
  // a converter ran together (…設立1945年7月日染興業…, 39,0439,677…), and a quotation the writer introduces with a colon.
4
4
  // Each is measured part by part, or not at all. Pure: the text in, the parts out.
5
5
 
6
+ import { escapeRegExp } from "../orthography.ts";
6
7
  import type { Span } from "../plugin.ts";
7
8
 
8
9
  const LINE_BREAK = /\n/u;
@@ -46,11 +47,19 @@ const GLUED_NUMBER = /\d[,,]\d{4}|\d(?:[..]\d+){4}/u;
46
47
  /** A run of numbers, signs and empty-cell dashes (39,0439,6773,503…△0.6); it is cut out when it holds glued cells. */
47
48
  const NUMBER_RUN = /[\d,,..△▲-−%%-]+/gu;
48
49
  const CUT = "\n";
49
- /** A date that opens a row, run into the cell before it and the cell after it (…設立1945年7月日染興業…). */
50
- const GLUED_DATE =
51
- /(?<=[\p{Script=Han}\p{Script=Katakana}\p{Script=Hiragana}ー])(?=[0-90-9]{4}年[0-90-9]{1,2}月[\p{Script=Han}\p{Script=Katakana}\p{L}])/gu;
50
+ /** The year of a date that opens a row: four digits, or an era name and its year (昭和59年, 令和元年). */
51
+ const rowYear = (eras: readonly string[]): string =>
52
+ eras.length === 0 ? "[0-90-9]{4}" : `(?:[0-90-9]{4}|(?:${eras.map(escapeRegExp).join("|")})(?:[0-90-9]{1,2}|元))`;
53
+ /** A date that opens a row, run into the cell before it and the cell after it (…設立1945年7月日染興業…, …を開始昭和59年4月東京…). */
54
+ const gluedDate = (eras: readonly string[]): RegExp =>
55
+ new RegExp(
56
+ `(?<=[\\p{Script=Han}\\p{Script=Katakana}\\p{Script=Hiragana}ー])(?=${rowYear(eras)}年[0-90-9]{1,2}月[\\p{Script=Han}\\p{Script=Katakana}\\p{L}])`,
57
+ "gu",
58
+ );
52
59
  /** Fewer glued dates than this are a sentence that names a date or two, not the rows of a chronology. */
53
60
  const MIN_GLUED_DATES = 3;
61
+ /** A space between Japanese words inside a flattened table: where the converter kept a cell apart (…に開設 (注)1.…). */
62
+ const CELL_SPACE = /(?<=[\p{Script=Han}\p{Script=Katakana}\p{Script=Hiragana}ー)」])\s+(?=[\p{Script=Han}\p{Script=Katakana}\p{Script=Hiragana}(「])/u;
54
63
 
55
64
  const nonEmpty = (parts: readonly string[]): string[] => parts.map((part) => part.trim()).filter((part) => part !== "");
56
65
 
@@ -61,11 +70,14 @@ export const hasGluedNumbers = (text: string): boolean => GLUED_NUMBER.test(text
61
70
  export const gluedNumberSpans = (text: string): Span[] =>
62
71
  [...text.matchAll(NUMBER_RUN)].filter((run) => GLUED_NUMBER.test(run[0])).map((run) => ({ start: run.index, end: run.index + run[0].length }));
63
72
 
64
- /** The cells of a table a converter flattened into one sentence, cut at the glued numbers or at each row's date. */
65
- export const flattenedTableParts = (text: string): readonly string[] | undefined => {
73
+ /**
74
+ * The cells of a table a converter flattened into one sentence, cut at the glued numbers or at each row's date. eras are
75
+ * the era names a row's year may be written with (the calendar-era lexicon).
76
+ */
77
+ export const flattenedTableParts = (text: string, eras: readonly string[] = []): readonly string[] | undefined => {
66
78
  if (hasGluedNumbers(text)) return nonEmpty(text.replace(NUMBER_RUN, (run) => (GLUED_NUMBER.test(run) ? CUT : run)).split(CUT));
67
- const rows = text.split(GLUED_DATE);
68
- return rows.length > MIN_GLUED_DATES ? nonEmpty(rows) : undefined;
79
+ const rows = text.split(gluedDate(eras));
80
+ return rows.length > MIN_GLUED_DATES ? nonEmpty(rows.flatMap((row) => row.split(CELL_SPACE))) : undefined;
69
81
  };
70
82
 
71
83
  /** A quotation the writer opens after a colon (has observed: "The credibility of money …"), in straight or curly quotes. */
@@ -78,6 +90,18 @@ export const colonQuotationParts = (text: string): readonly string[] | undefined
78
90
  return nonEmpty([text.replace(COLON_QUOTATION, ":"), ...quotes]);
79
91
  };
80
92
 
93
+ /**
94
+ * A sentence that opens the text inside parentheses and closes there ("(Don't bother … now.)"), then the next sentence: a
95
+ * splitter that does not cut after ".)" runs them together. Only at the start, where the splitter already cut before "(".
96
+ */
97
+ const PARENTHETICAL_SENTENCE_HEAD = /^\([^()]*[.?!]\)(?=\s+["“]?\p{Lu})/u;
98
+
99
+ /** A parenthesised sentence and the sentence after it, measured apart. */
100
+ export const parentheticalSentenceParts = (text: string): readonly string[] | undefined => {
101
+ const head = PARENTHETICAL_SENTENCE_HEAD.exec(text)?.[0];
102
+ return head === undefined ? undefined : nonEmpty([head, text.slice(head.length)]);
103
+ };
104
+
81
105
  /** A header cell closed by its unit in brackets (所有割合(%), 従業員数(人), 資本金(百万円)). */
82
106
  const UNIT_HEADER = /[((](?:%|%|人|名|株|件|台|社|円|千円|百万円)[))]/gu;
83
107
  /** Fewer unit headers than this are a sentence that names a unit or two, not a table's header row. */
@@ -90,8 +114,8 @@ const DITTO_CELLS = /〃\s*〃/u;
90
114
  * Whether a sentence is a table a converter flattened: glued numbers, rows opened by dates, a header row of cells closed by
91
115
  * units, or ditto cells.
92
116
  */
93
- export const isFlattenedTable = (text: string): boolean =>
94
- flattenedTableParts(text) !== undefined || (text.match(UNIT_HEADER)?.length ?? 0) >= MIN_UNIT_HEADERS || DITTO_CELLS.test(text);
117
+ export const isFlattenedTable = (text: string, eras: readonly string[] = []): boolean =>
118
+ flattenedTableParts(text, eras) !== undefined || (text.match(UNIT_HEADER)?.length ?? 0) >= MIN_UNIT_HEADERS || DITTO_CELLS.test(text);
95
119
 
96
120
  /** A decimal cell run in between a bracketed cell and the next cell's word ((日本)100.0自動車関連): where one row's cells meet. */
97
121
  const GLUED_DECIMAL_CELL = /[))]\d{1,3}\.\d+(?=\p{L})/gu;
@@ -3,6 +3,7 @@ import { dateSpans, wordsOf } from "./structure.ts";
3
3
  import { lexiconNotationOf, sourceNotAcronymSpans, unreportedAcronymSpans, type NotAcronymSpans } from "./acronym-context.ts";
4
4
  import { titledCodeSpans } from "./titled-code-citation.ts";
5
5
  import { abbreviates, expansionAt, termEntryAcronyms, type DefinitionWords, type ExpandedAt } from "./acronym-expansion.ts";
6
+ import { parentItemAcronyms } from "./acronym-parent-item.ts";
6
7
  import { isExplained } from "./acronym-compound.ts";
7
8
  import { statedAcronyms } from "./acronym-definition.ts";
8
9
  import { isBracketed, isInHeading, isNamePart } from "./acronym-lone.ts";
@@ -268,12 +269,14 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
268
269
  // 略語のすぐ後ろのダッシュで挟んだ同格(the VIX—a measure of …—)、同じ文の前に書いた名前(Small Business Administration … SBA)、
269
270
  // 2 つ以上の番号で引く続き物の名前(BCP 78、BCP 14)も、略語の説明と読む。
270
271
  // 文献一覧の見出し語([UNIX] The Open Group, "The Single UNIX Specification")と、見出しに番号で立てた書簡の続き物(### SR 26-8: …)も。
272
+ // 入れ子の箇条書きで、親の項目が書き出した名前(- No product owner: の下の - Unavailable PO)も。
271
273
  const headings = doc.sections.map((section) => halfWidth(section.heading));
272
274
  const counted = countedHitsOf(doc);
273
275
  // ファイルの種類の名前としてだけ書いた大文字(the MAP files、MAPファイル)も、展開を待つ略語ではない。
274
276
  const entries = new Set([
275
277
  ...fileTypeNames(counted.map(fileUseOf), patternsOf(doc, "file-noun")),
276
278
  ...termEntryAcronyms(doc.source),
279
+ ...parentItemAcronyms(doc.source),
277
280
  ...stated,
278
281
  ...linkedListTerms(doc.source),
279
282
  ...spelled,
@@ -8,10 +8,10 @@ import { quoteAround } from "./quote-around.ts";
8
8
  */
9
9
  const SPACED_MARK = /(?<=\p{L}[)\]}"'”’]?) (?=[.,;?!](?:[\s)\]"'”’]|$))/gu;
10
10
 
11
- /** 空白で区切った点の並び(". . .")。省略の印と、目次の点線。 */
12
- const SPACED_DOTS = /^\. ?\./u;
11
+ /** 空白で区切った点の並び(". . .")。省略の印と、目次の点線。行の折り返しが点の間に入ってもよい("vibrations .\n. . I")。 */
12
+ const SPACED_DOTS = /^\.(?: |\r?\n)?\./u;
13
13
 
14
- const DOTS_REACH = 3;
14
+ const DOTS_REACH = 4;
15
15
 
16
16
  const isSpacedEllipsis = (text: string, space: number): boolean => SPACED_DOTS.test(text.slice(space + 1, space + 1 + DOTS_REACH));
17
17
 
@@ -0,0 +1,37 @@
1
+ // The paragraphs of near-verbatim minutes that open with a speaker's name ("Mara: There's some history ..."). What
2
+ // follows the name is that person's own phrasing as the note-taker recorded it, not the writer's. Pure.
3
+ import type { Span } from "../plugin.ts";
4
+
5
+ /** How many names must each open MIN_TURNS paragraphs: one or two repeated labels are fields (Status:, Comments:). */
6
+ const MIN_SPEAKERS = 3;
7
+ const MIN_TURNS = 3;
8
+ /** The share of the paragraphs the names must open, so a few labelled lines in a report do not make it minutes. */
9
+ const MIN_TURN_SHARE = 0.2;
10
+
11
+ /** A name of up to three words, written at the very start of the paragraph, a colon, then the words said. */
12
+ const TURN = /^(?<name>\p{L}[\p{L}'’.-]*(?: \p{Lu}[\p{L}'’.-]*){0,2}): +\S/u;
13
+ const BLANK_LINES = /\n[ \t\r]*(?:\n[ \t\r]*)+/gu;
14
+
15
+ type Paragraph = { readonly span: Span; readonly name: string | undefined };
16
+
17
+ const paragraphsOf = (source: string): Paragraph[] => {
18
+ const breaks = [...source.matchAll(BLANK_LINES)];
19
+ const starts = [0, ...breaks.map((found) => found.index + found[0].length)];
20
+ const ends = [...breaks.map((found) => found.index), source.length];
21
+ return starts
22
+ .map((start, index) => ({ start, end: ends[index] ?? source.length }))
23
+ .filter(({ start, end }) => source.slice(start, end).trim() !== "")
24
+ .map((span) => ({ span, name: TURN.exec(source.slice(span.start, span.end))?.groups?.["name"] }));
25
+ };
26
+
27
+ const turnCounts = (paragraphs: readonly Paragraph[]): Map<string, number> =>
28
+ paragraphs.reduce((counts, { name }) => (name === undefined ? counts : counts.set(name, (counts.get(name) ?? 0) + 1)), new Map<string, number>());
29
+
30
+ /** The spans of the paragraphs a speaker's name opens, when the document reads as minutes of who said what; else none. */
31
+ export const speakerTurns = (source: string): Span[] => {
32
+ const paragraphs = paragraphsOf(source);
33
+ const turns = paragraphs.filter((paragraph) => paragraph.name !== undefined);
34
+ const speakers = [...turnCounts(turns).values()].filter((count) => count >= MIN_TURNS).length;
35
+ if (speakers < MIN_SPEAKERS || turns.length < paragraphs.length * MIN_TURN_SHARE) return [];
36
+ return turns.map((turn) => turn.span);
37
+ };
@@ -6,6 +6,7 @@ import type { Detector, Finding, ProseDocument, Sentence, Span, Token } from "..
6
6
  import { countedTokens, uncountedWordsOf, type UncountedWords } from "../uncounted-particles.ts";
7
7
  import { boundWordParticles } from "../bound-word-particles.ts";
8
8
  import { setPhraseParticles } from "../set-phrase-particles.ts";
9
+ import { clauseEnds, determinerParticles, longestClausePart } from "../clause-particles.ts";
9
10
  import { noteSentences } from "../note-paragraphs.ts";
10
11
  import { labelledNoteSentences } from "../labelled-note-paragraphs.ts";
11
12
  import { listLeadSentences } from "../list-lead-sentence.ts";
@@ -40,12 +41,20 @@ const clippedByForm = (doc: ProseDocument): ReadonlySet<Sentence> => {
40
41
  ]);
41
42
  };
42
43
 
44
+ /** 問いを閉じる助詞の語彙表(か)。 */
45
+ const QUESTION_PARTICLE_LEXICON = "question-particle";
46
+
47
+ /** 最後の語の後ろに問いの助詞がある文(どのような見直しが必要か。)。問いで、名詞で止めた文ではない。 */
48
+ const asksAfter = (sentence: Sentence, last: Token, questionParticles: ReadonlySet<string>): boolean =>
49
+ (sentence.tokens ?? []).some((token) => token.span.start >= last.span.end && token.pos === "PART" && questionParticles.has(token.surface));
50
+
43
51
  export const nounEnding: Detector = (doc, options): Finding[] => {
44
52
  const clipped = clippedByForm(doc);
53
+ const questionParticles = new Set((doc.lexicons[QUESTION_PARTICLE_LEXICON] ?? []).map((entry) => entry.pattern));
45
54
  const ended = doc.sentences.filter((sentence) => {
46
55
  if (inside(sentence.span, doc.listSpans) || clipped.has(sentence) || !isClosed(sentence) || !hasParticle(sentence)) return false;
47
56
  const last = lastContent(sentence);
48
- return last !== undefined && NOMINAL.has(last.pos) && !isDependent(last);
57
+ return last !== undefined && NOMINAL.has(last.pos) && !isDependent(last) && !asksAfter(sentence, last, questionParticles);
49
58
  });
50
59
  const first = ended[0];
51
60
  // 文書全体の数についての指摘なので、1 文ずつ出さない。13 件並べても直す順番が分からない。
@@ -121,12 +130,19 @@ const POSITION_LEXICON = "particle-run-position";
121
130
  /** 助詞を挟んで一語のように読む決まった言い回し(おそれのある)。中の助詞は入れ子の輪に数えない。 */
122
131
  const SET_PHRASE_LEXICON = "particle-run-set-phrase";
123
132
 
124
- /** 前の語と組んで一つの名前になる語(皆様、下)と決まった言い回し(おそれのある)。 */
125
- type Phrases = { readonly boundWords: readonly string[]; readonly setPhrases: readonly string[] };
133
+ /** どれを指すかだけを言う語(他の)。直後の「の」は名詞を名詞の中に入れない。 */
134
+ const DETERMINER_LEXICON = "particle-run-determiner";
126
135
 
127
- /** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語や置き場所を言う語の前の「の」、決まった言い回しの中の「の」)を除いた語。 */
128
- const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { boundWords, setPhrases }: Phrases): readonly Token[] => {
129
- const uncounted = new Set([...boundWordParticles(tokens, numbering.particles, boundWords), ...setPhraseParticles(tokens, numbering.particles, setPhrases)]);
136
+ /** 前の語と組んで一つの名前になる語(皆様、下)、決まった言い回し(おそれのある)、どれを指すかだけを言う語(他)。 */
137
+ type Phrases = { readonly boundWords: readonly string[]; readonly setPhrases: readonly string[]; readonly determiners: readonly string[] };
138
+
139
+ /** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語や置き場所を言う語の前の「の」、決まった言い回しの中の「の」、他の)を除いた語。 */
140
+ const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { boundWords, setPhrases, determiners }: Phrases): readonly Token[] => {
141
+ const uncounted = new Set([
142
+ ...boundWordParticles(tokens, numbering.particles, boundWords),
143
+ ...setPhraseParticles(tokens, numbering.particles, setPhrases),
144
+ ...determinerParticles(tokens, numbering.particles, determiners),
145
+ ]);
130
146
  const counted = countedTokens(tokens, numbering);
131
147
  return uncounted.size === 0 ? counted : counted.filter((token) => !uncounted.has(token));
132
148
  };
@@ -139,6 +155,7 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
139
155
  const phrases: Phrases = {
140
156
  boundWords: [HONORIFIC_GROUP_LEXICON, POSITION_LEXICON].flatMap((id) => (doc.lexicons[id] ?? []).map((entry) => entry.pattern)),
141
157
  setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
158
+ determiners: (doc.lexicons[DETERMINER_LEXICON] ?? []).map((entry) => entry.pattern),
142
159
  };
143
160
  const prose = doc.prose ?? doc.source;
144
161
  const namingMarkers = (doc.lexicons[NAMING_LEXICON] ?? []).map((entry) => entry.pattern);
@@ -155,7 +172,10 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
155
172
  ...namedLongForms(sentence.text, sentence.span.start, sentence.tokens ?? [], namingMarkers, continuesName),
156
173
  ...quotedNameSpans(sentence.text, sentence.span.start, names),
157
174
  ];
158
- const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
175
+ // 「の」で主語を示した節(番号のついた版)の前と後ろは別の句。どちらかの句の中で上限を超える連なりだけを、連なり全体で言う。
176
+ const ends = clauseEnds(tokens, nesting);
177
+ const isLong = (run: Run): boolean => run.tokens.length > options.limit && longestClausePart(run.tokens, ends) > options.limit;
178
+ const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter(isLong);
159
179
  const found = longRuns(quoted);
160
180
  // 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
161
181
  const runs = found.length === 0 ? found : longRuns([...quoted, ...documentNameSpans(prose, sentence.span, doc.namedDocument)]);
@@ -6,6 +6,7 @@ import { overLimit, ownTokens } from "./sentence-load.ts";
6
6
 
7
7
  const CLOSER_LEXICON = "topic-clause-close";
8
8
  const ARTICLE_LEXICON = "statute-article-opener";
9
+ const ADVERB_LEXICON = "topic-adverb";
9
10
 
10
11
  /**
11
12
  * Whether the sentence is an article of a statute quoted in another kind of document (第7条 … in a manual): the law's wording,
@@ -19,7 +20,8 @@ const quotesArticle = (doc: ProseDocument, genre: string | undefined): ((sentenc
19
20
 
20
21
  /** The distance from the sentence's topic (〜は) to the end, where its predicate is. Needs the language's tokens. */
21
22
  export const topicPredicateDistance: Detector = (doc, options) => {
22
- const words: TopicClauseWords = { closers: (doc.lexicons[CLOSER_LEXICON] ?? []).map((entry) => entry.pattern) };
23
+ const patterns = (lexicon: string): string[] => (doc.lexicons[lexicon] ?? []).map((entry) => entry.pattern);
24
+ const words: TopicClauseWords = { closers: patterns(CLOSER_LEXICON), adverbs: patterns(ADVERB_LEXICON) };
23
25
  const quoted = quotesArticle(doc, options.genre);
24
26
  return overLimit((sentence) => (sentence.tokens === undefined || quoted(sentence) ? undefined : topicDistance(ownTokens(sentence), words)))(doc, options);
25
27
  };
@@ -49,7 +49,8 @@ export type BracketProblem = {
49
49
  readonly partner?: string;
50
50
  };
51
51
 
52
- type Open = { readonly bracket: Bracket; readonly offset: number };
52
+ /** continues は、行の頭で同じ引用符を開き直したときの、その前の開き(詩の引用は行ごとに開き直し、終わりで一度だけ閉じる)。 */
53
+ type Open = { readonly bracket: Bracket; readonly offset: number; readonly continues?: Open };
53
54
  type Scan = { readonly open: Open[]; readonly problems: BracketProblem[] };
54
55
 
55
56
  /** 半角の「「」」。幅の違いは hankaku-kana が指すので、全角と組んでも幅の違いとしては指さない。 */
@@ -78,6 +79,22 @@ const closeWith = (scan: Scan, text: string, bracket: Bracket, offset: number):
78
79
  .forEach((inner) => scan.problems.push(unclosedOf(inner)));
79
80
  if (opened !== undefined && isWidthSlip(opened.bracket, bracket))
80
81
  scan.problems.push({ kind: "mismatch", offset, mark: bracket.close, partner: opened.bracket.open });
82
+ if (opened !== undefined && reopenedLines(opened) >= MIN_REOPENED_LINES) dropContinued(scan, opened.continues);
83
+ };
84
+
85
+ /**
86
+ * 行の頭で開き直した数がこれより少なければ、行の頭の引用符は中に引いた言葉(“I told her\n“go away” and left.”)と読む。
87
+ * 詩の引用は二行以上を続けて開き直す。
88
+ */
89
+ const MIN_REOPENED_LINES = 2;
90
+
91
+ const reopenedLines = (entry: Open | undefined): number => (entry?.continues === undefined ? 0 : 1 + reopenedLines(entry.continues));
92
+
93
+ /** 閉じた引用が開き直しで続けてきた前の開きを、閉じたものとして外す。 */
94
+ const dropContinued = (scan: Scan, prior: Open | undefined): void => {
95
+ if (prior === undefined || scan.open.at(-1) !== prior) return;
96
+ scan.open.pop();
97
+ dropContinued(scan, prior.continues);
81
98
  };
82
99
 
83
100
  /** 段落(空行で区切った塊)の最初の字。 */
@@ -85,14 +102,29 @@ const PARAGRAPH_HEAD = /(?:^|\n[ \t\u3000]*\n)[ \t\u3000]*(?=\S)/gu;
85
102
 
86
103
  const paragraphHeads = (text: string): ReadonlySet<number> => new Set([...text.matchAll(PARAGRAPH_HEAD)].map((match) => match.index + match[0].length));
87
104
 
105
+ /** 行の最初の字(字下げの後ろ)。 */
106
+ const LINE_HEAD = /(?:^|\n)[ \t\u3000]*(?=\S)/gu;
107
+
108
+ const lineHeads = (text: string): ReadonlySet<number> => new Set([...text.matchAll(LINE_HEAD)].map((match) => match.index + match[0].length));
109
+
110
+ type Heads = { readonly paragraphs: ReadonlySet<number>; readonly lines: ReadonlySet<number> };
111
+
88
112
  /** 人の言葉を引く括弧。続く段落を同じ開きで始めて、引用が続くことを示す書き方がある。 */
89
113
  const QUOTATIONS: ReadonlySet<string> = new Set(["quote", "kagi", "double-kagi"]);
90
114
 
91
- const openWith = (scan: Scan, bracket: Bracket, offset: number, opensParagraph: boolean): void => {
115
+ /** 空行。詩の連や、詩の一つ一つの区切り。 */
116
+ const BLANK_LINE = /\n[ \t\u3000]*\n/u;
117
+
118
+ const openWith = (scan: Scan, text: string, bracket: Bracket, offset: number, heads: Heads): void => {
119
+ const top = scan.open.at(-1);
120
+ const reopens = QUOTATIONS.has(bracket.family) && top?.bracket === bracket;
92
121
  // 段落をまたぐ台詞・引用(英語の小説)は、閉じずに次の段落を同じ開きで始める。前の開きはここで続く。
93
- // 行の頭では続きと読まない。折り返した台詞の行の頭の開きは、中に引いた別の言葉のこともある。
94
- if (opensParagraph && QUOTATIONS.has(bracket.family) && scan.open.at(-1)?.bracket === bracket) scan.open.pop();
95
- scan.open.push({ bracket, offset });
122
+ if (reopens && heads.paragraphs.has(offset)) scan.open.pop();
123
+ // 行の頭では、閉じるまで続きかどうか決められない。折り返した台詞の行の頭の開きは、中に引いた別の言葉のこともある。
124
+ // 続きと読むのは同じ連の中だけ。前の詩で閉じ忘れた開きを、次の詩の引用の続きにはしない。
125
+ const sameStanza = top !== undefined && !BLANK_LINE.test(text.slice(top.offset, offset));
126
+ const continues = reopens && sameStanza && !heads.paragraphs.has(offset) && heads.lines.has(offset) ? top : undefined;
127
+ scan.open.push(continues === undefined ? { bracket, offset } : { bracket, offset, continues });
96
128
  };
97
129
 
98
130
  /**
@@ -101,13 +133,13 @@ const openWith = (scan: Scan, bracket: Bracket, offset: number, opensParagraph:
101
133
  */
102
134
  export const bracketProblems = (text: string): BracketProblem[] => {
103
135
  const scan: Scan = { open: [], problems: [] };
104
- const heads = paragraphHeads(text);
136
+ const heads: Heads = { paragraphs: paragraphHeads(text), lines: lineHeads(text) };
105
137
  [...text.matchAll(MARKS)].forEach((match) => {
106
138
  const quoteOpen = scan.open.some((entry) => entry.bracket.family === "quote");
107
139
  if (isInchMark(text, match.index, quoteOpen) || isEmoticonMouth(text, match.index)) return;
108
140
  const opening = BY_OPEN.get(match[0]);
109
141
  const closing = BY_CLOSE.get(match[0]);
110
- if (opening !== undefined) openWith(scan, opening, match.index, heads.has(match.index));
142
+ if (opening !== undefined) openWith(scan, text, opening, match.index, heads);
111
143
  else if (closing !== undefined) closeWith(scan, text, closing, match.index);
112
144
  });
113
145
  return [...scan.problems, ...scan.open.map(unclosedOf)].toSorted((left, right) => left.offset - right.offset);