gcam ¶
Sparse GCAM dictionary counts and matched-word mean scores.
GCAMLexicon dataclass ¶
GCAMLexicon(name: str, dimensions: Mapping[str, frozenset[str]], weighted_dimensions: Mapping[str, Mapping[str, float]] = dict(), tokenization: Mapping[str, str] = dict(), patterns: Mapping[str, tuple[str, ...]] = dict(), lemmatization: Mapping[str, str] = dict(), exceptions: Mapping[str, tuple[str, ...]] = dict(), theme_dimensions: Mapping[str, str] = dict(), theme_lexicon: ThemeLexicon | None = None, emit_count: Mapping[str, bool] = dict(), exclusions: Mapping[str, tuple[str, ...]] = dict(), languages: Mapping[str, str] = dict())
Reusable GCAM count dictionaries, weighted scores, and matching options.
dimensions maps count keys to word sets; weighted_dimensions maps score keys to word weights. Load compiled profiles with from_json and select dictionaries or languages before analysis.
implemented_dimensions property ¶
All supported serialized keys, including value-only dimensions.
without_dictionaries ¶
Select a lexicon with the requested dictionaries excluded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disabled | Iterable[int | str] | Collection of dictionary names, integer IDs, or numeric strings. | () |
Returns:
| Type | Description |
|---|---|
GCAMLexicon | A reusable selection, or this lexicon if no applicable IDs are excluded. |
Raises:
| Type | Description |
|---|---|
TypeError | If selectors have invalid types or form a bare string. |
ValueError | If a dictionary name or ID is unknown. |
Source code in src/gdelt_regkg/fields/gcam.py
for_language ¶
Select dimensions for a supported language code, name, or regional tag.
Source code in src/gdelt_regkg/fields/gcam.py
from_json classmethod ¶
GCAMResult dataclass ¶
GCAMResult(word_count: int, counts: Mapping[str, int], implemented_dimensions: tuple[str, ...], lexicon_name: str, values: Mapping[str, float] = dict(), native_word_count: int | None = None)
GCAM counts and weighted scores with the profile's supported dimensions.
Attributes:
| Name | Type | Description |
|---|---|---|
word_count | int | English input token count. |
counts | Mapping[str, int] | Count-dimension matches, including supported zero counts. |
implemented_dimensions | tuple[str, ...] | Keys computed by the selected lexicon. |
lexicon_name | str | Profile identity. |
values | Mapping[str, float] | Weighted means for dimensions with matched words. |
native_word_count | int | None | Original-language token count when native text is supplied. |
to_gkg ¶
Serialize word counts and sparse dimension values in GCAM key order.
Zero counts are omitted. Matched weighted means of zero are retained.
Source code in src/gdelt_regkg/fields/gcam.py
analyze_gcam ¶
analyze_gcam(text: str, *, lexicon: GCAMLexicon | None = None, disabled_dictionaries: Iterable[int | str] = (), original_text: str | None = None, original_language: str | None = None) -> GCAMResult
Compute dictionary match counts and matched-word weighted means.
Original-language text is scored with dimensions for that language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Prepared English body. | required |
lexicon | GCAMLexicon | None | Reusable GCAM profile. Defaults to the configured local profile. | None |
disabled_dictionaries | Iterable[int | str] | Dictionary names or IDs to exclude before matching. | () |
original_text | str | None | Optional body before English translation. | None |
original_language | str | None | Non-English language of | None |
Returns:
| Type | Description |
|---|---|
GCAMResult | Counts, weighted means, and supported dimension keys. Unmatched weighted |
GCAMResult | means are omitted. |
Raises:
| Type | Description |
|---|---|
TypeError | If text, lexicon, or dictionary selectors have invalid types. |
ValueError | If dictionary selectors or the original-language inputs are invalid. |
ResourceUnavailableError | If the default local profile is unavailable. |