chaffjs 0.41.0 → 0.42.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/ai-score/human-shares.d.ts.map +1 -1
- package/dist/ai-score/human-shares.js +1 -0
- package/dist/ai-score/human-shares.js.map +1 -1
- package/dist/detectors/acronym-file-type.d.ts +14 -0
- package/dist/detectors/acronym-file-type.d.ts.map +1 -0
- package/dist/detectors/acronym-file-type.js +26 -0
- package/dist/detectors/acronym-file-type.js.map +1 -0
- package/dist/detectors/ai-structure.d.ts +2 -1
- package/dist/detectors/ai-structure.d.ts.map +1 -1
- package/dist/detectors/ai-structure.js +17 -6
- package/dist/detectors/ai-structure.js.map +1 -1
- package/dist/detectors/bibliography-entry.d.ts +3 -0
- package/dist/detectors/bibliography-entry.d.ts.map +1 -0
- package/dist/detectors/bibliography-entry.js +15 -0
- package/dist/detectors/bibliography-entry.js.map +1 -0
- package/dist/detectors/char-shape.d.ts +1 -0
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +13 -8
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/closing-cliche.d.ts.map +1 -1
- package/dist/detectors/closing-cliche.js +2 -1
- package/dist/detectors/closing-cliche.js.map +1 -1
- package/dist/detectors/contraction-mention.d.ts +2 -0
- package/dist/detectors/contraction-mention.d.ts.map +1 -1
- package/dist/detectors/contraction-mention.js +5 -2
- package/dist/detectors/contraction-mention.js.map +1 -1
- package/dist/detectors/contraction-mix.d.ts.map +1 -1
- package/dist/detectors/contraction-mix.js +4 -3
- package/dist/detectors/contraction-mix.js.map +1 -1
- package/dist/detectors/counter-edge.d.ts +11 -0
- package/dist/detectors/counter-edge.d.ts.map +1 -1
- package/dist/detectors/counter-edge.js +29 -0
- package/dist/detectors/counter-edge.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +1 -0
- package/dist/detectors/gram-furniture.d.ts.map +1 -1
- package/dist/detectors/gram-furniture.js +7 -0
- package/dist/detectors/gram-furniture.js.map +1 -1
- package/dist/detectors/gram-heading.d.ts +9 -0
- package/dist/detectors/gram-heading.d.ts.map +1 -0
- package/dist/detectors/gram-heading.js +20 -0
- package/dist/detectors/gram-heading.js.map +1 -0
- package/dist/detectors/gram-predicate.d.ts.map +1 -1
- package/dist/detectors/gram-predicate.js +19 -1
- package/dist/detectors/gram-predicate.js.map +1 -1
- package/dist/detectors/gram-repetition.d.ts.map +1 -1
- package/dist/detectors/gram-repetition.js +18 -3
- package/dist/detectors/gram-repetition.js.map +1 -1
- package/dist/detectors/gram-spread.d.ts +6 -0
- package/dist/detectors/gram-spread.d.ts.map +1 -0
- package/dist/detectors/gram-spread.js +18 -0
- package/dist/detectors/gram-spread.js.map +1 -0
- package/dist/detectors/kanji-run-pieces.d.ts +4 -0
- package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
- package/dist/detectors/kanji-run-pieces.js +7 -0
- package/dist/detectors/kanji-run-pieces.js.map +1 -1
- package/dist/detectors/list-lead-in.d.ts +2 -2
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +28 -3
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +16 -4
- package/dist/detectors/signals.js.map +1 -1
- package/dist/rule-of-three.d.ts +5 -1
- package/dist/rule-of-three.d.ts.map +1 -1
- package/dist/rule-of-three.js +11 -2
- package/dist/rule-of-three.js.map +1 -1
- package/dist/structure-shape/template-outline.d.ts +7 -0
- package/dist/structure-shape/template-outline.d.ts.map +1 -1
- package/dist/structure-shape/template-outline.js +10 -0
- package/dist/structure-shape/template-outline.js.map +1 -1
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +23 -1
- package/dist/topic-clause.js.map +1 -1
- package/package.json +3 -3
- package/rules/ai-structure.yaml +2 -2
- package/rules/closing-cliche.yaml +3 -3
- package/rules/colon-lead-in.yaml +3 -2
- package/rules/contraction-consistency.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +4 -3
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +3 -2
- package/src/ai-score/human-shares.ts +1 -0
- package/src/detectors/acronym-file-type.ts +33 -0
- package/src/detectors/ai-structure.ts +18 -10
- package/src/detectors/bibliography-entry.ts +18 -0
- package/src/detectors/char-shape.ts +12 -7
- package/src/detectors/closing-cliche.ts +6 -1
- package/src/detectors/contraction-mention.ts +6 -2
- package/src/detectors/contraction-mix.ts +5 -3
- package/src/detectors/counter-edge.ts +35 -0
- package/src/detectors/gram-furniture.ts +9 -0
- package/src/detectors/gram-heading.ts +27 -0
- package/src/detectors/gram-predicate.ts +24 -1
- package/src/detectors/gram-repetition.ts +23 -2
- package/src/detectors/gram-spread.ts +19 -0
- package/src/detectors/kanji-run-pieces.ts +10 -0
- package/src/detectors/list-lead-in.ts +36 -3
- package/src/detectors/signals.ts +19 -4
- package/src/rule-of-three.ts +16 -2
- package/src/structure-shape/template-outline.ts +12 -0
- package/src/topic-clause.ts +25 -1
|
@@ -38,6 +38,7 @@ extra_word_lists:
|
|
|
38
38
|
opening-conjunction,
|
|
39
39
|
product-name,
|
|
40
40
|
phone-label,
|
|
41
|
+
file-noun,
|
|
41
42
|
]
|
|
42
43
|
uses: [pos]
|
|
43
44
|
severity: info
|
|
@@ -90,8 +91,8 @@ example:
|
|
|
90
91
|
after: Our key goal indicator (KGI) this term is to reach product-market fit (PMF).
|
|
91
92
|
|
|
92
93
|
not_flagged:
|
|
93
|
-
ja: 誰でも知っている略語(URL、PDF など)と、前後の括弧で説明した略語、会社の名前の中の英字(㈱ADEKA、CO.,LTD.)は指しません。ひな形の名前の置き場所(OOOO、XX 月)と、外のページへのリンクを並べた一覧の題名の中の略語も指しません(題名の略語は数には入れます)。大文字の違うだけの書き方で説明した略語(TCoP と TCOP)、略語を話題にする文で語に書き出した略語(略語の DOB … date of birth)、一覧で語のすぐ下にその語を名指すリンクを入れ子にした語(- GPL の下の GNU General Public License)も指しません。判例の引用の中の当事者と裁判所の名前(Ashwander v. TVA, 297 U.S. 288、MCI Telecomms. Corp. v. AT&T、(SDNY 1952))、引用の中の行政機関の事件番号(NOV/CFA 01-01)も指しません(引用の略語は数には入れます)。判決の頭の MR. JUSTICE も指しません。括弧の中で略語に「or」で別の呼び名を添えたもの(Department of Health and Human Services (HHS or the Department))、ハイフンで繋いだ字まで名前と揃うもの(Agency for Health (ARPA-H))は説明したと読み、メールアドレスの中の英字(OASH-RFI@hhs.gov)は略語と読みません。文書の中に書いた ABNF の文法の規則の名前と値(CRLF、%x0D)、等級の並び(A と AA)、番号で引く官報や判例集(80 FR 66128、2022 WL 4447293)、日付の付いた識別子の前の種類(WD WD-ABC1-20200101)、PO Box の PO も指しません。文献を引いて始まる注(1. See L. Summers (2015), "…," IMF Economic Review)の中の略語は、引いた文献の題名や誌名の書き方なので指しません(数には入れます)。角括弧の見出しで始まる文献の項目([FETCH] WHATWG, …)の中の略語も同じです。2 つ以上の番号で引く続き物の名前(BCP 78 と BCP 14、DR 4339 と DR 4340)、同じ文の前のほうで名前を書き出した略語(U.S. Small Business Administration … SBA)、肩書きの後ろの判事の姓(Lord HOLT、Mr. Justice BULLER)、商標の印の付いた名前(Acrobat DC®)、条で引く法令集(44 USC. 3502、15 USCA § 709)と、編と区分で引く法令集(21 CFR subpart J)も指しません。ショートメッセージで送るキーワード(texting GNPCGS to 333111)、名前のまま書いた製品の版(Adobe Acrobat Reader DC)、頭だけ大文字の語に繋いだ名前の中の大文字(NITE SAFE-Lite)も指しません。同じ文の前のほうで、同じ名詞の前に小文字で書き出した略語(incident response plan … IR plans)と、括弧の中で小文字の語を添えた略語の名前の頭の頭文字が揃うもの(… Partnerships to Stimulate Cybersecurity Education (RAMPS program))は説明したと読みます。貼り付けたチャットの発言(<jinxer-wm> FIRING …)の中の略語は、発言した人やボットの言葉なので指しません(数には入れます)。番地から州と郵便番号まで揃った所在地の中の大文字(1600 Elm Rd. NE, MS K12-3, Springfield, GA 30329 の NE と MS)、SQL のキーワード(VIEW、WHERE)、文の中で頭だけ大文字の語にも書いた名前を大文字で書いたもの(a hotel / Airbnb と書いた文書の AIRBNB)も指しません。行の頭に大文字で書いた接続詞(OR, Skip to …、二つの選択肢の間に一行で置いた OR)も指しません。
|
|
94
|
-
en: Common acronyms (URL, PDF), acronyms spelled out in brackets next to them, and the letters of a company name (㈱ADEKA, CO.,LTD.) are not reported. Neither are a template's placeholders (OOOO, XX 月) or an acronym in the title of a page in a list of links (it still counts towards the limit). Nor are an acronym explained under another capitalisation (TCoP, then TCOP), one a sentence about the abbreviation writes out (the abbreviation DOB … date of birth), or a term in a list whose nested link names it (- GPL above GNU General Public License). Nor are the parties and courts of a case citation (Ashwander v. TVA, 297 U.S. 288; MCI Telecomms. Corp. v. AT&T; (SDNY 1952)), an agency's docket number in a citation (NOV/CFA 01-01); a citation's acronyms still count towards the limit. Nor is the MR. JUSTICE that opens a line of an opinion. An acronym given another name after "or" in its parenthesis (Department of Health and Human Services (HHS or the Department)) or spelled out with its hyphened letter (Agency for Health (ARPA-H)) counts as expanded, and the letters of an email address (OASH-RFI@hhs.gov) are not an acronym. Nor are the rule names and values of an ABNF grammar in the text (CRLF, %x0D), the rungs of a grade ladder (A and AA), a register or reporter cited by number (80 FR 66128, 2022 WL 4447293), the kind written before a dated identifier (WD WD-ABC1-20200101), or the PO of a PO Box. A note that opens with a citation (1. See L. Summers (2015), "…," IMF Economic Review) is written in the cited work's words, and its acronyms are not reported (they still count towards the limit); so is an entry of a reference list keyed by a bracketed label ([FETCH] WHATWG, …). Nor are capitals the document cites by two or more numbers (BCP 78 and BCP 14, DR 4339 and DR 4340), an acronym whose name the same sentence writes out before it (U.S. Small Business Administration … SBA), a judge's surname after his title (Lord HOLT, Mr. Justice BULLER), a name marked as a trademark (Acrobat DC®), a code cited by section (44 USC. 3502, 15 USCA § 709), or a code cited by title and division (21 CFR subpart J). Nor are a keyword to send by text message (texting GNPCGS to 333111), a product's edition written with the product's name (Adobe Acrobat Reader DC), or capitals joined to a capitalised word in a name (NITE SAFE-Lite). An acronym the same sentence writes out in lower case before the same noun (incident response plan … IR plans), and one bracketed with a word in lower case after a name whose head gives its letters (… Partnerships to Stimulate Cybersecurity Education (RAMPS program)), count as expanded. An acronym in a pasted chat line (<jinxer-wm> FIRING …) is the speaker's or the bot's words, and is not reported (it still counts towards the limit). Nor are the capitals inside a postal address that runs from a street number to a state and ZIP code (the NE and MS of 1600 Elm Rd. NE, MS K12-3, Springfield, GA 30329), a keyword of SQL (VIEW, WHERE), or a name in capitals that the document also writes inside a sentence with only its first letter a capital (AIRBNB in a text that writes a hotel / Airbnb). Nor is a conjunction written in capitals at the head of a line (OR, Skip to …; an OR alone between two options).
|
|
94
|
+
ja: 誰でも知っている略語(URL、PDF など)と、前後の括弧で説明した略語、会社の名前の中の英字(㈱ADEKA、CO.,LTD.)は指しません。ひな形の名前の置き場所(OOOO、XX 月)と、外のページへのリンクを並べた一覧の題名の中の略語も指しません(題名の略語は数には入れます)。大文字の違うだけの書き方で説明した略語(TCoP と TCOP)、略語を話題にする文で語に書き出した略語(略語の DOB … date of birth)、一覧で語のすぐ下にその語を名指すリンクを入れ子にした語(- GPL の下の GNU General Public License)も指しません。判例の引用の中の当事者と裁判所の名前(Ashwander v. TVA, 297 U.S. 288、MCI Telecomms. Corp. v. AT&T、(SDNY 1952))、引用の中の行政機関の事件番号(NOV/CFA 01-01)も指しません(引用の略語は数には入れます)。判決の頭の MR. JUSTICE も指しません。括弧の中で略語に「or」で別の呼び名を添えたもの(Department of Health and Human Services (HHS or the Department))、ハイフンで繋いだ字まで名前と揃うもの(Agency for Health (ARPA-H))は説明したと読み、メールアドレスの中の英字(OASH-RFI@hhs.gov)は略語と読みません。文書の中に書いた ABNF の文法の規則の名前と値(CRLF、%x0D)、等級の並び(A と AA)、番号で引く官報や判例集(80 FR 66128、2022 WL 4447293)、日付の付いた識別子の前の種類(WD WD-ABC1-20200101)、PO Box の PO も指しません。文献を引いて始まる注(1. See L. Summers (2015), "…," IMF Economic Review)の中の略語は、引いた文献の題名や誌名の書き方なので指しません(数には入れます)。角括弧の見出しで始まる文献の項目([FETCH] WHATWG, …)の中の略語も同じです。2 つ以上の番号で引く続き物の名前(BCP 78 と BCP 14、DR 4339 と DR 4340)、同じ文の前のほうで名前を書き出した略語(U.S. Small Business Administration … SBA)、肩書きの後ろの判事の姓(Lord HOLT、Mr. Justice BULLER)、商標の印の付いた名前(Acrobat DC®)、条で引く法令集(44 USC. 3502、15 USCA § 709)と、編と区分で引く法令集(21 CFR subpart J)も指しません。ショートメッセージで送るキーワード(texting GNPCGS to 333111)、名前のまま書いた製品の版(Adobe Acrobat Reader DC)、頭だけ大文字の語に繋いだ名前の中の大文字(NITE SAFE-Lite)も指しません。同じ文の前のほうで、同じ名詞の前に小文字で書き出した略語(incident response plan … IR plans)と、括弧の中で小文字の語を添えた略語の名前の頭の頭文字が揃うもの(… Partnerships to Stimulate Cybersecurity Education (RAMPS program))は説明したと読みます。貼り付けたチャットの発言(<jinxer-wm> FIRING …)の中の略語は、発言した人やボットの言葉なので指しません(数には入れます)。番地から州と郵便番号まで揃った所在地の中の大文字(1600 Elm Rd. NE, MS K12-3, Springfield, GA 30329 の NE と MS)、SQL のキーワード(VIEW、WHERE)、文の中で頭だけ大文字の語にも書いた名前を大文字で書いたもの(a hotel / Airbnb と書いた文書の AIRBNB)も指しません。行の頭に大文字で書いた接続詞(OR, Skip to …、二つの選択肢の間に一行で置いた OR)も指しません。ファイルの種類の名前としてだけ書いた大文字(the MAP files、MAPファイル、拡張子の “.MAP”)も指しません。辞書が間投詞としてしか知らない 3 文字以上の語を大文字で書いたもの(製品の名前の HEY)も指しません。
|
|
95
|
+
en: Common acronyms (URL, PDF), acronyms spelled out in brackets next to them, and the letters of a company name (㈱ADEKA, CO.,LTD.) are not reported. Neither are a template's placeholders (OOOO, XX 月) or an acronym in the title of a page in a list of links (it still counts towards the limit). Nor are an acronym explained under another capitalisation (TCoP, then TCOP), one a sentence about the abbreviation writes out (the abbreviation DOB … date of birth), or a term in a list whose nested link names it (- GPL above GNU General Public License). Nor are the parties and courts of a case citation (Ashwander v. TVA, 297 U.S. 288; MCI Telecomms. Corp. v. AT&T; (SDNY 1952)), an agency's docket number in a citation (NOV/CFA 01-01); a citation's acronyms still count towards the limit. Nor is the MR. JUSTICE that opens a line of an opinion. An acronym given another name after "or" in its parenthesis (Department of Health and Human Services (HHS or the Department)) or spelled out with its hyphened letter (Agency for Health (ARPA-H)) counts as expanded, and the letters of an email address (OASH-RFI@hhs.gov) are not an acronym. Nor are the rule names and values of an ABNF grammar in the text (CRLF, %x0D), the rungs of a grade ladder (A and AA), a register or reporter cited by number (80 FR 66128, 2022 WL 4447293), the kind written before a dated identifier (WD WD-ABC1-20200101), or the PO of a PO Box. A note that opens with a citation (1. See L. Summers (2015), "…," IMF Economic Review) is written in the cited work's words, and its acronyms are not reported (they still count towards the limit); so is an entry of a reference list keyed by a bracketed label ([FETCH] WHATWG, …). Nor are capitals the document cites by two or more numbers (BCP 78 and BCP 14, DR 4339 and DR 4340), an acronym whose name the same sentence writes out before it (U.S. Small Business Administration … SBA), a judge's surname after his title (Lord HOLT, Mr. Justice BULLER), a name marked as a trademark (Acrobat DC®), a code cited by section (44 USC. 3502, 15 USCA § 709), or a code cited by title and division (21 CFR subpart J). Nor are a keyword to send by text message (texting GNPCGS to 333111), a product's edition written with the product's name (Adobe Acrobat Reader DC), or capitals joined to a capitalised word in a name (NITE SAFE-Lite). An acronym the same sentence writes out in lower case before the same noun (incident response plan … IR plans), and one bracketed with a word in lower case after a name whose head gives its letters (… Partnerships to Stimulate Cybersecurity Education (RAMPS program)), count as expanded. An acronym in a pasted chat line (<jinxer-wm> FIRING …) is the speaker's or the bot's words, and is not reported (it still counts towards the limit). Nor are the capitals inside a postal address that runs from a street number to a state and ZIP code (the NE and MS of 1600 Elm Rd. NE, MS K12-3, Springfield, GA 30329), a keyword of SQL (VIEW, WHERE), or a name in capitals that the document also writes inside a sentence with only its first letter a capital (AIRBNB in a text that writes a hotel / Airbnb). Nor is a conjunction written in capitals at the head of a line (OR, Skip to …; an OR alone between two options). Nor are capitals a document writes only as the name of a kind of file (the MAP files, MAPファイル, the extension “.MAP”). Nor is a word of three letters or more that the dictionary knows only as an interjection, written in capitals (HEY, a product's name).
|
|
95
96
|
level_meaning:
|
|
96
97
|
ja: 説明のない略語が {limit} 種類あれば指摘。文書が自分で略語を {limit} 個展開していれば、1 つの抜けから指摘
|
|
97
98
|
en: reported once {limit} different acronyms go unexplained, or from the first one when the document itself spells out {limit} others
|
|
@@ -76,6 +76,7 @@ export const HUMAN_SHARES: HumanShares = {
|
|
|
76
76
|
"closing-cliche": {
|
|
77
77
|
academic: { documents: 10, fired: 0 },
|
|
78
78
|
blog: { documents: 23, fired: 0 },
|
|
79
|
+
business: { documents: 11, fired: 0 },
|
|
79
80
|
docs: { documents: 21, fired: 0 },
|
|
80
81
|
legal: { documents: 35, fired: 1 },
|
|
81
82
|
literature: { documents: 13, fired: 0 },
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Capitals a document writes only as the name of a kind of file (the MAP files, each MAP file, MAPファイル): the file type,
|
|
2
|
+
// named by its extension, not an acronym the reader needs spelled out. Pure; the file nouns come from the file-noun lexicon.
|
|
3
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
4
|
+
|
|
5
|
+
/** One place an acronym stands: the text right before and after it, and the part of speech of the word after it when the language reads one. */
|
|
6
|
+
export type AcronymUse = { readonly word: string; readonly preceding: string; readonly following: string; readonly nextPos?: string | undefined };
|
|
7
|
+
|
|
8
|
+
/** The extension itself (“.MAP”): a dot that does not end a word or a number (U.S.MAP, 1.MAP). */
|
|
9
|
+
const EXTENSION_DOT = /(?:^|[^\p{L}\p{N}_.])\.$/u;
|
|
10
|
+
|
|
11
|
+
/** A file noun ends where no Latin letter or digit follows: MAPファイルを reads ファイル, the MAP filesystem does not read file. */
|
|
12
|
+
const fileNounAhead = (fileNouns: readonly string[]): RegExp =>
|
|
13
|
+
new RegExp(String.raw`^[ \t]?(?:${fileNouns.map(escapeRegExp).join("|")})(?![\p{Script=Latin}\p{N}_])`, "iu");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The acronyms every use of which is followed by a file noun, or is the extension itself (“.MAP”). One use elsewhere (the WAL
|
|
17
|
+
* receiver beside a WAL file) shows the capitals name more than the file. At least one file noun must not be read as a verb
|
|
18
|
+
* (the SEC files a suit): the tagger misreads a few nouns (the MAP files themselves), so one noun reading is enough.
|
|
19
|
+
*/
|
|
20
|
+
export const fileTypeNames = (uses: readonly AcronymUse[], fileNouns: readonly string[]): Set<string> => {
|
|
21
|
+
if (fileNouns.length === 0) return new Set();
|
|
22
|
+
const ahead = fileNounAhead(fileNouns);
|
|
23
|
+
const isExtension = (use: AcronymUse): boolean => EXTENSION_DOT.test(use.preceding);
|
|
24
|
+
const isFileUse = (use: AcronymUse): boolean => isExtension(use) || ahead.test(use.following);
|
|
25
|
+
const isNounUse = (use: AcronymUse): boolean => isExtension(use) || use.nextPos !== "VERB";
|
|
26
|
+
const words = new Set(uses.map((use) => use.word));
|
|
27
|
+
return new Set(
|
|
28
|
+
[...words].filter((word) => {
|
|
29
|
+
const own = uses.filter((use) => use.word === word);
|
|
30
|
+
return own.every(isFileUse) && own.some(isNounUse);
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -4,35 +4,43 @@ import { STRUCTURE_TEXT } from "../outline/structure-text.ts";
|
|
|
4
4
|
import { structureOf } from "../structure-shape/of-document.ts";
|
|
5
5
|
import { headedSections } from "../structure-shape/features.ts";
|
|
6
6
|
import { headingWords } from "../structure-shape/heading-words.ts";
|
|
7
|
-
import { isTemplateOutline, templateSectionsOf } from "../structure-shape/template-outline.ts";
|
|
7
|
+
import { isTemplateOutline, isWholeTemplateOutline, templateSectionsOf } from "../structure-shape/template-outline.ts";
|
|
8
8
|
import { SAME_SHAPE } from "../ai-score/signals.ts";
|
|
9
9
|
import { SAME_SHAPE_VALUE } from "../composite-signals.ts";
|
|
10
10
|
|
|
11
11
|
/** The template outline's name in the message, beside the structure measures past the human articles. */
|
|
12
12
|
const TEMPLATE_NAME: Texts<string> = { ja: "提案書・報告書の定型の見出し", en: "the textbook proposal or report headings" };
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/** The name of the second count a template outline gives when it is the whole outline. */
|
|
15
|
+
const WHOLE_TEMPLATE_NAME: Texts<string> = { ja: "見出しのほとんどが定型", en: "almost no heading outside that outline" };
|
|
16
|
+
|
|
17
|
+
const headingWordsOf = (doc: ProseDocument): string[] => headedSections(doc.sections).map((section) => headingWords(section.heading));
|
|
18
|
+
|
|
19
|
+
/** The template names the outline earns: one for the textbook sections, one more when they are nearly all its headings. */
|
|
20
|
+
const templateNames = (doc: ProseDocument): Array<Texts<string>> => {
|
|
21
|
+
const headings = headingWordsOf(doc);
|
|
22
|
+
const lexicon = doc.lexicons["template-heading"] ?? [];
|
|
23
|
+
if (!isTemplateOutline(templateSectionsOf(headings, lexicon))) return [];
|
|
24
|
+
return isWholeTemplateOutline(headings, lexicon) ? [TEMPLATE_NAME, WHOLE_TEMPLATE_NAME] : [TEMPLATE_NAME];
|
|
25
|
+
};
|
|
19
26
|
|
|
20
27
|
/**
|
|
21
28
|
* The document's outline is past the human articles on several structure measures at once (chaff outline's structure
|
|
22
29
|
* block): many headings, three-way splits, bold labels, uniform sections. One alone is ordinary; the limit is how many.
|
|
23
|
-
* A textbook outline (Summary, Current Situation, Proposed Solution, Expected Benefits…) counts as one more
|
|
30
|
+
* A textbook outline (Summary, Current Situation, Proposed Solution, Expected Benefits…) counts as one more, and as one
|
|
31
|
+
* more again when it is nearly the whole outline; even then it needs a measure past the human articles to reach the limit.
|
|
24
32
|
*/
|
|
25
33
|
export const aiStructure: Detector = (doc, options): Finding[] => {
|
|
26
34
|
const scored = structureOf(doc);
|
|
27
|
-
const template =
|
|
28
|
-
const count = scored.score +
|
|
35
|
+
const template = templateNames(doc);
|
|
36
|
+
const count = scored.score + template.length;
|
|
29
37
|
if (count < options.limit) return [];
|
|
30
38
|
const language = uiLanguageOf(doc.language);
|
|
31
39
|
const text = STRUCTURE_TEXT[language];
|
|
32
40
|
const beyond = scored.placements.filter((placement) => placement.beyond).map((placement) => placement.feature.id);
|
|
33
41
|
const measures = beyond.map((id) => text.features[id].name);
|
|
34
42
|
const sameShape = beyond.flatMap((id) => SAME_SHAPE[id] ?? []);
|
|
35
|
-
const names =
|
|
43
|
+
const names = [...measures, ...template.map((name) => name[language])];
|
|
36
44
|
const heading = (doc.markup?.headings ?? []).find((entry) => entry.depth > 1) ?? doc.markup?.headings[0];
|
|
37
45
|
return [
|
|
38
46
|
{
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// A bibliographic entry written as a line of a note, as Japanese papers print them (SIST 02): fields closed by a period,
|
|
2
|
+
// "著者. 題. 出版者, 2025, p. 369." The words of the entry are the cited work's, not the writer's. Pure.
|
|
3
|
+
|
|
4
|
+
/** A period that closes a field: a full-width one, or an ASCII one after a letter that is not ASCII, a closing quote or bracket, followed by a space. */
|
|
5
|
+
const FIELD_END = /.(?=\S)|(?<=\P{ASCII})\.(?=\s)/gu;
|
|
6
|
+
|
|
7
|
+
/** What a reference carries and a sentence of prose does not: a year, a quoted title in “”, a link, or a page. */
|
|
8
|
+
const PUBLICATION_MARKS: readonly RegExp[] = [/(?<!\d)(?:1[89]|20)\d{2}(?!\d)/u, /“[^”]/u, /https?:\/\//u, /\bpp?\. ?\d/u];
|
|
9
|
+
|
|
10
|
+
/** Fields closed before the end of the text that it takes to be an entry and not one sentence: author, title, then the rest. */
|
|
11
|
+
const MIN_FIELD_ENDS = 2;
|
|
12
|
+
|
|
13
|
+
/** Whether the text is a bibliographic entry: two fields or more closed by a period inside it, and a mark only a reference carries. */
|
|
14
|
+
export const isBibliographyEntry = (text: string): boolean => {
|
|
15
|
+
const body = text.trim();
|
|
16
|
+
const fieldEnds = [...body.matchAll(FIELD_END)].filter((match) => match.index + match[0].length < body.length);
|
|
17
|
+
return fieldEnds.length >= MIN_FIELD_ENDS && PUBLICATION_MARKS.some((mark) => mark.test(body));
|
|
18
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Detector, DetectorOptions, DocumentProfile, Finding, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
|
|
2
2
|
import { compacted } from "./gram-place.ts";
|
|
3
|
-
import { leadingCounter, trailingPrefix } from "./counter-edge.ts";
|
|
3
|
+
import { leadingCounter, trailingOrdinals, trailingPrefix } from "./counter-edge.ts";
|
|
4
4
|
import { trailingAddressee, type AddresseeSuffix } from "./addressee-edge.ts";
|
|
5
5
|
import { leadingPrefix, trailingTitle, type AddresseeWords } from "./addressee-title-edge.ts";
|
|
6
6
|
import {
|
|
@@ -26,7 +26,8 @@ import { maskSpans } from "../mask.ts";
|
|
|
26
26
|
import { quotedSpans } from "../quoted-span.ts";
|
|
27
27
|
import { nameSpans } from "../team-names.ts";
|
|
28
28
|
import { isIn } from "../lexicon-genres.ts";
|
|
29
|
-
import { isTitledPerson, standaloneNames, unknownPieces } from "./kanji-run-pieces.ts";
|
|
29
|
+
import { holdsKnown, isInnerSuffix, isTitledPerson, standaloneNames, unknownPieces } from "./kanji-run-pieces.ts";
|
|
30
|
+
import { isBibliographyEntry } from "./bibliography-entry.ts";
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* 文字の並びを見る検出。漢字の連なりが住所か名前かだけは、形態素解析の固有名詞と数で決める。
|
|
@@ -207,12 +208,13 @@ const isAddresseeLine = (run: KanjiRun, words: NameWords): boolean => {
|
|
|
207
208
|
/** 宛名の行か、名前の並びの 1 項目。どちらも役職を付けた名前を 1 つずつ並べたもので、尻の役職は名前の外。 */
|
|
208
209
|
const isNamedEntry = (run: KanjiRun, words: NameWords): boolean => run.listItem || isAddresseeLine(run, words);
|
|
209
210
|
|
|
210
|
-
/** 尻の外す語:
|
|
211
|
+
/** 尻の外す語: 数に付く接頭の語か条や項の番号か宛先に付く語と、宛名の行ならその前の役職(日本博物館協会会長殿の「会長殿」)。 */
|
|
211
212
|
const tailOf = (tokens: readonly Token[], run: KanjiRun, span: Span, words: NameWords): Tail | undefined => {
|
|
212
213
|
const prefix = trailingPrefix(tokens, span.end, run.text);
|
|
213
214
|
const suffix =
|
|
214
215
|
prefix === undefined
|
|
215
|
-
? (
|
|
216
|
+
? (trailingOrdinals(tokens, span, run.text) ??
|
|
217
|
+
trailingConjunction(tokens, span.start, span.end, run.text) ??
|
|
216
218
|
trailingAddressee(tokens, span.end, run.text, words.addressee) ??
|
|
217
219
|
trailingAddressee(tokens, span.end, run.text, words.listSuffixes))
|
|
218
220
|
: { surface: prefix.surface, start: prefix.span.start };
|
|
@@ -270,16 +272,18 @@ const surfaceWithin = (token: Token, span: Span): string =>
|
|
|
270
272
|
* 連なりの、知っている語(文書がほかで単独で使う組織の名前と法令の名前、連なりを閉じる決まった語、職名の前後の人の名前)を外した残りのうち、最も長いもの。
|
|
271
273
|
* 安全保障理事会常任理事国は(安全保障理事会を単独で使う文書なら)「常任理事国」、日本国内閣総理大臣は「日本国」を数える。
|
|
272
274
|
* 名前に普通の語が続く連なり(日本弁護士連合会臨時総会決議)は、名前がその文書で単独で使われていなければ、まるごと数える。
|
|
275
|
+
* 連なりの中ほどの、並べた物の後ろに付く語(高齢運転者等専用駐車区間の「等」)は、語の終わりを見せるので、その前後を別に数える。
|
|
273
276
|
*/
|
|
274
277
|
const longestUnknown = (tokens: readonly Token[], rest: Span, keptHead: string, context: RunContext): string => {
|
|
275
278
|
const runTokens = coveringOf(tokens, rest).flatMap((index) => tokens.slice(index, index + 1));
|
|
276
279
|
const words = runTokens.map((token) => surfaceWithin(token, rest));
|
|
277
280
|
const whole = words.join("");
|
|
278
281
|
// A run as long as the text holds no known word; reading it word by word would take a pass per word.
|
|
279
|
-
if (![...context.terms, ...context.words.knownWords]
|
|
282
|
+
if (!holdsKnown(words, [...context.terms, ...context.words.knownWords], context.words.listSuffixes)) return keptHead + whole;
|
|
280
283
|
const isKnown = (start: number, end: number): boolean => {
|
|
281
284
|
const piece = words.slice(start, end).join("");
|
|
282
285
|
return (
|
|
286
|
+
(end === start + 1 && isInnerSuffix(words, start, context.words.listSuffixes)) ||
|
|
283
287
|
context.terms.has(piece) ||
|
|
284
288
|
(end === words.length && context.words.knownWords.has(piece)) ||
|
|
285
289
|
isTitledPerson(runTokens, words, { start, end }, context.words.knownWords, context.maxKnownWords)
|
|
@@ -346,7 +350,7 @@ const nameWordsOf = (doc: ProseDocument): NameWords => {
|
|
|
346
350
|
closingForms: (doc.lexicons["organisation-form"] ?? []).filter((entry) => entry.position !== "before").map((entry) => entry.pattern),
|
|
347
351
|
units: patterns("organisation-unit"),
|
|
348
352
|
};
|
|
349
|
-
|
|
353
|
+
return {
|
|
350
354
|
topUnits: new Set(patterns("prefecture-unit")),
|
|
351
355
|
organisation,
|
|
352
356
|
title: { endings: patterns("title-ending") },
|
|
@@ -358,7 +362,6 @@ const nameWordsOf = (doc: ProseDocument): NameWords => {
|
|
|
358
362
|
listSuffixes: patterns("list-suffix"),
|
|
359
363
|
knownWords: new Set(patterns("kanji-known-word")),
|
|
360
364
|
};
|
|
361
|
-
return words;
|
|
362
365
|
};
|
|
363
366
|
|
|
364
367
|
const contextOf = (doc: ProseDocument, options: DetectorOptions): RunContext => {
|
|
@@ -385,10 +388,12 @@ const contextOf = (doc: ProseDocument, options: DetectorOptions): RunContext =>
|
|
|
385
388
|
/**
|
|
386
389
|
* 漢字が続くと、どこで語が切れるのか読み手が探すことになる。
|
|
387
390
|
* 「情報処理推進機構認定試験」は 12 字。ひらがなを 1 つ挟むだけで読める。
|
|
391
|
+
* 文献の記述(著者. 題. 出版者, 2025.)の連なりは、引いた文献の題や名前で、書き手が割れないので数えない。
|
|
388
392
|
*/
|
|
389
393
|
export const kanjiRun: Detector = (doc, options): Finding[] => {
|
|
390
394
|
const context = contextOf(doc, options);
|
|
391
395
|
return doc.sentences
|
|
396
|
+
.filter((sentence) => !isBibliographyEntry(sentence.text))
|
|
392
397
|
.map((sentence) => ({ sentence, run: longestKanji(sentence, context) }))
|
|
393
398
|
.filter(({ run }) => run.length > options.limit)
|
|
394
399
|
.map(({ sentence, run }) => ({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Detector, Finding, LexiconEntry, Paragraph, Sentence } from "../plugin.ts";
|
|
2
2
|
import { closingSentences } from "../closing-paragraph.ts";
|
|
3
|
+
import { entriesForGenre } from "../lexicon-genres.ts";
|
|
3
4
|
import { exhortationIn, exhortationWords } from "./closing-exhortation.ts";
|
|
4
5
|
import { comparableText, entryIn, entryOpens } from "./lexicon-match.ts";
|
|
5
6
|
|
|
@@ -61,7 +62,11 @@ export const closingClicheWords = (lexicon: readonly LexiconEntry[]): Words => (
|
|
|
61
62
|
|
|
62
63
|
/** 結び(最後の節の終わりの段落)の定型の言い回し。limit は指摘に要る文の数。 */
|
|
63
64
|
export const closingCliche: Detector = (doc, options): Finding[] => {
|
|
64
|
-
const hits = closingClicheHits(
|
|
65
|
+
const hits = closingClicheHits(
|
|
66
|
+
closingSentences(doc.sections, doc.paragraphs),
|
|
67
|
+
doc.paragraphs,
|
|
68
|
+
closingClicheWords(entriesForGenre(options.lexicon ?? [], options.genre)),
|
|
69
|
+
);
|
|
65
70
|
if (hits.length < options.limit) return [];
|
|
66
71
|
return hits.map((hit) => ({
|
|
67
72
|
rule: "",
|
|
@@ -4,8 +4,9 @@ import type { Span } from "../plugin.ts";
|
|
|
4
4
|
|
|
5
5
|
// A short phrase in quotation marks ("Do Not Disturb", ‘we’re going to x’) is a name or an example: the form is mentioned,
|
|
6
6
|
// not used, so it says nothing about the document's register. Spoken words carry punctuation ("We don't know," she
|
|
7
|
-
// said)
|
|
8
|
-
// someone else's wording twice over.
|
|
7
|
+
// said) are counted, unless they are quoted inside another quotation (a platform's label in a quoted sentence), which is
|
|
8
|
+
// someone else's wording twice over. No form inside quotation marks is pointed at: the writer cannot change a quotation.
|
|
9
|
+
// The text must already have straight apostrophes, so a ’ left in it closes a quotation.
|
|
9
10
|
|
|
10
11
|
const MENTION_MARKS: Readonly<Record<string, string>> = { "“": "”", '"': '"', "‘": "’" };
|
|
11
12
|
/** More words than this in quotation marks is a quoted sentence, not a phrase named as an example. */
|
|
@@ -36,6 +37,9 @@ export const withoutMentions = (text: string): string => {
|
|
|
36
37
|
);
|
|
37
38
|
};
|
|
38
39
|
|
|
40
|
+
/** The text with everything in quotation marks blanked out. */
|
|
41
|
+
export const withoutQuotations = (text: string): string => blankSpans(text, quotedSpans(text, MENTION_MARKS));
|
|
42
|
+
|
|
39
43
|
/**
|
|
40
44
|
* The text (which starts at offset in the document) with the document ranges that fall in it blanked out.
|
|
41
45
|
* Ranges are in document coordinates; those outside the text change nothing.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pairMinority, type PairUses } from "./contraction-minority.ts";
|
|
2
|
-
import { blankRanges, isTermList, withoutMentions } from "./contraction-mention.ts";
|
|
2
|
+
import { blankRanges, isTermList, withoutMentions, withoutQuotations } from "./contraction-mention.ts";
|
|
3
3
|
import { stressedWords } from "./contraction-emphasis.ts";
|
|
4
4
|
import { noticeSentences, talksAboutContractions, warningSentences } from "./contraction-set-apart.ts";
|
|
5
5
|
import { escapeRegExp, straightApostrophes } from "../orthography.ts";
|
|
@@ -36,9 +36,11 @@ const comparableText = (text: string): string => {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* 指してよい字。一語だけ強調した形(does **not**)は強勢のために選んだ形なので指さない。
|
|
39
|
-
*
|
|
39
|
+
* 引用符の中の形(引いた標語、回答の文言、人の言葉)は書き手が変えられないので指さない。
|
|
40
|
+
* どちらも、どちらが多いかを数えるときは数える。
|
|
40
41
|
*/
|
|
41
|
-
const pointableText = (sentence: Sentence, stressed: readonly Span[]): string =>
|
|
42
|
+
const pointableText = (sentence: Sentence, stressed: readonly Span[]): string =>
|
|
43
|
+
comparableText(withoutQuotations(straightApostrophes(blankRanges(sentence.text, sentence.span.start, stressed))));
|
|
42
44
|
|
|
43
45
|
/** 語のすぐ後ろが句読点か文の終わり。名前として挙げた語("Use cannot, instead of can't.")はそう並ぶ。 */
|
|
44
46
|
const bareUses = (text: string, word: string): number => [...text.matchAll(new RegExp(`\\b${escapeRegExp(word)}\\b(?=\\s*(?:\\p{P}|$))`, "gu"))].length;
|
|
@@ -65,3 +65,38 @@ export const trailingPrefix = (tokens: readonly Token[], end: number, run: strin
|
|
|
65
65
|
if (prefix === undefined || !isPrefix(prefix) || !isNumber(wordAfter(tokens, at))) return undefined;
|
|
66
66
|
return run.endsWith(prefix.surface) ? prefix : undefined;
|
|
67
67
|
};
|
|
68
|
+
|
|
69
|
+
const isBound = (token: Token | undefined): boolean => token?.features?.["Bound"] === "Yes" && !isPrefix(token);
|
|
70
|
+
|
|
71
|
+
/** 語の並び run の、end(添字、含まない)で終わる序数の項(第三十条、第二項)の頭の添字。項でなければ undefined。 */
|
|
72
|
+
const ordinalGroupStart = (run: readonly Token[], end: number): number | undefined => {
|
|
73
|
+
if (!isBound(run[end - 1])) return undefined;
|
|
74
|
+
const numbersStart = run.slice(0, end - 1).findLastIndex((token) => !isNumber(token)) + 1;
|
|
75
|
+
const prefixAt = numbersStart - 1;
|
|
76
|
+
return numbersStart < end - 1 && isPrefix(run[prefixAt]) ? prefixAt : undefined;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** 語の並び run の尻の、序数の項の並びの頭の添字。項が無ければ run.length。 */
|
|
80
|
+
const ordinalChainStart = (run: readonly Token[], end: number = run.length): number => {
|
|
81
|
+
const start = ordinalGroupStart(run, end);
|
|
82
|
+
return start === undefined ? end : ordinalChainStart(run, start);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 漢字の連なり run(文書全体の座標で span)の尻の、序数の項の並び(学校教育法第三十条第二項の「第三十条第二項」)。条や項の番号は
|
|
87
|
+
* 前の名前を指す番号で、前の複合語の一部ではない。項の前に名前が残るときだけ。そうでなければ undefined。
|
|
88
|
+
*/
|
|
89
|
+
export const trailingOrdinals = (
|
|
90
|
+
tokens: readonly Token[],
|
|
91
|
+
span: { readonly start: number; readonly end: number },
|
|
92
|
+
run: string,
|
|
93
|
+
): { readonly surface: string; readonly start: number } | undefined => {
|
|
94
|
+
const words = tokens.filter((token) => token.span.start < span.end && span.start < token.span.end);
|
|
95
|
+
const start = ordinalChainStart(words);
|
|
96
|
+
const first = words[start];
|
|
97
|
+
if (start === 0 || first === undefined) return undefined;
|
|
98
|
+
const chain = words.slice(start);
|
|
99
|
+
const joined = chain.every((token, at) => at === 0 || chain[at - 1]?.span.end === token.span.start);
|
|
100
|
+
const surface = chain.map((token) => token.surface).join("");
|
|
101
|
+
return joined && run.endsWith(surface) ? { surface, start: first.span.start } : undefined;
|
|
102
|
+
};
|
|
@@ -137,3 +137,12 @@ const JA_PART_REFERENCE = /[表図][\d0-9]+(?:[--..][\d0-9]+)*|第[\
|
|
|
137
137
|
*/
|
|
138
138
|
export const partReferenceSpans = (text: string, unit: LengthUnit): Span[] =>
|
|
139
139
|
unit === "word" ? spansOf(text, LABEL_AND_NUMBER, (match) => PART_LABELS.has((match[1] ?? "").toLowerCase())) : spansOf(text, JA_PART_REFERENCE, () => true);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 角括弧でくくった画面の部品の名前([許可]、[ブックマーク]、[内容を確認]リンク)と、それに付く助詞一つの範囲。画面の手引きは手順ごとに
|
|
143
|
+
* 違う部品を指して同じ形で書く([…]をクリックすると)。名前にかかる語句と同じく、部品の名前に付いた所からの語句は数えない。
|
|
144
|
+
* 後ろの片仮名の語(ボタン、リンク)も名前に入れる。
|
|
145
|
+
*/
|
|
146
|
+
const SCREEN_LABEL = /[[[【][^[\][]【】]+[\]]】][\p{Script=Katakana}ー]*[をがにでへ]/gu;
|
|
147
|
+
|
|
148
|
+
export const screenLabelSpans = (text: string, unit: LengthUnit): Span[] => (unit === "char" ? spansOf(text, SCREEN_LABEL, () => true) : []);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LengthUnit } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
/** 語句を数える単位に分ける。英語は語、日本語は文字。 */
|
|
4
|
+
const unitsOf = (key: string, unit: LengthUnit): string[] => (unit === "char" ? [...key] : key.split(" "));
|
|
5
|
+
|
|
6
|
+
const joinUnits = (units: readonly string[], unit: LengthUnit): string => units.join(unit === "char" ? "" : " ");
|
|
7
|
+
|
|
8
|
+
/** 中身のある部分か。日本語は漢字か片仮名が 2 字続く(併記、ボタン)。英語は 2 語以上(create a ConfigMap)。 */
|
|
9
|
+
const CONTENT_RUN = /[\p{Script=Han}\p{Script=Katakana}ー]{2}/u;
|
|
10
|
+
|
|
11
|
+
const hasContent = (units: readonly string[], unit: LengthUnit): boolean => (unit === "char" ? CONTENT_RUN.test(units.join("")) : units.length >= 2);
|
|
12
|
+
|
|
13
|
+
/** units の連続する部分のうち、title にあって中身のある一番長いものの長さ(文字の数)。 */
|
|
14
|
+
const longestNamedRun = (units: readonly string[], title: string, unit: LengthUnit): number => {
|
|
15
|
+
const runs = units.flatMap((_, start) => units.slice(start + 1).map((__, offset) => units.slice(start, start + offset + 2)));
|
|
16
|
+
const named = runs.filter((run) => hasContent(run, unit) && title.includes(joinUnits(run, unit)));
|
|
17
|
+
return Math.max(0, ...named.map((run) => [...joinUnits(run, unit)].length));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 見出しが名付けた句か。語句の文字の過半が、見出しにある中身のある一続きの句(to create a ConfigMap の create a ConfigMap、
|
|
22
|
+
* 氏を併記した氏名 の 氏を併記した)。窓の幅は決まっているので、本文が見出しの句に前置詞や後ろの名詞を付けて使うと、窓は見出しの
|
|
23
|
+
* 句からはみ出す。文字で測るので、短い機能語だけの一続き(How you will be evaluated の will be)では過半に届かない。
|
|
24
|
+
* 題と見出しにある句は文書の主題で、名前と同じく、それに付いた語句も数えない。title は見出しを並べた文字列。
|
|
25
|
+
*/
|
|
26
|
+
export const namedByHeading = (key: string, title: string, unit: LengthUnit): boolean =>
|
|
27
|
+
title.includes(key) || longestNamedRun(unitsOf(key, unit), title, unit) * 2 > [...key].length;
|
|
@@ -25,6 +25,28 @@ const inCoordinatedNoun = (tokens: readonly Token[], index: number, unit: Length
|
|
|
25
25
|
NOUNS.has(tokens[index + 1]?.pos ?? "") &&
|
|
26
26
|
!isDependentNoun(tokens[index + 1]);
|
|
27
27
|
|
|
28
|
+
/** 名詞を並べる中黒(資質・能力)。半角(・)も同じ。 */
|
|
29
|
+
const NAKAGURO = new Set(["・", "・"]);
|
|
30
|
+
|
|
31
|
+
/** index から助動詞を飛ばした先(育成すべき の す から 資質)。 */
|
|
32
|
+
const afterAuxiliaries = (tokens: readonly Token[], index: number): number =>
|
|
33
|
+
tokens[index + 1]?.pos === "AUX" ? afterAuxiliaries(tokens, index + 1) : index + 1;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 日本語で、中黒で並べた名詞(資質・能力)を飾る動詞と助動詞(育成すべき資質・能力)。名詞を中黒で並べた語は文書の決まった用語で、
|
|
37
|
+
* それを飾る節も用語の一部として繰り返される。中黒の無い名詞の前の動詞(〜の中にあるコンポーネント)は言い回しの一部のまま。
|
|
38
|
+
*/
|
|
39
|
+
const modifiesNounPair = (tokens: readonly Token[], index: number, unit: LengthUnit): boolean => {
|
|
40
|
+
if (unit !== "char" || !PREDICATE_POS.has(tokens[index]?.pos ?? "")) return false;
|
|
41
|
+
const head = afterAuxiliaries(tokens, index);
|
|
42
|
+
return (
|
|
43
|
+
NOUNS.has(tokens[head]?.pos ?? "") &&
|
|
44
|
+
!isDependentNoun(tokens[head]) &&
|
|
45
|
+
NAKAGURO.has(tokens[head + 1]?.surface ?? "") &&
|
|
46
|
+
NOUNS.has(tokens[head + 2]?.pos ?? "")
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
28
50
|
/**
|
|
29
51
|
* 英語の大文字だけの語(AI、API)は略語の名前。解析器が動詞と読んでも(AI を ain't の ai と読む)述語ではない。
|
|
30
52
|
* 強調と分かった普通の語(NEVER、START)は除く。
|
|
@@ -42,7 +64,8 @@ const acronymAt = (tokens: readonly Token[], index: number, unit: LengthUnit): b
|
|
|
42
64
|
*/
|
|
43
65
|
const modifiesNoun = (tokens: readonly Token[], index: number, unit: LengthUnit): boolean =>
|
|
44
66
|
(unit === "word" && tokens[index]?.pos === "VERB" && (NOUNS.has(tokens[index + 1]?.pos ?? "") || acronymAt(tokens, index + 1, unit))) ||
|
|
45
|
-
inCoordinatedNoun(tokens, index, unit)
|
|
67
|
+
inCoordinatedNoun(tokens, index, unit) ||
|
|
68
|
+
modifiesNounPair(tokens, index, unit);
|
|
46
69
|
|
|
47
70
|
/** 英語で大文字の名前の一部になった動詞(Procedures Guide、the Location Object)と略語(AI)も、述語ではない。 */
|
|
48
71
|
const namePartAt = (tokens: readonly Token[], index: number, unit: LengthUnit): boolean =>
|
|
@@ -11,9 +11,12 @@ import {
|
|
|
11
11
|
quotedClosingSpans,
|
|
12
12
|
quotedSpans,
|
|
13
13
|
referenceClosings,
|
|
14
|
+
screenLabelSpans,
|
|
14
15
|
} from "./gram-furniture.ts";
|
|
15
16
|
import { hasPredicateIn } from "./gram-predicate.ts";
|
|
16
17
|
import { gramPassagesOf } from "./gram-passages.ts";
|
|
18
|
+
import { narrowestStretch, sentencePositions } from "./gram-spread.ts";
|
|
19
|
+
import { namedByHeading } from "./gram-heading.ts";
|
|
17
20
|
import { entryOpeners, filledForms, labelLines, nounFragments, rowEndCells, sectionOpeners } from "./gram-openers.ts";
|
|
18
21
|
import { nameSpans, touchesAny } from "../team-names.ts";
|
|
19
22
|
import type { Detector, Finding, LengthUnit, ProseDocument, Sentence, Span, StructureNode } from "../plugin.ts";
|
|
@@ -81,7 +84,7 @@ type Context = {
|
|
|
81
84
|
/** 数えない範囲: 名前(触れる窓を外す)と、飾り(過半を覆う窓を外す)。 */
|
|
82
85
|
const excludedIn = (context: Context, sentence: Sentence, text: string, source: ReturnType<typeof compacted>): { named: Span[]; mask: boolean[] } => {
|
|
83
86
|
const unit = context.doc.lengthUnit;
|
|
84
|
-
const named = [...nameSpans(text, context.names), ...fieldLabelSpans(text, unit), ...partReferenceSpans(text, unit)];
|
|
87
|
+
const named = [...nameSpans(text, context.names), ...fieldLabelSpans(text, unit), ...partReferenceSpans(text, unit), ...screenLabelSpans(text, unit)];
|
|
85
88
|
const linked = linkedIn(context.doc, sentence, source);
|
|
86
89
|
const mask = furnitureMask(text, linked);
|
|
87
90
|
[...fixedEndingSpans(text, context.endings), ...quotedSpans(text), ...quotedClosingSpans(text, context.closings, linked)].forEach((span) =>
|
|
@@ -152,6 +155,22 @@ const titleOf = (doc: ProseDocument): string =>
|
|
|
152
155
|
|
|
153
156
|
type Repeat = { readonly key: string; readonly occurrences: readonly Occurrence[] };
|
|
154
157
|
|
|
158
|
+
/**
|
|
159
|
+
* 上限を超える数の出現が収まる一番短い範囲が、これより長ければ数えない(文書の長さの単位)。読み手が前の出現を覚えているうちに次が
|
|
160
|
+
* 来ないので、言い直しとは読まれない。長い報告や論文が、測る出来事や量の名前(adopted a budget resolution、posts Grok judged true)を
|
|
161
|
+
* 節をまたいで使うのはこれ。値は chaff-corpus の判定済みの指摘で、正しい指摘の範囲より上、誤検知の範囲より下に置いた。
|
|
162
|
+
* 日本語の値は英語の値を MIN_DOCUMENT_LENGTH と同じ比で置き換えた。
|
|
163
|
+
*/
|
|
164
|
+
const READING_SPAN = { word: 4000, char: 10000 };
|
|
165
|
+
|
|
166
|
+
const spreadThin = (occurrences: readonly Occurrence[], positions: ReadonlyMap<Sentence, number>, limit: number, unit: LengthUnit): boolean => {
|
|
167
|
+
const stretch = narrowestStretch(
|
|
168
|
+
occurrences.map((occurrence) => positions.get(occurrence.sentence) ?? 0),
|
|
169
|
+
limit + 1,
|
|
170
|
+
);
|
|
171
|
+
return stretch !== undefined && stretch > READING_SPAN[unit];
|
|
172
|
+
};
|
|
173
|
+
|
|
155
174
|
/**
|
|
156
175
|
* 範囲(gram-passages.ts)ごとに数える。よくある質問の別々の答えは別の範囲。節の最初の文(gram-openers.ts)にだけ出るものは節のひな形。
|
|
157
176
|
* 節の書き出しは書き手の地の文でもあるので、ほかの所にも出れば書き出しのぶんも数える(節ごとの口癖)。
|
|
@@ -166,11 +185,13 @@ const repeatsOf = (doc: ProseDocument, limit: number): Repeat[] => {
|
|
|
166
185
|
const templates = templatesOf(doc);
|
|
167
186
|
const openers = sectionOpeners(doc.sections, doc.source);
|
|
168
187
|
const title = titleOf(doc);
|
|
188
|
+
const positions = sentencePositions(doc.sentences, doc.lengthUnit);
|
|
169
189
|
return gramPassagesOf(doc.sections).flatMap((sentences) =>
|
|
170
190
|
[...gramsOf(context, sentences).entries()].flatMap(([key, all]) => {
|
|
171
191
|
const occurrences = all.filter((occurrence) => !templates.has(occurrence.sentence));
|
|
172
192
|
const opensEverySection = occurrences.every((occurrence) => openers.has(occurrence.sentence));
|
|
173
|
-
|
|
193
|
+
const counted = occurrences.length > limit && isPhrasing(key, doc.lengthUnit) && !namedByHeading(key, title, doc.lengthUnit) && !opensEverySection;
|
|
194
|
+
return counted && !spreadThin(occurrences, positions, limit, doc.lengthUnit) ? [{ key, occurrences }] : [];
|
|
174
195
|
}),
|
|
175
196
|
);
|
|
176
197
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { lengthOf } from "../measure.ts";
|
|
2
|
+
import type { LengthUnit, Sentence } from "../plugin.ts";
|
|
3
|
+
|
|
4
|
+
/** 文の位置: その文より前の文の長さの合計(文書の長さの単位)。表や符号の塊は文ではないので、読む長さに入らない。 */
|
|
5
|
+
export const sentencePositions = (sentences: readonly Sentence[], unit: LengthUnit): ReadonlyMap<Sentence, number> => {
|
|
6
|
+
const positions = new Map<Sentence, number>();
|
|
7
|
+
sentences.reduce((position, sentence) => {
|
|
8
|
+
positions.set(sentence, position);
|
|
9
|
+
return position + lengthOf(sentence, unit);
|
|
10
|
+
}, 0);
|
|
11
|
+
return positions;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** 位置を count 個含む一番短い範囲の長さ。位置が count 個に満たなければ undefined。 */
|
|
15
|
+
export const narrowestStretch = (positions: readonly number[], count: number): number | undefined => {
|
|
16
|
+
if (count < 1 || positions.length < count) return undefined;
|
|
17
|
+
const sorted = positions.toSorted((left, right) => left - right);
|
|
18
|
+
return Math.min(...sorted.slice(count - 1).map((last, index) => last - (sorted[index] ?? last)));
|
|
19
|
+
};
|
|
@@ -84,3 +84,13 @@ export const isTitledPerson = (
|
|
|
84
84
|
(length) => isKnownWordAt(words, piece.end, piece.end + length, knownWords) || isKnownWordAt(words, piece.start - length, piece.start, knownWords),
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
|
+
|
|
88
|
+
/** words の index の語が、連なりの頭でも尻でもない、並べた物の後ろに付く語(高齢運転者等専用駐車区間の「等」)か。語の終わりを見せる。 */
|
|
89
|
+
export const isInnerSuffix = (words: readonly string[], index: number, suffixes: readonly string[]): boolean =>
|
|
90
|
+
index > 0 && index < words.length - 1 && suffixes.includes(words[index] ?? "");
|
|
91
|
+
|
|
92
|
+
/** 連なりの語(words)が、知っている語(known)か中ほどの並べた物の後ろに付く語(suffixes)を含むか。含まなければ、連なりをまるごと数える。 */
|
|
93
|
+
export const holdsKnown = (words: readonly string[], known: readonly string[], suffixes: readonly string[]): boolean => {
|
|
94
|
+
const whole = words.join("");
|
|
95
|
+
return known.some((word) => whole.includes(word)) || words.some((_, index) => isInnerSuffix(words, index, suffixes));
|
|
96
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { BulletList, Detector, DetectorOptions, Finding, ProseDocument, Sentence, Span } from "../plugin.ts";
|
|
1
|
+
import type { BulletList, Detector, DetectorOptions, Finding, LexiconEntry, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
|
|
2
2
|
import { densityFindings } from "./ai-phrasing.ts";
|
|
3
3
|
import { endsWithColon } from "./lead-in.ts";
|
|
4
|
+
import { comparableText, comparableWords, entryIn, entryRanges } from "./lexicon-match.ts";
|
|
4
5
|
import { isMarkdownPath } from "../structure/markdown-path.ts";
|
|
5
6
|
|
|
6
7
|
/** Between a lead-in and its list: only blank space. A thematic break (`***`) separates them; bold marks sit inside the sentence. */
|
|
@@ -108,6 +109,36 @@ const opensWithCode = (source: string, item: Span): boolean => source.slice(item
|
|
|
108
109
|
/** A list whose every item opens with a code span names values, options or members (`omit`: never send …): a parts list, which can stay. */
|
|
109
110
|
const isValueList = (list: BulletList, source: string): boolean => list.itemSpans.length > 1 && list.itemSpans.every((item) => opensWithCode(source, item));
|
|
110
111
|
|
|
112
|
+
/** The language's words of a duty (should, must, なければならない), from the lead-in-duty lexicon. */
|
|
113
|
+
const DUTY_LEXICON = "lead-in-duty";
|
|
114
|
+
|
|
115
|
+
/** A pronoun right after another word opens a clause inside the lead-in (Questions you should ask:, what you must know:). */
|
|
116
|
+
const opensInnerClause = (tokens: readonly Token[], index: number): boolean =>
|
|
117
|
+
tokens[index - 1]?.pos === "PRON" && tokens[index - 2] !== undefined && tokens[index - 2]?.pos !== "PUNCT";
|
|
118
|
+
|
|
119
|
+
/** The duty word as the lead-in's own verb (the lead should:), not inside a clause that names the list (Questions you should ask:). */
|
|
120
|
+
const dutyAsVerb = (sentence: Sentence, entry: LexiconEntry): boolean => {
|
|
121
|
+
const tokens = sentence.tokens;
|
|
122
|
+
if (tokens === undefined || tokens.length === 0) return entryIn(sentence, entry);
|
|
123
|
+
return entryRanges(sentence, entry).some((range) => !opensInnerClause(tokens, range.start));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** The lead-in without its colon and bold marks at the end. */
|
|
127
|
+
const withoutColon = (text: string): string => {
|
|
128
|
+
const chars = Array.from(text);
|
|
129
|
+
return chars.slice(0, chars.findLastIndex((char) => !LABEL_END.test(char)) + 1).join("");
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** The duty at the lead-in's end, where a predicate-final language puts it (行わなければならない:). */
|
|
133
|
+
const closesLeadIn = (sentence: Sentence, entry: LexiconEntry): boolean => withoutColon(comparableText(sentence)).endsWith(comparableWords(entry.pattern));
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A lead-in that states a duty (the lead should:, Each entry must include:) hands over what has to be done or contained:
|
|
137
|
+
* the steps or parts of a procedure, a real list that can stay. A word with position: after counts only at the lead-in's end.
|
|
138
|
+
*/
|
|
139
|
+
const statesDuty = (sentence: Sentence, duties: readonly LexiconEntry[]): boolean =>
|
|
140
|
+
duties.some((entry) => (entry.position === "after" ? closesLeadIn(sentence, entry) : dutyAsVerb(sentence, entry)));
|
|
141
|
+
|
|
111
142
|
/**
|
|
112
143
|
* Prose sentences ending in a colon that hand the reader straight to a list (「以下の通りです:」, "Here's what you need:").
|
|
113
144
|
* An item of a list is not prose: 「例: `code`」 ends in a colon once its code is masked, and it leads nowhere.
|
|
@@ -118,6 +149,7 @@ export const colonLeadIns = (
|
|
|
118
149
|
listSpans: readonly Span[],
|
|
119
150
|
source: string,
|
|
120
151
|
markdown = true,
|
|
152
|
+
duties: readonly LexiconEntry[] = [],
|
|
121
153
|
): Sentence[] => {
|
|
122
154
|
const leadIns = lists.flatMap((list) => {
|
|
123
155
|
if (isValueList(list, source)) return [];
|
|
@@ -126,7 +158,7 @@ export const colonLeadIns = (
|
|
|
126
158
|
});
|
|
127
159
|
const fields = fieldLabels(leadIns);
|
|
128
160
|
const namesItsList = (sentence: Sentence): boolean => (markdown ? isBoldNounLabel(sentence, source) : isPlainNounLabel(sentence, source));
|
|
129
|
-
return leadIns.filter((sentence) => !fields.has(labelWords(sentence.text)) && !namesItsList(sentence));
|
|
161
|
+
return leadIns.filter((sentence) => !fields.has(labelWords(sentence.text)) && !namesItsList(sentence) && !statesDuty(sentence, duties));
|
|
130
162
|
};
|
|
131
163
|
|
|
132
164
|
/** Lead-ins in one or two sections are a how-to's procedure or a pair of lists; the rule's why is section after section. */
|
|
@@ -150,7 +182,8 @@ const sectionsHolding = (doc: ProseDocument, leadIns: readonly Sentence[]): numb
|
|
|
150
182
|
*/
|
|
151
183
|
export const colonLeadIn: Detector = (doc, options): Finding[] => {
|
|
152
184
|
const inDocumentLanguage = doc.sentences.filter((sentence) => sentence.embeddedLanguage === undefined);
|
|
153
|
-
const
|
|
185
|
+
const duties = doc.lexicons[DUTY_LEXICON] ?? [];
|
|
186
|
+
const leadIns = colonLeadIns(inDocumentLanguage, doc.lists, doc.listSpans, doc.source, isMarkdownPath(doc.path), duties);
|
|
154
187
|
if (sectionsHolding(doc, leadIns) < minSections(options)) return [];
|
|
155
188
|
const hits = leadIns.map((sentence) => ({ sentence, matched: sentence.text.trim() }));
|
|
156
189
|
return densityFindings(doc, hits, options.limit);
|