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_QQP_PACK: Pack = Pack {
	name: "glue_qqp",
	version: "1.0.0",
	license: "various (GLUE collection)",
	files: &[PackFile {
		name: "QQP.zip",
		size: 41_696_084,
		shake256: "06dd9ffb81cada2085b998104c5c7b174654d14978d8a34f3fb76d6800c1b613",
		urls: &["https://dl.fbaipublicfiles.com/glue/data/QQP.zip"],
	}],
};

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

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

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

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