chaffjs 0.43.0 → 0.45.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.
- package/dist/bound-word-particles.d.ts +9 -0
- package/dist/bound-word-particles.d.ts.map +1 -0
- package/dist/bound-word-particles.js +16 -0
- package/dist/bound-word-particles.js.map +1 -0
- package/dist/derived/stays.d.ts +0 -1
- package/dist/derived/stays.d.ts.map +1 -1
- package/dist/derived/stays.js +3 -1
- package/dist/derived/stays.js.map +1 -1
- package/dist/detectors/absolute-exception.d.ts.map +1 -1
- package/dist/detectors/absolute-exception.js +10 -4
- package/dist/detectors/absolute-exception.js.map +1 -1
- package/dist/detectors/abstract-length.d.ts +5 -1
- package/dist/detectors/abstract-length.d.ts.map +1 -1
- package/dist/detectors/abstract-length.js +13 -5
- package/dist/detectors/abstract-length.js.map +1 -1
- package/dist/detectors/adversative-ga.d.ts +1 -1
- package/dist/detectors/adversative-ga.d.ts.map +1 -1
- package/dist/detectors/adversative-ga.js +19 -2
- package/dist/detectors/adversative-ga.js.map +1 -1
- package/dist/detectors/agreement-slip.d.ts +2 -0
- package/dist/detectors/agreement-slip.d.ts.map +1 -1
- package/dist/detectors/agreement-slip.js +22 -8
- package/dist/detectors/agreement-slip.js.map +1 -1
- package/dist/detectors/bold-label.d.ts +5 -1
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +74 -14
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/bold-quoted.d.ts +4 -0
- package/dist/detectors/bold-quoted.d.ts.map +1 -0
- package/dist/detectors/bold-quoted.js +17 -0
- package/dist/detectors/bold-quoted.js.map +1 -0
- package/dist/detectors/caps-caption.d.ts +5 -0
- package/dist/detectors/caps-caption.d.ts.map +1 -1
- package/dist/detectors/caps-caption.js +7 -0
- package/dist/detectors/caps-caption.js.map +1 -1
- package/dist/detectors/char-shape.d.ts +0 -6
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +4 -21
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/clause-shape.d.ts +2 -0
- package/dist/detectors/clause-shape.d.ts.map +1 -1
- package/dist/detectors/clause-shape.js +11 -2
- package/dist/detectors/clause-shape.js.map +1 -1
- package/dist/detectors/cleft-focus.d.ts +4 -0
- package/dist/detectors/cleft-focus.d.ts.map +1 -0
- package/dist/detectors/cleft-focus.js +31 -0
- package/dist/detectors/cleft-focus.js.map +1 -0
- package/dist/detectors/count-per-section.d.ts.map +1 -1
- package/dist/detectors/count-per-section.js +7 -4
- package/dist/detectors/count-per-section.js.map +1 -1
- package/dist/detectors/defined-term-form.d.ts.map +1 -1
- package/dist/detectors/defined-term-form.js +2 -1
- package/dist/detectors/defined-term-form.js.map +1 -1
- package/dist/detectors/definition-use.d.ts.map +1 -1
- package/dist/detectors/definition-use.js +13 -3
- package/dist/detectors/definition-use.js.map +1 -1
- package/dist/detectors/emoticon.d.ts +6 -0
- package/dist/detectors/emoticon.d.ts.map +1 -0
- package/dist/detectors/emoticon.js +19 -0
- package/dist/detectors/emoticon.js.map +1 -0
- package/dist/detectors/empty-section.d.ts +1 -1
- package/dist/detectors/empty-section.d.ts.map +1 -1
- package/dist/detectors/empty-section.js +3 -2
- package/dist/detectors/empty-section.js.map +1 -1
- package/dist/detectors/en-shape.d.ts +6 -1
- package/dist/detectors/en-shape.d.ts.map +1 -1
- package/dist/detectors/en-shape.js +9 -1
- package/dist/detectors/en-shape.js.map +1 -1
- package/dist/detectors/fullwidth-alnum.d.ts +2 -2
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +19 -3
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/heading-echo.d.ts.map +1 -1
- package/dist/detectors/heading-echo.js +20 -7
- package/dist/detectors/heading-echo.js.map +1 -1
- package/dist/detectors/heading-number.d.ts +7 -0
- package/dist/detectors/heading-number.d.ts.map +1 -0
- package/dist/detectors/heading-number.js +21 -0
- package/dist/detectors/heading-number.js.map +1 -0
- package/dist/detectors/katakana-density.d.ts +6 -1
- package/dist/detectors/katakana-density.d.ts.map +1 -1
- package/dist/detectors/katakana-density.js +14 -1
- package/dist/detectors/katakana-density.js.map +1 -1
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +2 -1
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/lookalike-character.d.ts +2 -1
- package/dist/detectors/lookalike-character.d.ts.map +1 -1
- package/dist/detectors/lookalike-character.js +14 -1
- package/dist/detectors/lookalike-character.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +8 -3
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +55 -16
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/mentioned-phrase.d.ts +3 -1
- package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
- package/dist/detectors/mentioned-phrase.js +9 -0
- package/dist/detectors/mentioned-phrase.js.map +1 -1
- package/dist/detectors/middle-dot.d.ts +7 -0
- package/dist/detectors/middle-dot.d.ts.map +1 -1
- package/dist/detectors/middle-dot.js +19 -0
- package/dist/detectors/middle-dot.js.map +1 -1
- package/dist/detectors/named-by-context.d.ts +13 -0
- package/dist/detectors/named-by-context.d.ts.map +1 -0
- package/dist/detectors/named-by-context.js +10 -0
- package/dist/detectors/named-by-context.js.map +1 -0
- package/dist/detectors/number-style.d.ts.map +1 -1
- package/dist/detectors/number-style.js +13 -1
- package/dist/detectors/number-style.js.map +1 -1
- package/dist/detectors/obligation-without-deadline.d.ts +10 -2
- package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
- package/dist/detectors/obligation-without-deadline.js +47 -2
- package/dist/detectors/obligation-without-deadline.js.map +1 -1
- package/dist/detectors/open-end-names.d.ts +2 -0
- package/dist/detectors/open-end-names.d.ts.map +1 -1
- package/dist/detectors/open-end-names.js +8 -1
- package/dist/detectors/open-end-names.js.map +1 -1
- package/dist/detectors/orthographic-variant.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant.js +5 -3
- package/dist/detectors/orthographic-variant.js.map +1 -1
- package/dist/detectors/paragraph-pointer.d.ts +4 -0
- package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
- package/dist/detectors/paragraph-pointer.js +22 -0
- package/dist/detectors/paragraph-pointer.js.map +1 -0
- package/dist/detectors/phrase-match.d.ts +4 -1
- package/dist/detectors/phrase-match.d.ts.map +1 -1
- package/dist/detectors/phrase-match.js +12 -5
- package/dist/detectors/phrase-match.js.map +1 -1
- package/dist/detectors/placeholder-context.d.ts +16 -0
- package/dist/detectors/placeholder-context.d.ts.map +1 -0
- package/dist/detectors/placeholder-context.js +57 -0
- package/dist/detectors/placeholder-context.js.map +1 -0
- package/dist/detectors/placeholder-text.d.ts +2 -0
- package/dist/detectors/placeholder-text.d.ts.map +1 -1
- package/dist/detectors/placeholder-text.js +1 -1
- package/dist/detectors/placeholder-text.js.map +1 -1
- package/dist/detectors/redundant-pair.d.ts +5 -0
- package/dist/detectors/redundant-pair.d.ts.map +1 -0
- package/dist/detectors/redundant-pair.js +18 -0
- package/dist/detectors/redundant-pair.js.map +1 -0
- package/dist/detectors/registry/middle-dot.js +1 -1
- package/dist/detectors/registry/redundant-pair.d.ts +3 -0
- package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
- package/dist/detectors/registry/redundant-pair.js +3 -0
- package/dist/detectors/registry/redundant-pair.js.map +1 -0
- package/dist/detectors/request-owner.d.ts +1 -0
- package/dist/detectors/request-owner.d.ts.map +1 -1
- package/dist/detectors/request-owner.js +6 -3
- package/dist/detectors/request-owner.js.map +1 -1
- package/dist/detectors/sentence-counts.d.ts +2 -0
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +13 -4
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +10 -1
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +1 -0
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +6 -5
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/superlative-context.d.ts +7 -0
- package/dist/detectors/superlative-context.d.ts.map +1 -1
- package/dist/detectors/superlative-context.js +9 -0
- package/dist/detectors/superlative-context.js.map +1 -1
- package/dist/detectors/template-sections.d.ts +1 -0
- package/dist/detectors/template-sections.d.ts.map +1 -1
- package/dist/detectors/template-sections.js +1 -1
- package/dist/detectors/template-sections.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +7 -5
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
- package/dist/detectors/unbalanced-bracket.js +2 -1
- package/dist/detectors/unbalanced-bracket.js.map +1 -1
- package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
- package/dist/detectors/unfilled-placeholder.js +18 -1
- package/dist/detectors/unfilled-placeholder.js.map +1 -1
- package/dist/detectors/verse-block.d.ts +4 -0
- package/dist/detectors/verse-block.d.ts.map +1 -0
- package/dist/detectors/verse-block.js +40 -0
- package/dist/detectors/verse-block.js.map +1 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1 -0
- package/dist/document.js.map +1 -1
- package/dist/email-parts.d.ts +2 -0
- package/dist/email-parts.d.ts.map +1 -1
- package/dist/email-parts.js +10 -7
- package/dist/email-parts.js.map +1 -1
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +3 -0
- package/dist/eval.js.map +1 -1
- package/dist/paragraph-length.d.ts +4 -0
- package/dist/paragraph-length.d.ts.map +1 -1
- package/dist/paragraph-length.js +6 -0
- package/dist/paragraph-length.js.map +1 -1
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/reasons.d.ts +2 -0
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +2 -0
- package/dist/reasons.js.map +1 -1
- package/dist/rule-of-three.d.ts +13 -1
- package/dist/rule-of-three.d.ts.map +1 -1
- package/dist/rule-of-three.js +32 -3
- package/dist/rule-of-three.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -1
- package/dist/run.js.map +1 -1
- package/dist/structure/build.d.ts.map +1 -1
- package/dist/structure/build.js +2 -1
- package/dist/structure/build.js.map +1 -1
- package/dist/structure/cited-elsewhere.d.ts +5 -2
- package/dist/structure/cited-elsewhere.d.ts.map +1 -1
- package/dist/structure/cited-elsewhere.js +16 -6
- package/dist/structure/cited-elsewhere.js.map +1 -1
- package/dist/structure/definition-use.d.ts +2 -1
- package/dist/structure/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +10 -2
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure/issues.js +1 -1
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure/negated-act.d.ts +1 -0
- package/dist/structure/negated-act.d.ts.map +1 -1
- package/dist/structure/negated-act.js +1 -1
- package/dist/structure/negated-act.js.map +1 -1
- package/dist/structure/own-name.d.ts +4 -0
- package/dist/structure/own-name.d.ts.map +1 -0
- package/dist/structure/own-name.js +20 -0
- package/dist/structure/own-name.js.map +1 -0
- package/dist/structure/percent-sum-prose.d.ts.map +1 -1
- package/dist/structure/percent-sum-prose.js +9 -1
- package/dist/structure/percent-sum-prose.js.map +1 -1
- package/dist/structure/percent-sum.d.ts +2 -0
- package/dist/structure/percent-sum.d.ts.map +1 -1
- package/dist/structure/percent-sum.js.map +1 -1
- package/dist/structure/reference-text.d.ts.map +1 -1
- package/dist/structure/reference-text.js +3 -1
- package/dist/structure/reference-text.js.map +1 -1
- package/dist/te-form-helper.d.ts +22 -0
- package/dist/te-form-helper.d.ts.map +1 -0
- package/dist/te-form-helper.js +35 -0
- package/dist/te-form-helper.js.map +1 -0
- package/dist/word-use.d.ts +7 -0
- package/dist/word-use.d.ts.map +1 -1
- package/dist/word-use.js +11 -0
- package/dist/word-use.js.map +1 -1
- package/package.json +3 -3
- package/rules/absolute-exception.yaml +3 -3
- package/rules/abstract-length.yaml +2 -2
- package/rules/adversative-ga-repeat.yaml +2 -2
- package/rules/all-caps-shouting.yaml +2 -2
- package/rules/attachment-not-attached.yaml +11 -6
- package/rules/bold-label-list.yaml +29 -6
- package/rules/bracket-width-consistency.yaml +2 -2
- package/rules/demonstrative-opener-run.yaml +2 -2
- package/rules/duration-mismatch.yaml +2 -2
- package/rules/emoji-density.yaml +2 -2
- package/rules/empty-section.yaml +2 -2
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/katakana-density.yaml +3 -3
- package/rules/lookalike-character.yaml +8 -5
- package/rules/max-kanji-continuous.yaml +4 -0
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/number-style-consistency.yaml +2 -2
- package/rules/obligation-without-deadline.yaml +2 -2
- package/rules/padded-intro.yaml +1 -1
- package/rules/paragraph-length-variance.yaml +27 -3
- package/rules/redundant-expression.yaml +1 -1
- package/rules/repeated-sentence-ending.yaml +2 -2
- package/rules/request-without-deadline.yaml +2 -2
- package/rules/requirement-smell.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/sentence-spacing-consistency.yaml +2 -2
- package/rules/teki-overuse.yaml +2 -0
- package/rules/unfilled-placeholder.yaml +2 -2
- package/rules/use-before-definition.yaml +2 -2
- package/src/bound-word-particles.ts +23 -0
- package/src/derived/stays.ts +4 -1
- package/src/detectors/absolute-exception.ts +11 -5
- package/src/detectors/abstract-length.ts +16 -6
- package/src/detectors/adversative-ga.ts +24 -2
- package/src/detectors/agreement-slip.ts +35 -10
- package/src/detectors/bold-label.ts +82 -14
- package/src/detectors/bold-quoted.ts +21 -0
- package/src/detectors/caps-caption.ts +10 -0
- package/src/detectors/char-shape.ts +8 -22
- package/src/detectors/clause-shape.ts +14 -3
- package/src/detectors/cleft-focus.ts +40 -0
- package/src/detectors/count-per-section.ts +9 -4
- package/src/detectors/defined-term-form.ts +2 -1
- package/src/detectors/definition-use.ts +23 -4
- package/src/detectors/emoticon.ts +21 -0
- package/src/detectors/empty-section.ts +3 -2
- package/src/detectors/en-shape.ts +10 -1
- package/src/detectors/fullwidth-alnum.ts +24 -3
- package/src/detectors/heading-echo.ts +21 -8
- package/src/detectors/heading-number.ts +20 -0
- package/src/detectors/katakana-density.ts +17 -2
- package/src/detectors/lexicon.ts +2 -1
- package/src/detectors/lookalike-character.ts +19 -2
- package/src/detectors/mark-shape.ts +61 -13
- package/src/detectors/mentioned-phrase.ts +13 -1
- package/src/detectors/middle-dot.ts +22 -0
- package/src/detectors/named-by-context.ts +15 -0
- package/src/detectors/number-style.ts +14 -1
- package/src/detectors/obligation-without-deadline.ts +69 -5
- package/src/detectors/open-end-names.ts +21 -2
- package/src/detectors/orthographic-variant.ts +20 -15
- package/src/detectors/paragraph-pointer.ts +28 -0
- package/src/detectors/phrase-match.ts +13 -5
- package/src/detectors/placeholder-context.ts +72 -0
- package/src/detectors/placeholder-text.ts +1 -1
- package/src/detectors/redundant-pair.ts +25 -0
- package/src/detectors/registry/middle-dot.ts +1 -1
- package/src/detectors/registry/redundant-pair.ts +4 -0
- package/src/detectors/request-owner.ts +6 -3
- package/src/detectors/sentence-counts.ts +16 -4
- package/src/detectors/signals.ts +11 -1
- package/src/detectors/structure-tree.ts +1 -0
- package/src/detectors/structure.ts +6 -5
- package/src/detectors/superlative-context.ts +12 -0
- package/src/detectors/template-sections.ts +1 -1
- package/src/detectors/token-shape.ts +10 -7
- package/src/detectors/unbalanced-bracket.ts +2 -1
- package/src/detectors/unfilled-placeholder.ts +22 -1
- package/src/detectors/verse-block.ts +48 -0
- package/src/document.ts +1 -0
- package/src/email-parts.ts +16 -7
- package/src/eval.ts +2 -0
- package/src/paragraph-length.ts +10 -0
- package/src/plugin.ts +4 -0
- package/src/reasons.ts +4 -0
- package/src/rule-of-three.ts +47 -4
- package/src/run.ts +3 -1
- package/src/structure/build.ts +2 -1
- package/src/structure/cited-elsewhere.ts +18 -6
- package/src/structure/definition-use.ts +10 -1
- package/src/structure/issues.ts +1 -1
- package/src/structure/negated-act.ts +1 -1
- package/src/structure/own-name.ts +28 -0
- package/src/structure/percent-sum-prose.ts +12 -1
- package/src/structure/percent-sum.ts +2 -0
- package/src/structure/reference-text.ts +5 -1
- package/src/te-form-helper.ts +52 -0
- package/src/word-use.ts +13 -0
- package/src/honorific-group.ts +0 -22
|
@@ -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
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Detector, Finding, MarkupHeading } from "../plugin.ts";
|
|
2
2
|
import { findingAt, writtenHeadings } from "./markup-finding.ts";
|
|
3
|
+
import { opensSubsection } from "./heading-number.ts";
|
|
3
4
|
|
|
4
5
|
/** HTML のコメント(「<!-- 後で書く -->」)。読み手には見えない。一つずつ外す(間の本文ごと一つのコメントと読まない)。 */
|
|
5
6
|
const HTML_COMMENT = /<!--[\s\S]*?-->/gu;
|
|
@@ -8,12 +9,12 @@ const showsNothing = (written: string): boolean => written.replace(HTML_COMMENT,
|
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* 中身の無い節。見出しのすぐ後ろに、同じ深さか浅い見出しが来るもの(remark-lint の no-empty-sections)。
|
|
11
|
-
*
|
|
12
|
+
* 深い見出しが続くのは、節を小さな節に分けただけなので中身がある。同じ深さでも、番号が節の下の番号(3. の後の 3.1、4. の後の (1))なら同じ。文書の最後の見出しは、後ろに何も無ければ空。
|
|
12
13
|
*/
|
|
13
14
|
export const emptySections = (source: string, headings: readonly MarkupHeading[]): MarkupHeading[] =>
|
|
14
15
|
headings.filter((heading, index) => {
|
|
15
16
|
const next = headings[index + 1];
|
|
16
|
-
if (next !== undefined && next.depth > heading.depth) return false;
|
|
17
|
+
if (next !== undefined && (next.depth > heading.depth || (next.depth === heading.depth && opensSubsection(heading.text, next.text)))) return false;
|
|
17
18
|
return showsNothing(source.slice(heading.end, next?.start ?? source.length));
|
|
18
19
|
});
|
|
19
20
|
|
|
@@ -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
|
|
|
@@ -89,15 +89,36 @@ export type AlnumRun = {
|
|
|
89
89
|
readonly glued: boolean;
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
+
type Piece = { readonly 0: string; readonly index: number };
|
|
93
|
+
|
|
94
|
+
/** 一つの幅で書いた部分。 */
|
|
95
|
+
const SAME_WIDTH = /[A-Za-z0-9]+|[A-Za-z0-9]+/gu;
|
|
96
|
+
const ONE_LETTER = /^[A-Za-zA-Za-z]$/u;
|
|
97
|
+
const DIGITS = /^[0-90-9]+$/u;
|
|
98
|
+
|
|
99
|
+
/** 英字一字と数字の、幅の違う組(Q5、H30、600w)か。 */
|
|
100
|
+
const isLetterAndNumber = (parts: readonly Piece[]): boolean =>
|
|
101
|
+
parts.length === 2 && parts.some((part) => ONE_LETTER.test(part[0])) && parts.some((part) => DIGITS.test(part[0]));
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 並びを、一つの幅で書いた部分に分ける。英字一字と数字を違う幅で書いた並び(Q5、H30)は、英字と数字に分けてそれぞれの組で数える。
|
|
105
|
+
* 「一字の英字は全角、2桁以上は半角」の H30 は、H も 30 もその組の中でそろう。ほかの混ざった並び(IoT)は数えない。
|
|
106
|
+
*/
|
|
107
|
+
const widthPieces = (match: RegExpExecArray): Piece[] => {
|
|
108
|
+
if (FULLWIDTH.test(match[0]) || HALFWIDTH.test(match[0])) return [match];
|
|
109
|
+
const parts = [...match[0].matchAll(SAME_WIDTH)].map((part) => ({ 0: part[0], index: match.index + part.index }));
|
|
110
|
+
return isLetterAndNumber(parts) ? parts : [];
|
|
111
|
+
};
|
|
112
|
+
|
|
92
113
|
/**
|
|
93
|
-
*
|
|
94
|
-
* offset は文書の中の位置。
|
|
114
|
+
* 文の中の英字・数字の並び。鉤括弧で引いたものの中、項目と注の番号、箇条書きの頭の番号、版の番号の続き(TLS1.2 の 2)は数えない。
|
|
115
|
+
* 英字一字と数字を違う幅で書いた並びは分ける。offset は文書の中の位置。
|
|
95
116
|
*/
|
|
96
117
|
export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
|
|
97
118
|
const quoted: readonly Span[] = quotedSpans(sentence.text, QUOTATION_MARKS);
|
|
98
119
|
const glued = gluedNumberSpans(sentence.text);
|
|
99
120
|
return [...sentence.text.matchAll(ALNUM_RUN)]
|
|
100
|
-
.
|
|
121
|
+
.flatMap(widthPieces)
|
|
101
122
|
.filter((match) => !isWithinAny(quoted, { start: match.index, end: match.index + match[0].length }))
|
|
102
123
|
.filter((match) => !isLabel(sentence.text, match.index, match.index + match[0].length))
|
|
103
124
|
.filter((match) => !isListItemNumber(source, sentence.span.start + match.index))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lengthOf, proseText } from "../measure.ts";
|
|
2
|
+
import { cleftFocus } from "./cleft-focus.ts";
|
|
2
3
|
import { newContentMorphemes } from "./content-morphemes.ts";
|
|
3
4
|
import { echoedHeadingUnits, trigrams } from "./heading-overlap.ts";
|
|
4
5
|
import { fieldValueStart } from "./field-label.ts";
|
|
@@ -9,7 +10,7 @@ import { handsOver } from "./lead-in.ts";
|
|
|
9
10
|
import { holdsLink, namesLocation } from "./location-pointer.ts";
|
|
10
11
|
import { withoutQuotedVariants } from "./quoted-variant.ts";
|
|
11
12
|
import { namesHeadingSubject } from "./subject-name-line.ts";
|
|
12
|
-
import type { Detector, Finding, LengthUnit, ProseDocument, Section, Sentence } from "../plugin.ts";
|
|
13
|
+
import type { Detector, Finding, LengthUnit, ProseDocument, Section, Sentence, Token } from "../plugin.ts";
|
|
13
14
|
|
|
14
15
|
/** 見出しが短すぎると、偶然の一致で 100% になる。これ未満の見出しは見ない。 */
|
|
15
16
|
const MIN_GRAMS = 4;
|
|
@@ -46,11 +47,23 @@ const NEW_CONTENT_MORPHEMES = 1;
|
|
|
46
47
|
/** 重なりを測る見出し。頭の番号の札(例 3:、Step 3:、1.)は本文で繰り返されないので、数えると短い見出しほど重なりが下がる。 */
|
|
47
48
|
const measuredHeading = (section: Section): string => section.unlabeledHeading ?? section.heading;
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* 内容を測る文の語。分裂文(いちばん大きく変わったのは、季節の移り変わりに気づくようになったことだ。)は焦点の語だけ:
|
|
52
|
+
* 主題の節は焦点を差し出すだけで、焦点が見出しを言い直していれば、文は見出しを繰り返している。
|
|
53
|
+
*/
|
|
54
|
+
const statedTokens = (doc: ProseDocument, sentence: Sentence): readonly Token[] | undefined => {
|
|
55
|
+
const focus = cleftFocus(sentence.text, doc.lexicons["cleft-frame"] ?? []);
|
|
56
|
+
if (sentence.tokens === undefined || focus === undefined) return sentence.tokens;
|
|
57
|
+
const [start, end] = [sentence.span.start + focus.start, sentence.span.start + focus.end];
|
|
58
|
+
return sentence.tokens.filter((token) => token.span.start >= start && token.span.end <= end);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const addsLittle = (doc: ProseDocument, section: Section, unit: LengthUnit): boolean => {
|
|
50
62
|
const first = section.firstSentence;
|
|
51
63
|
if (first === undefined) return false;
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
const stated = statedTokens(doc, first);
|
|
65
|
+
if (unit === "char" && stated !== undefined && section.headingTokens !== undefined)
|
|
66
|
+
return newContentMorphemes(titleTokens(section.heading, measuredHeading(section), section.headingTokens), stated) <= NEW_CONTENT_MORPHEMES;
|
|
54
67
|
return lengthOf(first, unit) - echoedHeadingUnits(measuredHeading(section), proseText(first), unit) <= NEW_MATERIAL[unit];
|
|
55
68
|
};
|
|
56
69
|
|
|
@@ -74,10 +87,10 @@ const pointsElsewhere = (doc: ProseDocument, section: Section): boolean => {
|
|
|
74
87
|
* 予告や指示の語(covers, below, 説明, 以下)だけを述語にする文は、見出しを言い直しているだけで繰り返し。
|
|
75
88
|
*/
|
|
76
89
|
const statesClaim = (doc: ProseDocument, section: Section): boolean => {
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
90
|
+
const stated = section.firstSentence === undefined ? undefined : statedTokens(doc, section.firstSentence);
|
|
91
|
+
if (stated === undefined || section.headingTokens === undefined) return false;
|
|
79
92
|
const heading = titleTokens(section.heading, measuredHeading(section), section.headingTokens);
|
|
80
|
-
return makesClaim(heading,
|
|
93
|
+
return makesClaim(heading, stated, announcerWords(doc.lexicons["heading-announcer"] ?? []));
|
|
81
94
|
};
|
|
82
95
|
|
|
83
96
|
/** A figure, with its thousands separators (1,320,000), compared without them. */
|
|
@@ -138,7 +151,7 @@ const echoedText = (section: Section): string =>
|
|
|
138
151
|
export const headingEcho: Detector = (doc, options): Finding[] => {
|
|
139
152
|
const leadIns = (doc.lexicons["lead-in"] ?? []).map((entry) => entry.pattern);
|
|
140
153
|
return doc.sections
|
|
141
|
-
.filter((section) => section.heading.length > 0 && section.firstSentence !== undefined && addsLittle(section, doc.lengthUnit))
|
|
154
|
+
.filter((section) => section.heading.length > 0 && section.firstSentence !== undefined && addsLittle(doc, section, doc.lengthUnit))
|
|
142
155
|
.filter(
|
|
143
156
|
(section) =>
|
|
144
157
|
!leadsIn(doc, section, leadIns) &&
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A heading's number at its head: 3, 4.2, 4.2.1 (a full stop after it, as in "3.", is not part of it). */
|
|
2
|
+
const DOTTED_NUMBER = /^(\d{1,3}(?:\.\d{1,3})*)\.?(?!\d)/u;
|
|
3
|
+
/** The first item of a bracketed series under a numbered heading: (1), (1). */
|
|
4
|
+
const FIRST_BRACKETED = /^\(1\)/u;
|
|
5
|
+
|
|
6
|
+
const numberOf = (heading: string): string | undefined => DOTTED_NUMBER.exec(heading.normalize("NFKC").trim())?.[1];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether `child`, the next heading at the same depth, opens a subsection of `parent` by its number: 3. then 3.1, 4.2 then
|
|
10
|
+
* 4.2.1, or a numbered heading then its first bracketed item ((1)). Some documents number their subsections at the
|
|
11
|
+
* heading level of the section itself, so the depth alone does not show the split.
|
|
12
|
+
*/
|
|
13
|
+
export const opensSubsection = (parent: string, child: string): boolean => {
|
|
14
|
+
const parentNumber = numberOf(parent);
|
|
15
|
+
if (parentNumber === undefined) return false;
|
|
16
|
+
const normalizedChild = child.normalize("NFKC").trim();
|
|
17
|
+
if (FIRST_BRACKETED.test(normalizedChild)) return true;
|
|
18
|
+
const childNumber = numberOf(normalizedChild);
|
|
19
|
+
return childNumber !== undefined && childNumber.startsWith(`${parentNumber}.`) && !childNumber.slice(parentNumber.length + 1).includes(".");
|
|
20
|
+
};
|
|
@@ -33,8 +33,23 @@ export const mostFrequent = (words: readonly string[], count: number): string[]
|
|
|
33
33
|
.map(([word]) => word);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
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
|
package/src/detectors/lexicon.ts
CHANGED
|
@@ -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) ||
|
|
@@ -7,8 +7,9 @@ import { codePointName } from "./invisible-character.ts";
|
|
|
7
7
|
* compatibility: a CJK compatibility ideograph (or one of its supplement) that Unicode maps to a unified one (樂 U+F914 for 樂).
|
|
8
8
|
* decomposed: a letter and a separate combining mark (か + U+3099 for が, e + U+0301 for é), from file names or text
|
|
9
9
|
* copied on macOS. spacing-mark: kana followed by the spacing ゛ or ゜, typed in place of the combined letter.
|
|
10
|
+
* dash: a dash or minus between katakana (ニュ-ス, U+FF0D), typed in place of the long-vowel mark ー.
|
|
10
11
|
*/
|
|
11
|
-
export type LookalikeKind = "radical" | "compatibility" | "decomposed" | "spacing-mark";
|
|
12
|
+
export type LookalikeKind = "radical" | "compatibility" | "decomposed" | "spacing-mark" | "dash";
|
|
12
13
|
|
|
13
14
|
export type Lookalike = { readonly span: Span; readonly kind: LookalikeKind; readonly written: string; readonly usual: string };
|
|
14
15
|
|
|
@@ -48,8 +49,24 @@ const spacingMarkLookalikes = (source: string): Lookalike[] =>
|
|
|
48
49
|
return [{ span: { start: match.index, end: match.index + match[0].length }, kind: "spacing-mark", written: match[0], usual }];
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
const LONG_VOWEL = "ー";
|
|
53
|
+
/**
|
|
54
|
+
* A dash, a minus or a box line after a katakana letter that can be lengthened and before another katakana letter. The
|
|
55
|
+
* half-width - is left out: between katakana it joins the parts of a template or a range (<アルゴリズム>-<ハッシュ>, ァ-ヶ).
|
|
56
|
+
*/
|
|
57
|
+
const DASH_FOR_LONG_VOWEL = /(?<=[ァ-ヂツ-ヲヴ-ヺ])[\u2010-\u2015\u2212\uFF0D\u2500\u2501](?=[ァ-ヺ])/gu;
|
|
58
|
+
|
|
59
|
+
/** A dash typed in place of the long-vowel mark between katakana (ニュ-ス → ニュース). */
|
|
60
|
+
const dashLookalikes = (source: string): Lookalike[] =>
|
|
61
|
+
[...source.matchAll(DASH_FOR_LONG_VOWEL)].map((match) => ({
|
|
62
|
+
span: { start: match.index, end: match.index + match[0].length },
|
|
63
|
+
kind: "dash",
|
|
64
|
+
written: match[0],
|
|
65
|
+
usual: LONG_VOWEL,
|
|
66
|
+
}));
|
|
67
|
+
|
|
51
68
|
export const lookalikesIn = (source: string): Lookalike[] =>
|
|
52
|
-
[...singleLookalikes(source), ...decomposedLookalikes(source), ...spacingMarkLookalikes(source)].toSorted(
|
|
69
|
+
[...singleLookalikes(source), ...decomposedLookalikes(source), ...spacingMarkLookalikes(source), ...dashLookalikes(source)].toSorted(
|
|
53
70
|
(left, right) => left.span.start - right.span.start,
|
|
54
71
|
);
|
|
55
72
|
|
|
@@ -6,11 +6,12 @@ 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";
|
|
13
13
|
import { isInCopiedText } from "./hyphen-copied-text.ts";
|
|
14
|
+
import { verseBlockSpans } from "./verse-block.ts";
|
|
14
15
|
|
|
15
16
|
/** The letters a mark must touch to count as part of the document's text, by language. */
|
|
16
17
|
const SCRIPT: Readonly<Record<string, RegExp>> = {
|
|
@@ -180,6 +181,22 @@ export const noteMarkerOffsets = (source: string): ReadonlySet<number> =>
|
|
|
180
181
|
|
|
181
182
|
const NOTE_KIND = "\u0000note";
|
|
182
183
|
|
|
184
|
+
/**
|
|
185
|
+
* A note's number cited in the prose (注(24)で示した): an author writes it as the notes' labels are, or as the prose's
|
|
186
|
+
* brackets are, and either is the document's own notation for it.
|
|
187
|
+
*/
|
|
188
|
+
const NOTE_ADDRESS = /(?<=[注註])(?:\([0-90-9]{1,3}\)|([0-90-9]{1,3}))/gu;
|
|
189
|
+
|
|
190
|
+
/** The offsets in `source` of the brackets of every note's cited number. */
|
|
191
|
+
export const noteAddressOffsets = (source: string): ReadonlySet<number> =>
|
|
192
|
+
new Set([...source.matchAll(NOTE_ADDRESS)].flatMap((match) => [match.index, match.index + match[0].length - 1]));
|
|
193
|
+
|
|
194
|
+
const NOTE_ADDRESS_KIND = "\u0000noteaddress";
|
|
195
|
+
|
|
196
|
+
/** A note's cited number is a kind of its own, compared only with the other cited note numbers. */
|
|
197
|
+
const withNoteAddressKind = (mark: Mark, addresses: ReadonlySet<number>): Mark =>
|
|
198
|
+
addresses.has(mark.offset) ? { ...mark, form: { ...mark.form, kind: `${mark.form.kind}${NOTE_ADDRESS_KIND}` } } : mark;
|
|
199
|
+
|
|
183
200
|
/** A note marker's bracket is a kind of its own, compared only with the other note markers' brackets. */
|
|
184
201
|
const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
|
|
185
202
|
notes.has(mark.offset) && !mark.form.kind.endsWith(ENUMERATOR_KIND) ? { ...mark, form: { ...mark.form, kind: `${mark.form.kind}${NOTE_KIND}` } } : mark;
|
|
@@ -199,8 +216,11 @@ export const markConsistency: Detector = (doc, options): Finding[] => {
|
|
|
199
216
|
const enumerators = enumeratorBracketOffsets(doc.source);
|
|
200
217
|
const doubled = doubledParenOffsets(doc.source);
|
|
201
218
|
const notes = noteMarkerOffsets(doc.source);
|
|
219
|
+
const noteAddresses = noteAddressOffsets(doc.source);
|
|
202
220
|
const marks = ownSentences(doc).flatMap((sentence) =>
|
|
203
|
-
marksIn(doc.source, sentence, forms, script).map((mark) =>
|
|
221
|
+
marksIn(doc.source, sentence, forms, script).map((mark) =>
|
|
222
|
+
withNoteAddressKind(withNoteKind(withDoubledKind(withEnumeratorKind(mark, enumerators), doubled), notes), noteAddresses),
|
|
223
|
+
),
|
|
204
224
|
);
|
|
205
225
|
const kinds = [...new Set(marks.map((mark) => mark.form.kind))];
|
|
206
226
|
return kinds.flatMap((kind) =>
|
|
@@ -219,18 +239,25 @@ export const markConsistency: Detector = (doc, options): Finding[] => {
|
|
|
219
239
|
const SENTENCE_END = /(?<![\p{L}\d.])\p{Ll}{2,}[.!?]["'”’)\]]?$/u;
|
|
220
240
|
/** The next sentence starts with a capital, past an opening quote: not a citation ("[ISO99]") or an aside in brackets. */
|
|
221
241
|
const SENTENCE_START = /^["'“‘]?\p{Lu}/u;
|
|
242
|
+
/** "Affiliation: …", "Note: …": a field's label opens what follows, as in an author block joined into one line. */
|
|
243
|
+
const FIELD_LABEL = /^\p{Lu}\p{Ll}+:\s/u;
|
|
222
244
|
const ONE_SPACE = " ";
|
|
223
245
|
const TWO_SPACES = " ";
|
|
224
246
|
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
247
|
+
/**
|
|
248
|
+
* The space between two sentences on one line, when the first ends with a period, question or exclamation mark. spaced is
|
|
249
|
+
* two spaces. A pause inside a verse line ("I'm nobody! Who are you?") is the stanza's layout, not the prose's spacing.
|
|
250
|
+
*/
|
|
251
|
+
export const sentenceGaps = (doc: ProseDocument): Sided[] => {
|
|
252
|
+
const stanzas = verseBlockSpans(doc.source);
|
|
253
|
+
return ownSentences(doc).flatMap((sentence, at, sentences) => {
|
|
228
254
|
const next = sentences[at + 1];
|
|
229
|
-
if (next === undefined || !SENTENCE_END.test(sentence.text) || !SENTENCE_START.test(next.text)) return [];
|
|
255
|
+
if (next === undefined || !SENTENCE_END.test(sentence.text) || !SENTENCE_START.test(next.text) || FIELD_LABEL.test(next.text)) return [];
|
|
230
256
|
const gap = doc.source.slice(sentence.span.end, next.span.start);
|
|
231
|
-
if (gap !== ONE_SPACE && gap !== TWO_SPACES) return [];
|
|
257
|
+
if ((gap !== ONE_SPACE && gap !== TWO_SPACES) || isWithinSorted(stanzas, { start: sentence.span.end, end: next.span.start })) return [];
|
|
232
258
|
return [{ sentence: next, spaced: gap === TWO_SPACES, offset: sentence.span.end }];
|
|
233
259
|
});
|
|
260
|
+
};
|
|
234
261
|
|
|
235
262
|
/** One space between sentences and two, mixed in one document: the less common is reported. */
|
|
236
263
|
export const sentenceSpacing: Detector = (doc, options): Finding[] =>
|
|
@@ -260,6 +287,20 @@ const reportFrom = (hits: readonly Hit[], limit: number): Finding[] => (hits.len
|
|
|
260
287
|
/** A spaced hyphen or a double hyphen between words, standing for a dash ("late - very late", "late--very late"). */
|
|
261
288
|
const HYPHEN_DASH = /(?<=[\p{L},;)]) -{1,2} (?=[\p{L}(])|(?<=\p{L})--(?=\p{L})/gu;
|
|
262
289
|
|
|
290
|
+
/** A spaced hyphen whose side is masked out of the sentence's text: a code span may stand there ("`float` - everything"). */
|
|
291
|
+
const MASKED_SIDE_HYPHEN = /(?<=\s) -{1,2} (?=[\p{L}(])|(?<=[\p{L},;)]) -{1,2} (?=\s)/gu;
|
|
292
|
+
const CODE_MARK = "`";
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* A spaced hyphen between a code span and a word, either way round ("`float` - everything", "two properties - `x`"). Code
|
|
296
|
+
* is masked out of the text, so the code side reads as spaces; the source shows the code mark right beside the hyphen.
|
|
297
|
+
* Code on both sides ("`query` - `form`") is a mapping, not a dash.
|
|
298
|
+
*/
|
|
299
|
+
const besideCode = (source: string, hit: Hit): boolean => {
|
|
300
|
+
const end = hit.offset + hit.matched.length + 2;
|
|
301
|
+
return (source[hit.offset - 1] === CODE_MARK) !== (source[end] === CODE_MARK);
|
|
302
|
+
};
|
|
303
|
+
|
|
263
304
|
/** A dash set as a character (an em dash, an en dash). */
|
|
264
305
|
const TRUE_DASH = /[—–]/u;
|
|
265
306
|
const DOUBLE_HYPHEN = "--";
|
|
@@ -276,10 +317,11 @@ export const hyphenDash: Detector = (doc, options): Finding[] => {
|
|
|
276
317
|
const sentences = ownSentences(doc);
|
|
277
318
|
const setsDashes = sentences.some((sentence) => TRUE_DASH.test(sentence.text));
|
|
278
319
|
const divisionLabel = divisionLabelPattern((doc.lexicons["numbered-division"] ?? []).map((entry) => entry.pattern));
|
|
320
|
+
const codeHits = hitsOf(sentences, MASKED_SIDE_HYPHEN).filter((hit) => besideCode(doc.source, hit));
|
|
279
321
|
return reportFrom(
|
|
280
|
-
hitsOf(sentences, HYPHEN_DASH)
|
|
281
|
-
(
|
|
282
|
-
|
|
322
|
+
[...hitsOf(sentences, HYPHEN_DASH), ...codeHits]
|
|
323
|
+
.toSorted((left, right) => left.offset - right.offset)
|
|
324
|
+
.filter((hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset)),
|
|
283
325
|
options.limit,
|
|
284
326
|
);
|
|
285
327
|
};
|
|
@@ -332,8 +374,8 @@ export const isShouting = (run: string, known: ReadonlySet<string>, conventional
|
|
|
332
374
|
|
|
333
375
|
/**
|
|
334
376
|
* 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,
|
|
336
|
-
* placeholder in square brackets.
|
|
377
|
+
* caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, a
|
|
378
|
+
* placeholder in square brackets, or a whole quotation.
|
|
337
379
|
*/
|
|
338
380
|
export const capsShouting: Detector = (doc, options): Finding[] => {
|
|
339
381
|
const known = lowerCaseWords(doc.prose ?? doc.source);
|
|
@@ -343,7 +385,13 @@ export const capsShouting: Detector = (doc, options): Finding[] => {
|
|
|
343
385
|
const placeholders = bracketPlaceholderSpans(doc.source);
|
|
344
386
|
const isCaptionOrLetterhead = (hit: Hit): boolean => {
|
|
345
387
|
const span = { start: hit.offset, end: hit.offset + hit.matched.length };
|
|
346
|
-
return
|
|
388
|
+
return (
|
|
389
|
+
captions.has(hit.matched) ||
|
|
390
|
+
isCaptionAt(doc.source, span.start, span.end) ||
|
|
391
|
+
isWithinSorted(capitalLines, span) ||
|
|
392
|
+
isWithinAny(placeholders, span) ||
|
|
393
|
+
isWholeQuotation(doc.source, span.start, span.end)
|
|
394
|
+
);
|
|
347
395
|
};
|
|
348
396
|
const hits = hitsOf(ownSentences(doc), CAPS_RUN).filter((hit) => isShouting(hit.matched, known, conventional) && !isCaptionOrLetterhead(hit));
|
|
349
397
|
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
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Detector, Finding } from "../plugin.ts";
|
|
2
|
+
|
|
1
3
|
const MIDDLE_DOT = /・/gu;
|
|
2
4
|
|
|
3
5
|
/** 文頭か行頭(前に空白だけ)の「・」。前に並べる項目が無いので、箇条書きの印。 */
|
|
@@ -13,3 +15,23 @@ const withoutWordDots = (text: string, words: readonly string[]): string =>
|
|
|
13
15
|
*/
|
|
14
16
|
export const parallelDotCount = (text: string, words: readonly string[] = []): number =>
|
|
15
17
|
[...withoutWordDots(text, words).replace(BULLET_DOT, "$1").matchAll(MIDDLE_DOT)].length;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 中黒で並べると、どこまでが 1 つの項目か分からなくなる。
|
|
21
|
+
* 「企画・開発・運用・保守体制」は、保守体制が 1 つなのか保守と体制なのか読めない。
|
|
22
|
+
* 語彙表(nakaguro-word)の、中黒を含めて 1 語の語(キャッシュ・フロー)の中黒は並べていないので数えない。
|
|
23
|
+
*/
|
|
24
|
+
export const middleDot: Detector = (doc, options): Finding[] => {
|
|
25
|
+
const words = (options.lexicon ?? []).map((entry) => entry.pattern).toSorted((left, right) => right.length - left.length);
|
|
26
|
+
return doc.sentences
|
|
27
|
+
.map((sentence) => ({ sentence, count: parallelDotCount(sentence.text, words) }))
|
|
28
|
+
.filter(({ count }) => count > options.limit)
|
|
29
|
+
.map(({ sentence, count }) => ({
|
|
30
|
+
rule: "no-nakaguro-parallel",
|
|
31
|
+
severity: "info",
|
|
32
|
+
line: 0,
|
|
33
|
+
column: 0,
|
|
34
|
+
quote: sentence.text.trim(),
|
|
35
|
+
values: { count, limit: options.limit, offset: sentence.span.start },
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 連なりの前後の字と、名前を示す句の語彙。 */
|
|
2
|
+
type Surroundings = { readonly before: string; readonly next: string };
|
|
3
|
+
type ContextWords = { readonly designations: readonly string[]; readonly noticeEndings: readonly string[] };
|
|
4
|
+
|
|
5
|
+
/** 連なりの後ろ(next)が、制度が区分に入れることを言う句で始まるか(認定希少種保全動植物園等として認定)。 */
|
|
6
|
+
const isDesignated = (run: Surroundings, words: ContextWords): boolean => words.designations.some((phrase) => run.next.startsWith(phrase));
|
|
7
|
+
|
|
8
|
+
/** 行がお知らせの題で、連なりがその「の」の前か([e-Gov]〜設定解除完了のお知らせ)。題は句点で閉じない一行。 */
|
|
9
|
+
const isNoticeTitle = (run: Surroundings, words: ContextWords): boolean => {
|
|
10
|
+
const next = run.next.trim();
|
|
11
|
+
return !run.before.includes("\n") && words.noticeEndings.some((ending) => next === `の${ending}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** 前後の字が、漢字の連なりを名前と示しているか: 制度が決めた区分の名前か、送り手が付けたお知らせの題の名前。 */
|
|
15
|
+
export const isNamedByContext = (run: Surroundings, words: ContextWords): boolean => isDesignated(run, words) || isNoticeTitle(run, words);
|
|
@@ -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
|
});
|