glazing.framenet.loader¶
Loading FrameNet data from JSON Lines.
loader
¶
FrameNet JSON Lines data loader.
This module provides functionality to load FrameNet data from JSON Lines files with validation, lazy loading for large datasets, and frame index building.
| CLASS | DESCRIPTION |
|---|---|
FrameNetLoader |
Load FrameNet data from JSON Lines format with automatic loading. |
FrameIndex |
In-memory index for fast frame lookups. |
| FUNCTION | DESCRIPTION |
|---|---|
load_frames |
Load Frame models from JSON Lines file. |
load_lexical_units |
Load LexicalUnit models from JSON Lines file. |
build_frame_index |
Build searchable index from frames data. |
Examples:
>>> from glazing.framenet.loader import FrameNetLoader
>>> # Data loads automatically on initialization
>>> loader = FrameNetLoader()
>>> frames = loader.frames # Access loaded frames via property
>>>
>>> # Or disable autoload for manual control
>>> loader = FrameNetLoader(autoload=False)
>>> frames = loader.load() # Load manually when needed
Classes¶
FrameIndex(frames: list[Frame] | None = None)
¶
In-memory index for fast FrameNet frame lookups.
Provides efficient lookup methods for frames by various criteria including name, ID, frame elements, and lexical units.
| PARAMETER | DESCRIPTION |
|---|---|
frames
|
List of Frame models to index.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
_by_id |
Index frames by ID.
TYPE:
|
_by_name |
Index frames by name (case-insensitive).
TYPE:
|
_by_fe_name |
Index frames by frame element names.
TYPE:
|
_by_lu_name |
Index frames by lexical unit names.
TYPE:
|
_by_definition |
Index frames by words in definition.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get_frame_by_id |
Get frame by ID. |
get_frame_by_name |
Get frame by name (case-insensitive). |
find_frames_with_fe |
Find frames containing a specific frame element. |
find_frames_with_lu |
Find frames containing a specific lexical unit. |
search_definitions |
Search frames by definition text. |
get_all_frame_names |
Get sorted list of all frame names. |
get_statistics |
Get index statistics. |
Initialize frame index.
| PARAMETER | DESCRIPTION |
|---|---|
frames
|
Frames to index. If None, creates empty index.
TYPE:
|
Source code in src/glazing/framenet/loader.py
Functions¶
add_frame(frame: Frame) -> None
¶
Add a single frame to the index.
| PARAMETER | DESCRIPTION |
|---|---|
frame
|
Frame to add to index.
TYPE:
|
Source code in src/glazing/framenet/loader.py
add_frames(frames: list[Frame]) -> None
¶
Add frames to the index.
| PARAMETER | DESCRIPTION |
|---|---|
frames
|
Frames to add to index.
TYPE:
|
find_frames_with_fe(fe_name: str) -> list[Frame]
¶
Find frames containing a specific frame element.
| PARAMETER | DESCRIPTION |
|---|---|
fe_name
|
Frame element name to search for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
Frames containing the frame element. |
Source code in src/glazing/framenet/loader.py
find_frames_with_lu(lu_name: str) -> list[Frame]
¶
Find frames containing a specific lexical unit.
| PARAMETER | DESCRIPTION |
|---|---|
lu_name
|
Lexical unit name (lemma) to search for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
Frames containing the lexical unit. |
Source code in src/glazing/framenet/loader.py
get_all_frame_names() -> list[str]
¶
Get sorted list of all frame names.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
Sorted frame names. |
get_frame_by_id(frame_id: FrameID) -> Frame | None
¶
Get frame by ID.
| PARAMETER | DESCRIPTION |
|---|---|
frame_id
|
Frame ID to look up.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Frame | None
|
Frame if found, None otherwise. |
Source code in src/glazing/framenet/loader.py
get_frame_by_name(name: str) -> Frame | None
¶
Get frame by name (case-insensitive).
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Frame name to look up.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Frame | None
|
Frame if found, None otherwise. |
Source code in src/glazing/framenet/loader.py
get_statistics() -> dict[str, int]
¶
Get index statistics.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
Dictionary with index statistics. |
Source code in src/glazing/framenet/loader.py
search_definitions(query: str) -> list[Frame]
¶
Search frames by definition text.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Search query (single word or phrase).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
Frames with definitions containing the query. |
Source code in src/glazing/framenet/loader.py
FrameNetLoader(data_path: Path | str | None = None, lazy: bool = False, autoload: bool = True, cache_size: int = 1000)
¶
Load FrameNet data from JSON Lines format with automatic loading.
Handles loading of Frame and LexicalUnit models from JSON Lines files with validation, lazy loading, and index building capabilities. By default, data is loaded automatically on initialization.
| PARAMETER | DESCRIPTION |
|---|---|
data_path
|
Path to FrameNet JSON Lines file. If None, uses default path.
TYPE:
|
lazy
|
Whether to use lazy loading.
TYPE:
|
autoload
|
Whether to automatically load data on initialization. Only applies when lazy=False.
TYPE:
|
cache_size
|
Number of items to cache when using lazy loading.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
frames |
Property that returns loaded frames, loading them if needed.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
load |
Load all frames from the data file. |
load_frames |
Load Frame models from JSON Lines file. |
load_lexical_units |
Load LexicalUnit models from JSON Lines file. |
load_semantic_types |
Load SemanticType models from JSON Lines file. |
build_frame_index |
Build searchable index from frames data. |
load_and_index_frames |
Load frames and build index in one step. |
validate_frame_data |
Validate frame data file without loading into memory. |
Examples:
>>> # Automatic loading (default)
>>> loader = FrameNetLoader()
>>> frames = loader.frames # Already loaded
>>>
>>> # Manual loading
>>> loader = FrameNetLoader(autoload=False)
>>> frames = loader.load()
Initialize FrameNet loader.
| PARAMETER | DESCRIPTION |
|---|---|
data_path
|
Path to FrameNet JSON Lines file. If None, uses default path from environment.
TYPE:
|
lazy
|
Whether to use lazy loading.
TYPE:
|
autoload
|
Whether to automatically load data on initialization. Only applies when lazy=False.
TYPE:
|
cache_size
|
Number of items to cache when using lazy loading.
TYPE:
|
Source code in src/glazing/framenet/loader.py
Attributes¶
frames: list[Frame]
property
¶
Get loaded frames.
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
List of loaded Frame models. Loads automatically if not yet loaded. |
Functions¶
build_frame_index(frames: list[Frame]) -> FrameIndex
¶
Build searchable index from frames data.
| PARAMETER | DESCRIPTION |
|---|---|
frames
|
Frames to index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FrameIndex
|
Searchable frame index. |
Source code in src/glazing/framenet/loader.py
load() -> list[Frame]
¶
Load all frames from the data file.
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
List of loaded Frame models. |
Source code in src/glazing/framenet/loader.py
load_and_index_frames(filepath: Path | str, skip_errors: bool = False) -> FrameIndex
¶
Load frames and build index in one step.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file containing Frame data.
TYPE:
|
skip_errors
|
If True, skip invalid lines rather than raising errors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FrameIndex
|
Loaded and indexed frames. |
Source code in src/glazing/framenet/loader.py
load_frames(filepath: Path | str | None = None, skip_errors: bool = False) -> list[Frame]
¶
Load Frame models from JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file containing Frame data. If None, uses the default data path from initialization.
TYPE:
|
skip_errors
|
If True, skip invalid lines rather than raising errors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
List of loaded Frame models. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
ValueError
|
If skip_errors=False and a line fails validation. |
Source code in src/glazing/framenet/loader.py
load_fulltext(filepath: Path | str | None = None, skip_errors: bool = False) -> list[Sentence]
¶
Load Sentence models from fulltext JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file containing Sentence data.
If None, looks for
TYPE:
|
skip_errors
|
If True, skip invalid lines rather than raising errors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Sentence]
|
List of loaded Sentence models. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
Source code in src/glazing/framenet/loader.py
load_lexical_units(filepath: Path | str, skip_errors: bool = False) -> list[LexicalUnit]
¶
Load LexicalUnit models from JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file containing LexicalUnit data.
TYPE:
|
skip_errors
|
If True, skip invalid lines rather than raising errors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LexicalUnit]
|
List of loaded LexicalUnit models. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
ValueError
|
If skip_errors=False and a line fails validation. |
Source code in src/glazing/framenet/loader.py
load_semantic_types(filepath: Path | str | None = None, skip_errors: bool = False) -> list[SemanticType]
¶
Load SemanticType models from JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file containing SemanticType data.
If None, looks for
TYPE:
|
skip_errors
|
If True, skip invalid lines rather than raising errors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[SemanticType]
|
List of loaded SemanticType models. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
ValueError
|
If skip_errors=False and a line fails validation. |
Source code in src/glazing/framenet/loader.py
validate_frame_data(filepath: Path | str) -> dict[str, str | int | float | list[str]]
¶
Validate frame data file without loading into memory.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str | int | float | list[str]]
|
Validation results including error counts and statistics. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
Source code in src/glazing/framenet/loader.py
Functions¶
build_frame_index(frames: list[Frame]) -> FrameIndex
¶
Build searchable index from frames data.
| PARAMETER | DESCRIPTION |
|---|---|
frames
|
Frames to index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FrameIndex
|
Searchable frame index. |
Source code in src/glazing/framenet/loader.py
load_and_index_frames(filepath: Path | str, skip_errors: bool = False) -> FrameIndex
¶
Load frames and build index in one step.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file.
TYPE:
|
skip_errors
|
Whether to skip invalid lines.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FrameIndex
|
Loaded and indexed frames. |
Source code in src/glazing/framenet/loader.py
load_frames(filepath: Path | str, skip_errors: bool = False) -> list[Frame]
¶
Load Frame models from JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file.
TYPE:
|
skip_errors
|
Whether to skip invalid lines.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Frame]
|
Loaded Frame models. |
Source code in src/glazing/framenet/loader.py
load_lexical_units(filepath: Path | str, skip_errors: bool = False) -> list[LexicalUnit]
¶
Load LexicalUnit models from JSON Lines file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to JSON Lines file.
TYPE:
|
skip_errors
|
Whether to skip invalid lines.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LexicalUnit]
|
Loaded LexicalUnit models. |