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 SUPERGLUE_WIC_PACK: Pack = Pack {
	name: "superglue_wic",
	version: "1.0.0",
	license: "various (SuperGLUE collection)",
	files: &[PackFile {
		name: "WiC.zip",
		size: 396_213,
		shake256: "e96945cab4791290b8eaeb33cc02b4771850be6bf073d89f6c1637ba1f714737",
		urls: &["https://dl.fbaipublicfiles.com/glue/superglue/data/v2/WiC.zip"],
	}],
};

/// Split member selection.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SuperglueWicSplit {
	/// `train.jsonl` member.
	#[default]
	Train,
	/// `val.jsonl` member.
	Validation,
	/// `test.jsonl` member (unlabeled).
	Test,
}

/// Load options for [`SuperglueWic`][crate::text::superglue_wic::SuperglueWic].
#[derive(Clone, Debug)]
pub struct SuperglueWicConfig {
	/// Which split member to decode.
	pub split: SuperglueWicSplit,
	/// 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 SuperglueWicConfig {
	fn default() -> Self {
		Self {
			split: SuperglueWicSplit::Train,
			cache_dir: None,
		}
	}
}

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

impl super::SuperglueWic {
	/// 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: &SuperglueWicConfig) -> 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: &SuperglueWicConfig) -> 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: &SuperglueWicConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}