NanGram
Negative Nancy's expression generator & parser! XD
Write grammars, generate random expressions, parse expressions.
Installation
pip install nangram
Usage
First write yourself a nice little grammar like this!:
grammar.bnf:
determiner = "the " | "a " .
noun = "cat " | "dog " | "chair " .
verb = "runs " | "snacks " | "plays " .
adverb = "quickly" | "ferociously" | "sneakily" .
noun_phrase = determiner noun .
verb_phrase = verb adverb .
sentence = noun_phrase verb_phrase .
main = sentence .
Then import nangram and load the grammar source:
import nangram
grammar = nangram.Grammar.load_bnf('grammar.bnf')
Then generate some expressions!:
for expression in grammar.generate():
print(expression)
And you get...
the cat plays ferociously
the dog plays ferociously
the chair snacks quickly
a cat snacks quickly
a dog runs quickly
a dog snacks ferociously
a dog plays quickly
a chair plays ferociously
Then try parsing something:
for parse_tree in grammar.parse('a cat snacks sneakily'):
print(parse_tree)
And you get...
sentence = 'a cat snacks sneakily'
├ noun_phrase = 'a cat '
│ ├ determiner = 'a '
│ └ noun = 'cat '
└ verb_phrase = 'snacks sneakily'
├ verb = 'snacks '
└ adverb = 'sneakily'
(The parser will yield as many parse trees as are valid, so if you have an ambiguous grammar, for example, you can parse all variations. If the expression is not in the language, you won't get any parse trees.)
See examples/english.bnf and examples/english.py for another example.
Metadata
Release files for nangram 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nangram-0.0.6.tar.gz | 8.2 kB | Without provenance | Details for nangram-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nangram-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for nangram-0.0.6-py3-none-any.whl |
Total release size: 17.4 kB
Release files / nangram-0.0.6.tar.gz
| Download URL | nangram-0.0.6.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f971ed2d20d5ed9d9c8920996941e8cff73f75d9e171d3f1c3eb5771cc0129f0
|
|
BLAKE2b-256 checksum How to use checksums |
224fae6457796d38c916b840bd485dfa8ab821c7e5f9162c3e5c65016d181b5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|
Release files / nangram-0.0.6-py3-none-any.whl
| Download URL | nangram-0.0.6-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bdfa3ee6c236b22edcdfc0d7de76f67520b48f927343a72e98ad7adbc60a0cf6
|
|
BLAKE2b-256 checksum How to use checksums |
855de8cb1f316bb9dae1a4fcea1700a24050c1777a79f65cf685eb4da0c1c937
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
|
Security for nangram 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.