nl2time 0.1.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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/clock/index.d.ts +40 -0
- package/dist/clock/index.js +99 -0
- package/dist/context.d.ts +48 -0
- package/dist/context.js +75 -0
- package/dist/corpus/runner.d.ts +81 -0
- package/dist/corpus/runner.js +220 -0
- package/dist/data/dayPeriods.d.ts +18 -0
- package/dist/data/dayPeriods.js +24 -0
- package/dist/data/weekData.d.ts +11 -0
- package/dist/data/weekData.js +25 -0
- package/dist/describe/index.d.ts +25 -0
- package/dist/describe/index.js +289 -0
- package/dist/engine/resolve.d.ts +31 -0
- package/dist/engine/resolve.js +684 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/ir/types.d.ts +165 -0
- package/dist/ir/types.js +31 -0
- package/dist/ir/validate.d.ts +11 -0
- package/dist/ir/validate.js +205 -0
- package/dist/llm/index.d.ts +26 -0
- package/dist/llm/index.js +89 -0
- package/dist/parse/en.d.ts +18 -0
- package/dist/parse/en.js +2708 -0
- package/dist/parse/index.d.ts +20 -0
- package/dist/parse/index.js +230 -0
- package/dist/parse/tokenizer.d.ts +33 -0
- package/dist/parse/tokenizer.js +118 -0
- package/package.json +56 -0
- package/schema/timeexpr.schema.json +239 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/AndyFooBlah/nl2time/schema/timeexpr.schema.json",
|
|
4
|
+
"title": "nl2time TimeExpr v1",
|
|
5
|
+
"description": "Language-neutral intermediate representation for temporal expressions. A TimeExpr is a small operator tree over timeline intervals, resolved deterministically against a reference context (now, timeZone, locale, week policy).",
|
|
6
|
+
"$ref": "#/$defs/TimeExpr",
|
|
7
|
+
"$defs": {
|
|
8
|
+
"TimeExpr": {
|
|
9
|
+
"oneOf": [
|
|
10
|
+
{ "$ref": "#/$defs/Now" },
|
|
11
|
+
{ "$ref": "#/$defs/Literal" },
|
|
12
|
+
{ "$ref": "#/$defs/Offset" },
|
|
13
|
+
{ "$ref": "#/$defs/Snap" },
|
|
14
|
+
{ "$ref": "#/$defs/Span" },
|
|
15
|
+
{ "$ref": "#/$defs/Between" },
|
|
16
|
+
{ "$ref": "#/$defs/Seek" },
|
|
17
|
+
{ "$ref": "#/$defs/Intersect" },
|
|
18
|
+
{ "$ref": "#/$defs/Duration" },
|
|
19
|
+
{ "$ref": "#/$defs/Amount" },
|
|
20
|
+
{ "$ref": "#/$defs/Holiday" },
|
|
21
|
+
{ "$ref": "#/$defs/Recur" }
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"Unit": {
|
|
25
|
+
"enum": ["second", "minute", "hour", "day", "week", "month", "quarter", "year"]
|
|
26
|
+
},
|
|
27
|
+
"Weekday": { "enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] },
|
|
28
|
+
"DayPeriod": { "enum": ["morning", "afternoon", "evening", "night"] },
|
|
29
|
+
"Mod": { "enum": ["approx", "start", "mid", "end"] },
|
|
30
|
+
"CalendarAmount": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"description": "Unit-preserving calendar amount; fields may be negative.",
|
|
33
|
+
"properties": {
|
|
34
|
+
"years": { "type": "integer" },
|
|
35
|
+
"months": { "type": "integer" },
|
|
36
|
+
"weeks": { "type": "integer" },
|
|
37
|
+
"days": { "type": "integer" },
|
|
38
|
+
"hours": { "type": "integer" },
|
|
39
|
+
"minutes": { "type": "integer" },
|
|
40
|
+
"seconds": { "type": "integer" }
|
|
41
|
+
},
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"minProperties": 1
|
|
44
|
+
},
|
|
45
|
+
"Target": {
|
|
46
|
+
"oneOf": [
|
|
47
|
+
{
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": { "kind": { "const": "weekday" }, "weekday": { "$ref": "#/$defs/Weekday" } },
|
|
50
|
+
"required": ["kind", "weekday"],
|
|
51
|
+
"additionalProperties": false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"type": "object",
|
|
55
|
+
"properties": { "kind": { "const": "month" }, "month": { "type": "integer", "minimum": 1, "maximum": 12 } },
|
|
56
|
+
"required": ["kind", "month"],
|
|
57
|
+
"additionalProperties": false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "object",
|
|
61
|
+
"properties": { "kind": { "const": "dayPeriod" }, "period": { "$ref": "#/$defs/DayPeriod" } },
|
|
62
|
+
"required": ["kind", "period"],
|
|
63
|
+
"additionalProperties": false
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"type": "object",
|
|
67
|
+
"properties": { "kind": { "const": "unit" }, "unit": { "$ref": "#/$defs/Unit" } },
|
|
68
|
+
"required": ["kind", "unit"],
|
|
69
|
+
"additionalProperties": false
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"Now": {
|
|
74
|
+
"type": "object",
|
|
75
|
+
"description": "The reference instant supplied by the resolution context.",
|
|
76
|
+
"properties": { "op": { "const": "now" }, "mod": { "$ref": "#/$defs/Mod" } },
|
|
77
|
+
"required": ["op"],
|
|
78
|
+
"additionalProperties": false
|
|
79
|
+
},
|
|
80
|
+
"Literal": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"description": "Civil components asserted by the source text. Missing components are completed at resolution time under context policy (bias past/future); a time with meridiem 'unknown' produces AM and PM candidates.",
|
|
83
|
+
"properties": {
|
|
84
|
+
"op": { "const": "literal" },
|
|
85
|
+
"date": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {
|
|
88
|
+
"year": { "type": "integer" },
|
|
89
|
+
"month": { "type": "integer", "minimum": 1, "maximum": 12 },
|
|
90
|
+
"day": { "type": "integer", "minimum": 1, "maximum": 31 }
|
|
91
|
+
},
|
|
92
|
+
"additionalProperties": false
|
|
93
|
+
},
|
|
94
|
+
"time": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {
|
|
97
|
+
"hour": { "type": "integer", "minimum": 0, "maximum": 23 },
|
|
98
|
+
"minute": { "type": "integer", "minimum": 0, "maximum": 59 },
|
|
99
|
+
"second": { "type": "integer", "minimum": 0, "maximum": 59 },
|
|
100
|
+
"meridiem": { "enum": ["am", "pm", "unknown"] }
|
|
101
|
+
},
|
|
102
|
+
"additionalProperties": false
|
|
103
|
+
},
|
|
104
|
+
"dayPeriod": { "$ref": "#/$defs/DayPeriod" },
|
|
105
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
106
|
+
},
|
|
107
|
+
"required": ["op"],
|
|
108
|
+
"additionalProperties": false
|
|
109
|
+
},
|
|
110
|
+
"Offset": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"description": "Calendar offset: offset(now, -1, week) is one week before now. Day-and-coarser offsets preserve wall-clock time across DST transitions.",
|
|
113
|
+
"properties": {
|
|
114
|
+
"op": { "const": "offset" },
|
|
115
|
+
"base": { "$ref": "#/$defs/TimeExpr" },
|
|
116
|
+
"amount": { "type": "integer" },
|
|
117
|
+
"unit": { "$ref": "#/$defs/Unit" },
|
|
118
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
119
|
+
},
|
|
120
|
+
"required": ["op", "base", "amount", "unit"],
|
|
121
|
+
"additionalProperties": false
|
|
122
|
+
},
|
|
123
|
+
"Snap": {
|
|
124
|
+
"type": "object",
|
|
125
|
+
"description": "The containing unit interval of the base ('last week' = snap(offset(now,-1,week), week)). Weeks honor the context week start. edge collapses the interval to its start or end point.",
|
|
126
|
+
"properties": {
|
|
127
|
+
"op": { "const": "snap" },
|
|
128
|
+
"base": { "$ref": "#/$defs/TimeExpr" },
|
|
129
|
+
"unit": { "$ref": "#/$defs/Unit" },
|
|
130
|
+
"edge": { "enum": ["start", "end"] },
|
|
131
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
132
|
+
},
|
|
133
|
+
"required": ["op", "base", "unit"],
|
|
134
|
+
"additionalProperties": false
|
|
135
|
+
},
|
|
136
|
+
"Span": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"description": "Anchored span: span(now, {days:-3}) is the 3 days ending at now ('the last 3 days'). Subject to the context partial-period policy.",
|
|
139
|
+
"properties": {
|
|
140
|
+
"op": { "const": "span" },
|
|
141
|
+
"anchor": { "$ref": "#/$defs/TimeExpr" },
|
|
142
|
+
"amount": { "$ref": "#/$defs/CalendarAmount" },
|
|
143
|
+
"business": { "type": "boolean", "description": "Count weekdays only (business-day spans)." },
|
|
144
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
145
|
+
},
|
|
146
|
+
"required": ["op", "anchor", "amount"],
|
|
147
|
+
"additionalProperties": false
|
|
148
|
+
},
|
|
149
|
+
"Between": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"properties": {
|
|
152
|
+
"op": { "const": "between" },
|
|
153
|
+
"start": { "$ref": "#/$defs/TimeExpr" },
|
|
154
|
+
"end": { "$ref": "#/$defs/TimeExpr" },
|
|
155
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
156
|
+
},
|
|
157
|
+
"required": ["op", "start", "end"],
|
|
158
|
+
"additionalProperties": false
|
|
159
|
+
},
|
|
160
|
+
"Seek": {
|
|
161
|
+
"type": "object",
|
|
162
|
+
"description": "Directed calendar navigation: seek(now, next, weekday tue) is 'next Tuesday' (exact semantics owned by the context nextWeekday policy); with n, the nth occurrence within the base interval ('the 2nd Monday of March').",
|
|
163
|
+
"properties": {
|
|
164
|
+
"op": { "const": "seek" },
|
|
165
|
+
"base": { "$ref": "#/$defs/TimeExpr" },
|
|
166
|
+
"dir": { "enum": ["next", "prev", "nearest"] },
|
|
167
|
+
"target": { "$ref": "#/$defs/Target" },
|
|
168
|
+
"n": { "type": "integer", "minimum": 1 },
|
|
169
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
170
|
+
},
|
|
171
|
+
"required": ["op", "base", "dir", "target"],
|
|
172
|
+
"additionalProperties": false
|
|
173
|
+
},
|
|
174
|
+
"Intersect": {
|
|
175
|
+
"type": "object",
|
|
176
|
+
"description": "Constraint intersection, evaluated left to right with each part anchored to the accumulated interval: 'tomorrow at 4' = intersect(tomorrow, 4 o'clock).",
|
|
177
|
+
"properties": {
|
|
178
|
+
"op": { "const": "intersect" },
|
|
179
|
+
"parts": {
|
|
180
|
+
"type": "array",
|
|
181
|
+
"items": { "$ref": "#/$defs/TimeExpr" },
|
|
182
|
+
"minItems": 2
|
|
183
|
+
},
|
|
184
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
185
|
+
},
|
|
186
|
+
"required": ["op", "parts"],
|
|
187
|
+
"additionalProperties": false
|
|
188
|
+
},
|
|
189
|
+
"Duration": {
|
|
190
|
+
"type": "object",
|
|
191
|
+
"description": "An exact elapsed duration as an ISO-8601 duration string.",
|
|
192
|
+
"properties": {
|
|
193
|
+
"op": { "const": "duration" },
|
|
194
|
+
"iso": { "type": "string", "pattern": "^-?P" },
|
|
195
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
196
|
+
},
|
|
197
|
+
"required": ["op", "iso"],
|
|
198
|
+
"additionalProperties": false
|
|
199
|
+
},
|
|
200
|
+
"Amount": {
|
|
201
|
+
"type": "object",
|
|
202
|
+
"description": "A calendar amount as a value ('2 months').",
|
|
203
|
+
"properties": {
|
|
204
|
+
"op": { "const": "amount" },
|
|
205
|
+
"amount": { "$ref": "#/$defs/CalendarAmount" },
|
|
206
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
207
|
+
},
|
|
208
|
+
"required": ["op", "amount"],
|
|
209
|
+
"additionalProperties": false
|
|
210
|
+
},
|
|
211
|
+
"Holiday": {
|
|
212
|
+
"type": "object",
|
|
213
|
+
"description": "A named holiday resolved by the engine's table (fixed-date, nth-weekday, or computed — Easter). Without a year: candidate occurrences around the reference, ordered by bias; dir forces the strictly previous/next occurrence.",
|
|
214
|
+
"properties": {
|
|
215
|
+
"op": { "const": "holiday" },
|
|
216
|
+
"name": {
|
|
217
|
+
"enum": ["black-friday", "earth-day", "st-patricks", "workers-day", "new-year", "new-year-eve", "valentines", "easter", "halloween", "thanksgiving", "christmas", "christmas-eve", "independence-day", "labor-day", "memorial-day", "mothers-day", "fathers-day"]
|
|
218
|
+
},
|
|
219
|
+
"year": { "type": "integer" },
|
|
220
|
+
"dir": { "enum": ["prev", "next"] },
|
|
221
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
222
|
+
},
|
|
223
|
+
"required": ["op", "name"],
|
|
224
|
+
"additionalProperties": false
|
|
225
|
+
},
|
|
226
|
+
"Recur": {
|
|
227
|
+
"type": "object",
|
|
228
|
+
"description": "Recurrence ('every Tuesday' = recur every week, filter seek weekday tue). Representable and serializable in v1; resolution ships in v2.",
|
|
229
|
+
"properties": {
|
|
230
|
+
"op": { "const": "recur" },
|
|
231
|
+
"every": { "$ref": "#/$defs/Unit" },
|
|
232
|
+
"filter": { "$ref": "#/$defs/TimeExpr" },
|
|
233
|
+
"mod": { "$ref": "#/$defs/Mod" }
|
|
234
|
+
},
|
|
235
|
+
"required": ["op", "every"],
|
|
236
|
+
"additionalProperties": false
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|