2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
25#ifndef ARACHNE_ARACHNE_HPP
26#define ARACHNE_ARACHNE_HPP
30using std::chrono_literals::operator
""h;
36
37
38
39
40
41
42
43
44
45
46
53
54
55
56
57
58
59
60
61
62
63
64
65
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
90
91
92
93
94
95
96
97
98
99
100
103
104
105
106
107
108
109
110
111 static std::string
entity_root(
const std::string& id);
114
115
116
117
118
119
120
121
122
126
127
128
129
130
131
132
133
134
135
139
140
141
142
143
144
145
146
149
150
151
152
153
154
155
156
157
158
159 static bool parse_id(
const std::string& entity, size_t& pos,
int& id);
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
187
188
189
190
191
192
193
197
198
199
200
201
202
203
204
205
206
207
208
211 std::chrono::milliseconds age
215
216
217
218
219
220
221
222
223
224
225
226
232
233
234
235
236
237
238
239
240
241
242
243 bool touch_entity(
const std::string& id_with_prefix)
noexcept;
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
264 const std::string& id_with_prefix,
bool force =
false,
265 std::string name =
""
Accumulates entity IDs into per-kind batches and organizes groups.
std::unordered_map< std::string, int > candidates
std::array< std::unordered_set< std::string >, batched_kind_count > extra_batches
bool touch_entity(const std::string &id_with_prefix) noexcept
Increment the touch counter for a single full ID (prefix REQUIRED).
static std::string entity_root(const std::string &id)
Extract the lexeme root from a full ID string.
std::string current_group
int touch_ids(std::span< const int > ids, corespace::entity_kind kind)
Batch variant of touch for numeric IDs.
static bool parse_id(const std::string &entity, size_t &pos, int &id)
Parse a full ID string and extract the numeric portion.
bool new_group(std::string name="")
Create or select a group and make it current.
size_t add_entity(const std::string &id_with_prefix, bool force=false, std::string name="")
Enqueue a full (prefixed) ID string and add it to a group.
std::unordered_map< std::string, std::unordered_set< std::string > > groups
std::chrono::milliseconds staleness_threshold
bool enqueue(std::string_view id, corespace::entity_kind kind, bool interactive) const
Decide whether an entity should be enqueued for fetching.
const size_t batch_threshold
Typical unauthenticated entity-per-request cap.
const int candidates_threshold
Intentional high bar for curiosity-driven candidates.
static std::string normalize(int id, corespace::entity_kind kind)
Normalize a numeric ID with the given kind to a prefixed string.
static bool ask_update(std::string_view id, corespace::entity_kind kind, std::chrono::milliseconds age)
Placeholder for interactive staleness confirmation.
void select_group(std::string name)
Select an existing group or create it on demand.
std::array< std::unordered_set< std::string >, batched_kind_count > main_batches
int queue_size(corespace::entity_kind kind) const noexcept
Get the number of queued (pending) entities tracked in the main batch containers.
static corespace::entity_kind identify(const std::string &entity) noexcept
Determine the kind of a full ID string.
bool flush(corespace::entity_kind kind=corespace::entity_kind::any)
Flush (send) up to batch_threshold entities of a specific kind.
size_t add_ids(std::span< const int > ids, corespace::entity_kind kind, std::string name="")
Enqueue numeric IDs with a given kind and add them to a group.
Batch courier for Wikidata/Commons: collects IDs, issues HTTP requests, and returns a merged JSON pay...
static constexpr std::string prefixes
constexpr std::size_t batched_kind_count
Number of batchable kinds (Q, P, L, M, E, form, sense).
entity_kind
Wikidata entity kind.
@ any
API selector (e.g., flush(any)); not directly batchable.
@ lexeme
IDs prefixed with 'L'.
@ form
Lexeme form IDs such as "L<lexeme>-F<form>".
@ unknown
Unrecognized/invalid identifier.
@ sense
Lexeme sense IDs such as "L<lexeme>-S<sense>".
std::string random_hex(const std::size_t n)
Return exactly n random hexadecimal characters (lowercase).