language ¶
Optional local language identification for prepared article bodies.
LanguageDetection dataclass ¶
A language candidate with confidence and detector identity.
Attributes:
| Name | Type | Description |
|---|---|---|
language | str | Lowercase ISO 639-3 code. |
confidence | float | Detector score for the best candidate. |
margin | float | Score difference between the best and second-best candidates. |
detector | str | Detector identity. |
LanguageDetector ¶
Bases: Protocol
Interface for backends implementing detect(text) with a LanguageDetection.
LanguageDetectionError ¶
Bases: ValueError
No language candidate exists, or strict detection rejects weak evidence.
LinguaDetector ¶
LinguaDetector(*, strict: bool = False, min_letters: int = 40, min_confidence: float = 0.8, min_margin: float = 0.2)
Local language identifier with optional confidence thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strict | bool | Reject short text and candidates below the configured thresholds. | False |
min_letters | int | Minimum alphabetic sample length in strict mode. | 40 |
min_confidence | float | Minimum candidate confidence in strict mode. | 0.8 |
min_margin | float | Minimum gap from the next candidate in strict mode. | 0.2 |
Source code in src/gdelt_regkg/fields/language.py
detect ¶
Identify a language candidate using this detector's thresholds.
confirm ¶
Use full models to compare a proposed correction with the supplied label.
Source code in src/gdelt_regkg/fields/language.py
detect_language ¶
Identify a language candidate for a prepared article body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Body to analyze. | required |
detector | LanguageDetector | None | Custom detector. Defaults to a permissive local Lingua detector. | None |
Returns:
| Type | Description |
|---|---|
LanguageDetection | A language code, confidence, margin, and detector identity. |
Raises:
| Type | Description |
|---|---|
TypeError | If |
LanguageDetectionError | If no candidate exists or strict thresholds fail. |
OptionalDependencyError | If the default detector's dependency is unavailable. |
Source code in src/gdelt_regkg/fields/language.py
script_mismatch ¶
Flag a dominant alphabet incompatible with a normalized language label.
Source code in src/gdelt_regkg/fields/language.py
verify_language ¶
verify_language(text: str, language: str, *, check: LanguageCheck = 'script', detector: LanguageDetector | None = None) -> LanguageDetection | None
Check supplied labels; alphabet conflicts require a confident decision.