ftmq.aggregate
Fast paths to merge trusted entity data without building FtM objects (and with that without value validation): statement dicts or entity fragment dicts into EntityDicts. Both expect an input stream sorted by entity id, and both merge conflicting schemata leniently via merge_schema. Consumers that need more than the entity dict (the statements, the first_seen bounds, a StatementEntity) iterate EntityPayloads instead, from statements via aggregate_statement_payloads or from entity dicts via EntityPayload.from_dict.
Aggregate trusted statement dicts (e.g. db rows) into entity dicts.
A fast path around StatementEntity.from_statements(...).to_dict(), without
FtM object construction and with that without value validation. Values and
lists are sorted, the caption is the first value of the first caption
property. Conflicting schemata merge leniently (merge_schema).
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[StatementDict]
|
Statement dicts, sorted by |
required |
skip_errors
|
bool
|
Log and skip an entity whose schemata don't merge instead of
raising |
False
|
Returns:
| Type | Description |
|---|---|
Iterator[EntityDict]
|
A generator of entity dicts, one per canonical id |
Source code in ftmq/aggregate.py
Merge trusted entity fragment dicts by id into entity dicts.
A fast path around EntityProxy.merge: the result is what
Fragments.iterate() yields, as to_dict(), without FtM object construction
and with that without value cleaning. Values unite in order of appearance,
every other key becomes the list of its unique values (caption is
dropped); a single fragment keeps its properties as is. Text and html values
that would push a merged entity past the PROP_VALUE_MAX size are rejected,
as EntityProxy.unsafe_add does. Conflicting schemata merge leniently
(merge_schema).
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[dict[str, Any]]
|
Entity fragment dicts, sorted by |
required |
skip_errors
|
bool
|
Log and skip an entity whose schemata don't merge instead of
raising |
False
|
Returns:
| Type | Description |
|---|---|
Iterator[EntityDict]
|
A generator of entity dicts, one per id |
Source code in ftmq/aggregate.py
Bases: TypedDict
An entity as the *_unsafe aggregations yield it, in the shape of
to_dict(): from statements as StatementEntity, with caption,
datasets, referents, the timestamps and the statements' origin /
role; from fragments as EntityProxy, with every other fragment key merged
into a list.
Source code in ftmq/aggregate.py
Group trusted statement dicts into one EntityPayload per entity, for
consumers that need more than the entity dict (the statements,
min_first_seen / max_first_seen, to_entity()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[StatementDict]
|
Statement dicts, sorted by |
required |
dataset
|
str | None
|
Dataset name for |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[EntityPayload]
|
A generator of |
Source code in ftmq/aggregate.py
The statements, the fragments or the dict of one entity.
Statements are kept as they come and folded once, on first access; fragments
are folded as they come, as EntityProxy.merge does. statements stays empty
for a payload of fragments or of a dict (from_dict).
Source code in ftmq/aggregate.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
max_first_seen
property
Latest first_seen across all statements, id rows included; of a
dict, over its first_seen and last_change.
min_first_seen
property
Earliest first_seen across all statements, id rows included
(unlike first_seen in to_dict()); of a dict, over its first_seen
and last_change.
origins
property
Every origin asserting something about this entity.
from_dict(data, dataset=None)
classmethod
The payload of an entity dict, e.g. a line of an entities.ftm.json
(smart_stream_json): to_dict() returns it, with its datasets,
referents, origin and role as lists.
Source code in ftmq/aggregate.py
to_dict()
The entity dict, built once.
Raises:
| Type | Description |
|---|---|
InvalidData
|
If the schemata don't merge (see |
to_entity()
The entity as a StatementEntity, with FtM validation.
Source code in ftmq/aggregate.py
Lenient model.common_schema over any number of schemata.
Schemata another one extends are absorbed, as model.common_schema does; if
more than one remains, they merge to their most specific common ancestor. The
result doesn't depend on the order: unlike a pairwise fold, a later schema
can't specialize a merge that already fell back to an ancestor.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*schemata
|
str | Schema
|
Schemata (or their names) to merge |
()
|
Returns:
| Type | Description |
|---|---|
Schema
|
The merged schema |
Raises:
| Type | Description |
|---|---|
InvalidData
|
For an unknown schema, or schemata without a common ancestor |