@chaffjs/lang-en 0.21.0 → 0.23.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/browser/package-files.d.ts +6 -0
- package/dist/browser/package-files.d.ts.map +1 -0
- package/dist/browser/package-files.js +10 -0
- package/dist/browser/package-files.js.map +1 -0
- package/dist/browser/wink-modules.d.ts +3 -0
- package/dist/browser/wink-modules.d.ts.map +1 -0
- package/dist/browser/wink-modules.js +7 -0
- package/dist/browser/wink-modules.js.map +1 -0
- package/dist/dates.d.ts.map +1 -1
- package/dist/dates.js +54 -2
- package/dist/dates.js.map +1 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +46 -3
- package/dist/definitions.js.map +1 -1
- package/dist/dictionary.d.ts.map +1 -1
- package/dist/dictionary.js +3 -5
- package/dist/dictionary.js.map +1 -1
- package/dist/gerund.d.ts +7 -0
- package/dist/gerund.d.ts.map +1 -0
- package/dist/gerund.js +14 -0
- package/dist/gerund.js.map +1 -0
- package/dist/lexicons.d.ts.map +1 -1
- package/dist/lexicons.js +4 -6
- package/dist/lexicons.js.map +1 -1
- package/dist/package-files.d.ts +7 -0
- package/dist/package-files.d.ts.map +1 -0
- package/dist/package-files.js +12 -0
- package/dist/package-files.js.map +1 -0
- package/dist/pos.d.ts.map +1 -1
- package/dist/pos.js +5 -5
- package/dist/pos.js.map +1 -1
- package/dist/wink-modules.d.ts +5 -0
- package/dist/wink-modules.d.ts.map +1 -0
- package/dist/wink-modules.js +8 -0
- package/dist/wink-modules.js.map +1 -0
- package/lexicons/breakdown-gap-joiner.yaml +8 -0
- package/lexicons/breakdown-phrase.yaml +11 -0
- package/lexicons/calendar-name.yaml +22 -0
- package/lexicons/company-form.yaml +15 -0
- package/lexicons/comparative-baseline.yaml +41 -0
- package/lexicons/concrete-deadline.yaml +19 -0
- package/lexicons/deadline-permission.yaml +7 -0
- package/lexicons/demonstrative-not-opener.yaml +125 -0
- package/lexicons/demonstrative-opener.yaml +10 -0
- package/lexicons/discount-word.yaml +10 -0
- package/lexicons/extra-word.yaml +1 -0
- package/lexicons/generic-heading-label.yaml +13 -0
- package/lexicons/party-role.yaml +23 -0
- package/lexicons/party-short-name.yaml +7 -0
- package/lexicons/quote-attribution.yaml +21 -0
- package/lexicons/total-phrase.yaml +11 -0
- package/lexicons/unit-symbol.yaml +32 -0
- package/lexicons/vague-deadline.yaml +16 -0
- package/lexicons/year-reference.yaml +52 -0
- package/package.json +7 -1
- package/src/browser/package-files.ts +15 -0
- package/src/browser/wink-modules.ts +9 -0
- package/src/browser/wink.d.ts +10 -0
- package/src/dates.ts +56 -2
- package/src/definitions.ts +54 -3
- package/src/dictionary.ts +3 -5
- package/src/gerund.ts +15 -0
- package/src/lexicons.ts +4 -6
- package/src/package-files.ts +16 -0
- package/src/pos.ts +5 -6
- package/src/wink-modules.ts +11 -0
package/src/lexicons.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
1
|
import { parse } from "yaml";
|
|
5
2
|
import type { Lexicon, LexiconEntry } from "chaffjs/plugin";
|
|
3
|
+
import { PACKAGE_DIR, joinPath, readDir, readText } from "./package-files.ts";
|
|
6
4
|
|
|
7
|
-
const DIR =
|
|
5
|
+
const DIR = joinPath(PACKAGE_DIR, "lexicons");
|
|
8
6
|
|
|
9
7
|
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
8
|
|
|
@@ -32,10 +30,10 @@ const toEntry = (raw: unknown): LexiconEntry | undefined => {
|
|
|
32
30
|
*/
|
|
33
31
|
export const loadLexicons = (dir: string = DIR): Record<string, Lexicon> =>
|
|
34
32
|
Object.fromEntries(
|
|
35
|
-
|
|
33
|
+
readDir(dir)
|
|
36
34
|
.filter((file) => file.endsWith(".yaml"))
|
|
37
35
|
.flatMap((file): [string, Lexicon][] => {
|
|
38
|
-
const raw: unknown = parse(
|
|
36
|
+
const raw: unknown = parse(readText(joinPath(dir, file)));
|
|
39
37
|
if (!isRecord(raw) || typeof raw["id"] !== "string" || !Array.isArray(raw["entries"])) return [];
|
|
40
38
|
return [[raw["id"], raw["entries"].map(toEntry).filter((entry) => entry !== undefined)]];
|
|
41
39
|
}),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// Every read of a file this package ships (lexicons, the word list) goes through here, so a build without a file
|
|
6
|
+
// system can put its own reads in this module's place.
|
|
7
|
+
|
|
8
|
+
/** The package's folder: src/ and dist/ both sit right under it. */
|
|
9
|
+
export const PACKAGE_DIR = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
|
|
11
|
+
/** node:path join, for the paths read here. */
|
|
12
|
+
export const joinPath = (...parts: readonly string[]): string => join(...parts);
|
|
13
|
+
|
|
14
|
+
export const readText = (path: string): string => readFileSync(path, "utf8");
|
|
15
|
+
|
|
16
|
+
export const readDir = (path: string): string[] => readdirSync(path);
|
package/src/pos.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import type { Token } from "chaffjs/plugin";
|
|
3
2
|
import { straightApostrophes } from "./apostrophe.ts";
|
|
4
3
|
import { loadLexicons } from "./lexicons.ts";
|
|
@@ -6,8 +5,8 @@ import { blankLongRuns } from "./long-runs.ts";
|
|
|
6
5
|
import { lowercasedAt, properNounChecked, rereadAt, sentenceInitialCommonWord } from "./proper-noun.ts";
|
|
7
6
|
import { isStativeParticiple, stativeVocabulary } from "./stative-participle.ts";
|
|
8
7
|
import { isEmphasisedAdverb } from "./emphasis.ts";
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { gerundFeatures } from "./gerund.ts";
|
|
9
|
+
import { winkLexiconWords, winkPosTagger } from "./wink-modules.ts";
|
|
11
10
|
|
|
12
11
|
/** wink は CommonJS で、辞書を同期に持つ。初期化は 130 ms ほど。 */
|
|
13
12
|
type Tagged = { readonly value: string; readonly pos: string; readonly lemma?: string };
|
|
@@ -30,7 +29,7 @@ const callMethod = (owner: Record<string, unknown>, name: string, args: readonly
|
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
const build = (): Tagger => {
|
|
33
|
-
const factory
|
|
32
|
+
const factory = winkPosTagger();
|
|
34
33
|
if (!isCallable(factory)) throw new Error("wink-pos-tagger が関数を export していません");
|
|
35
34
|
const tagger: unknown = factory();
|
|
36
35
|
if (!isRecord(tagger)) throw new Error("wink-pos-tagger が object を返しませんでした");
|
|
@@ -206,7 +205,7 @@ const withOtherReading = (entry: Tagged, found: Features): Features => {
|
|
|
206
205
|
const featuresOf = (tagged: readonly Tagged[], at: number): Features => {
|
|
207
206
|
const entry = tagged[at];
|
|
208
207
|
if (entry === undefined) return {};
|
|
209
|
-
if (entry.pos === "VBG") return { features:
|
|
208
|
+
if (entry.pos === "VBG") return { features: gerundFeatures(entry.value, state.vocabulary) };
|
|
210
209
|
if (entry.pos !== "VBN") return withOtherReading(entry, nounOrDeterminerFeatures(entry));
|
|
211
210
|
return { features: isPassive(tagged, at) ? { VerbForm: "Part", Voice: "Pass" } : { VerbForm: "Part" } };
|
|
212
211
|
};
|
|
@@ -217,7 +216,7 @@ type Vocabulary = (word: string) => readonly string[] | undefined;
|
|
|
217
216
|
const isTags = (value: unknown): value is readonly string[] => Array.isArray(value) && value.every((tag) => typeof tag === "string");
|
|
218
217
|
|
|
219
218
|
const buildVocabulary = (): Vocabulary => {
|
|
220
|
-
const words
|
|
219
|
+
const words = winkLexiconWords();
|
|
221
220
|
if (!isRecord(words)) throw new Error("wink-lexicon の語彙が object ではありません");
|
|
222
221
|
return (word) => {
|
|
223
222
|
const tags = Object.hasOwn(words, word) ? words[word] : undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
// Where the wink tagger and its vocabulary come from. A build without a file system puts its own module in this one's place.
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
/** wink is CommonJS and holds its dictionary synchronously: from ESM it is taken with createRequire. */
|
|
8
|
+
export const winkPosTagger = (): unknown => require("wink-pos-tagger");
|
|
9
|
+
|
|
10
|
+
/** The vocabulary the tagger reads (word → Penn Treebank tags): the one wink-pos-tagger loads from its own dependency. */
|
|
11
|
+
export const winkLexiconWords = (): unknown => createRequire(require.resolve("wink-pos-tagger"))("wink-lexicon/src/lexicon.js");
|