1515
1616class Formula (object ):
1717 """
18+ The part transform a formula to the parsed abstracted syntax tree.
19+
20+ Parameters
21+ ----------
22+ formula: str or List[Dict]
23+ latex formula string or the parsed abstracted syntax tree
24+ variable_standardization
25+ const_mathord
26+ init
27+ args
28+ kwargs
29+
1830 Examples
1931 --------
2032 >>> f = Formula("x")
@@ -29,22 +41,21 @@ class Formula(object):
2941 <Formula: x>
3042 >>> f.elements
3143 [{'id': 0, 'type': 'mathord', 'text': 'x', 'role': None, 'var': 0}]
32- """
3344
45+ Attributes
46+ ------------
47+ ast
48+ show all ast details
49+ elements
50+ just show elements' id, type, text and role
51+ ast_graph
52+ draw a ast graph
53+ to_str
54+ resetable
55+ return bool
56+ """
3457 def __init__ (self , formula : (str , List [Dict ]), variable_standardization = False , const_mathord = None ,
3558 init = True , * args , ** kwargs ):
36- """
37-
38- Parameters
39- ----------
40- formula: str or List[Dict]
41- latex formula string or the parsed abstracted syntax tree
42- variable_standardization
43- const_mathord
44- init
45- args
46- kwargs
47- """
4859 self ._formula = formula
4960 self ._ast = None
5061 if init is True :
@@ -55,6 +66,15 @@ def __init__(self, formula: (str, List[Dict]), variable_standardization=False, c
5566 )
5667
5768 def variable_standardization (self , inplace = False , const_mathord = None , variable_connect_dict = None ):
69+ """
70+ It makes same parmeters have the same number.
71+
72+ Parameters
73+ ----------
74+ inplace
75+ const_mathord
76+ variable_connect_dict
77+ """
5878 const_mathord = const_mathord if const_mathord is not None else CONST_MATHORD
5979 ast_tree = self ._ast if inplace else deepcopy (self ._ast )
6080 var_code = variable_connect_dict ["var_code" ] if variable_connect_dict is not None else {}
@@ -118,6 +138,26 @@ def resetable(self):
118138
119139class FormulaGroup (object ):
120140 """
141+ The part transform a group of formula to the parsed abstracted syntax forest.
142+
143+ Attributes
144+ ------------
145+ to_str
146+ ast
147+ show all ast details
148+ elements
149+ just show elements' id, type, text and role
150+ ast_graph
151+ draw a ast graph
152+
153+ Parameters
154+ ----------
155+ formula: str or List[Dict] or List[Formula]
156+ latex formula string or the parsed abstracted syntax tree or a group of parsed abstracted syntax tree
157+ variable_standardization
158+ const_mathord
159+ detach
160+
121161 Examples
122162 ---------
123163 >>> fg = FormulaGroup(["x + y", "y + x", "z + x"])
@@ -128,15 +168,16 @@ class FormulaGroup(object):
128168 <FormulaGroup: <Formula: x + y>;<Formula: y + x>;<Formula: z + x>>
129169 >>> fg = FormulaGroup(["x", Formula("y"), "x"])
130170 >>> fg.elements
131- [{'id': 0, 'type': 'mathord', 'text': 'x', 'role': None}, {'id': 1, 'type': 'mathord', 'text': 'y', 'role': None},\
132- {'id': 2, 'type': 'mathord', 'text': 'x', 'role': None}]
171+ [{'id': 0, 'type': 'mathord', 'text': 'x', 'role': None}, \
172+ {'id': 1, 'type': 'mathord', 'text': 'y', 'role': None}, \
173+ {'id': 2, 'type': 'mathord', 'text': 'x', 'role': None}]
133174 >>> fg = FormulaGroup(["x", Formula("y"), "x"], variable_standardization=True)
134175 >>> fg.elements
135176 [{'id': 0, 'type': 'mathord', 'text': 'x', 'role': None, 'var': 0}, \
136177 {'id': 1, 'type': 'mathord', 'text': 'y', 'role': None, 'var': 1}, \
137178 {'id': 2, 'type': 'mathord', 'text': 'x', 'role': None, 'var': 0}]
138- """
139179
180+ """
140181 def __init__ (self ,
141182 formula_list : (list , List [str ], List [Formula ]),
142183 variable_standardization = False ,
@@ -186,6 +227,15 @@ def __contains__(self, item) -> bool:
186227 return item in self ._formulas
187228
188229 def variable_standardization (self , inplace = False , const_mathord = None , variable_connect_dict = None ):
230+ """
231+ It makes same parmeters have the same number.
232+
233+ Parameters
234+ ----------
235+ inplace
236+ const_mathord
237+ variable_connect_dict
238+ """
189239 ret = []
190240 for formula in self ._formulas :
191241 ret .append (formula .variable_standardization (inplace = inplace , const_mathord = const_mathord ,
@@ -220,6 +270,15 @@ def ast_graph(self) -> (nx.Graph, nx.DiGraph):
220270
221271
222272def link_formulas (* formula : Formula , link_vars = True , ** kwargs ):
273+ """
274+
275+ Parameters
276+ ----------
277+ formula
278+ the parsed abstracted syntax tree
279+ link_vars
280+ kwargs
281+ """
223282 forest = []
224283 for form in formula :
225284 forest += form .reset_ast (
0 commit comments