Jump to content

ഉപയോക്താവ്:Mashithantu/mashiPreProcessBot.py

വിക്കിനിഘണ്ടു സംരംഭത്തിൽ നിന്ന്
import re

def main():
    inputPage = open('./data.txt','r')
    outputPage = open('./dataInput.txt','w')
    data = inputPage.read()

    meaningSearchR = re.compile(r'=([^=]+)=([^=]+)=([^=]*)=*\n')
    #meaningSearchR = re.compile(r'##([^#]+)#([^#]+)*#*([^#]+)#\n')
    phraseSearchR = re.compile(r'([^,]+),[\s]*')
    wordSearchR = re.compile(r'([^\s]+)')
    storedWord = ""
    storedMeaning1 = ""
    storedMeaning2 = ""
    for word, meaning1, meaning2 in meaningSearchR.findall(data):
	    if meaning2=="":
		meaning2 = meaning1
		meaning1 = ""
	    if storedWord == word:
		if meaning1 != "":
			if storedMeaning1 != "":
				storedMeaning1 = storedMeaning1 + ', '+ meaning1
			else:
				storedMeaning1 = meaning1
		storedMeaning2 = storedMeaning2 + ', '+ meaning2
	    else:
		if storedWord != "":
			outputPage.write('='+storedWord+'=')
			if storedMeaning1 != "" and storedMeaning1 != " ":
				outputPage.write(storedMeaning1+'=')
			outputPage.write(storedMeaning2+'=\n')
		storedWord = word
		storedMeaning1 = meaning1
		storedMeaning2 = meaning2
    outputPage.write('='+storedWord+'=')
    if storedMeaning1 != "" and storedMeaning1 != " ":
	outputPage.write(storedMeaning1+'=')
    outputPage.write(storedMeaning2+'=\n')

if __name__ == "__main__":
    try:
        main()
    finally:
        print ""
"https://ml.wiktionary.org/w/index.php?title=ഉപയോക്താവ്:Mashithantu/mashiPreProcessBot.py&oldid=66119" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്