Utility functions¶
- exception mathparse.mathwords.InvalidLanguageCodeException[source]¶
Exception to be raised when a language code is given that is not a part of the ISO 639-2 standard.
- mathparse.mathwords.word_groups_for_language(language_code)[source]¶
Return the math word groups for a language code. The language_code should be an ISO 639-2 language code. https://www.loc.gov/standards/iso639-2/php/code_list.php
- mathparse.mathwords.words_for_language(language_code)[source]¶
Return the math words for a language code. The language_code should be an ISO 639-2 language code. https://www.loc.gov/standards/iso639-2/php/code_list.php
Parsing strings¶
Methods for evaluating mathematical equations in strings.
- exception mathparse.mathparse.PostfixTokenEvaluationException[source]¶
Exception to be raised when a language code is given that is not a part of the ISO 639-2 standard.
- mathparse.mathparse.evaluate_postfix(tokens)[source]¶
Given a list of evaluatable tokens in postfix format, calculate a solution.
- mathparse.mathparse.extract_expression(dirty_string, language)[source]¶
Give a string such as: “What is 4 + 4?” Return the string “4 + 4”
- mathparse.mathparse.find_word_groups(string, words)[source]¶
Find matches for words in the format “3 thousand 6 hundred 2”. The words parameter should be the list of words to check for such as “hundred”.
- mathparse.mathparse.is_binary(string)[source]¶
Return true if the string is a defined binary operator.
- mathparse.mathparse.is_constant(string)[source]¶
Return true if the string is a mathematical constant.
- mathparse.mathparse.is_unary(string)[source]¶
Return true if the string is a defined unary mathematical operator function.
- mathparse.mathparse.is_word(word, language)[source]¶
Return true if the word is a math word for the specified language.
- mathparse.mathparse.parse(string, language=None)[source]¶
Return a solution to the equation in the input string.
- mathparse.mathparse.replace_word_tokens(string, language)[source]¶
Given a string and an ISO 639-2 language code, return the string with the words replaced with an operational equivalent.