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