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 ANLI_R3_PACK: Pack = Pack {
	name: "anli_r3",
	version: "1.0.0",
	license: "CC BY-NC-SA 4.0",
	files: &[PackFile {
		name: "anli_v1.0.zip",
		size: 18_708_061,
		shake256: "6f5c3a18039e4a58ee0bb2b4a7baeabf76297d596f4b3bd773dad89aa51a555a",
		urls: &["https://dl.fbaipublicfiles.com/anli/anli_v1.0.zip"],
	}],
};

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

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

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

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