pipeline ¶
Generate and serialize GKG records from prepared English text and metadata.
OVERRIDABLE_COLUMNS module-attribute ¶
GKG column names accepted by the overrides argument of generate_gkg.
IncompleteGKGWarning ¶
Bases: UserWarning
The record contains unavailable fields.
IncompleteGKGError ¶
Bases: ValueError
Strict generation requires every field to be available.
generate_gkg ¶
generate_gkg(text: str, metadata: RecordMetadata, resources: Resources | None = None, *, overrides: Mapping[str, str | None] | None = None, ner_result: NERResult | None = None, count_locations: Iterable[CountLocation] = (), numeric_date_order: NumericDateOrder | None = None, gcam_disabled_dictionaries: Iterable[int | str] = (), gcam_original_text: str | None = None, strict: bool = False) -> GKGRecord
Build a GKG record from prepared English text and supplied metadata.
Enhanced offsets refer to text. For translated input, copy language and engine metadata with RecordMetadata.from_translation. Overridden cells may share analysis dependencies with other fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Prepared English body to analyze. | required |
metadata | RecordMetadata | Document identity, timestamps, media, and translation metadata. | required |
resources | Resources | None | Resource configuration. Defaults to | None |
overrides | Mapping[str, str | None] | None | Encoded output cells keyed by names in | None |
ner_result | NERResult | None | Precomputed entities for this exact body, taking precedence over the configured recognizer. | None |
count_locations | Iterable[CountLocation] | Explicit count geography. Nonempty input takes precedence over locations derived from entities. | () |
numeric_date_order | NumericDateOrder | None |
| None |
gcam_disabled_dictionaries | Iterable[int | str] | GCAM dictionary names or IDs to exclude. | () |
gcam_original_text | str | None | Original body for native-language GCAM scoring, paired with | None |
strict | bool | Raise an error if any output field is unavailable. | False |
Returns:
| Type | Description |
|---|---|
GKGRecord | A 27-field record. |
Raises:
| Type | Description |
|---|---|
TypeError | If argument types or output cell types are invalid. |
ValueError | If metadata, overrides, date order, or analysis inputs are invalid. A supplied NER result must describe |
IncompleteGKGError | If |
ResourceUnavailableError | If a required default resource is missing. |
Warns:
| Type | Description |
|---|---|
IncompleteGKGWarning | If fields are unavailable and |
Source code in src/gdelt_regkg/pipeline.py
158 159 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 | |
serialize_gkg ¶
Serialize one record as an unquoted 27-column TSV line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record | Mapping[str, str | None] | Mapping with exactly the column names in | required |
allow_incomplete | bool | Convert unavailable ( | False |
Returns:
| Type | Description |
|---|---|
str | A tab-separated line in GKG column order, ending with a newline. |
Raises:
| Type | Description |
|---|---|
TypeError | If a cell has an invalid type. |
ValueError | If keys are incorrect, a cell contains row separators, or unavailable cells are present while |
Source code in src/gdelt_regkg/pipeline.py
write_gkg ¶
write_gkg(records: Iterable[Mapping[str, str | None]], stream: TextIO, *, allow_incomplete: bool = False) -> int
Write GKG records to a text stream as headerless TSV rows.
Each row is validated before writing. Earlier rows remain if a later row fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records | Iterable[Mapping[str, str | None]] | Record mappings in output order. | required |
stream | TextIO | Writable text stream, which remains open after writing. | required |
allow_incomplete | bool | Convert unavailable ( | False |
Returns:
| Type | Description |
|---|---|
int | The number of records written. |
Raises:
| Type | Description |
|---|---|
TypeError | If a cell has an invalid type. |
ValueError | If record validation fails. |
OSError | If writing to the stream fails. |