mathparse 0.2.6__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mathparse-0.2.8/PKG-INFO +125 -0
- mathparse-0.2.8/README.md +99 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse/__init__.py +1 -1
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse/mathwords.py +2 -2
- mathparse-0.2.8/mathparse.egg-info/PKG-INFO +125 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/pyproject.toml +16 -1
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_complex_statements.py +2 -2
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_prefix_unary_operations.py +14 -2
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_replace_word_tokens.py +20 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_unary_operations.py +8 -0
- mathparse-0.2.6/PKG-INFO +0 -69
- mathparse-0.2.6/README.md +0 -43
- mathparse-0.2.6/mathparse.egg-info/PKG-INFO +0 -69
- {mathparse-0.2.6 → mathparse-0.2.8}/LICENSE +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse/mathparse.py +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse.egg-info/SOURCES.txt +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse.egg-info/dependency_links.txt +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse.egg-info/requires.txt +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/mathparse.egg-info/top_level.txt +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/setup.cfg +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_binary_operations.py +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_language_support.py +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_simplified_chinese.py +0 -0
- {mathparse-0.2.6 → mathparse-0.2.8}/tests/test_utils.py +0 -0
mathparse-0.2.8/PKG-INFO
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mathparse
|
|
3
|
+
Version: 0.2.8
|
|
4
|
+
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
|
+
Author: Gunther Cox
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Documentation, https://mathparse.chatterbot.us
|
|
8
|
+
Project-URL: Repository, https://github.com/gunthercox/mathparse
|
|
9
|
+
Project-URL: Changelog, https://github.com/gunthercox/mathparse/releases
|
|
10
|
+
Keywords: mathparse,mathematics,math,nlp,calculator,expression-parser,eval-alternative,safe-eval,multilingual,natural-language,postfix-notation,reverse-polish-notation,rpn,math-parser,expression-evaluator,secure-evaluation,language-processing,mathematical-expressions,formula-parser
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
+
Classifier: Topic :: Text Processing :: General
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Requires-Python: <3.15,>=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: flake8; extra == "test"
|
|
24
|
+
Requires-Dist: sphinx<9.0,>=7.4; extra == "test"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# mathparse
|
|
28
|
+
|
|
29
|
+
**A secure, multilingual mathematical expression evaluator for Python**
|
|
30
|
+
|
|
31
|
+
`mathparse` is a Python library that safely parses and evaluates mathematical expressions from strings, supporting both numeric operators and natural language words across 13+ languages. Unlike Python's dangerous `eval()` function, mathparse provides a secure, zero-dependency solution for evaluating user-provided mathematical expressions.
|
|
32
|
+
|
|
33
|
+
## Why mathparse?
|
|
34
|
+
|
|
35
|
+
✅ **Security First** - Never uses `eval()`, protecting against arbitrary code execution
|
|
36
|
+
✅ **Multilingual Support** - Parse math in English, Spanish, French, German, Chinese, and 8+ more languages
|
|
37
|
+
✅ **Zero Dependencies** - Pure Python implementation with no external requirements
|
|
38
|
+
✅ **Natural Language** - Understands "fifty times twenty plus ten" alongside standard notation
|
|
39
|
+
✅ **Production Ready** - Used in chatbots, calculators, voice assistants, and educational applications
|
|
40
|
+
✅ **Well Tested** - Comprehensive test suite ensuring reliability
|
|
41
|
+
|
|
42
|
+
## Quick Examples
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from mathparse import mathparse
|
|
46
|
+
|
|
47
|
+
# Standard numeric expressions
|
|
48
|
+
mathparse.parse('50 * (85 / 100)')
|
|
49
|
+
>>> 42.5
|
|
50
|
+
|
|
51
|
+
# Natural language in English
|
|
52
|
+
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
53
|
+
>>> 5400
|
|
54
|
+
|
|
55
|
+
# Mixed notation
|
|
56
|
+
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
57
|
+
>>> 24
|
|
58
|
+
|
|
59
|
+
# Other languages (French, Spanish, German, Chinese, etc.)
|
|
60
|
+
mathparse.parse('cinq plus trois', language='FRE')
|
|
61
|
+
>>> 8
|
|
62
|
+
|
|
63
|
+
mathparse.parse('cinco más tres', language='ESP')
|
|
64
|
+
>>> 8
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Use Cases
|
|
68
|
+
|
|
69
|
+
- 🤖 **Chatbots & Voice Assistants** - Parse natural language math queries
|
|
70
|
+
- 🧮 **Calculator Applications** - Build safe calculators that accept text input
|
|
71
|
+
- 📚 **Educational Software** - Evaluate student-provided math expressions
|
|
72
|
+
- 🌐 **Multilingual Apps** - Support math parsing in users' native languages
|
|
73
|
+
- 🔐 **Secure Code Evaluation** - Replace dangerous `eval()` calls with safe parsing
|
|
74
|
+
- 📊 **Data Processing** - Extract and calculate values from natural language text
|
|
75
|
+
|
|
76
|
+
## Security: Why Not eval()?
|
|
77
|
+
|
|
78
|
+
Python's `eval()` function executes arbitrary code, creating severe security vulnerabilities:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# DANGEROUS - Never do this with user input!
|
|
82
|
+
eval("__import__('os').system('rm -rf /')") # Deletes files
|
|
83
|
+
eval("__import__('requests').get('evil.com')") # Network access
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**mathparse is the safe alternative:**
|
|
87
|
+
|
|
88
|
+
| Feature | eval() | mathparse |
|
|
89
|
+
|---------|--------|-----------|
|
|
90
|
+
| Mathematical expressions | ✅ | ✅ |
|
|
91
|
+
| Arbitrary code execution | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
92
|
+
| File system access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
93
|
+
| Network access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
94
|
+
| Import statements | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
95
|
+
| Security risk | 🔴 **CRITICAL** | 🟢 Safe |
|
|
96
|
+
| Dependencies | 0 | 0 |
|
|
97
|
+
| Natural language support | ❌ No | ✅ Yes |
|
|
98
|
+
| Multilingual | ❌ No | ✅ 13+ languages |
|
|
99
|
+
|
|
100
|
+
mathparse uses [postfix (Reverse Polish) notation](https://mathparse.chatterbot.us/postfix/) internally, ensuring only valid mathematical operations are performed. See our [security documentation](https://mathparse.chatterbot.us/postfix/) for technical details.
|
|
101
|
+
|
|
102
|
+
## Performance
|
|
103
|
+
|
|
104
|
+
- **Fast**: Simple numeric expressions parse in microseconds
|
|
105
|
+
- **Efficient**: Minimal memory footprint, suitable for high-volume applications
|
|
106
|
+
- **Scalable**: Linear time complexity for expression evaluation
|
|
107
|
+
|
|
108
|
+
## Language Support
|
|
109
|
+
|
|
110
|
+
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
111
|
+
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
112
|
+
|
|
113
|
+
## Installation
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install mathparse
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Documentation
|
|
120
|
+
|
|
121
|
+
See the full documentation at https://mathparse.chatterbot.us
|
|
122
|
+
|
|
123
|
+
## Changelog
|
|
124
|
+
|
|
125
|
+
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# mathparse
|
|
2
|
+
|
|
3
|
+
**A secure, multilingual mathematical expression evaluator for Python**
|
|
4
|
+
|
|
5
|
+
`mathparse` is a Python library that safely parses and evaluates mathematical expressions from strings, supporting both numeric operators and natural language words across 13+ languages. Unlike Python's dangerous `eval()` function, mathparse provides a secure, zero-dependency solution for evaluating user-provided mathematical expressions.
|
|
6
|
+
|
|
7
|
+
## Why mathparse?
|
|
8
|
+
|
|
9
|
+
✅ **Security First** - Never uses `eval()`, protecting against arbitrary code execution
|
|
10
|
+
✅ **Multilingual Support** - Parse math in English, Spanish, French, German, Chinese, and 8+ more languages
|
|
11
|
+
✅ **Zero Dependencies** - Pure Python implementation with no external requirements
|
|
12
|
+
✅ **Natural Language** - Understands "fifty times twenty plus ten" alongside standard notation
|
|
13
|
+
✅ **Production Ready** - Used in chatbots, calculators, voice assistants, and educational applications
|
|
14
|
+
✅ **Well Tested** - Comprehensive test suite ensuring reliability
|
|
15
|
+
|
|
16
|
+
## Quick Examples
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from mathparse import mathparse
|
|
20
|
+
|
|
21
|
+
# Standard numeric expressions
|
|
22
|
+
mathparse.parse('50 * (85 / 100)')
|
|
23
|
+
>>> 42.5
|
|
24
|
+
|
|
25
|
+
# Natural language in English
|
|
26
|
+
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
27
|
+
>>> 5400
|
|
28
|
+
|
|
29
|
+
# Mixed notation
|
|
30
|
+
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
31
|
+
>>> 24
|
|
32
|
+
|
|
33
|
+
# Other languages (French, Spanish, German, Chinese, etc.)
|
|
34
|
+
mathparse.parse('cinq plus trois', language='FRE')
|
|
35
|
+
>>> 8
|
|
36
|
+
|
|
37
|
+
mathparse.parse('cinco más tres', language='ESP')
|
|
38
|
+
>>> 8
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Use Cases
|
|
42
|
+
|
|
43
|
+
- 🤖 **Chatbots & Voice Assistants** - Parse natural language math queries
|
|
44
|
+
- 🧮 **Calculator Applications** - Build safe calculators that accept text input
|
|
45
|
+
- 📚 **Educational Software** - Evaluate student-provided math expressions
|
|
46
|
+
- 🌐 **Multilingual Apps** - Support math parsing in users' native languages
|
|
47
|
+
- 🔐 **Secure Code Evaluation** - Replace dangerous `eval()` calls with safe parsing
|
|
48
|
+
- 📊 **Data Processing** - Extract and calculate values from natural language text
|
|
49
|
+
|
|
50
|
+
## Security: Why Not eval()?
|
|
51
|
+
|
|
52
|
+
Python's `eval()` function executes arbitrary code, creating severe security vulnerabilities:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
# DANGEROUS - Never do this with user input!
|
|
56
|
+
eval("__import__('os').system('rm -rf /')") # Deletes files
|
|
57
|
+
eval("__import__('requests').get('evil.com')") # Network access
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**mathparse is the safe alternative:**
|
|
61
|
+
|
|
62
|
+
| Feature | eval() | mathparse |
|
|
63
|
+
|---------|--------|-----------|
|
|
64
|
+
| Mathematical expressions | ✅ | ✅ |
|
|
65
|
+
| Arbitrary code execution | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
66
|
+
| File system access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
67
|
+
| Network access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
68
|
+
| Import statements | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
69
|
+
| Security risk | 🔴 **CRITICAL** | 🟢 Safe |
|
|
70
|
+
| Dependencies | 0 | 0 |
|
|
71
|
+
| Natural language support | ❌ No | ✅ Yes |
|
|
72
|
+
| Multilingual | ❌ No | ✅ 13+ languages |
|
|
73
|
+
|
|
74
|
+
mathparse uses [postfix (Reverse Polish) notation](https://mathparse.chatterbot.us/postfix/) internally, ensuring only valid mathematical operations are performed. See our [security documentation](https://mathparse.chatterbot.us/postfix/) for technical details.
|
|
75
|
+
|
|
76
|
+
## Performance
|
|
77
|
+
|
|
78
|
+
- **Fast**: Simple numeric expressions parse in microseconds
|
|
79
|
+
- **Efficient**: Minimal memory footprint, suitable for high-volume applications
|
|
80
|
+
- **Scalable**: Linear time complexity for expression evaluation
|
|
81
|
+
|
|
82
|
+
## Language Support
|
|
83
|
+
|
|
84
|
+
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
85
|
+
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
86
|
+
|
|
87
|
+
## Installation
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install mathparse
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
See the full documentation at https://mathparse.chatterbot.us
|
|
96
|
+
|
|
97
|
+
## Changelog
|
|
98
|
+
|
|
99
|
+
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mathparse
|
|
3
|
+
Version: 0.2.8
|
|
4
|
+
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
|
+
Author: Gunther Cox
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Documentation, https://mathparse.chatterbot.us
|
|
8
|
+
Project-URL: Repository, https://github.com/gunthercox/mathparse
|
|
9
|
+
Project-URL: Changelog, https://github.com/gunthercox/mathparse/releases
|
|
10
|
+
Keywords: mathparse,mathematics,math,nlp,calculator,expression-parser,eval-alternative,safe-eval,multilingual,natural-language,postfix-notation,reverse-polish-notation,rpn,math-parser,expression-evaluator,secure-evaluation,language-processing,mathematical-expressions,formula-parser
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
+
Classifier: Topic :: Text Processing :: General
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Requires-Python: <3.15,>=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: flake8; extra == "test"
|
|
24
|
+
Requires-Dist: sphinx<9.0,>=7.4; extra == "test"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# mathparse
|
|
28
|
+
|
|
29
|
+
**A secure, multilingual mathematical expression evaluator for Python**
|
|
30
|
+
|
|
31
|
+
`mathparse` is a Python library that safely parses and evaluates mathematical expressions from strings, supporting both numeric operators and natural language words across 13+ languages. Unlike Python's dangerous `eval()` function, mathparse provides a secure, zero-dependency solution for evaluating user-provided mathematical expressions.
|
|
32
|
+
|
|
33
|
+
## Why mathparse?
|
|
34
|
+
|
|
35
|
+
✅ **Security First** - Never uses `eval()`, protecting against arbitrary code execution
|
|
36
|
+
✅ **Multilingual Support** - Parse math in English, Spanish, French, German, Chinese, and 8+ more languages
|
|
37
|
+
✅ **Zero Dependencies** - Pure Python implementation with no external requirements
|
|
38
|
+
✅ **Natural Language** - Understands "fifty times twenty plus ten" alongside standard notation
|
|
39
|
+
✅ **Production Ready** - Used in chatbots, calculators, voice assistants, and educational applications
|
|
40
|
+
✅ **Well Tested** - Comprehensive test suite ensuring reliability
|
|
41
|
+
|
|
42
|
+
## Quick Examples
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from mathparse import mathparse
|
|
46
|
+
|
|
47
|
+
# Standard numeric expressions
|
|
48
|
+
mathparse.parse('50 * (85 / 100)')
|
|
49
|
+
>>> 42.5
|
|
50
|
+
|
|
51
|
+
# Natural language in English
|
|
52
|
+
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
53
|
+
>>> 5400
|
|
54
|
+
|
|
55
|
+
# Mixed notation
|
|
56
|
+
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
57
|
+
>>> 24
|
|
58
|
+
|
|
59
|
+
# Other languages (French, Spanish, German, Chinese, etc.)
|
|
60
|
+
mathparse.parse('cinq plus trois', language='FRE')
|
|
61
|
+
>>> 8
|
|
62
|
+
|
|
63
|
+
mathparse.parse('cinco más tres', language='ESP')
|
|
64
|
+
>>> 8
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Use Cases
|
|
68
|
+
|
|
69
|
+
- 🤖 **Chatbots & Voice Assistants** - Parse natural language math queries
|
|
70
|
+
- 🧮 **Calculator Applications** - Build safe calculators that accept text input
|
|
71
|
+
- 📚 **Educational Software** - Evaluate student-provided math expressions
|
|
72
|
+
- 🌐 **Multilingual Apps** - Support math parsing in users' native languages
|
|
73
|
+
- 🔐 **Secure Code Evaluation** - Replace dangerous `eval()` calls with safe parsing
|
|
74
|
+
- 📊 **Data Processing** - Extract and calculate values from natural language text
|
|
75
|
+
|
|
76
|
+
## Security: Why Not eval()?
|
|
77
|
+
|
|
78
|
+
Python's `eval()` function executes arbitrary code, creating severe security vulnerabilities:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# DANGEROUS - Never do this with user input!
|
|
82
|
+
eval("__import__('os').system('rm -rf /')") # Deletes files
|
|
83
|
+
eval("__import__('requests').get('evil.com')") # Network access
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**mathparse is the safe alternative:**
|
|
87
|
+
|
|
88
|
+
| Feature | eval() | mathparse |
|
|
89
|
+
|---------|--------|-----------|
|
|
90
|
+
| Mathematical expressions | ✅ | ✅ |
|
|
91
|
+
| Arbitrary code execution | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
92
|
+
| File system access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
93
|
+
| Network access | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
94
|
+
| Import statements | ⚠️ **YES - DANGEROUS** | ❌ No |
|
|
95
|
+
| Security risk | 🔴 **CRITICAL** | 🟢 Safe |
|
|
96
|
+
| Dependencies | 0 | 0 |
|
|
97
|
+
| Natural language support | ❌ No | ✅ Yes |
|
|
98
|
+
| Multilingual | ❌ No | ✅ 13+ languages |
|
|
99
|
+
|
|
100
|
+
mathparse uses [postfix (Reverse Polish) notation](https://mathparse.chatterbot.us/postfix/) internally, ensuring only valid mathematical operations are performed. See our [security documentation](https://mathparse.chatterbot.us/postfix/) for technical details.
|
|
101
|
+
|
|
102
|
+
## Performance
|
|
103
|
+
|
|
104
|
+
- **Fast**: Simple numeric expressions parse in microseconds
|
|
105
|
+
- **Efficient**: Minimal memory footprint, suitable for high-volume applications
|
|
106
|
+
- **Scalable**: Linear time complexity for expression evaluation
|
|
107
|
+
|
|
108
|
+
## Language Support
|
|
109
|
+
|
|
110
|
+
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
111
|
+
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
112
|
+
|
|
113
|
+
## Installation
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install mathparse
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Documentation
|
|
120
|
+
|
|
121
|
+
See the full documentation at https://mathparse.chatterbot.us
|
|
122
|
+
|
|
123
|
+
## Changelog
|
|
124
|
+
|
|
125
|
+
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
|
@@ -12,7 +12,7 @@ version = {attr = "mathparse.__version__"}
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "mathparse"
|
|
15
|
-
requires-python = ">=3.
|
|
15
|
+
requires-python = ">=3.10,<3.15"
|
|
16
16
|
urls = { Documentation = "https://mathparse.chatterbot.us", Repository = "https://github.com/gunthercox/mathparse", Changelog = "https://github.com/gunthercox/mathparse/releases" }
|
|
17
17
|
authors = [
|
|
18
18
|
{name = "Gunther Cox"},
|
|
@@ -26,6 +26,21 @@ keywords = [
|
|
|
26
26
|
"mathematics",
|
|
27
27
|
"math",
|
|
28
28
|
"nlp",
|
|
29
|
+
"calculator",
|
|
30
|
+
"expression-parser",
|
|
31
|
+
"eval-alternative",
|
|
32
|
+
"safe-eval",
|
|
33
|
+
"multilingual",
|
|
34
|
+
"natural-language",
|
|
35
|
+
"postfix-notation",
|
|
36
|
+
"reverse-polish-notation",
|
|
37
|
+
"rpn",
|
|
38
|
+
"math-parser",
|
|
39
|
+
"expression-evaluator",
|
|
40
|
+
"secure-evaluation",
|
|
41
|
+
"language-processing",
|
|
42
|
+
"mathematical-expressions",
|
|
43
|
+
"formula-parser",
|
|
29
44
|
]
|
|
30
45
|
classifiers = [
|
|
31
46
|
"Development Status :: 4 - Beta",
|
|
@@ -70,11 +70,11 @@ class ComplexStatementsTestCase(TestCase):
|
|
|
70
70
|
Test using the unicode π symbol as a constant.
|
|
71
71
|
"""
|
|
72
72
|
result = mathparse.parse('2 * π')
|
|
73
|
-
self.assertAlmostEqual(result, 2 * 3.
|
|
73
|
+
self.assertAlmostEqual(result, 2 * 3.141593, places=5)
|
|
74
74
|
|
|
75
75
|
def test_unicode_pi_in_expression(self):
|
|
76
76
|
"""
|
|
77
77
|
Test using the unicode π symbol in a complex expression.
|
|
78
78
|
"""
|
|
79
79
|
result = mathparse.parse('π + 1')
|
|
80
|
-
self.assertAlmostEqual(result, 3.
|
|
80
|
+
self.assertAlmostEqual(result, 3.141593 + 1, places=5)
|
|
@@ -155,7 +155,13 @@ class NegativeWithUnaryFunctionsTestCase(TestCase):
|
|
|
155
155
|
# Verify it causes the expected math error
|
|
156
156
|
with self.assertRaises(ValueError) as context:
|
|
157
157
|
mathparse.parse('sqrt -16')
|
|
158
|
-
|
|
158
|
+
# Python 3.14+ uses more specific error messages
|
|
159
|
+
error_msg = str(context.exception).lower()
|
|
160
|
+
self.assertTrue(
|
|
161
|
+
"math domain error" in error_msg or
|
|
162
|
+
"expected a nonnegative input" in error_msg,
|
|
163
|
+
f"Unexpected error message: {error_msg}"
|
|
164
|
+
)
|
|
159
165
|
|
|
160
166
|
def test_log_with_negative_causes_math_error(self):
|
|
161
167
|
"""
|
|
@@ -168,7 +174,13 @@ class NegativeWithUnaryFunctionsTestCase(TestCase):
|
|
|
168
174
|
# Verify it causes the expected math error
|
|
169
175
|
with self.assertRaises(ValueError) as context:
|
|
170
176
|
mathparse.parse('log -10')
|
|
171
|
-
|
|
177
|
+
# Python 3.14+ uses more specific error messages
|
|
178
|
+
error_msg = str(context.exception).lower()
|
|
179
|
+
self.assertTrue(
|
|
180
|
+
"math domain error" in error_msg or
|
|
181
|
+
"expected a positive input" in error_msg,
|
|
182
|
+
f"Unexpected error message: {error_msg}"
|
|
183
|
+
)
|
|
172
184
|
|
|
173
185
|
def test_sqrt_with_positive_after_operator(self):
|
|
174
186
|
"""
|
|
@@ -52,12 +52,32 @@ class EnglishWordTokenTestCase(TestCase):
|
|
|
52
52
|
)
|
|
53
53
|
self.assertEqual(result, '19 * (50 + 4)')
|
|
54
54
|
|
|
55
|
+
def test_tens_with_compound_numbers(self):
|
|
56
|
+
result = mathparse.replace_word_tokens(
|
|
57
|
+
'ninety seven - 7', language='ENG'
|
|
58
|
+
)
|
|
59
|
+
self.assertEqual(result, '(90 + 7) - 7')
|
|
60
|
+
|
|
61
|
+
def test_tens_with_compound_numbers_hyphenated(self):
|
|
62
|
+
result = mathparse.replace_word_tokens(
|
|
63
|
+
'ninety-seven - 7', language='ENG'
|
|
64
|
+
)
|
|
65
|
+
self.assertEqual(result, '(90 + 7) - 7')
|
|
66
|
+
|
|
55
67
|
def test_tens_and_hundreds_with_spaces(self):
|
|
56
68
|
result = mathparse.replace_word_tokens(
|
|
57
69
|
'one hundred times fifty four', language='ENG'
|
|
58
70
|
)
|
|
59
71
|
self.assertEqual(result, '(1 * 100) * (50 + 4)')
|
|
60
72
|
|
|
73
|
+
def test_tens_with_hundreds_multiplier(self):
|
|
74
|
+
result = mathparse.replace_word_tokens(
|
|
75
|
+
'eighteen hundred and twenty-one',
|
|
76
|
+
language='ENG',
|
|
77
|
+
stopwords={'and'}
|
|
78
|
+
)
|
|
79
|
+
self.assertEqual(result, '(18 * 100) + (20 + 1)')
|
|
80
|
+
|
|
61
81
|
def test_hyphenated_numbers(self):
|
|
62
82
|
result = mathparse.replace_word_tokens(
|
|
63
83
|
'one hundred times fifty-four', language='ENG'
|
|
@@ -37,6 +37,14 @@ class UnaryWordOperatorTestCase(TestCase):
|
|
|
37
37
|
|
|
38
38
|
self.assertEqual(result, 2)
|
|
39
39
|
|
|
40
|
+
def test_square_root_with_decimal(self):
|
|
41
|
+
mathparse.parse('sqrt(4) . 5')
|
|
42
|
+
|
|
43
|
+
# TODO: Should this raise a parsing error instead of
|
|
44
|
+
# returning a number (2.5)?
|
|
45
|
+
|
|
46
|
+
raise self.skipTest('Skip until decision is made on expected behavior')
|
|
47
|
+
|
|
40
48
|
def test_negative_number(self):
|
|
41
49
|
result = mathparse.parse('-4 + 2')
|
|
42
50
|
|
mathparse-0.2.6/PKG-INFO
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: mathparse
|
|
3
|
-
Version: 0.2.6
|
|
4
|
-
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
|
-
Author: Gunther Cox
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Documentation, https://mathparse.chatterbot.us
|
|
8
|
-
Project-URL: Repository, https://github.com/gunthercox/mathparse
|
|
9
|
-
Project-URL: Changelog, https://github.com/gunthercox/mathparse/releases
|
|
10
|
-
Keywords: mathparse,mathematics,math,nlp
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
-
Classifier: Topic :: Text Processing :: General
|
|
17
|
-
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
-
Classifier: Programming Language :: Python
|
|
19
|
-
Requires-Python: <3.14,>=3.9
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
License-File: LICENSE
|
|
22
|
-
Provides-Extra: test
|
|
23
|
-
Requires-Dist: flake8; extra == "test"
|
|
24
|
-
Requires-Dist: sphinx<9.0,>=7.4; extra == "test"
|
|
25
|
-
Dynamic: license-file
|
|
26
|
-
|
|
27
|
-
# mathparse
|
|
28
|
-
|
|
29
|
-
The `mathparse` library is a Python module designed to evaluate mathematical equations contained in strings.
|
|
30
|
-
|
|
31
|
-
Here are a few examples:
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
from mathparse import mathparse
|
|
35
|
-
|
|
36
|
-
mathparse.parse('50 * (85 / 100)')
|
|
37
|
-
>>> 42.5
|
|
38
|
-
|
|
39
|
-
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
40
|
-
>>> 5400
|
|
41
|
-
|
|
42
|
-
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
43
|
-
>>> 24
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Security
|
|
47
|
-
|
|
48
|
-
Mathparse does not employ the use of Python's [`eval` function](https://docs.python.org/3/library/functions.html#eval) when evaluating provided mathematical expressions. This is a measure to prevent arbitrary code execution vulnerabilities. See https://mathparse.chatterbot.us/postfix/ for additional details.
|
|
49
|
-
|
|
50
|
-
Mathparse is a standalone Python package and requires zero dependencies to function.
|
|
51
|
-
|
|
52
|
-
## Language Support
|
|
53
|
-
|
|
54
|
-
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
55
|
-
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
pip install mathparse
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Documentation
|
|
64
|
-
|
|
65
|
-
See the full documentation at https://mathparse.chatterbot.us
|
|
66
|
-
|
|
67
|
-
## Changelog
|
|
68
|
-
|
|
69
|
-
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
mathparse-0.2.6/README.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# mathparse
|
|
2
|
-
|
|
3
|
-
The `mathparse` library is a Python module designed to evaluate mathematical equations contained in strings.
|
|
4
|
-
|
|
5
|
-
Here are a few examples:
|
|
6
|
-
|
|
7
|
-
```python
|
|
8
|
-
from mathparse import mathparse
|
|
9
|
-
|
|
10
|
-
mathparse.parse('50 * (85 / 100)')
|
|
11
|
-
>>> 42.5
|
|
12
|
-
|
|
13
|
-
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
14
|
-
>>> 5400
|
|
15
|
-
|
|
16
|
-
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
17
|
-
>>> 24
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Security
|
|
21
|
-
|
|
22
|
-
Mathparse does not employ the use of Python's [`eval` function](https://docs.python.org/3/library/functions.html#eval) when evaluating provided mathematical expressions. This is a measure to prevent arbitrary code execution vulnerabilities. See https://mathparse.chatterbot.us/postfix/ for additional details.
|
|
23
|
-
|
|
24
|
-
Mathparse is a standalone Python package and requires zero dependencies to function.
|
|
25
|
-
|
|
26
|
-
## Language Support
|
|
27
|
-
|
|
28
|
-
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
29
|
-
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pip install mathparse
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Documentation
|
|
38
|
-
|
|
39
|
-
See the full documentation at https://mathparse.chatterbot.us
|
|
40
|
-
|
|
41
|
-
## Changelog
|
|
42
|
-
|
|
43
|
-
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: mathparse
|
|
3
|
-
Version: 0.2.6
|
|
4
|
-
Summary: mathparse is a library for solving mathematical equations contained in strings
|
|
5
|
-
Author: Gunther Cox
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Documentation, https://mathparse.chatterbot.us
|
|
8
|
-
Project-URL: Repository, https://github.com/gunthercox/mathparse
|
|
9
|
-
Project-URL: Changelog, https://github.com/gunthercox/mathparse/releases
|
|
10
|
-
Keywords: mathparse,mathematics,math,nlp
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
-
Classifier: Topic :: Text Processing :: General
|
|
17
|
-
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
-
Classifier: Programming Language :: Python
|
|
19
|
-
Requires-Python: <3.14,>=3.9
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
License-File: LICENSE
|
|
22
|
-
Provides-Extra: test
|
|
23
|
-
Requires-Dist: flake8; extra == "test"
|
|
24
|
-
Requires-Dist: sphinx<9.0,>=7.4; extra == "test"
|
|
25
|
-
Dynamic: license-file
|
|
26
|
-
|
|
27
|
-
# mathparse
|
|
28
|
-
|
|
29
|
-
The `mathparse` library is a Python module designed to evaluate mathematical equations contained in strings.
|
|
30
|
-
|
|
31
|
-
Here are a few examples:
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
from mathparse import mathparse
|
|
35
|
-
|
|
36
|
-
mathparse.parse('50 * (85 / 100)')
|
|
37
|
-
>>> 42.5
|
|
38
|
-
|
|
39
|
-
mathparse.parse('one hundred times fifty four', language='ENG')
|
|
40
|
-
>>> 5400
|
|
41
|
-
|
|
42
|
-
mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
|
|
43
|
-
>>> 24
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Security
|
|
47
|
-
|
|
48
|
-
Mathparse does not employ the use of Python's [`eval` function](https://docs.python.org/3/library/functions.html#eval) when evaluating provided mathematical expressions. This is a measure to prevent arbitrary code execution vulnerabilities. See https://mathparse.chatterbot.us/postfix/ for additional details.
|
|
49
|
-
|
|
50
|
-
Mathparse is a standalone Python package and requires zero dependencies to function.
|
|
51
|
-
|
|
52
|
-
## Language Support
|
|
53
|
-
|
|
54
|
-
The language parameter must be set in order to evaluate an equation that uses word operators.
|
|
55
|
-
The language code should be a valid [ISO 639-2](https://www.loc.gov/standards/iso639-2/php/code_list.php) language code.
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
pip install mathparse
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Documentation
|
|
64
|
-
|
|
65
|
-
See the full documentation at https://mathparse.chatterbot.us
|
|
66
|
-
|
|
67
|
-
## Changelog
|
|
68
|
-
|
|
69
|
-
See [release notes](https://github.com/gunthercox/mathparse/releases) for changes.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|