use std::error::Error;
use udgraph::graph::Sentence;
pub mod categorical;
pub mod dependency;
pub mod depseq;
pub mod layer;
pub mod lemma;
#[derive(Debug)]
pub struct EncodingProb<E> {
encoding: E,
prob: f32,
}
impl<E> EncodingProb<E>
where
E: ToOwned,
{
pub fn new(encoding: E, prob: f32) -> Self {
EncodingProb { encoding, prob }
}
pub fn encoding(&self) -> &E {
&self.encoding
}
pub fn prob(&self) -> f32 {
self.prob
}
}
impl<E> From<EncodingProb<E>> for (String, f32)
where
E: Clone + ToString,
{
fn from(prob: EncodingProb<E>) -> Self {
(prob.encoding().to_string(), prob.prob())
}
}
pub trait SentenceDecoder {
type Encoding: ToOwned;
type Error: Error;
fn decode<S>(&self, labels: &[S], sentence: &mut Sentence) -> Result<(), Self::Error>
where
S: AsRef<[EncodingProb<Self::Encoding>]>;
}
pub trait SentenceEncoder {
type Encoding;
type Error: Error;
fn encode(&self, sentence: &Sentence) -> Result<Vec<Self::Encoding>, Self::Error>;
}