metadata ¶
Caller-supplied document metadata for GKG records.
RecordMetadata dataclass ¶
RecordMetadata(identifier: str, batch_time: Timestamp, sequence: int, published_at: Timestamp | None = None, source_collection: int = 1, source_name: str | None = None, sharing_image: str | None = None, related_images: Iterable[str] | None = None, social_image_embeds: Iterable[str] | None = None, social_video_embeds: Iterable[str] | None = None, extras: Mapping[str, XMLValue] | None = None, source_language: str | None = None, translation_engine: str | None = None)
Document identity, timestamps, media, and translation provenance.
None media values mark unavailable data. Empty values mark known absence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier | str | Document URL, DOI, or citation. | required |
batch_time | Timestamp | Record batch timestamp. | required |
sequence | int | Caller-managed positive sequence number within the batch. | required |
published_at | Timestamp | None | Optional precise publication timestamp for extras. | None |
source_collection | int | GKG source collection code, from 1 through 6. | 1 |
source_name | str | None | Explicit source label; defaults to a web URL's hostname. | None |
sharing_image | str | None | Selected sharing-image URL. | None |
related_images | Iterable[str] | None | Selected article image URLs. | None |
social_image_embeds | Iterable[str] | None | Social-post URLs containing images. | None |
social_video_embeds | Iterable[str] | None | Selected video URLs. | None |
extras | Mapping[str, XMLValue] | None | Additional XML extension elements. | None |
source_language | str | None | Original language code for translated bodies. | None |
translation_engine | str | None | Engine citation, supplied with | None |
from_translation classmethod ¶
Copy translation provenance into a new metadata instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result | TranslationResult | Translation result whose English text will be analyzed. | required |
metadata | RecordMetadata | Existing document metadata. | required |
Returns:
| Type | Description |
|---|---|
RecordMetadata | Updated metadata with source language and engine for translated input. |
Raises:
| Type | Description |
|---|---|
TypeError | If argument types are invalid. |
ValueError | If translation provenance conflicts with existing metadata. |
Source code in src/gdelt_regkg/fields/metadata.py
to_mapping ¶
Format the record identity, source, batch date, and translation cells.
Source code in src/gdelt_regkg/fields/metadata.py
format_date ¶
Format a UTC timestamp as YYYYMMDDHHMMSS; None/0 means unknown.
Aware datetimes are converted to UTC; naive datetimes are treated as UTC. Strings must already contain exactly fourteen ASCII digits (or '0').
Source code in src/gdelt_regkg/fields/metadata.py
format_record_id ¶
format_record_id(batch_time: datetime | str | int, sequence: int, *, translated: bool = False) -> str
Build a local record ID from batch time and caller-managed sequence.
The caller owns uniqueness; these IDs are not assigned by GDELT. Batch time is separate from the document's publication time.
Source code in src/gdelt_regkg/fields/metadata.py
format_source_collection ¶
1 web, 2 citation, 3 CORE, 4 DTIC, 5 JSTOR, 6 nontextual source.
Source code in src/gdelt_regkg/fields/metadata.py
source_common_name ¶
Use an explicit source label, otherwise extract a web URL's hostname.
Keeps subdomains; registrable-domain normalization is not implemented. Offline sources should always supply name explicitly.
Source code in src/gdelt_regkg/fields/metadata.py
document_identifier ¶
Preserve a supplied URL, DOI, or citation without fetching it.
format_translation_info ¶
Format the source language and translation engine; does not translate.
Supply both an ISO 639-2 code and an engine citation, or neither. Only the code's shape is checked, not membership in ISO 639-2.
Source code in src/gdelt_regkg/fields/metadata.py
format_sharing_image ¶
Format a supplied image URL; None is unavailable and '' means no image.
format_related_images ¶
Format caller-selected article image URLs, preserving order and duplicates.
format_social_image_embeds ¶
Format supplied social-post URLs; the caller determines image content.
format_social_video_embeds ¶
Format supplied video URLs; the caller identifies and normalizes embeds.