duckling 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Rakefile +6 -1
- data/ext/duckling/Cargo.lock +619 -0
- data/ext/duckling/Cargo.toml +13 -0
- data/ext/duckling/extconf.rb +4 -0
- data/ext/duckling/src/lib.rs +284 -0
- data/lib/duckling/version.rb +1 -1
- data/lib/duckling.rb +1 -5
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe25d8f066c9db7ff9bbb809ec0f378a25914f525d05bc5fbeba8a78e345efb1
|
|
4
|
+
data.tar.gz: ddf3d1b812d73ef13c9bf283829e140664ad00d4f45fb3727a25605975b5d2ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 724a9586cb00a77029d7f88f97105d0f3b8cb2722d38998f7661e6ce4966f2d2e9f1d4d52fdb2f3a9a119dfcd27c8ce8755d24752e9190133193bdb52bcf1429
|
|
7
|
+
data.tar.gz: 8b504420c796318a30e4bda52620ce537e26b2fd78c4dd93c92f1357552647e3881e27f7e57063ac97fc0ca10c09a0caf36d366b8c70b668541be89c83f4e57a
|
data/CHANGELOG.md
CHANGED
|
@@ -5,3 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.2] - 2026-07-01
|
|
10
|
+
|
|
11
|
+
## What's Changed
|
|
12
|
+
* Retry release pipeline as 0.1.2 by @cpb in https://github.com/cpb/duckling/pull/7
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
**Full Changelog**: https://github.com/cpb/duckling/compare/v0.1.1...v0.1.2
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [0.1.1] - 2026-07-01
|
|
19
|
+
|
|
20
|
+
## What's Changed
|
|
21
|
+
* Automate gem release: tag-triggered publish to RubyGems by @cpb in https://github.com/cpb/duckling/pull/5
|
|
22
|
+
|
|
23
|
+
## New Contributors
|
|
24
|
+
* @cpb made their first contribution in https://github.com/cpb/duckling/pull/5
|
|
25
|
+
|
|
26
|
+
**Full Changelog**: https://github.com/cpb/duckling/compare/v0.1.0...v0.1.1
|
data/Rakefile
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
4
|
require "minitest/test_task"
|
|
5
|
+
require "rake/extensiontask"
|
|
6
|
+
|
|
7
|
+
Rake::ExtensionTask.new("duckling") do |ext|
|
|
8
|
+
ext.lib_dir = "lib/duckling"
|
|
9
|
+
end
|
|
5
10
|
|
|
6
11
|
Minitest::TestTask.create
|
|
7
12
|
|
|
8
13
|
require "standard/rake"
|
|
9
14
|
|
|
10
|
-
task default: %i[test
|
|
15
|
+
task default: %i[standard compile test]
|
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "aho-corasick"
|
|
7
|
+
version = "1.1.4"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"memchr",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "android_system_properties"
|
|
16
|
+
version = "0.1.5"
|
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
+
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"libc",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "autocfg"
|
|
25
|
+
version = "1.5.1"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "bindgen"
|
|
31
|
+
version = "0.72.1"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"bitflags",
|
|
36
|
+
"cexpr",
|
|
37
|
+
"clang-sys",
|
|
38
|
+
"itertools",
|
|
39
|
+
"proc-macro2",
|
|
40
|
+
"quote",
|
|
41
|
+
"regex",
|
|
42
|
+
"rustc-hash",
|
|
43
|
+
"shlex 1.3.0",
|
|
44
|
+
"syn",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[[package]]
|
|
48
|
+
name = "bitflags"
|
|
49
|
+
version = "2.13.0"
|
|
50
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
51
|
+
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
|
|
52
|
+
|
|
53
|
+
[[package]]
|
|
54
|
+
name = "bumpalo"
|
|
55
|
+
version = "3.20.3"
|
|
56
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
58
|
+
|
|
59
|
+
[[package]]
|
|
60
|
+
name = "cc"
|
|
61
|
+
version = "1.2.65"
|
|
62
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
63
|
+
checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96"
|
|
64
|
+
dependencies = [
|
|
65
|
+
"find-msvc-tools",
|
|
66
|
+
"shlex 2.0.1",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[[package]]
|
|
70
|
+
name = "cexpr"
|
|
71
|
+
version = "0.6.0"
|
|
72
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
73
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
74
|
+
dependencies = [
|
|
75
|
+
"nom",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[[package]]
|
|
79
|
+
name = "cfg-if"
|
|
80
|
+
version = "1.0.4"
|
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
82
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "chrono"
|
|
86
|
+
version = "0.4.45"
|
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
+
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
|
89
|
+
dependencies = [
|
|
90
|
+
"iana-time-zone",
|
|
91
|
+
"js-sys",
|
|
92
|
+
"num-traits",
|
|
93
|
+
"serde",
|
|
94
|
+
"wasm-bindgen",
|
|
95
|
+
"windows-link",
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
[[package]]
|
|
99
|
+
name = "clang-sys"
|
|
100
|
+
version = "1.8.1"
|
|
101
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
102
|
+
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
|
103
|
+
dependencies = [
|
|
104
|
+
"glob",
|
|
105
|
+
"libc",
|
|
106
|
+
"libloading",
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
[[package]]
|
|
110
|
+
name = "core-foundation-sys"
|
|
111
|
+
version = "0.8.7"
|
|
112
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
113
|
+
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
|
114
|
+
|
|
115
|
+
[[package]]
|
|
116
|
+
name = "duckling"
|
|
117
|
+
version = "0.1.0"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"chrono",
|
|
120
|
+
"duckling 0.4.0",
|
|
121
|
+
"magnus",
|
|
122
|
+
"rb-sys",
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
[[package]]
|
|
126
|
+
name = "duckling"
|
|
127
|
+
version = "0.4.0"
|
|
128
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
129
|
+
checksum = "978b87ce9afe88369d26490f008bfd942676e15309c60830480a16863cb98430"
|
|
130
|
+
dependencies = [
|
|
131
|
+
"chrono",
|
|
132
|
+
"log",
|
|
133
|
+
"once_cell",
|
|
134
|
+
"regex",
|
|
135
|
+
"serde",
|
|
136
|
+
"serde_json",
|
|
137
|
+
"smallvec",
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
[[package]]
|
|
141
|
+
name = "either"
|
|
142
|
+
version = "1.16.0"
|
|
143
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
144
|
+
checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
|
|
145
|
+
|
|
146
|
+
[[package]]
|
|
147
|
+
name = "find-msvc-tools"
|
|
148
|
+
version = "0.1.9"
|
|
149
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
150
|
+
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
|
151
|
+
|
|
152
|
+
[[package]]
|
|
153
|
+
name = "futures-core"
|
|
154
|
+
version = "0.3.32"
|
|
155
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
156
|
+
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
|
157
|
+
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "futures-task"
|
|
160
|
+
version = "0.3.32"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
|
163
|
+
|
|
164
|
+
[[package]]
|
|
165
|
+
name = "futures-util"
|
|
166
|
+
version = "0.3.32"
|
|
167
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
168
|
+
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
|
169
|
+
dependencies = [
|
|
170
|
+
"futures-core",
|
|
171
|
+
"futures-task",
|
|
172
|
+
"pin-project-lite",
|
|
173
|
+
"slab",
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
[[package]]
|
|
177
|
+
name = "glob"
|
|
178
|
+
version = "0.3.3"
|
|
179
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
180
|
+
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
|
181
|
+
|
|
182
|
+
[[package]]
|
|
183
|
+
name = "iana-time-zone"
|
|
184
|
+
version = "0.1.65"
|
|
185
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
186
|
+
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
|
|
187
|
+
dependencies = [
|
|
188
|
+
"android_system_properties",
|
|
189
|
+
"core-foundation-sys",
|
|
190
|
+
"iana-time-zone-haiku",
|
|
191
|
+
"js-sys",
|
|
192
|
+
"log",
|
|
193
|
+
"wasm-bindgen",
|
|
194
|
+
"windows-core",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
[[package]]
|
|
198
|
+
name = "iana-time-zone-haiku"
|
|
199
|
+
version = "0.1.2"
|
|
200
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
201
|
+
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
|
202
|
+
dependencies = [
|
|
203
|
+
"cc",
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
[[package]]
|
|
207
|
+
name = "itertools"
|
|
208
|
+
version = "0.13.0"
|
|
209
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
210
|
+
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
|
211
|
+
dependencies = [
|
|
212
|
+
"either",
|
|
213
|
+
]
|
|
214
|
+
|
|
215
|
+
[[package]]
|
|
216
|
+
name = "itoa"
|
|
217
|
+
version = "1.0.18"
|
|
218
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
219
|
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|
220
|
+
|
|
221
|
+
[[package]]
|
|
222
|
+
name = "js-sys"
|
|
223
|
+
version = "0.3.103"
|
|
224
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
+
checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102"
|
|
226
|
+
dependencies = [
|
|
227
|
+
"cfg-if",
|
|
228
|
+
"futures-util",
|
|
229
|
+
"wasm-bindgen",
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "lazy_static"
|
|
234
|
+
version = "1.5.0"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|
237
|
+
|
|
238
|
+
[[package]]
|
|
239
|
+
name = "libc"
|
|
240
|
+
version = "0.2.186"
|
|
241
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
242
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
243
|
+
|
|
244
|
+
[[package]]
|
|
245
|
+
name = "libloading"
|
|
246
|
+
version = "0.8.9"
|
|
247
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
248
|
+
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
249
|
+
dependencies = [
|
|
250
|
+
"cfg-if",
|
|
251
|
+
"windows-link",
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
[[package]]
|
|
255
|
+
name = "log"
|
|
256
|
+
version = "0.4.33"
|
|
257
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
258
|
+
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
|
259
|
+
|
|
260
|
+
[[package]]
|
|
261
|
+
name = "magnus"
|
|
262
|
+
version = "0.8.2"
|
|
263
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
264
|
+
checksum = "3b36a5b126bbe97eb0d02d07acfeb327036c6319fd816139a49824a83b7f9012"
|
|
265
|
+
dependencies = [
|
|
266
|
+
"magnus-macros",
|
|
267
|
+
"rb-sys",
|
|
268
|
+
"rb-sys-env",
|
|
269
|
+
"seq-macro",
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
[[package]]
|
|
273
|
+
name = "magnus-macros"
|
|
274
|
+
version = "0.8.0"
|
|
275
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
276
|
+
checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
|
|
277
|
+
dependencies = [
|
|
278
|
+
"proc-macro2",
|
|
279
|
+
"quote",
|
|
280
|
+
"syn",
|
|
281
|
+
]
|
|
282
|
+
|
|
283
|
+
[[package]]
|
|
284
|
+
name = "memchr"
|
|
285
|
+
version = "2.8.2"
|
|
286
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
287
|
+
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
|
|
288
|
+
|
|
289
|
+
[[package]]
|
|
290
|
+
name = "minimal-lexical"
|
|
291
|
+
version = "0.2.1"
|
|
292
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
293
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
294
|
+
|
|
295
|
+
[[package]]
|
|
296
|
+
name = "nom"
|
|
297
|
+
version = "7.1.3"
|
|
298
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
299
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
|
300
|
+
dependencies = [
|
|
301
|
+
"memchr",
|
|
302
|
+
"minimal-lexical",
|
|
303
|
+
]
|
|
304
|
+
|
|
305
|
+
[[package]]
|
|
306
|
+
name = "num-traits"
|
|
307
|
+
version = "0.2.19"
|
|
308
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
309
|
+
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
310
|
+
dependencies = [
|
|
311
|
+
"autocfg",
|
|
312
|
+
]
|
|
313
|
+
|
|
314
|
+
[[package]]
|
|
315
|
+
name = "once_cell"
|
|
316
|
+
version = "1.21.4"
|
|
317
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
318
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
319
|
+
|
|
320
|
+
[[package]]
|
|
321
|
+
name = "pin-project-lite"
|
|
322
|
+
version = "0.2.17"
|
|
323
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
324
|
+
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
|
325
|
+
|
|
326
|
+
[[package]]
|
|
327
|
+
name = "proc-macro2"
|
|
328
|
+
version = "1.0.106"
|
|
329
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
330
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
331
|
+
dependencies = [
|
|
332
|
+
"unicode-ident",
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
[[package]]
|
|
336
|
+
name = "quote"
|
|
337
|
+
version = "1.0.46"
|
|
338
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
339
|
+
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
|
340
|
+
dependencies = [
|
|
341
|
+
"proc-macro2",
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
[[package]]
|
|
345
|
+
name = "rb-sys"
|
|
346
|
+
version = "0.9.128"
|
|
347
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
348
|
+
checksum = "45ca28513560e56cfb79a62b1fce363c73af170a182024ce880c77ee9429920a"
|
|
349
|
+
dependencies = [
|
|
350
|
+
"rb-sys-build",
|
|
351
|
+
]
|
|
352
|
+
|
|
353
|
+
[[package]]
|
|
354
|
+
name = "rb-sys-build"
|
|
355
|
+
version = "0.9.128"
|
|
356
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
357
|
+
checksum = "ce04b2c55eff3a21aaa623fcc655d94373238e72cac6b3e1a3641ff31649f99a"
|
|
358
|
+
dependencies = [
|
|
359
|
+
"bindgen",
|
|
360
|
+
"lazy_static",
|
|
361
|
+
"proc-macro2",
|
|
362
|
+
"quote",
|
|
363
|
+
"regex",
|
|
364
|
+
"shell-words",
|
|
365
|
+
"syn",
|
|
366
|
+
]
|
|
367
|
+
|
|
368
|
+
[[package]]
|
|
369
|
+
name = "rb-sys-env"
|
|
370
|
+
version = "0.2.3"
|
|
371
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
372
|
+
checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
|
|
373
|
+
|
|
374
|
+
[[package]]
|
|
375
|
+
name = "regex"
|
|
376
|
+
version = "1.12.4"
|
|
377
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
378
|
+
checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba"
|
|
379
|
+
dependencies = [
|
|
380
|
+
"aho-corasick",
|
|
381
|
+
"memchr",
|
|
382
|
+
"regex-automata",
|
|
383
|
+
"regex-syntax",
|
|
384
|
+
]
|
|
385
|
+
|
|
386
|
+
[[package]]
|
|
387
|
+
name = "regex-automata"
|
|
388
|
+
version = "0.4.14"
|
|
389
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
390
|
+
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
|
391
|
+
dependencies = [
|
|
392
|
+
"aho-corasick",
|
|
393
|
+
"memchr",
|
|
394
|
+
"regex-syntax",
|
|
395
|
+
]
|
|
396
|
+
|
|
397
|
+
[[package]]
|
|
398
|
+
name = "regex-syntax"
|
|
399
|
+
version = "0.8.11"
|
|
400
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
401
|
+
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
|
402
|
+
|
|
403
|
+
[[package]]
|
|
404
|
+
name = "rustc-hash"
|
|
405
|
+
version = "2.1.2"
|
|
406
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
407
|
+
checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"
|
|
408
|
+
|
|
409
|
+
[[package]]
|
|
410
|
+
name = "rustversion"
|
|
411
|
+
version = "1.0.22"
|
|
412
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
413
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
414
|
+
|
|
415
|
+
[[package]]
|
|
416
|
+
name = "seq-macro"
|
|
417
|
+
version = "0.3.6"
|
|
418
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
419
|
+
checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
|
|
420
|
+
|
|
421
|
+
[[package]]
|
|
422
|
+
name = "serde"
|
|
423
|
+
version = "1.0.228"
|
|
424
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
425
|
+
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
|
426
|
+
dependencies = [
|
|
427
|
+
"serde_core",
|
|
428
|
+
"serde_derive",
|
|
429
|
+
]
|
|
430
|
+
|
|
431
|
+
[[package]]
|
|
432
|
+
name = "serde_core"
|
|
433
|
+
version = "1.0.228"
|
|
434
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
435
|
+
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
436
|
+
dependencies = [
|
|
437
|
+
"serde_derive",
|
|
438
|
+
]
|
|
439
|
+
|
|
440
|
+
[[package]]
|
|
441
|
+
name = "serde_derive"
|
|
442
|
+
version = "1.0.228"
|
|
443
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
444
|
+
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|
445
|
+
dependencies = [
|
|
446
|
+
"proc-macro2",
|
|
447
|
+
"quote",
|
|
448
|
+
"syn",
|
|
449
|
+
]
|
|
450
|
+
|
|
451
|
+
[[package]]
|
|
452
|
+
name = "serde_json"
|
|
453
|
+
version = "1.0.150"
|
|
454
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
455
|
+
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
|
456
|
+
dependencies = [
|
|
457
|
+
"itoa",
|
|
458
|
+
"memchr",
|
|
459
|
+
"serde",
|
|
460
|
+
"serde_core",
|
|
461
|
+
"zmij",
|
|
462
|
+
]
|
|
463
|
+
|
|
464
|
+
[[package]]
|
|
465
|
+
name = "shell-words"
|
|
466
|
+
version = "1.1.1"
|
|
467
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
468
|
+
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
|
|
469
|
+
|
|
470
|
+
[[package]]
|
|
471
|
+
name = "shlex"
|
|
472
|
+
version = "1.3.0"
|
|
473
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
474
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
475
|
+
|
|
476
|
+
[[package]]
|
|
477
|
+
name = "shlex"
|
|
478
|
+
version = "2.0.1"
|
|
479
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
480
|
+
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
481
|
+
|
|
482
|
+
[[package]]
|
|
483
|
+
name = "slab"
|
|
484
|
+
version = "0.4.12"
|
|
485
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
486
|
+
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
|
487
|
+
|
|
488
|
+
[[package]]
|
|
489
|
+
name = "smallvec"
|
|
490
|
+
version = "1.15.2"
|
|
491
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
492
|
+
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
|
493
|
+
|
|
494
|
+
[[package]]
|
|
495
|
+
name = "syn"
|
|
496
|
+
version = "2.0.118"
|
|
497
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
498
|
+
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
|
499
|
+
dependencies = [
|
|
500
|
+
"proc-macro2",
|
|
501
|
+
"quote",
|
|
502
|
+
"unicode-ident",
|
|
503
|
+
]
|
|
504
|
+
|
|
505
|
+
[[package]]
|
|
506
|
+
name = "unicode-ident"
|
|
507
|
+
version = "1.0.24"
|
|
508
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
509
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
510
|
+
|
|
511
|
+
[[package]]
|
|
512
|
+
name = "wasm-bindgen"
|
|
513
|
+
version = "0.2.126"
|
|
514
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
515
|
+
checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4"
|
|
516
|
+
dependencies = [
|
|
517
|
+
"cfg-if",
|
|
518
|
+
"once_cell",
|
|
519
|
+
"rustversion",
|
|
520
|
+
"wasm-bindgen-macro",
|
|
521
|
+
"wasm-bindgen-shared",
|
|
522
|
+
]
|
|
523
|
+
|
|
524
|
+
[[package]]
|
|
525
|
+
name = "wasm-bindgen-macro"
|
|
526
|
+
version = "0.2.126"
|
|
527
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
528
|
+
checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1"
|
|
529
|
+
dependencies = [
|
|
530
|
+
"quote",
|
|
531
|
+
"wasm-bindgen-macro-support",
|
|
532
|
+
]
|
|
533
|
+
|
|
534
|
+
[[package]]
|
|
535
|
+
name = "wasm-bindgen-macro-support"
|
|
536
|
+
version = "0.2.126"
|
|
537
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
538
|
+
checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e"
|
|
539
|
+
dependencies = [
|
|
540
|
+
"bumpalo",
|
|
541
|
+
"proc-macro2",
|
|
542
|
+
"quote",
|
|
543
|
+
"syn",
|
|
544
|
+
"wasm-bindgen-shared",
|
|
545
|
+
]
|
|
546
|
+
|
|
547
|
+
[[package]]
|
|
548
|
+
name = "wasm-bindgen-shared"
|
|
549
|
+
version = "0.2.126"
|
|
550
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
551
|
+
checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24"
|
|
552
|
+
dependencies = [
|
|
553
|
+
"unicode-ident",
|
|
554
|
+
]
|
|
555
|
+
|
|
556
|
+
[[package]]
|
|
557
|
+
name = "windows-core"
|
|
558
|
+
version = "0.62.2"
|
|
559
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
560
|
+
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
|
561
|
+
dependencies = [
|
|
562
|
+
"windows-implement",
|
|
563
|
+
"windows-interface",
|
|
564
|
+
"windows-link",
|
|
565
|
+
"windows-result",
|
|
566
|
+
"windows-strings",
|
|
567
|
+
]
|
|
568
|
+
|
|
569
|
+
[[package]]
|
|
570
|
+
name = "windows-implement"
|
|
571
|
+
version = "0.60.2"
|
|
572
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
573
|
+
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
|
574
|
+
dependencies = [
|
|
575
|
+
"proc-macro2",
|
|
576
|
+
"quote",
|
|
577
|
+
"syn",
|
|
578
|
+
]
|
|
579
|
+
|
|
580
|
+
[[package]]
|
|
581
|
+
name = "windows-interface"
|
|
582
|
+
version = "0.59.3"
|
|
583
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
584
|
+
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
|
585
|
+
dependencies = [
|
|
586
|
+
"proc-macro2",
|
|
587
|
+
"quote",
|
|
588
|
+
"syn",
|
|
589
|
+
]
|
|
590
|
+
|
|
591
|
+
[[package]]
|
|
592
|
+
name = "windows-link"
|
|
593
|
+
version = "0.2.1"
|
|
594
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
595
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
596
|
+
|
|
597
|
+
[[package]]
|
|
598
|
+
name = "windows-result"
|
|
599
|
+
version = "0.4.1"
|
|
600
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
601
|
+
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
|
602
|
+
dependencies = [
|
|
603
|
+
"windows-link",
|
|
604
|
+
]
|
|
605
|
+
|
|
606
|
+
[[package]]
|
|
607
|
+
name = "windows-strings"
|
|
608
|
+
version = "0.5.1"
|
|
609
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
610
|
+
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
|
611
|
+
dependencies = [
|
|
612
|
+
"windows-link",
|
|
613
|
+
]
|
|
614
|
+
|
|
615
|
+
[[package]]
|
|
616
|
+
name = "zmij"
|
|
617
|
+
version = "1.0.21"
|
|
618
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
619
|
+
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "duckling"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
magnus = { version = "0.8" }
|
|
11
|
+
duckling = "0.4"
|
|
12
|
+
chrono = "0.4"
|
|
13
|
+
rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
|
data/ext/duckling/extconf.rb
CHANGED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
use chrono::DateTime;
|
|
2
|
+
use duckling::{
|
|
3
|
+
parse as duckling_parse, Context, DimensionKind, DimensionValue, Entity, Lang, Locale, Options,
|
|
4
|
+
Region, TimePoint, TimeValue,
|
|
5
|
+
};
|
|
6
|
+
use magnus::{function, prelude::*, scan_args, Error, RArray, Ruby, Value};
|
|
7
|
+
|
|
8
|
+
// `Duckling` is the gem's whole public surface today (one module, one method),
|
|
9
|
+
// so Magnus defines it directly rather than nesting a separate binding module
|
|
10
|
+
// underneath it — there's no second Ruby-level API to keep stable independent
|
|
11
|
+
// of the native layer yet. Revisit if/when the gem grows enough public Ruby
|
|
12
|
+
// behavior (e.g. locale/dimension helpers) to warrant its own file.
|
|
13
|
+
#[magnus::init]
|
|
14
|
+
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
15
|
+
let module = ruby.define_module("Duckling")?;
|
|
16
|
+
module.define_singleton_method("parse", function!(parse, -1))?;
|
|
17
|
+
Ok(())
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// `Duckling.parse(text, locale: "en", dims: ["time"], reference_time: nil, with_latent: false)`
|
|
21
|
+
///
|
|
22
|
+
/// - `locale`: BCP-47 tag (e.g. `"en"`, `"en-GB"`); unsupported codes raise `ArgumentError`.
|
|
23
|
+
/// - `dims`: dimension names to extract; only `"time"` is implemented in 0.2.0,
|
|
24
|
+
/// other values raise `ArgumentError`.
|
|
25
|
+
/// - `reference_time`: Unix seconds anchoring relative expressions like "tomorrow";
|
|
26
|
+
/// defaults to `Context::default()` (now, UTC).
|
|
27
|
+
/// - `with_latent`: include ambiguous/latent matches (e.g. bare "morning").
|
|
28
|
+
fn parse(ruby: &Ruby, args: &[Value]) -> Result<RArray, Error> {
|
|
29
|
+
let args = scan_args::scan_args::<(String,), (), (), (), _, ()>(args)?;
|
|
30
|
+
let kw = scan_args::get_kwargs::<
|
|
31
|
+
_,
|
|
32
|
+
(),
|
|
33
|
+
(
|
|
34
|
+
Option<String>,
|
|
35
|
+
Option<Vec<String>>,
|
|
36
|
+
Option<i64>,
|
|
37
|
+
Option<bool>,
|
|
38
|
+
),
|
|
39
|
+
(),
|
|
40
|
+
>(
|
|
41
|
+
args.keywords,
|
|
42
|
+
&[],
|
|
43
|
+
&["locale", "dims", "reference_time", "with_latent"],
|
|
44
|
+
)?;
|
|
45
|
+
|
|
46
|
+
let text = args.required.0;
|
|
47
|
+
let (locale_str, dims_strs, ref_time_i, with_latent) = kw.optional;
|
|
48
|
+
let locale_str = locale_str.unwrap_or_else(|| "en".to_string());
|
|
49
|
+
let dims_strs = dims_strs.unwrap_or_else(|| vec!["time".to_string()]);
|
|
50
|
+
let with_latent = with_latent.unwrap_or(false);
|
|
51
|
+
|
|
52
|
+
let locale = parse_locale(ruby, &locale_str)?;
|
|
53
|
+
let dims = parse_dims(ruby, &dims_strs)?;
|
|
54
|
+
let context = build_context(ruby, ref_time_i)?;
|
|
55
|
+
let options = Options { with_latent };
|
|
56
|
+
|
|
57
|
+
let entities = duckling_parse(&text, &locale, &dims, &context, &options);
|
|
58
|
+
|
|
59
|
+
let out = ruby.ary_new();
|
|
60
|
+
for e in &entities {
|
|
61
|
+
out.push(entity_to_ruby(ruby, e)?)?;
|
|
62
|
+
}
|
|
63
|
+
Ok(out)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn parse_locale(ruby: &Ruby, locale_str: &str) -> Result<Locale, Error> {
|
|
67
|
+
let mut parts = locale_str.splitn(2, '-');
|
|
68
|
+
let lang_code = parts.next().unwrap_or("");
|
|
69
|
+
let region_code = parts.next();
|
|
70
|
+
|
|
71
|
+
let lang = lang_from_code(lang_code).ok_or_else(|| {
|
|
72
|
+
Error::new(
|
|
73
|
+
ruby.exception_arg_error(),
|
|
74
|
+
format!("unsupported locale: {locale_str:?}"),
|
|
75
|
+
)
|
|
76
|
+
})?;
|
|
77
|
+
|
|
78
|
+
let region = match region_code {
|
|
79
|
+
Some(code) => Some(region_from_code(code).ok_or_else(|| {
|
|
80
|
+
Error::new(
|
|
81
|
+
ruby.exception_arg_error(),
|
|
82
|
+
format!("unsupported locale: {locale_str:?}"),
|
|
83
|
+
)
|
|
84
|
+
})?),
|
|
85
|
+
None => None,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
Ok(Locale::new(lang, region))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn lang_from_code(code: &str) -> Option<Lang> {
|
|
92
|
+
Some(match code.to_ascii_lowercase().as_str() {
|
|
93
|
+
"af" => Lang::AF,
|
|
94
|
+
"ar" => Lang::AR,
|
|
95
|
+
"bg" => Lang::BG,
|
|
96
|
+
"bn" => Lang::BN,
|
|
97
|
+
"ca" => Lang::CA,
|
|
98
|
+
"cs" => Lang::CS,
|
|
99
|
+
"da" => Lang::DA,
|
|
100
|
+
"de" => Lang::DE,
|
|
101
|
+
"el" => Lang::EL,
|
|
102
|
+
"en" => Lang::EN,
|
|
103
|
+
"es" => Lang::ES,
|
|
104
|
+
"et" => Lang::ET,
|
|
105
|
+
"fa" => Lang::FA,
|
|
106
|
+
"fi" => Lang::FI,
|
|
107
|
+
"fr" => Lang::FR,
|
|
108
|
+
"ga" => Lang::GA,
|
|
109
|
+
"he" => Lang::HE,
|
|
110
|
+
"hi" => Lang::HI,
|
|
111
|
+
"hr" => Lang::HR,
|
|
112
|
+
"hu" => Lang::HU,
|
|
113
|
+
"id" => Lang::ID,
|
|
114
|
+
"is" => Lang::IS,
|
|
115
|
+
"it" => Lang::IT,
|
|
116
|
+
"ja" => Lang::JA,
|
|
117
|
+
"ka" => Lang::KA,
|
|
118
|
+
"km" => Lang::KM,
|
|
119
|
+
"kn" => Lang::KN,
|
|
120
|
+
"ko" => Lang::KO,
|
|
121
|
+
"lo" => Lang::LO,
|
|
122
|
+
"ml" => Lang::ML,
|
|
123
|
+
"mn" => Lang::MN,
|
|
124
|
+
"my" => Lang::MY,
|
|
125
|
+
"nb" => Lang::NB,
|
|
126
|
+
"ne" => Lang::NE,
|
|
127
|
+
"nl" => Lang::NL,
|
|
128
|
+
"pl" => Lang::PL,
|
|
129
|
+
"pt" => Lang::PT,
|
|
130
|
+
"ro" => Lang::RO,
|
|
131
|
+
"ru" => Lang::RU,
|
|
132
|
+
"sk" => Lang::SK,
|
|
133
|
+
"sv" => Lang::SV,
|
|
134
|
+
"sw" => Lang::SW,
|
|
135
|
+
"ta" => Lang::TA,
|
|
136
|
+
"te" => Lang::TE,
|
|
137
|
+
"th" => Lang::TH,
|
|
138
|
+
"tr" => Lang::TR,
|
|
139
|
+
"uk" => Lang::UK,
|
|
140
|
+
"vi" => Lang::VI,
|
|
141
|
+
"zh" => Lang::ZH,
|
|
142
|
+
_ => return None,
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn region_from_code(code: &str) -> Option<Region> {
|
|
147
|
+
Some(match code.to_ascii_uppercase().as_str() {
|
|
148
|
+
"AR" => Region::AR,
|
|
149
|
+
"US" => Region::US,
|
|
150
|
+
"GB" => Region::GB,
|
|
151
|
+
"AU" => Region::AU,
|
|
152
|
+
"BE" => Region::BE,
|
|
153
|
+
"BZ" => Region::BZ,
|
|
154
|
+
"CA" => Region::CA,
|
|
155
|
+
"CL" => Region::CL,
|
|
156
|
+
"CN" => Region::CN,
|
|
157
|
+
"CO" => Region::CO,
|
|
158
|
+
"EG" => Region::EG,
|
|
159
|
+
"ES" => Region::ES,
|
|
160
|
+
"HK" => Region::HK,
|
|
161
|
+
"IE" => Region::IE,
|
|
162
|
+
"IN" => Region::IN,
|
|
163
|
+
"JM" => Region::JM,
|
|
164
|
+
"MO" => Region::MO,
|
|
165
|
+
"MX" => Region::MX,
|
|
166
|
+
"NZ" => Region::NZ,
|
|
167
|
+
"PE" => Region::PE,
|
|
168
|
+
"PH" => Region::PH,
|
|
169
|
+
"TT" => Region::TT,
|
|
170
|
+
"TW" => Region::TW,
|
|
171
|
+
"VE" => Region::VE,
|
|
172
|
+
"ZA" => Region::ZA,
|
|
173
|
+
_ => return None,
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
fn parse_dims(ruby: &Ruby, dims_strs: &[String]) -> Result<Vec<DimensionKind>, Error> {
|
|
178
|
+
dims_strs
|
|
179
|
+
.iter()
|
|
180
|
+
.map(|s| match s.as_str() {
|
|
181
|
+
"time" => Ok(DimensionKind::Time),
|
|
182
|
+
"number" => Ok(DimensionKind::Numeral),
|
|
183
|
+
"ordinal" => Ok(DimensionKind::Ordinal),
|
|
184
|
+
"temperature" => Ok(DimensionKind::Temperature),
|
|
185
|
+
"distance" => Ok(DimensionKind::Distance),
|
|
186
|
+
"volume" => Ok(DimensionKind::Volume),
|
|
187
|
+
"quantity" => Ok(DimensionKind::Quantity),
|
|
188
|
+
"amount-of-money" => Ok(DimensionKind::AmountOfMoney),
|
|
189
|
+
"email" => Ok(DimensionKind::Email),
|
|
190
|
+
"phone-number" => Ok(DimensionKind::PhoneNumber),
|
|
191
|
+
"url" => Ok(DimensionKind::Url),
|
|
192
|
+
"credit-card-number" => Ok(DimensionKind::CreditCardNumber),
|
|
193
|
+
"time-grain" => Ok(DimensionKind::TimeGrain),
|
|
194
|
+
"duration" => Ok(DimensionKind::Duration),
|
|
195
|
+
other => Err(Error::new(
|
|
196
|
+
ruby.exception_arg_error(),
|
|
197
|
+
format!("unsupported dimension: {other:?}"),
|
|
198
|
+
)),
|
|
199
|
+
})
|
|
200
|
+
.collect()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
fn build_context(ruby: &Ruby, ref_time_i: Option<i64>) -> Result<Context, Error> {
|
|
204
|
+
match ref_time_i {
|
|
205
|
+
Some(secs) => {
|
|
206
|
+
let utc = DateTime::from_timestamp(secs, 0)
|
|
207
|
+
.ok_or_else(|| Error::new(ruby.exception_arg_error(), "invalid reference_time"))?;
|
|
208
|
+
Ok(Context::new(utc.fixed_offset(), Locale::default()))
|
|
209
|
+
}
|
|
210
|
+
None => Ok(Context::default()),
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fn time_point_to_ruby(ruby: &Ruby, tp: &TimePoint) -> Result<Value, Error> {
|
|
215
|
+
let h = ruby.hash_new();
|
|
216
|
+
h.aset(ruby.to_symbol("type"), ruby.to_symbol("value"))?;
|
|
217
|
+
match tp {
|
|
218
|
+
TimePoint::Naive { value, grain } => {
|
|
219
|
+
h.aset(
|
|
220
|
+
ruby.to_symbol("value"),
|
|
221
|
+
value.format("%Y-%m-%dT%H:%M:%S").to_string(),
|
|
222
|
+
)?;
|
|
223
|
+
h.aset(ruby.to_symbol("grain"), ruby.to_symbol(grain.as_str()))?;
|
|
224
|
+
}
|
|
225
|
+
TimePoint::Instant { value, grain } => {
|
|
226
|
+
h.aset(ruby.to_symbol("value"), value.to_rfc3339())?;
|
|
227
|
+
h.aset(ruby.to_symbol("grain"), ruby.to_symbol(grain.as_str()))?;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
Ok(h.as_value())
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
fn time_value_to_ruby(ruby: &Ruby, tv: &TimeValue) -> Result<Value, Error> {
|
|
234
|
+
let h = ruby.hash_new();
|
|
235
|
+
match tv {
|
|
236
|
+
TimeValue::Single { value, values, .. } => {
|
|
237
|
+
h.aset(ruby.to_symbol("type"), ruby.to_symbol("value"))?;
|
|
238
|
+
match value {
|
|
239
|
+
TimePoint::Naive { value: dt, grain } => {
|
|
240
|
+
h.aset(
|
|
241
|
+
ruby.to_symbol("value"),
|
|
242
|
+
dt.format("%Y-%m-%dT%H:%M:%S").to_string(),
|
|
243
|
+
)?;
|
|
244
|
+
h.aset(ruby.to_symbol("grain"), ruby.to_symbol(grain.as_str()))?;
|
|
245
|
+
}
|
|
246
|
+
TimePoint::Instant { value: dt, grain } => {
|
|
247
|
+
h.aset(ruby.to_symbol("value"), dt.to_rfc3339())?;
|
|
248
|
+
h.aset(ruby.to_symbol("grain"), ruby.to_symbol(grain.as_str()))?;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
let vals = ruby.ary_new();
|
|
252
|
+
for tp in values {
|
|
253
|
+
vals.push(time_point_to_ruby(ruby, tp)?)?;
|
|
254
|
+
}
|
|
255
|
+
h.aset(ruby.to_symbol("values"), vals)?;
|
|
256
|
+
}
|
|
257
|
+
TimeValue::Interval { from, to, .. } => {
|
|
258
|
+
h.aset(ruby.to_symbol("type"), ruby.to_symbol("interval"))?;
|
|
259
|
+
if let Some(tp) = from {
|
|
260
|
+
h.aset(ruby.to_symbol("from"), time_point_to_ruby(ruby, tp)?)?;
|
|
261
|
+
}
|
|
262
|
+
if let Some(tp) = to {
|
|
263
|
+
h.aset(ruby.to_symbol("to"), time_point_to_ruby(ruby, tp)?)?;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
Ok(h.as_value())
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
fn entity_to_ruby(ruby: &Ruby, entity: &Entity) -> Result<Value, Error> {
|
|
271
|
+
let h = ruby.hash_new();
|
|
272
|
+
h.aset(ruby.to_symbol("body"), entity.body.clone())?;
|
|
273
|
+
h.aset(ruby.to_symbol("start"), entity.start)?;
|
|
274
|
+
h.aset(ruby.to_symbol("end"), entity.end)?;
|
|
275
|
+
let dim_str = entity.value.dim_kind().to_string();
|
|
276
|
+
h.aset(ruby.to_symbol("dim"), ruby.to_symbol(dim_str.as_str()))?;
|
|
277
|
+
if let Some(latent) = entity.latent {
|
|
278
|
+
h.aset(ruby.to_symbol("latent"), latent)?;
|
|
279
|
+
}
|
|
280
|
+
if let DimensionValue::Time(ref tv) = entity.value {
|
|
281
|
+
h.aset(ruby.to_symbol("value"), time_value_to_ruby(ruby, tv)?)?;
|
|
282
|
+
}
|
|
283
|
+
Ok(h.as_value())
|
|
284
|
+
}
|
data/lib/duckling/version.rb
CHANGED
data/lib/duckling.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: duckling
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Caleb Buxton
|
|
@@ -51,7 +51,10 @@ files:
|
|
|
51
51
|
- LICENSE.txt
|
|
52
52
|
- README.md
|
|
53
53
|
- Rakefile
|
|
54
|
+
- ext/duckling/Cargo.lock
|
|
55
|
+
- ext/duckling/Cargo.toml
|
|
54
56
|
- ext/duckling/extconf.rb
|
|
57
|
+
- ext/duckling/src/lib.rs
|
|
55
58
|
- lib/duckling.rb
|
|
56
59
|
- lib/duckling/version.rb
|
|
57
60
|
homepage: https://github.com/cpb/duckling
|