Skip to content

Commit 62735cf

Browse files
authored
Track changes in API, etc. (#29)
* Track changes in API, etc. * Add script to check version * Need dev mathics scanner * Use PatternLite instead of defunct pattern, but we get a loss in quality
1 parent e89bc27 commit 62735cf

File tree

8 files changed

+49
-19
lines changed

8 files changed

+49
-19
lines changed

.github/workflows/consistency-checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
# python -m pip install --upgrade pip
2424
python -m pip install pytest
2525
# Can comment out when next Mathics3 core and Mathics-scanner are released
26-
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
26+
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
2727
python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
28-
(cd src/mathics3 && bash ./admin-tools/make-op-tables.sh)
28+
(cd src/mathics3 && bash ./admin-tools/make-JSON-tables.sh)
2929
# python -m pip install Mathics3[full]
3030
- name: Install Pymathics.natlang
3131
run: |

.github/workflows/ubuntu.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
# python -m pip install --upgrade pip
2525
python -m pip install pytest
2626
# Can comment out when next Mathics3 core and Mathics-scanner are released
27-
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
28-
# python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
27+
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
28+
python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
2929
git clone https://github.com/Mathics3/mathics-core
30-
# (cd mathics-core && pip3 install -e .[full])
31-
# (cd mathics-core && bash ./admin-tools/make-op-tables.sh)
30+
(cd mathics-core && pip3 install -e .[full])
31+
(cd mathics-core && bash ./admin-tools/make-JSON-tables.sh)
3232
python -m pip install Mathics3[full]
3333
- name: install pymathics natlang
3434
run: |

admin-tools/check-versions.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
function finish {
3+
cd $mathics_natlang_owd
4+
}
5+
6+
# FIXME put some of the below in a common routine
7+
mathics_natlang_owd=$(pwd)
8+
trap finish EXIT
9+
10+
cd $(dirname ${BASH_SOURCE[0]})
11+
if ! source ./pyenv-versions ; then
12+
exit $?
13+
fi
14+
15+
cd ..
16+
for version in $PYVERSIONS; do
17+
echo --- $version ---
18+
if ! pyenv local $version ; then
19+
exit $?
20+
fi
21+
make clean && pip install -e .
22+
if ! make check; then
23+
exit $?
24+
fi
25+
echo === $version ===
26+
done
27+
finish

pymathics/natlang/nltk.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from itertools import chain
88

99
import nltk
10+
from pattern.en import lexeme, pluralize
11+
1012
from mathics.builtin.codetables import iso639_3
1113
from mathics.core.atoms import String
1214
from mathics.core.builtin import Builtin, MessageException
@@ -304,12 +306,9 @@ def inflected_forms(self, syn, desc):
304306
try:
305307
word, pos, _ = desc
306308
if pos == "Verb":
307-
from pattern.en import lexeme
308309

309310
return [w for w in reversed(lexeme(word)) if w != word]
310311
elif pos == "Noun":
311-
from pattern.en import pluralize
312-
313312
return [pluralize(word)]
314313
elif pos == "Adjective":
315314
from pattern.en import comparative, superlative

pymathics/natlang/normalization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class TextCases(_SpacyBuiltin):
101101
## >> TextCases[Import["ExampleData/EinsteinSzilLetter.txt"], "Person", 3][[2;;3]]
102102
## = {L. Szilard, Joliot}
103103
104-
>> TextCases["Anne, Peter and Mr Johnes say hello.", "Person", 3][[2;;3]]
104+
>> TextCases["Saul, Peter and Mr Johnes say hello.", "Person", 3][[2;;3]]
105105
= {Peter, Johnes}
106106
107107
"""

pymathics/natlang/textual_analysis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ class WordSimilarity(_SpacyBuiltin):
217217
</dl>
218218
219219
>> NumberForm[WordSimilarity["car", "train"], 3]
220-
= 0.439
220+
= 0.169
221221
222222
>> NumberForm[WordSimilarity["car", "hedgehog"], 3]
223-
= 0.195
223+
= 0.0173
224224
225225
>> NumberForm[WordSimilarity[{"An ocean full of water.", {2, 2}}, { "A desert full of sand.", {2, 5}}], 3]
226-
= {0.505, 0.481}
226+
= {0.127, 0.256}
227227
"""
228228

229229
messages = merge_dictionaries(

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def read(*rnames):
5959
"langid", # replace with a supported newer package, e.g. via spacy
6060
"llvmlite>=0.36",
6161
"nltk>=3.8.0",
62-
"pattern>=3.6.0",
62+
"PatternLite",
6363
"pyenchant>=3.2.0",
6464
"pycountry>=3.2.0",
6565
"spacy>=3.4",
@@ -76,11 +76,11 @@ def read(*rnames):
7676
"Intended Audience :: Science/Research",
7777
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
7878
"Programming Language :: Python",
79-
"Programming Language :: Python :: 3.7",
8079
"Programming Language :: Python :: 3.8",
8180
"Programming Language :: Python :: 3.9",
8281
"Programming Language :: Python :: 3.10",
8382
"Programming Language :: Python :: 3.11",
83+
"Programming Language :: Python :: 3.12",
8484
"Programming Language :: Python :: Implementation :: CPython",
8585
"Programming Language :: Python :: Implementation :: PyPy",
8686
"Topic :: Scientific/Engineering",

test/consistency-and-style/test_summary_text.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import pytest
88

9+
from types import ModuleType
10+
from typing import Dict
11+
912
from mathics.core.load_builtin import name_is_builtin_symbol
1013
from mathics.core.builtin import Builtin
1114
from mathics.doc.gather import skip_doc
@@ -60,7 +63,7 @@
6063
language_tool = None
6164
if CHECK_GRAMMAR:
6265
try:
63-
import language_tool_python
66+
import language_tool_python # type: ignore[import-not-found]
6467

6568
language_tool = language_tool_python.LanguageToolPublicAPI("en-US")
6669
# , config={ 'cacheSize': 1000, 'pipelineCaching': True })
@@ -95,14 +98,15 @@ def import_module(module_name: str):
9598
module_names.append(f"{subdir}.{modname}")
9699

97100

98-
modules = dict()
101+
modules: Dict[str, ModuleType] = dict()
99102
for module_name in module_names:
100103
import_module(module_name)
101104

102105
# modules = {"compilation": modules["compilation"],}
103106

104107

105108
def check_grammar(text: str):
109+
assert language_tool is not None
106110
matches = language_tool.check(text)
107111
filtered_matches = []
108112
if matches:
@@ -138,10 +142,10 @@ def check_well_formatted_docstring(docstr: str, instance: Builtin, module_name:
138142
), f"missing <dd> field {instance.get_name()} from {module_name}"
139143
assert (
140144
docstr.count("</dt>") == 0
141-
), f"unnecesary </dt> {instance.get_name()} from {module_name}"
145+
), f"unnecessary </dt> {instance.get_name()} from {module_name}"
142146
assert (
143147
docstr.count("</dd>") == 0
144-
), f"unnecesary </dd> field {instance.get_name()} from {module_name}"
148+
), f"unnecessary </dd> field {instance.get_name()} from {module_name}"
145149

146150
assert (
147151
docstr.count("<url>") > 0

0 commit comments

Comments
 (0)