nl2time 0.1.0 → 0.3.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.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Language registry: rule sets and merge connectors per BCP-47 language.
3
+ * Unknown languages fall back to English. Adding a language = a rules module
4
+ * (Latin-factory lexicon or bespoke rules for non-Latin scripts) plus its
5
+ * imported corpus + baseline (docs/evals.md, issue #13).
6
+ */
7
+ import { type Rule } from './en.js';
8
+ export interface LanguageDef {
9
+ ruleEntries: readonly {
10
+ name: string;
11
+ rule: Rule;
12
+ }[];
13
+ /** Words transparent between a date part and a time part when merging. */
14
+ connectors: readonly string[];
15
+ }
16
+ export declare function languageDef(language: string): LanguageDef;
17
+ export declare const SUPPORTED_LANGUAGES: string[];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Language registry: rule sets and merge connectors per BCP-47 language.
3
+ * Unknown languages fall back to English. Adding a language = a rules module
4
+ * (Latin-factory lexicon or bespoke rules for non-Latin scripts) plus its
5
+ * imported corpus + baseline (docs/evals.md, issue #13).
6
+ */
7
+ import { EN_RULE_ENTRIES } from './en.js';
8
+ import { ES_CONNECTORS, ES_RULE_ENTRIES } from './es.js';
9
+ import { FR_CONNECTORS, FR_RULE_ENTRIES } from './fr.js';
10
+ import { DE_CONNECTORS, DE_RULE_ENTRIES } from './de.js';
11
+ import { JA_CONNECTORS, JA_RULE_ENTRIES } from './ja.js';
12
+ import { ZH_CONNECTORS, ZH_RULE_ENTRIES } from './zh.js';
13
+ const EN_CONNECTORS = ['at', 'on', 'in', 'of', 'the', 'for', 'from', 'around', 'about', '-'];
14
+ const REGISTRY = {
15
+ en: { ruleEntries: EN_RULE_ENTRIES, connectors: EN_CONNECTORS },
16
+ es: { ruleEntries: ES_RULE_ENTRIES, connectors: ES_CONNECTORS },
17
+ fr: { ruleEntries: FR_RULE_ENTRIES, connectors: FR_CONNECTORS },
18
+ de: { ruleEntries: DE_RULE_ENTRIES, connectors: DE_CONNECTORS },
19
+ ja: { ruleEntries: JA_RULE_ENTRIES, connectors: JA_CONNECTORS },
20
+ zh: { ruleEntries: ZH_RULE_ENTRIES, connectors: ZH_CONNECTORS },
21
+ };
22
+ export function languageDef(language) {
23
+ return REGISTRY[language] ?? REGISTRY['en'];
24
+ }
25
+ export const SUPPORTED_LANGUAGES = Object.keys(REGISTRY);
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Parameterized rule factory for Latin-script languages (Spanish, French,
3
+ * German, …). A LatinLexicon supplies the vocabulary; the factory supplies
4
+ * the grammar patterns these languages share:
5
+ *
6
+ * deictic days hoy / hier / übermorgen
7
+ * rel + unit la semana pasada · nächste Woche · le mois dernier
8
+ * rel + weekday el próximo martes · letzten Montag
9
+ * ago / in hace 3 días · il y a 3 jours · vor 3 Tagen · in 3 Tagen
10
+ * last/next N units los últimos 3 días · les 3 derniers jours
11
+ * month-day dates 15 de marzo de 2026 · 15. März 2026 · le 15 mars
12
+ * day periods por la mañana · le matin · am Abend
13
+ * clock times a las 15:30 · à 15h30 (via extras) · um 15 Uhr
14
+ * weekend el fin de semana · le week-end · das Wochenende
15
+ *
16
+ * Modifier placement is handled on both sides of the noun (Romance languages
17
+ * postpose: "semana pasada"). Language-specific oddities go in `extras`,
18
+ * which run before the factory rules.
19
+ */
20
+ import type { DayPeriod, TimeExpr, Unit, Weekday } from '../ir/types.js';
21
+ import type { Rule } from './en.js';
22
+ export interface LatinLexicon {
23
+ /** Articles / filler tokens skippable inside phrases (el, la, le, der, die…). */
24
+ articles: string[];
25
+ units: Record<string, Unit>;
26
+ weekdays: Record<string, Weekday>;
27
+ months: Record<string, number>;
28
+ /** Day-period nouns. Words also used deictically (Spanish "mañana") must be
29
+ * listed here AND in `deictic`; bare uses read as the deictic. */
30
+ periods: Record<string, DayPeriod>;
31
+ smallNumbers: Record<string, number>;
32
+ /** Single-word deictics: hoy 0, ayer −1, mañana +1, anteayer −2, vorgestern −2… */
33
+ deictic: Record<string, number>;
34
+ /** Multi-word deictics: "pasado mañana" +2. */
35
+ deicticPhrases?: {
36
+ words: string[];
37
+ delta: number;
38
+ }[];
39
+ /** Modifiers before the noun: próximo +1, este 0, letzte −1. */
40
+ preMods: Record<string, -1 | 0 | 1>;
41
+ /** Modifiers after the noun: pasada −1, dernier −1, prochain +1. */
42
+ postMods: Record<string, -1 | 0 | 1>;
43
+ /** Multi-word post-modifiers: "que viene" +1. */
44
+ postModPhrases?: {
45
+ words: string[];
46
+ delta: -1 | 0 | 1;
47
+ }[];
48
+ /** "ago" marker phrases that PRECEDE the amount: hace, il y a, vor. */
49
+ agoPrefixes: string[][];
50
+ /** "in/within" marker phrases: en, dans, in, dentro de. */
51
+ inPrefixes: string[][];
52
+ /** Plural adjectives for "last N units": últimos, derniers, letzten. */
53
+ lastNAdjs: string[];
54
+ /** Plural adjectives for "next N units": próximos, prochains, nächsten. */
55
+ nextNAdjs: string[];
56
+ /** Clock-time lead-ins licensing a bare hour: a las, à, um. */
57
+ atPhrases: string[][];
58
+ /** Period markers before a period noun: por la, de la, am, le. */
59
+ periodMarkers: string[][];
60
+ /** Word(s) linking day-month-year: de ("15 de marzo de 2026"). Empty for German. */
61
+ dateSep: string[];
62
+ /** Weekend noun phrase: fin de semana, week-end, wochenende. */
63
+ weekendPhrases: string[][];
64
+ /** Special single/multi-word datetimes: anoche → yesterday∩night. */
65
+ specialPhrases?: {
66
+ words: string[];
67
+ expr: TimeExpr;
68
+ role?: 'date' | 'time' | 'datetime';
69
+ }[];
70
+ /** noon / midnight words. */
71
+ noonWords?: string[];
72
+ midnightWords?: string[];
73
+ /** "mil" / "mille" / "tausend" for word-number years. */
74
+ thousandWords?: string[];
75
+ /** Range markers: desde/entre/de … hasta/a/y. */
76
+ rangeFrom?: string[][];
77
+ rangeTo?: string[][];
78
+ rangeAnd?: string[];
79
+ /** Duration trigger words: durante, pendant, für. */
80
+ durationTriggers?: string[];
81
+ /** Numeric-date order for numdate tokens (default 'DMY'). */
82
+ dateOrder?: 'DMY' | 'MDY';
83
+ /** Ordinal day words usable as day-of-month: primero 1, premier 1, erste 1. */
84
+ dayOrdinals?: Record<string, number>;
85
+ /** "end of" marker phrases: al final de, à la fin de, am Ende von. */
86
+ endOfMarkers?: string[][];
87
+ /** First/last adjectives for "última semana de julio" style scoped weeks. */
88
+ firstAdjs?: string[];
89
+ lastAdjs?: string[];
90
+ }
91
+ export declare function makeLatinRules(lex: LatinLexicon, extras?: {
92
+ name: string;
93
+ rule: Rule;
94
+ }[]): {
95
+ name: string;
96
+ rule: Rule;
97
+ }[];