@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.
Files changed (66) hide show
  1. package/dist/browser/package-files.d.ts +6 -0
  2. package/dist/browser/package-files.d.ts.map +1 -0
  3. package/dist/browser/package-files.js +10 -0
  4. package/dist/browser/package-files.js.map +1 -0
  5. package/dist/browser/wink-modules.d.ts +3 -0
  6. package/dist/browser/wink-modules.d.ts.map +1 -0
  7. package/dist/browser/wink-modules.js +7 -0
  8. package/dist/browser/wink-modules.js.map +1 -0
  9. package/dist/dates.d.ts.map +1 -1
  10. package/dist/dates.js +54 -2
  11. package/dist/dates.js.map +1 -1
  12. package/dist/definitions.d.ts.map +1 -1
  13. package/dist/definitions.js +46 -3
  14. package/dist/definitions.js.map +1 -1
  15. package/dist/dictionary.d.ts.map +1 -1
  16. package/dist/dictionary.js +3 -5
  17. package/dist/dictionary.js.map +1 -1
  18. package/dist/gerund.d.ts +7 -0
  19. package/dist/gerund.d.ts.map +1 -0
  20. package/dist/gerund.js +14 -0
  21. package/dist/gerund.js.map +1 -0
  22. package/dist/lexicons.d.ts.map +1 -1
  23. package/dist/lexicons.js +4 -6
  24. package/dist/lexicons.js.map +1 -1
  25. package/dist/package-files.d.ts +7 -0
  26. package/dist/package-files.d.ts.map +1 -0
  27. package/dist/package-files.js +12 -0
  28. package/dist/package-files.js.map +1 -0
  29. package/dist/pos.d.ts.map +1 -1
  30. package/dist/pos.js +5 -5
  31. package/dist/pos.js.map +1 -1
  32. package/dist/wink-modules.d.ts +5 -0
  33. package/dist/wink-modules.d.ts.map +1 -0
  34. package/dist/wink-modules.js +8 -0
  35. package/dist/wink-modules.js.map +1 -0
  36. package/lexicons/breakdown-gap-joiner.yaml +8 -0
  37. package/lexicons/breakdown-phrase.yaml +11 -0
  38. package/lexicons/calendar-name.yaml +22 -0
  39. package/lexicons/company-form.yaml +15 -0
  40. package/lexicons/comparative-baseline.yaml +41 -0
  41. package/lexicons/concrete-deadline.yaml +19 -0
  42. package/lexicons/deadline-permission.yaml +7 -0
  43. package/lexicons/demonstrative-not-opener.yaml +125 -0
  44. package/lexicons/demonstrative-opener.yaml +10 -0
  45. package/lexicons/discount-word.yaml +10 -0
  46. package/lexicons/extra-word.yaml +1 -0
  47. package/lexicons/generic-heading-label.yaml +13 -0
  48. package/lexicons/party-role.yaml +23 -0
  49. package/lexicons/party-short-name.yaml +7 -0
  50. package/lexicons/quote-attribution.yaml +21 -0
  51. package/lexicons/total-phrase.yaml +11 -0
  52. package/lexicons/unit-symbol.yaml +32 -0
  53. package/lexicons/vague-deadline.yaml +16 -0
  54. package/lexicons/year-reference.yaml +52 -0
  55. package/package.json +7 -1
  56. package/src/browser/package-files.ts +15 -0
  57. package/src/browser/wink-modules.ts +9 -0
  58. package/src/browser/wink.d.ts +10 -0
  59. package/src/dates.ts +56 -2
  60. package/src/definitions.ts +54 -3
  61. package/src/dictionary.ts +3 -5
  62. package/src/gerund.ts +15 -0
  63. package/src/lexicons.ts +4 -6
  64. package/src/package-files.ts +16 -0
  65. package/src/pos.ts +5 -6
  66. 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 = join(dirname(fileURLToPath(import.meta.url)), "..", "lexicons");
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
- readdirSync(dir)
33
+ readDir(dir)
36
34
  .filter((file) => file.endsWith(".yaml"))
37
35
  .flatMap((file): [string, Lexicon][] => {
38
- const raw: unknown = parse(readFileSync(join(dir, file), "utf8"));
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
- const require = createRequire(import.meta.url);
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: unknown = require("wink-pos-tagger");
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: { VerbForm: "Ger" } };
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: unknown = createRequire(require.resolve("wink-pos-tagger"))("wink-lexicon/src/lexicon.js");
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");