A Pangram is essentially a sentence that uses all the letters of the alphabet. According to Wikipedia the best-known English pangram is "The quick brown fox jumps over the lazy dog". This script makes a pangram every time it be executed. The idea is simple:
- a pangram contains words which begins with all the letters of the alphabet;
- so we make a list with the all alphabet letters
- we shuffle them and
- we constrict a sentenceusing every letter in the alphabet list.
Ex.
Given:
['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']
we make this:
['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', 'a']
and, finally, we construct a sentence like
'brave cats dart effortlessly for good-hearted individuals juggling keenly like mindful nannies openly promoting quick reactions swiftly to unitedly visualize x-rayed zebras androgynously.'
To do that we've used a Spacy NLP library that offers pre-trained language models for various languages; specifically,we've used 'en_core_web_sm' language model which provides various functionalities for processing and analyzing English text, including features like tokenization (that is splitting text into individual words or tokens), part-of-speech tagging, named entity recognition, syntactic parsing, and more. So, we iterate over each letter, and create meaningful sentences while respecting the constraints mentioned above.
spacy==3.3.0
Name | Stmts | Miss | Branch | BrPart | Cover |
---|---|---|---|---|---|
pangram.py | 9 | 1 | 2 | 1 | 82% |
pangram_generator_test.py | 20 | 1 | 4 | 1 | 92% |
random_pangram.py | 7 | 0 | 2 | 0 | 100% |
sentence_constructor.py | 11 | 0 | 2 | 0 | 100% |
TOTAL | 47 | 2 | 10 | 2 | 95.74% |
This project is licensed under the MIT License - see the LICENSE.md file for details