Fonetic is a python library to assess pronounceablility of a given text based on an algorithm invented by Somdev Sangwan. A related research paper can be found here.
fonetic can be used in:
- Detecting randomly generated strings
- Heuristic checking for spell checkers
- Improving made-up word generators
- Optimizing brute-force attacks
Open an issue to extend this list.
fonetic has only 33 lines of executable code which is optimized to the boolean level. It has no external imports and it can be used with any Python version and operating system.
The recommended method to install fonetic is using pip
, as follows:
pip install fonetic
fonetic is minimal and can be implemented in just 2 lines of code as follows:
>>> from fonetic import count
>>> count('christmxs')
(8, 6, 2)
The output is a tuple containing values of total bigrams, pronounceable bigrams and unpronounceable bigrams respectively.
The python script and related files used for benchmarking can be downloaded from here
The result below was produced by parsing a 4.3 MB text file containing the entire oxford dictionary with a 3GB RAM and a 4th Gen intel i3 processor.
~> python benchmark.py /root/oxford.txt
---Result---
- Text length: 4478566 bytes
- English text length: 3262241 bytes
- Total valid bigrams: 2566359
- Pronounceable bigrams: 2533266
- Unpronounceable bigrams: 33105
- Meaningful text: 98%
---Benchmark---
- Parsing started: 1577194614
- Parsing ended: 1577194616
- Time taken: 2 seconds
The error of 2% in Oxford dictionary was unexpected but manual checking revealed that it was caused by abbreviations and words from other languages. Such an entry is given below:
zygote n. biol. cel
. biol. cell formed by the union of two
two gametes. [greek zugotos yoked: relat
tes. [greek zugotos yoked: related to *z
yoked: related to *zeugma]