counts ¶
Event-related quantity extraction from English text.
CountRules dataclass ¶
CountRules(name: str, triggers: Mapping[str, str | tuple[str, ...]], active_triggers: tuple[str, ...], object_nouns: tuple[str, ...], auxiliaries: tuple[str, ...], unsafe_phrases: tuple[str, ...], unsafe_suffixes: tuple[str, ...], bad_object_words: tuple[str, ...], max_object_modifiers: int = 3, context_words: int = 10, patterns: tuple[dict, ...] = (), allow_bare_active: bool = False, reject_time_objects: bool = False, empty_object_nouns: tuple[str, ...] = ())
Named vocabulary, context bounds, and templates for count extraction.
Trigger phrases map to one or more count labels. Load custom rule files with from_json and reuse the compiled rules across documents.
from_json classmethod ¶
Load source-neutral rule input or the legacy count-rules object.
Source code in src/gdelt_regkg/fields/counts.py
CountLocation dataclass ¶
CountLocation(start: int, end: int, geo_type: str = '', full_name: str = '', country_code: str = '', adm1_code: str = '', latitude: str = '', longitude: str = '', feature_id: str = '')
Resolved geography for attaching a location to a count mention.
start and end delimit a source-text span. Geographic components use GKG location types and compatible FIPS/GNS/GNIS identifiers; empty values are allowed.
CountMention dataclass ¶
CountMention(count_type: str, number: int, object_type: str, start: int, end: int, trigger_start: int, location: CountLocation | None = None)
An event label, exact quantity, object description, and optional geography.
start identifies the quantity, end ends the matched construction, and trigger_start identifies its trigger. Offsets are zero-based characters.
CountIssue dataclass ¶
A rejected count candidate's start, exclusive end, and rejection reason.
CountResult dataclass ¶
CountResult(mentions: tuple[CountMention, ...], issues: tuple[CountIssue, ...], profile_name: str = PROFILE, empty_object_nouns: tuple[str, ...] = ())
Count mentions, rejected candidates, and the extraction profile name.
empty_object_nouns identifies object labels omitted during serialization.
to_gkg ¶
Serialize standard or enhanced count entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enhanced | bool | Append each quantity's source character offset. | False |
Returns:
| Type | Description |
|---|---|
str | Semicolon-terminated entries, or an empty string for no matches. |
Source code in src/gdelt_regkg/fields/counts.py
analyze_counts ¶
analyze_counts(text: str, *, locations: Iterable[CountLocation] = (), rules: CountRules | None = None) -> CountResult
Extract event-related quantities using English vocabulary and templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Prepared English body. | required |
locations | Iterable[CountLocation] | Resolved geographic spans for this body. Counts use the nearest supplied location. | () |
rules | CountRules | None | Reusable count rules. Defaults to the configured profile. | None |
Returns:
| Type | Description |
|---|---|
CountResult | Count mentions and diagnostics for rejected trigger matches. |
Raises:
| Type | Description |
|---|---|
TypeError | If text, rules, or locations have invalid types. |
ValueError | If a supplied location extends beyond the body. |
ResourceUnavailableError | If the default profile is unavailable. |
Source code in src/gdelt_regkg/fields/counts.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |