Last active
October 4, 2018 11:12
-
-
Save matthewdeanmartin/6b0f8b630fff7193328c7fd1b9f0cda7 to your computer and use it in GitHub Desktop.
Convert arbitrary English text to almost chantable text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import pyphen | |
dic = pyphen.Pyphen(lang='en') | |
# nature of reality (prajña) | |
text = "The removal of suffering then, requires a deep understanding of praj-na. While philosophical analysis of arguments and concepts is clearly necessary to develop this understanding, it is not enough to remove our unskillful mental habits and deeply ingrained prejudices, which require meditation, paired with understanding. According to the Buddha, we need to train the mind in meditation to be able to truly see the nature of reality, which is said to have the marks of suffering, impermanence and not-self. Understanding and meditation are said to work together to 'clearly see' the nature of human experience and this is said to lead to liberation." | |
line_length = 6 | |
words = text.split(" ") | |
so_far = 0 | |
for word in words: | |
preexisting = len([x for x in word if x == "-"]) | |
hyphenated = dic.inserted(word) | |
current = len([x for x in hyphenated if x == "-"])+1 -preexisting | |
so_far += current | |
if so_far >= line_length: | |
overage = ("", " *" + str(so_far - line_length))[int(so_far - line_length != 0)] | |
print(hyphenated + overage) | |
so_far = 0 | |
else: | |
print(hyphenated, end=" ") | |
print() | |
print() | |
print("* syllables over {0}".format(line_length)) | |
# | |
# The re-moval of suf-fer-ing *1 | |
# then, re-quires a deep un-der-stand-ing *3 | |
# of pra-j--na. While philo-soph-i-cal *3 | |
# anal-y-sis of ar-gu-ments *1 | |
# and con-cepts is clear-ly | |
# nec-es-sary to de-vel-op *1 | |
# this un-der-stand-ing, it | |
# is not enough to re-move | |
# our un-skill-ful men-tal | |
# habits and deeply in-grained prej-u-dices, *2 | |
# which re-quire med-i-ta-tion, *1 | |
# paired with un-der-stand-ing. | |
# Ac-cord-ing to the Bud-dha, *1 | |
# we need to train the mind | |
# in med-i-ta-tion to | |
# be able to tru-ly see | |
# the na-ture of re-al-i-ty, *2 | |
# which is said to have the | |
# marks of suf-fer-ing, im-per-ma-nence *3 | |
# and not--self. Un-der-stand-ing *1 | |
# and med-i-ta-tion are | |
# said to work to-geth-er | |
# to 'clear-ly see' the na-ture *1 | |
# of hu-man ex-pe-ri-ence *1 | |
# and this is said to lead | |
# to lib-er-a-tion. | |
# | |
# * syllables over 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment