syntaxdot_encoders/
lib.rs1use std::error::Error;
4
5use udgraph::graph::Sentence;
6
7pub mod categorical;
8
9pub mod dependency;
10
11pub mod depseq;
12
13pub mod layer;
14
15pub mod lang;
16
17pub mod lemma;
18
19#[derive(Debug)]
21pub struct EncodingProb<E> {
22 encoding: E,
23 prob: f32,
24}
25
26impl<E> EncodingProb<E>
27where
28 E: ToOwned,
29{
30 pub fn new(encoding: E, prob: f32) -> Self {
34 EncodingProb { encoding, prob }
35 }
36
37 pub fn encoding(&self) -> &E {
39 &self.encoding
40 }
41
42 pub fn prob(&self) -> f32 {
44 self.prob
45 }
46}
47
48impl<E> From<EncodingProb<E>> for (String, f32)
49where
50 E: Clone + ToString,
51{
52 fn from(prob: EncodingProb<E>) -> Self {
53 (prob.encoding().to_string(), prob.prob())
54 }
55}
56
57pub trait SentenceDecoder {
62 type Encoding: ToOwned;
63
64 type Error: Error;
66
67 fn decode<S>(&self, labels: &[S], sentence: &mut Sentence) -> Result<(), Self::Error>
68 where
69 S: AsRef<[EncodingProb<Self::Encoding>]>;
70}
71
72pub trait SentenceEncoder {
77 type Encoding;
78
79 type Error: Error;
81
82 fn encode(&self, sentence: &Sentence) -> Result<Vec<Self::Encoding>, Self::Error>;
84}