import re

def stransform(inputw):
    return re.sub(r' (.)\1', r'-\1-\1', inputw)



def beautify(phon):
	return phon.replace("[yᵉhwāˌh]","ʔăḏōnāy").replace("ḏ","d").replace("ḡ","g").replace("ṯ","t").replace("ḵ","x").replace("ʔ","ʾ").replace("ʕ","ʿ").replace("ₐ","a").replace("î","ī").replace("ê","ē").replace("ô","ō").replace("û","ū").replace("ᵒ","ŏ").replace("ᵉ","ĕ").replace("ᵃ","ă").replace("ᵊ","ᵉ").replace("ʸ","").replace("ˈ",'<sub id="s">́</sub>').replace("ˌ",'<sub id="s">́</sub>').replace("  "," ").replace(" -","-").replace("- ","-").replace('[yᵉhwā<sub id="s">́</sub>h]','ʔăḏōnā<sub id="s">́</sub>y').replace('[yhwā<sub id="s">́</sub>h]','ʔăḏōnā<sub id="s">́</sub>y')

def syntannot(input):
    return re.sub(u"\{([^\}]*)\}([^ ]{1,})", u"<span class='syx \\2'>\\1</span>", input)




def repl(inputw):
    text=beautify(inputw)
    return text

##########################
####  Start  here ########
##########################


import pandas as pd
print('Loading verses...\r',end="")    
df=pd.read_csv("bible-selected.csv",sep=",")
dft=pd.read_csv("bibletranslate-selected.csv",sep=",")
## df : hebtext	number	book	chapter	verse	trchapter	trverse	trtext	translit
##      0       1       2       3       4       5           6       7       8
print('Done.\r',end="")    

df["translit"]=df["translit"].apply(beautify).apply(stransform)

df["translit"] = df["translit"].apply(syntannot)
df["hebtext"] = df["hebtext"].apply(syntannot)
dft["text"]=dft["text"].apply(syntannot)

df.to_csv("bible-beautified-phon.csv", sep=",", index=None)
dft.to_csv("bibletranslate-beautified-phon.csv", sep=",", index=None)


print("Done.")


