rust_sbml/
mathml.rs

1use super::UnitSIdRef;
2use serde::{Deserialize, Serialize};
3
4/// Math attribute which contains MathNodes of the very partially implemented
5/// [MathML version 3.0 spec](https://www.w3.org/TR/2014/REC-MathML3-20140410).
6#[derive(Deserialize, Debug, Serialize, Eq, PartialEq, Clone)]
7pub struct Math {
8    #[serde(rename = "$value")]
9    pub content: MathNode,
10}
11
12/// Content identifier <ci>
13#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
14pub struct Apply {
15    #[serde(rename = "$value")]
16    pub content: Vec<MathNode>,
17}
18
19/// Content identifier <ci>
20#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
21pub struct Ci {
22    #[serde(rename = "$value")]
23    content: String,
24    #[serde(rename = "type")]
25    ci_type: Option<String>,
26}
27
28/// Content identifier <ci>
29#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
30#[serde(rename = "lowercase")]
31pub struct Bvar {
32    #[serde(rename = "$value")]
33    ci: Ci,
34    ci_type: Option<String>,
35}
36
37/// Number type (default to Real)
38#[derive(Debug, Serialize, Eq, PartialEq, Deserialize, Clone)]
39#[serde(rename_all = "camelCase")]
40pub enum NumberType {
41    Real,
42    Integer,
43    Rational,
44    ComplexCartesian,
45    ComplexPolar,
46    Constant,
47    ENotation,
48}
49
50impl Default for NumberType {
51    fn default() -> Self {
52        Self::Real
53    }
54}
55
56/// Base of a number (default to 10)
57#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
58pub struct Base(pub u32);
59
60impl Default for Base {
61    fn default() -> Self {
62        Base(10)
63    }
64}
65
66/// Numbers <cn>
67#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
68#[serde(rename_all = "camelCase")]
69pub struct Cn {
70    #[serde(rename = "$value")]
71    pub content: String,
72    #[serde(rename = "sbml:units")]
73    pub unit: Option<UnitSIdRef>,
74    #[serde(rename = "type", default)]
75    pub cn_type: NumberType,
76    #[serde(default)]
77    pub base: Base,
78    pub definition_url: Option<String>,
79    pub encoding: Option<String>,
80}
81
82/// Main node of MathML
83///
84/// Very partial implementation
85#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
86#[serde(rename_all = "camelCase")]
87pub enum MathNode {
88    Apply(Box<Apply>),
89    Text(String),
90    Ci {
91        #[serde(rename = "$value")]
92        content: String,
93        #[serde(rename = "type")]
94        ci_type: Option<String>,
95    },
96    Csymbol {
97        cd: Option<String>,
98        encoding: Option<String>,
99        #[serde(rename = "$value")]
100        children: Vec<MathNode>,
101    },
102    Cn(Cn),
103    Comment(String),
104    PI(String, Option<String>),
105    Lambda {
106        #[serde(rename = "$value")]
107        children: Vec<MathNode>,
108    },
109    Bvar,
110    // rest of operations
111    Factorial,
112    Minus,
113    Abs,
114    Conjugate,
115    Arg,
116    Real,
117    Imaginary,
118    Floor,
119    Ceiling,
120    Not,
121    Inverse,
122    Ident,
123    Domain,
124    Codomain,
125    Image,
126    Sin,
127    Cos,
128    Tan,
129    Sec,
130    Csc,
131    Cot,
132    Sinh,
133    Cosh,
134    Tanh,
135    Sech,
136    Csch,
137    Coth,
138    Arcsin,
139    Arccos,
140    Arctan,
141    Arccosh,
142    Arccot,
143    Arccoth,
144    Arccsc,
145    Arccsch,
146    Arcsec,
147    Arcsech,
148    Arcsinh,
149    Arctanh,
150    Exp,
151    Ln,
152    Log,
153    Determinant,
154    Transpose,
155    Divergence,
156    Grad,
157    Curl,
158    Laplacian,
159    Card,
160    Quotient,
161    Divide,
162    Power,
163    Rem,
164    Implies,
165    Equivalent,
166    Approx,
167    Setdiff,
168    Vectorproduct,
169    Scalarproduct,
170    Outerproduct,
171    Plus,
172    Times,
173    Max,
174    Min,
175    Gcd,
176    Lcm,
177    Mean,
178    Sdev,
179    Variance,
180    Median,
181    Mode,
182    And,
183    Or,
184    Xor,
185    Selector,
186    Union,
187    Intersect,
188    Cartesianproduct,
189    Compose,
190    #[serde(rename = "fn")]
191    Fun,
192    Int,
193    Sum,
194    Product,
195    Diff,
196    Partialdiff,
197    Forall,
198    Exists,
199    Eq,
200    Neq,
201    Gt,
202    Lt,
203    Geq,
204    Leq,
205    Root,
206}
207
208impl MathNode {
209    pub fn apply(x: Vec<MathNode>) -> Self {
210        MathNode::Apply(Box::new(Apply { content: x }))
211    }
212}