pub struct DatasetLoader { /* private fields */ }Expand description
Loads and caches NER datasets.
§Caching Strategy (Tiered)
- Local cache (
~/.cache/anno/datasets/): Checked first, fastest - S3 cache (
s3://anno-data/): Checked ifANNO_S3_CACHE=1and AWS credentials available - URL download: Original source URL, last resort
This tiered approach:
- Maximizes speed (local cache hit is instant)
- Provides redundancy (S3 backup if original URLs go down)
- Allows sharing datasets across machines via S3
§Environment Variables
ANNO_CACHE_DIR: Override default cache locationANNO_S3_CACHE: Set to “1” to enable S3 fallback (requires AWS credentials)ANNO_S3_BUCKET: Override S3 bucket name (default:arc-anno-data)
§Example
# Enable S3 caching
export ANNO_S3_CACHE=1
export AWS_PROFILE=default # or set AWS_ACCESS_KEY_ID, etc.
# Now load_or_download() will try S3 before URLImplementations§
Source§impl DatasetLoader
impl DatasetLoader
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new loader with default cache directory.
Default location: ~/.cache/anno/datasets (platform cache via dirs crate)
Falls back to .anno/datasets in current directory if dirs crate unavailable.
S3 fallback is enabled if ANNO_S3_CACHE=1 environment variable is set.
Sourcepub fn with_cache_dir(cache_dir: impl Into<PathBuf>) -> Result<Self>
pub fn with_cache_dir(cache_dir: impl Into<PathBuf>) -> Result<Self>
Create a loader with a custom cache directory.
Sourcepub fn s3_enabled(&self) -> bool
pub fn s3_enabled(&self) -> bool
Whether S3 fallback caching is enabled.
Sourcepub fn cached_manifest_entries(&self) -> Vec<CacheManifestEntry>
pub fn cached_manifest_entries(&self) -> Vec<CacheManifestEntry>
Snapshot of cached dataset manifest entries (cloned).
This is intended for tooling (CLI/scripts) that wants to iterate cached datasets without holding the manifest lock for a long time.
Sourcepub fn upload_cached_dataset_to_s3(
&self,
bucket: &str,
id: DatasetId,
) -> Result<()>
pub fn upload_cached_dataset_to_s3( &self, bucket: &str, id: DatasetId, ) -> Result<()>
Upload a locally cached dataset (by DatasetId) to S3, using its manifest entry.
This uses the same object layout as load_or_download()’s best-effort upload:
datasets/<cache_filename>(legacy/mutable key)datasets/by-sha256/<sha>/<cache_filename>(immutable snapshot)datasets/<cache_filename>.latest.json(pointer)datasets/<cache_filename>.manifest.json(sidecar metadata)
Sourcepub fn cache_path(&self, id: LoadableDatasetId) -> PathBuf
pub fn cache_path(&self, id: LoadableDatasetId) -> PathBuf
Get the cache path for a dataset.
Sourcepub fn is_cached(&self, id: LoadableDatasetId) -> bool
pub fn is_cached(&self, id: LoadableDatasetId) -> bool
Check if a dataset is cached locally.
Sourcepub fn load(&self, id: LoadableDatasetId) -> Result<LoadedDataset>
pub fn load(&self, id: LoadableDatasetId) -> Result<LoadedDataset>
Load a dataset from cache.
Returns an error if the dataset is not cached.
Sourcepub fn load_or_download(&self, id: LoadableDatasetId) -> Result<LoadedDataset>
pub fn load_or_download(&self, id: LoadableDatasetId) -> Result<LoadedDataset>
Load or download a dataset.
Tries cache first, then S3 (if enabled), then downloads from URL.
Sourcepub fn parse_content_str(
&self,
content: &str,
id: DatasetId,
) -> Result<LoadedDataset>
pub fn parse_content_str( &self, content: &str, id: DatasetId, ) -> Result<LoadedDataset>
Parse content based on dataset format.
This is intentionally pub (behind the eval module) to enable offline evaluation
workflows and integration tests that want to exercise parsing without network I/O.
It does not download or read from cache. For typical usage, prefer
DatasetLoader::load_or_download / DatasetLoader::load.
Sourcepub fn load_coref(&self, id: DatasetId) -> Result<Vec<CorefDocument>>
pub fn load_coref(&self, id: DatasetId) -> Result<Vec<CorefDocument>>
Load coreference dataset, returning documents with chains.
Use this for GAP, PreCo, and LitBank datasets.
Sourcepub fn load_or_download_coref(
&self,
id: DatasetId,
) -> Result<Vec<CorefDocument>>
pub fn load_or_download_coref( &self, id: DatasetId, ) -> Result<Vec<CorefDocument>>
Load coreference dataset, downloading if needed.
Sourcepub fn load_relation(&self, id: DatasetId) -> Result<Vec<RelationDocument>>
pub fn load_relation(&self, id: DatasetId) -> Result<Vec<RelationDocument>>
Load relation extraction dataset, returning documents with relations.
Use this for DocRED and ReTACRED datasets.
Sourcepub fn load_or_download_relation(
&self,
id: DatasetId,
) -> Result<Vec<RelationDocument>>
pub fn load_or_download_relation( &self, id: DatasetId, ) -> Result<Vec<RelationDocument>>
Load relation extraction dataset, downloading if needed.
Sourcepub fn load_all_cached(&self) -> Vec<(DatasetId, Result<LoadedDataset>)>
pub fn load_all_cached(&self) -> Vec<(DatasetId, Result<LoadedDataset>)>
Load all cached datasets.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DatasetLoader
impl RefUnwindSafe for DatasetLoader
impl Send for DatasetLoader
impl Sync for DatasetLoader
impl Unpin for DatasetLoader
impl UnsafeUnpin for DatasetLoader
impl UnwindSafe for DatasetLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more