Esempio n. 1
0
def translitArabic():
    text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()

    if(getattr(args, 'delimited') != None):
      text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.arabicToBetaCode(match.group(1)), text, flags=re.DOTALL)
    
    else:
      text = betaCode.arabicToBetaCode(text)

    sys.stdout.buffer.write(text.encode('utf8'))
Esempio n. 2
0
def regenerateFile(file):
    with open(targetFolder+file[:-4]+"_Working.txt", "r", encoding="utf8") as f:
        hadith = f.read()

        hadith = re.split(div, hadith)

        # arabicOriginal
        arabicOriginal = re.sub("\n+", "\n", hadith[2])
        arabicOriginal = arabicOriginal.split("\n")[1]
        #input(arabicOriginal)
        #place to apply some additional conversions (salla allahu `alayhi wasallama > sl`m)

        # regenerate betaCodeAuto
        betaCodeAutoNew = betaCode.arabicToBetaCode(arabicOriginal)
        betaCodeAuto = re.sub("\n+", "\n", hadith[3])
        betaCodeAuto = betaCodeAuto.split("\n")
        betaCodeAuto[1] = betaCodeAutoNew
        hadith[3] = "\n".join(betaCodeAuto)

        # betaCodeManual
        betaCodeManual = re.sub("\n+", "\n", hadith[4])
        betaCodeManual = betaCodeManual.split("\n")[1]

        # regenerate betaCodeTranslit
        betaCodeTranslitNew = betaCode.betacodeToTranslit(betaCodeManual)
        betaCodeTranslit = re.sub("\n+", "\n", hadith[5])
        betaCodeTranslit = betaCodeTranslit.split("\n")
        betaCodeTranslit[1] = betaCodeTranslitNew
        hadith[5] = "\n".join(betaCodeTranslit)

        # regenerate betaCodeArabic
        betaCodeArabicNew = betaCode.betacodeToArabic(betaCodeManual)
        betaCodeArabic = re.sub("\n+", "\n", hadith[6])
        betaCodeArabic = betaCodeArabic.split("\n")
        betaCodeArabic[1] = betaCodeArabicNew
        hadith[6] = "\n".join(betaCodeArabic)

        # translationBetaCode
        translationBetaCode = re.sub("\n+", "\n", hadith[7])
        translationBetaCode = translationBetaCode.split("\n")[1]

        # regenerate translationTranslit
        translationTranslitNew = betaCode.betacodeToTranslit(translationBetaCode)
        translationTranslit = re.sub("\n+", "\n", hadith[8])
        translationTranslit = translationTranslit.split("\n")
        translationTranslit[1] = translationTranslitNew
        hadith[8] = "\n".join(translationTranslit)

        # collect the record back
        newWorking = ""
        for section in hadith[1:]:
            newWorking = newWorking + div + section + "\n\n"

        newWorking = re.sub("\n{3,}", "\n\n", newWorking)
        
        #input(newWorking)

        # save the text
        with open(targetFolder+file[:-4]+"_Working.txt", "w", encoding="utf8") as f:
            f.write(newWorking)
Esempio n. 3
0
def generateFile(file):
    with open(sourceFolder + file, "r", encoding="utf8") as f:
        hadith = f.read()
        hadithID = re.search(r"hadithID::(.*)\n", hadith).group(1).strip()
        hadithText = re.search(r"arHadithInit::(.*)\n",
                               hadith).group(1).strip()

        # reformat optatives and other recognizeable elements

        # form the text
        hadithHeader = div + "## hadithID::     %s\n## Completed by:: ADDYOURNAME\n## Finished::     NO/YES\n\n" % hadithID
        arabicOriginal = div + "## ArabicInitial\n%s\n\n" % hadithText
        betaCodeAutoVar = betaCode.arabicToBetaCode(hadithText)
        betaCodeAuto = div + "## betaCodeAuto\n%s\n\n" % betaCodeAutoVar
        betaCodeManual = div + "## betaCodeManual\n%s\n\n" % betaCodeAutoVar
        betaCodeTranslit = div + "## betaCodeManual>Translit\n%s\n\n" % betaCode.betacodeToTranslit(
            betaCodeAutoVar)
        betaCodeArabic = div + "## betaCodeManual>Arabic\n%s\n\n" % betaCode.betacodeToArabic(
            betaCodeAutoVar)
        translationBetaCode = div + "## TranslationBetaCode\nType your translation on this line\n\n"
        translationTranslit = div + "## TranslationTranslit\nTranslation with transliterated names will appear here\n\n"

        newWorkingFile = hadithHeader + arabicOriginal + betaCodeAuto + betaCodeManual + betaCodeTranslit + betaCodeArabic + translationBetaCode + translationTranslit

        # save the text
        with open(targetFolder + file[:-4] + "_Working.txt",
                  "w",
                  encoding="utf8") as f:
            f.write(newWorkingFile)
Esempio n. 4
0
def translitArabic(mainFolder):
    print("Converting Arabic into Translit: %s" % mainFolder)
    testLine = "###KEEP#THIS#LINE#TEXT#WILL#BE#GENERATED#BELOW#\n"
    listOfFiles = os.listdir(mainFolder)
    for file in listOfFiles:
        print(file)
        if file.startswith("."):
            pass
        else:
            with open(mainFolder + file, "r", encoding="utf8") as f:
                text = f.read()
                test = re.search(testLine, text)
                if test:
                    print("Transliterating %s" % file)
                    text = re.split(testLine, text)
                    textToConvert = text[0]

                    translitBetaCode = betaCode.arabicToBetaCode(textToConvert)

                    translitBC = "###TRANSLIT#BETACODE###\n\n%s" % translitBetaCode
                    translitOTO = "###TRANSLIT#ONE#TO#ONE###\n\n%s" % betaCode.betacodeToTranslit(
                        translitBetaCode)
                    translitLOC = "###TRANSLIT#LIBRARY#OF#CONGRESS###\n\n%s" % betaCode.betacodeToLOC(
                        translitBetaCode)
                    translitSearch = "###TRANSLIT#SEARCHEABLE###\n\n%s" % betaCode.betacodeToSearch(
                        translitBetaCode)

                    newText = text[
                        0] + "\n" + testLine + translitBC + translitOTO + translitLOC + translitSearch
                    newText = re.sub("\n{2,}", "\n\n", newText)

                    with open(mainFolder + file, "w", encoding="utf8") as f:
                        f.write(newText)
                else:
                    print(
                        """File %s does not have the trigger line.\nIf you want the contents of this file converted, add the following line at the end of the file:\n\n%s\n\n"""
                        % (file, testLine))
Esempio n. 5
0
def generateFile(file):
    with open(sourceFolder+file, "r", encoding="utf8") as f:
        hadith = f.read()
        hadithID = re.search(r"hadithID::(.*)\n", hadith).group(1).strip()
        hadithText = re.search(r"arHadithInit::(.*)\n", hadith).group(1).strip()
        
        # reformat optatives and other recognizeable elements
        
        # form the text
        hadithHeader = div + "## hadithID::     %s\n## Completed by:: ADDYOURNAME\n## Finished::     NO/YES\n\n" % hadithID
        arabicOriginal = div + "## ArabicInitial\n%s\n\n" % hadithText
        betaCodeAutoVar = betaCode.arabicToBetaCode(hadithText)
        betaCodeAuto = div + "## betaCodeAuto\n%s\n\n" % betaCodeAutoVar
        betaCodeManual = div + "## betaCodeManual\n%s\n\n" % betaCodeAutoVar
        betaCodeTranslit = div + "## betaCodeManual>Translit\n%s\n\n" % betaCode.betacodeToTranslit(betaCodeAutoVar)
        betaCodeArabic = div + "## betaCodeManual>Arabic\n%s\n\n" % betaCode.betacodeToArabic(betaCodeAutoVar)
        translationBetaCode = div + "## TranslationBetaCode\nType your translation on this line\n\n"
        translationTranslit = div + "## TranslationTranslit\nTranslation with transliterated names will appear here\n\n"

        newWorkingFile = hadithHeader + arabicOriginal + betaCodeAuto + betaCodeManual + betaCodeTranslit + betaCodeArabic + translationBetaCode + translationTranslit

        # save the text
        with open(targetFolder+file[:-4]+"_Working.txt", "w", encoding="utf8") as f:
            f.write(newWorkingFile)
Esempio n. 6
0
def regenerateFile(file):
    with open(targetFolder + file[:-4] + "_Working.txt", "r",
              encoding="utf8") as f:
        hadith = f.read()

        hadith = re.split(div, hadith)

        # arabicOriginal
        arabicOriginal = re.sub("\n+", "\n", hadith[2])
        arabicOriginal = arabicOriginal.split("\n")[1]
        #input(arabicOriginal)
        #place to apply some additional conversions (salla allahu `alayhi wasallama > sl`m)

        # regenerate betaCodeAuto
        betaCodeAutoNew = betaCode.arabicToBetaCode(arabicOriginal)
        betaCodeAuto = re.sub("\n+", "\n", hadith[3])
        betaCodeAuto = betaCodeAuto.split("\n")
        betaCodeAuto[1] = betaCodeAutoNew
        hadith[3] = "\n".join(betaCodeAuto)

        # betaCodeManual
        betaCodeManual = re.sub("\n+", "\n", hadith[4])
        betaCodeManual = betaCodeManual.split("\n")[1]

        # regenerate betaCodeTranslit
        betaCodeTranslitNew = betaCode.betacodeToTranslit(betaCodeManual)
        betaCodeTranslit = re.sub("\n+", "\n", hadith[5])
        betaCodeTranslit = betaCodeTranslit.split("\n")
        betaCodeTranslit[1] = betaCodeTranslitNew
        hadith[5] = "\n".join(betaCodeTranslit)

        # regenerate betaCodeArabic
        betaCodeArabicNew = betaCode.betacodeToArabic(betaCodeManual)
        betaCodeArabic = re.sub("\n+", "\n", hadith[6])
        betaCodeArabic = betaCodeArabic.split("\n")
        betaCodeArabic[1] = betaCodeArabicNew
        hadith[6] = "\n".join(betaCodeArabic)

        # translationBetaCode
        translationBetaCode = re.sub("\n+", "\n", hadith[7])
        translationBetaCode = translationBetaCode.split("\n")[1]

        # regenerate translationTranslit
        translationTranslitNew = betaCode.betacodeToTranslit(
            translationBetaCode)
        translationTranslit = re.sub("\n+", "\n", hadith[8])
        translationTranslit = translationTranslit.split("\n")
        translationTranslit[1] = translationTranslitNew
        hadith[8] = "\n".join(translationTranslit)

        # collect the record back
        newWorking = ""
        for section in hadith[1:]:
            newWorking = newWorking + div + section + "\n\n"

        newWorking = re.sub("\n{3,}", "\n\n", newWorking)

        #input(newWorking)

        # save the text
        with open(targetFolder + file[:-4] + "_Working.txt",
                  "w",
                  encoding="utf8") as f:
            f.write(newWorking)