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_CB_PACK: Pack = Pack {
	name: "superglue_cb",
	version: "1.0.0",
	license: "various (SuperGLUE collection)",
	files: &[PackFile {
		name: "CB.zip",
		size: 75_482,
		shake256: "11ebabb13312c467a866beaeca9d6acfb3c06bde2e9f57001d7e335dc4d36d7e",
		urls: &["https://dl.fbaipublicfiles.com/glue/superglue/data/v2/CB.zip"],
	}],
};

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

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

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

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