Skip to content

Commit da3aa3e

Browse files
committed
Code to do Alphabet[] more properly
Perhaps we will expand this for other things...
1 parent 82d0911 commit da3aa3e

File tree

10 files changed

+397
-0
lines changed

10 files changed

+397
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = tab
8+
indent_size = 4
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4
17+
trim_trailing_whitespace: true

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*~
2+
.python-version
3+
/ChangeLog
4+
/build
5+
/dist
6+
/pymathics_language.egg-info
7+
/pymathics_natlang.egg-info
8+
/tmp
9+
__pycache__

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
default_language_version:
2+
python: python
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.0.1
6+
hooks:
7+
- id: check-merge-conflict
8+
- id: debug-statements
9+
stages: [commit]
10+
- id: end-of-file-fixer
11+
stages: [commit]
12+
- id: trailing-whitespace
13+
- repo: https://github.com/psf/black
14+
rev: 22.3.0
15+
hooks:
16+
- id: black
17+
language_version: python3
18+
exclude: 'mathicsscript/version.py'
19+
- repo: https://github.com/pycqa/flake8
20+
rev: 3.9.2
21+
hooks:
22+
- id: flake8
23+
stages: [commit]

CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
.
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Mathics Language and Translation Toolkit module.
2+
3+
Example Session
4+
---------------
5+
6+
::
7+
8+
$ mathicsscript
9+
In[1]:= LoadModule["pymathics.language"]
10+
Out[1]= pymathics.language
11+
In[2]= Alphabet["Croatian"]
12+
Out[2]= {['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'z', 'ć', 'č', 'đ', 'š', 'ž', 'dž', 'lj', 'nj']}

pymathics/language/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Pymathics Language
2+
3+
This module provides Mathics functions and varialbles to work with
4+
Lanugages and Translations
5+
"""
6+
7+
8+
from pymathics.language.__main__ import Alphabet
9+
from pymathics.language.version import __version__
10+
11+
pymathics_version_data = {
12+
"author": "The Mathics Team",
13+
"version": __version__,
14+
"name": "Language",
15+
"requires": ["PyICU"],
16+
}
17+
18+
__all__ = ["Alphabet", "pymathics_version_data", "__version__"]

pymathics/language/__main__.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Languages & Translations
5+
"""
6+
7+
# PYTHON MODULES USED IN HERE
8+
9+
# PyICU: human-language alphabets and locales
10+
11+
12+
from icu import Locale, LocaleData
13+
from typing import List, Optional
14+
15+
from mathics.builtin.base import Builtin
16+
from mathics.core.atoms import String
17+
from mathics.core.convert.expression import to_mathics_list
18+
19+
availableLocales = Locale.getAvailableLocales()
20+
language2locale = {
21+
availableLocale.getDisplayLanguage(): locale_name
22+
for locale_name, availableLocale in availableLocales.items()
23+
}
24+
25+
26+
def eval_alphabet(language_name: String) -> Optional[List[String]]:
27+
28+
py_language_name = language_name.value
29+
locale = language2locale.get(py_language_name, py_language_name)
30+
if locale not in availableLocales:
31+
return
32+
alphabet_set = LocaleData(locale).getExemplarSet(0, 0)
33+
return to_mathics_list(list(alphabet_set), elements_conversion_fn=String)
34+
35+
36+
class Alphabet(Builtin):
37+
"""
38+
Basic lowercase alphabet via <url>:Unicode: https://home.unicode.org/</url> and <url>:PyICU: https://pypi.org/project/PyICU/</url>
39+
<dl>
40+
<dt>'Alphabet'[]
41+
<dd>gives the list of lowercase letters a-z in the English alphabet .
42+
43+
<dt>'Alphabet[$type$]'
44+
<dd> gives the alphabet for the language or class $type$.
45+
</dl>
46+
47+
>> Alphabet[]
48+
= {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}
49+
>> Alphabet["Ukrainian"]
50+
= {a, ä, b, c, d, e, f, g, h, i, j, k, l, m, n, o, ö, p, q, r, s, ß, t, u, ü, v, w, x, y, z}
51+
52+
Some languages have the same basic set of letters.
53+
>> Alphabet["en_NZ"] == Alphabet["en"]
54+
= True
55+
"""
56+
57+
messages = {
58+
"nalph": "The alphabet `` is not known or not available.",
59+
}
60+
61+
rules = {
62+
"Alphabet[]": """Alphabet["English"]""",
63+
}
64+
65+
summary_text = "lowercase letters in an alphabet"
66+
67+
def apply(self, alpha: String, evaluation):
68+
"""Alphabet[alpha_String]"""
69+
alphabet_list = eval_alphabet(alpha)
70+
if alphabet_list is None:
71+
evaluation.message("Alphabet", "nalph", alpha)
72+
return
73+
return alphabet_list

pymathics/language/version.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
# This file is suitable for sourcing inside POSIX shell as
5+
# well as importing into Python. That's why there is no
6+
# space around "=" below.
7+
# fmt: off
8+
__version__="5.0.0" # noqa

setup.cfg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[bdist_wheel]
2+
universal = False
3+
4+
[metadata]
5+
description_file = README.rst
6+
7+
# Recommended flake8 settings while editing zoom, we use Black for the final
8+
# linting/say in how code is formatted
9+
#
10+
# pip install flake8 flake8-bugbear
11+
#
12+
# This will warn/error on things that black does not fix, on purpose.
13+
14+
# This config file MUST be ASCII to prevent weird flake8 dropouts
15+
16+
[flake8]
17+
# max-line-length setting: NO we do not want everyone writing 120-character lines!
18+
# We are setting the maximum line length big here because there are longer
19+
# lines allowed by black in some cases that are forbidden by flake8. Since
20+
# black has the final say about code formatting issues, this setting is here to
21+
# make sure that flake8 doesn't fail the build on longer lines allowed by
22+
# black.
23+
max-line-length = 120
24+
max-complexity = 12
25+
select = E,F,W,C,B,B9
26+
ignore =
27+
# E123 closing bracket does not match indentation of opening bracket's line
28+
E123
29+
# E203 whitespace before ':' (Not PEP8 compliant, Python Black)
30+
E203
31+
# E501 line too long (82 > 79 characters) (replaced by B950 from flake8-bugbear,
32+
# https://github.com/PyCQA/flake8-bugbear)
33+
E501
34+
# W503 line break before binary operator (Not PEP8 compliant, Python Black)
35+
W503
36+
# W504 line break after binary operator (Not PEP8 compliant, Python Black)
37+
W504
38+
# C901 function too complex - since many of zz9 functions are too complex with a lot
39+
# of if branching
40+
C901
41+
# module level import not at top of file. This is too restrictive. Can't even have a
42+
# docstring higher.
43+
E402

0 commit comments

Comments
 (0)