oadsrust 0.3.0

Content-addressed dataset packs and loaders for OA
// @generated by tool/gen/ds/generate.py — edit tool/gen/ds/schema/packs.json instead.
use crate::core::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const GLUE_WNLI_PACK: Pack = Pack {
	name: "glue_wnli",
	version: "1.0.0",
	license: "various (GLUE collection)",
	files: &[PackFile {
		name: "WNLI.zip",
		size: 28_999,
		shake256: "d491ad3b8394cb55ca7adda2d164c8ad901c3cf654a6cae7d4f8381dc806affb",
		urls: &["https://dl.fbaipublicfiles.com/glue/data/WNLI.zip"],
	}],
};

/// GLUE split member selection.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum GlueWnliSplit {
	/// `train.tsv` member.
	#[default]
	Train,
	/// `dev.tsv` member.
	Validation,
}

/// Load options for [`GlueWnli`][crate::text::glue_wnli::GlueWnli].
#[derive(Clone, Debug)]
pub struct GlueWnliConfig {
	/// Which split member to decode.
	pub split: GlueWnliSplit,
	/// Cache root override. `None` resolves `OA_DATA_DIR`, then the platform
	/// cache directory; see [`data_root`](crate::pack::data_root).
	pub cache_dir: Option<PathBuf>,
}

impl Default for GlueWnliConfig {
	fn default() -> Self {
		Self {
			split: GlueWnliSplit::Train,
			cache_dir: None,
		}
	}
}

impl GlueWnliConfig {
	/// Construct the record with its default state.
	#[inline]
	#[must_use]
	pub fn new() -> Self {
		Self::default()
	}
}

impl super::GlueWnli {
	/// Decode the selected split and upload it on this thread's
	/// default engine.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_on`](Self::load_on).
	#[inline]
	pub fn load(config: &GlueWnliConfig) -> Result<Self> {
		Self::load_on(&Engine::current()?, config)
	}

	/// Decode the selected split and upload it on `engine`.
	///
	/// This is the [`load`](Self::load) contract evaluated on
	/// `engine` instead of this thread's default engine.
	///
	/// # Errors
	///
	/// Returns the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_on(engine: &Engine, config: &GlueWnliConfig) -> Result<Self> {
		Self::load_with_progress_on(engine, config, &mut |_| true)
	}

	/// [`load`](Self::load) with a fetch progress callback.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_with_progress(
		config: &GlueWnliConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}