glazing.base¶
Base models and shared functionality.
base
¶
Base models and utilities for the glazing package.
This module provides base classes and common functionality used throughout the glazing package. All dataset-specific models inherit from these base classes to ensure consistent behavior and validation.
| CLASS | DESCRIPTION |
|---|---|
GlazingBaseModel |
Extended Pydantic BaseModel with JSON Lines support. |
CrossReferenceBase |
Base class for cross-dataset references. |
MappingBase |
Base class for dataset mappings. |
| FUNCTION | DESCRIPTION |
|---|---|
validate_pattern |
Validate a string against a regex pattern. |
validate_confidence_score |
Validate a confidence score is between 0.0 and 1.0. |
Notes
This module uses Pydantic v2 for data validation and serialization. All models support JSON Lines export/import for efficient data storage.
Classes¶
ConflictResolution
pydantic-model
¶
Bases: GlazingBaseModel
Model for representing mapping conflict resolution.
| ATTRIBUTE | DESCRIPTION |
|---|---|
conflict_type |
Type of conflict detected.
TYPE:
|
resolution_strategy |
Strategy used to resolve the conflict.
TYPE:
|
selected_mapping |
The mapping selected after resolution.
TYPE:
|
rejected_mappings |
Mappings that were rejected.
TYPE:
|
resolution_confidence |
Confidence in the resolution.
TYPE:
|
Fields:
-
conflict_type(ConflictType) -
resolution_strategy(str) -
selected_mapping(CrossReferenceBase | None) -
rejected_mappings(list[CrossReferenceBase]) -
resolution_confidence(MappingConfidenceScore)
Validators:
CrossReferenceBase
pydantic-model
¶
Bases: GlazingBaseModel
Base class for cross-dataset references.
Provides common fields and validation for references between FrameNet, PropBank, VerbNet, and WordNet.
| ATTRIBUTE | DESCRIPTION |
|---|---|
source_dataset |
The source dataset.
TYPE:
|
source_id |
Identifier in the source dataset.
TYPE:
|
target_dataset |
The target dataset.
TYPE:
|
target_id |
Identifier(s) in the target dataset.
TYPE:
|
mapping_type |
Type of mapping relationship.
TYPE:
|
confidence |
Confidence score for the mapping.
TYPE:
|
mapping_source |
Provenance of the mapping.
TYPE:
|
notes |
Additional notes about the mapping.
TYPE:
|
Fields:
-
source_dataset(DatasetType) -
source_id(str) -
target_dataset(DatasetType) -
target_id(str | list[str]) -
mapping_type(MappingType) -
confidence(MappingConfidenceScore | None) -
mapping_source(MappingSource | None) -
notes(str | None)
Validators:
-
validate_ids→source_id,target_id -
validate_datasets
Functions¶
get_confidence_score() -> float
¶
Get confidence score with default fallback.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Confidence score, or 0.5 if not specified. |
is_high_confidence(threshold: float = 0.8) -> bool
¶
Check if this is a high-confidence mapping.
| PARAMETER | DESCRIPTION |
|---|---|
threshold
|
Minimum confidence score for high confidence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if confidence exceeds threshold. |
Source code in src/glazing/base.py
validate_datasets() -> Self
pydantic-validator
¶
Source and target must be different datasets.
Source code in src/glazing/base.py
validate_ids(v: str | list[str]) -> str | list[str]
pydantic-validator
¶
IDs must be non-empty strings.
Source code in src/glazing/base.py
GlazingBaseModel
pydantic-model
¶
Bases: BaseModel
Base model class for all glazing data models.
Extends Pydantic's BaseModel with JSON Lines support and common validation functionality used across all linguistic datasets.
| ATTRIBUTE | DESCRIPTION |
|---|---|
model_config |
Pydantic configuration for the model.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
to_jsonl |
Export model to JSON Lines format. |
from_jsonl |
Load model from JSON Lines format. |
to_json_lines_file |
Write model to JSON Lines file. |
from_json_lines_file |
Load model from JSON Lines file. |
Examples:
>>> class MyModel(GlazingBaseModel):
... name: str
... value: int
>>> model = MyModel(name="test", value=42)
>>> jsonl = model.to_jsonl()
>>> loaded = MyModel.from_jsonl(jsonl)
Config:
populate_by_name:Truevalidate_assignment:Trueuse_enum_values:Falsejson_schema_extra:{'description': 'Base model for glazing package data structures'}
Functions¶
from_json_lines_file(path: Path | str, skip_errors: bool = False) -> Generator[Self, None, None]
classmethod
¶
Load models from a JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the JSON Lines file.
TYPE:
|
skip_errors
|
If True, skip lines that fail validation.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
Self
|
Instances of the model class. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If skip_errors is False and a line fails validation. |
Source code in src/glazing/base.py
from_jsonl(line: str) -> Self
classmethod
¶
Load model from a JSON Lines string.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
Single line of JSON Lines format.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Instance of the model class. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the JSON is invalid or doesn't match the model schema. |
Source code in src/glazing/base.py
to_json_lines_file(path: Path | str) -> None
¶
Write model to a JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the output file.
TYPE:
|
Source code in src/glazing/base.py
to_jsonl() -> str
¶
Export model to JSON Lines format.
| RETURNS | DESCRIPTION |
|---|---|
str
|
JSON Lines string representation of the model. |
validate_many(items: Iterable[dict[str, ModelValue]]) -> list[tuple[Self | None, Exception | None]]
classmethod
¶
Validate multiple items and return results with errors.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Items to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Self | None, Exception | None]]
|
List of (model, error) tuples. If validation succeeds, error is None. If validation fails, model is None. |
Source code in src/glazing/base.py
MappingBase
pydantic-model
¶
Bases: GlazingBaseModel
Base class for mapping metadata.
Provides common fields for tracking mapping provenance, validation status, and versioning.
| ATTRIBUTE | DESCRIPTION |
|---|---|
created_date |
When the mapping was created.
TYPE:
|
created_by |
Person or system that created the mapping.
TYPE:
|
modified_date |
When the mapping was last modified.
TYPE:
|
modified_by |
Person or system that last modified the mapping.
TYPE:
|
version |
Dataset version this mapping was created for.
TYPE:
|
validation_status |
Current validation status.
TYPE:
|
validation_method |
How the mapping was validated.
TYPE:
|
Fields:
-
created_date(datetime) -
created_by(str) -
modified_date(datetime | None) -
modified_by(str | None) -
version(VersionString) -
validation_status(ValidationStatus) -
validation_method(str | None)
Validators:
Functions¶
mark_validated(method: str, validator: str | None = None) -> None
¶
Mark the mapping as validated.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
Validation method used.
TYPE:
|
validator
|
Person or system that performed validation.
TYPE:
|
Source code in src/glazing/base.py
validate_modification() -> Self
pydantic-validator
¶
If modified_by is set, modified_at must also be set.
Source code in src/glazing/base.py
Functions¶
validate_confidence_score(value: float) -> float
¶
Validate a confidence score is between 0.0 and 1.0.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The confidence score to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The validated confidence score. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the value is not between 0.0 and 1.0. |
Source code in src/glazing/base.py
validate_fe_name(value: str) -> str
¶
validate_frame_id(value: int | str) -> str
¶
validate_frame_name(value: str) -> str
¶
validate_hex_color(value: str) -> str
¶
validate_lemma(value: str) -> str
¶
validate_pattern(value: str, pattern: str, field_name: str) -> str
¶
Validate a string against a regex pattern.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value to validate.
TYPE:
|
pattern
|
The regex pattern to match.
TYPE:
|
field_name
|
Name of the field being validated (for error messages).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The validated value. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the value doesn't match the pattern. |