1use std::error::Error;
4
5use conllu::graph::Sentence;
6
7pub mod categorical;
8
9pub mod deprel;
10
11pub mod layer;
12
13pub mod lemma;
14
15#[derive(Debug)]
17pub struct EncodingProb<E> {
18 encoding: E,
19 prob: f32,
20}
21
22impl<E> EncodingProb<E>
23where
24 E: ToOwned,
25{
26 pub fn new(encoding: E, prob: f32) -> Self {
30 EncodingProb { encoding, prob }
31 }
32
33 pub fn encoding(&self) -> &E {
35 &self.encoding
36 }
37
38 pub fn prob(&self) -> f32 {
40 self.prob
41 }
42}
43
44impl<E> From<EncodingProb<E>> for (String, f32)
45where
46 E: Clone + ToString,
47{
48 fn from(prob: EncodingProb<E>) -> Self {
49 (prob.encoding().to_string(), prob.prob())
50 }
51}
52
53pub trait SentenceDecoder {
58 type Encoding: ToOwned;
59
60 type Error: Error;
62
63 fn decode<S>(&self, labels: &[S], sentence: &mut Sentence) -> Result<(), Self::Error>
64 where
65 S: AsRef<[EncodingProb<Self::Encoding>]>;
66}
67
68pub trait SentenceEncoder {
73 type Encoding;
74
75 type Error: Error;
77
78 fn encode(&self, sentence: &Sentence) -> Result<Vec<Self::Encoding>, Self::Error>;
80}