ഉപയോക്താവ്: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 ""