@chaffjs/lang-en 0.22.0 → 0.24.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 (67) 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 +42 -2
  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/lexicons.d.ts.map +1 -1
  19. package/dist/lexicons.js +4 -6
  20. package/dist/lexicons.js.map +1 -1
  21. package/dist/package-files.d.ts +7 -0
  22. package/dist/package-files.d.ts.map +1 -0
  23. package/dist/package-files.js +12 -0
  24. package/dist/package-files.js.map +1 -0
  25. package/dist/pos.d.ts.map +1 -1
  26. package/dist/pos.js +3 -4
  27. package/dist/pos.js.map +1 -1
  28. package/dist/wink-modules.d.ts +5 -0
  29. package/dist/wink-modules.d.ts.map +1 -0
  30. package/dist/wink-modules.js +8 -0
  31. package/dist/wink-modules.js.map +1 -0
  32. package/lexicons/article-sound.yaml +7 -1
  33. package/lexicons/breakdown-gap-joiner.yaml +8 -0
  34. package/lexicons/breakdown-phrase.yaml +11 -0
  35. package/lexicons/change-base.yaml +9 -0
  36. package/lexicons/change-direction-not.yaml +5 -0
  37. package/lexicons/change-direction.yaml +27 -0
  38. package/lexicons/change-target.yaml +6 -0
  39. package/lexicons/company-form.yaml +15 -0
  40. package/lexicons/concrete-deadline.yaml +19 -0
  41. package/lexicons/deadline-permission.yaml +7 -0
  42. package/lexicons/demonstrative-not-opener.yaml +125 -0
  43. package/lexicons/demonstrative-opener.yaml +10 -0
  44. package/lexicons/discount-word.yaml +10 -0
  45. package/lexicons/message-date-field.yaml +8 -0
  46. package/lexicons/party-role.yaml +23 -0
  47. package/lexicons/party-short-name.yaml +7 -0
  48. package/lexicons/quote-attribution.yaml +21 -0
  49. package/lexicons/relative-day.yaml +7 -0
  50. package/lexicons/relative-week.yaml +8 -0
  51. package/lexicons/share-label.yaml +7 -0
  52. package/lexicons/total-phrase.yaml +11 -0
  53. package/lexicons/vague-deadline.yaml +16 -0
  54. package/lexicons/version-lead.yaml +14 -0
  55. package/lexicons/version-range.yaml +20 -0
  56. package/lexicons/year-reference.yaml +52 -0
  57. package/package.json +7 -1
  58. package/src/browser/package-files.ts +15 -0
  59. package/src/browser/wink-modules.ts +9 -0
  60. package/src/browser/wink.d.ts +10 -0
  61. package/src/dates.ts +56 -2
  62. package/src/definitions.ts +49 -2
  63. package/src/dictionary.ts +3 -5
  64. package/src/lexicons.ts +4 -6
  65. package/src/package-files.ts +16 -0
  66. package/src/pos.ts +3 -5
  67. package/src/wink-modules.ts +11 -0
@@ -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";
@@ -7,8 +6,7 @@ import { lowercasedAt, properNounChecked, rereadAt, sentenceInitialCommonWord }
7
6
  import { isStativeParticiple, stativeVocabulary } from "./stative-participle.ts";
8
7
  import { isEmphasisedAdverb } from "./emphasis.ts";
9
8
  import { gerundFeatures } from "./gerund.ts";
10
-
11
- const require = createRequire(import.meta.url);
9
+ import { winkLexiconWords, winkPosTagger } from "./wink-modules.ts";
12
10
 
13
11
  /** wink は CommonJS で、辞書を同期に持つ。初期化は 130 ms ほど。 */
14
12
  type Tagged = { readonly value: string; readonly pos: string; readonly lemma?: string };
@@ -31,7 +29,7 @@ const callMethod = (owner: Record<string, unknown>, name: string, args: readonly
31
29
  };
32
30
 
33
31
  const build = (): Tagger => {
34
- const factory: unknown = require("wink-pos-tagger");
32
+ const factory = winkPosTagger();
35
33
  if (!isCallable(factory)) throw new Error("wink-pos-tagger が関数を export していません");
36
34
  const tagger: unknown = factory();
37
35
  if (!isRecord(tagger)) throw new Error("wink-pos-tagger が object を返しませんでした");
@@ -218,7 +216,7 @@ type Vocabulary = (word: string) => readonly string[] | undefined;
218
216
  const isTags = (value: unknown): value is readonly string[] => Array.isArray(value) && value.every((tag) => typeof tag === "string");
219
217
 
220
218
  const buildVocabulary = (): Vocabulary => {
221
- const words: unknown = createRequire(require.resolve("wink-pos-tagger"))("wink-lexicon/src/lexicon.js");
219
+ const words = winkLexiconWords();
222
220
  if (!isRecord(words)) throw new Error("wink-lexicon の語彙が object ではありません");
223
221
  return (word) => {
224
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");