Skip to content

Commit

Permalink
Merge pull request #22 from SHADE-AI/feat/#21-python-module
Browse files Browse the repository at this point in the history
feat(parser)!: made daidepp into installable python package
  • Loading branch information
byung-o authored Sep 15, 2022
2 parents efaa042 + 7477a23 commit 29a17d6
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 25 deletions.
177 changes: 177 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Mac OS
.DS_Store

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@
| Git | [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org) |
| Formatting | [![Black](https://img.shields.io/badge/Code%20Style-black-000000)](https://github.com/psf/black) [![docformatter](https://img.shields.io/badge/Docstring%20Formatter-docformatter-fedcba.svg)](https://github.com/PyCQA/docformatter) [![numpy](https://img.shields.io/badge/Docstring%20Style-numpy-459db9.svg)](https://numpydoc.readthedocs.io/en/latest/format.html) [![Imports: isort](https://img.shields.io/badge/%20Imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) |

Repo to store universal communication specification and parser.
DAIDE parser using [parsimonious](https://github.com/erikrose/parsimonious). Parsimonious is a python package that uses "a simplified sort of EBNF notation" to define a grammar. The parser currently supports all 130 levels of DAIDE.

- The original DAIDE specification is [here](daide-syntax.pdf)
- The working markdown document that will included DAIDE enhancements is [here](daide-specification.md)
- The machine-parsable grammar can be found in [this `.py` file](./daidepp/parser/grammar.py)
- The machine-parsable grammar can be found in [this `.py` file](./src/daidepp/grammar.py)

## Use

Using the grammar in grammar.py, you can create a parse tree from a DAIDE press message or reply. The nodes of the parse tree can be visited to return something more useful. The visiting rules for each of the nodes of the parse tree are defined in node_visitor.py.

Example:

```python3
>>> from daidepp import create_daide_grammar, daide_visitor
>>> grammar = create_daide_grammar(level=130)
>>> message = 'PRP (AND (SLO (ENG)) (SLO (GER)) (SLO (RUS)) (AND (SLO (ENG)) (SLO (GER)) (SLO (RUS))))'
>>> parse_tree = grammar.parse(message)
>>> output = daide_visitor.visit(parse_tree)
>>> print(output)
('PRP', ('AND', [('SLO', 'ENG'), ('SLO', 'GER'), ('SLO', 'RUS'), ('AND', [('SLO', 'ENG'), ('SLO', 'GER'), ('SLO', 'RUS')])]))
```

If the DAIDE token is not in the grammar or if the message is malformed, the parser will just thrown an exception. We're currently working on returning a list of unrecognized tokens instead of just erroring out.

## Pull Requests

Three files should be updated whenever making a PR:

- [`grammar.py`](./daidepp/parser/grammar.py): the machine-readable grammar
- [`node_visitor.py`](./daidepp/parser/node_visitor.py): the visitor object to parse a message
- [`grammar.py`](./src/daidepp/grammar.py): the machine-readable grammar
- [`node_visitor.py`](./src/daidepp/node_visitor.py): the visitor object to parse a message
- [The daide markdown specification](./daide-specification.md): the human-readable specification
20 changes: 0 additions & 20 deletions daidepp/README.md

This file was deleted.

1 change: 0 additions & 1 deletion daidepp/requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=65"]
build-backend = "setuptools.build_meta"
64 changes: 64 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[metadata]
name = daidepp
version = 0.1.0
author = Byung Oh
author_email = [email protected]
description = "DAIDE Parser"
long_description = file: README.md
long_description_content_type = text/markdown

[options]
package_dir =
=src
packages = find:
python_requires = >=3.7
install_requires =
parsimonious==0.9.0

[options.packages.find]
where = src

[options.extras_require]
dev =
black>=22.8.0
docformatter==1.4
isort>=5.10.1
pydocstyle==6.1.1
pylint==2.12.2
pytest==7.0.0
pytest-cov==3.0.0
pytest-dependency==0.5.1
pytest-mypy==0.9.1
pytest-timeout==2.1.0

[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
line_length = 88
known_first_party = daidepp

[mypy]
ignore_missing_imports = True
disallow_untyped_calls = False
disallow_untyped_defs = True
disallow_incomplete_defs = True
files = src/
exclude = tests/
follow_imports = silent

[tool:pytest]
testpaths = tests
addopts =
--cov=daidepp
--cov-report html
timeout = 10

[pylint.MESSAGES CONTROL]
extension-pkg-whitelist =
pydantic

[pydocstyle]
convention = numpy
add_ignore = D2,D105,D101,D100,D104,D106
2 changes: 2 additions & 0 deletions src/daidepp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from daidepp.grammar import create_daide_grammar
from daidepp.node_visitor import daide_visitor
File renamed without changes.
File renamed without changes.

0 comments on commit 29a17d6

Please sign in to comment.