mwptoolkit.utils.preprocess_tool.equation_operator¶
- mwptoolkit.utils.preprocess_tool.equation_operator.EN_rule1_stat(datas, sample_k=100)[source]¶
equation norm rule1
- Parameters
datas (list) – dataset.
sample_k (int) – number of random sample.
- Returns
classified equations. equivalent equations will be in the same class.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.EN_rule2(equ_list)[source]¶
equation norm rule2
- Parameters
equ_list (list) – equation.
- Returns
equivalent equation.
- Return type
list
- mwptoolkit.utils.preprocess_tool.equation_operator.from_infix_to_multi_way_tree(expression)[source]¶
- mwptoolkit.utils.preprocess_tool.equation_operator.from_infix_to_postfix(expression)[source]¶
convert infix equation to postfix equation.
- Parameters
expression (list) – infix expression.
- Returns
postfix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.from_infix_to_prefix(expression)[source]¶
convert infix equation to prefix equation
- Parameters
expression (list) – infix expression.
- Returns
prefix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.from_postfix_to_infix(expression)[source]¶
convert postfix equation to infix equation
- Parameters
expression (list) – postfix expression.
- Returns
infix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.from_postfix_to_prefix(expression)[source]¶
convert postfix equation to prefix equation
- Parameters
expression (list) – postfix expression.
- Returns
prefix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.from_prefix_to_infix(expression)[source]¶
convert prefix equation to infix equation
- Parameters
expression (list) – prefix expression.
- Returns
infix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.from_prefix_to_postfix(expression)[source]¶
convert prefix equation to postfix equation
- Parameters
expression (list) – prefix expression.
- Returns
postfix expression.
- Return type
(list)
- mwptoolkit.utils.preprocess_tool.equation_operator.infix_to_postfix(equation, free_symbols: list, join_output: bool = True)[source]¶
- mwptoolkit.utils.preprocess_tool.equation_operator.orig_infix_to_postfix(equation: Union[str, List[str]], number_token_map: dict, free_symbols: list, join_output: bool = True)[source]¶
Read infix equation string and convert it into a postfix string
- Parameters
equation (Union[str,List[str]]) – Either one of these. - A single string of infix equation. e.g. “5 + 4” - Tokenized sequence of infix equation. e.g. [“5”, “+”, “4”]
number_token_map (dict) – Mapping from a number token to its anonymized representation (e.g. N_0)
free_symbols (list) – List of free symbols (for return)
join_output (bool) – True if the output need to be joined. Otherwise, this method will return the tokenized postfix sequence.
- Return type
Union[str, List[str]]
- Returns
Either one of these. - A single string of postfix equation. e.g. “5 4 +” - Tokenized sequence of postfix equation. e.g. [“5”, “4”, “+”]
- mwptoolkit.utils.preprocess_tool.equation_operator.postfix_parser(equation, memory: list) int [source]¶
Read Op-token postfix equation and transform it into Expression-token sequence.
- Parameters
equation (List[Union[str,Tuple[str,Any]]]) – List of op-tokens to be parsed into a Expression-token sequence Item of this list should be either - an operator string - a tuple of (operand source, operand value)
memory (list) – List where previous execution results of expressions are stored
- Return type
int
- Returns
Size of stack after processing. Value 1 means parsing was done without any free expression.