use crate::{
TokenType,
UnifiedTokenVocab,
alloc::sync::Arc,
prelude::*,
pretrained::factory::vocab_query::VocabQuery,
};
#[derive(Debug, Clone)]
pub struct VocabDescription {
id: VocabQuery,
context: Vec<String>,
description: String,
}
impl VocabDescription {
pub fn new<Q, C, D>(
id: Q,
context: &[C],
description: D,
) -> Self
where
Q: Into<VocabQuery>,
C: AsRef<str>,
D: AsRef<str>,
{
let id = id.into();
let context = context.iter().map(|c| c.as_ref().to_string()).collect();
let description = description.as_ref().to_string();
Self {
id,
context,
description,
}
}
pub fn id(&self) -> &VocabQuery {
&self.id
}
pub fn context(&self) -> &[String] {
&self.context
}
pub fn description(&self) -> &str {
&self.description
}
}
#[derive(Debug, Clone)]
pub struct VocabListing {
source: String,
description: String,
vocabs: Vec<VocabDescription>,
}
impl VocabListing {
pub fn new(
source: &str,
description: &str,
vocabs: Vec<VocabDescription>,
) -> Self {
Self {
source: source.to_string(),
description: description.to_string(),
vocabs,
}
}
pub fn provider(&self) -> &str {
&self.source
}
pub fn description(&self) -> &str {
&self.description
}
pub fn vocabs(&self) -> &[VocabDescription] {
&self.vocabs
}
}
#[derive(Clone)]
pub struct LabeledVocab<T: TokenType> {
description: VocabDescription,
vocab: Arc<UnifiedTokenVocab<T>>,
}
impl<T: TokenType> LabeledVocab<T> {
pub fn new(
description: VocabDescription,
vocab: Arc<UnifiedTokenVocab<T>>,
) -> Self {
Self { description, vocab }
}
pub fn description(&self) -> &VocabDescription {
&self.description
}
pub fn vocab(&self) -> &Arc<UnifiedTokenVocab<T>> {
&self.vocab
}
}