Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python3
- #Universal parameters
- delim1 = ";"
- delim2 = "\t"
- number_of_words = 113
- source1 = "vocabulary.txt"
- source2 = "WK_sen.txt"
- output = "vsound.txt"
- #Actual coding
- def NextLine(filename):
- y = filename.read(1)
- while y != "\n":
- y = filename.read(1)
- def NextCol(filename,delim):
- y = filename.read(1)
- while y != delim:
- y = filename.read(1)
- def GoToCol(filename, n, delim):
- x = 0
- while x < n:
- y = filename.read(1)
- while y != delim:
- y = filename.read(1)
- x = x+1
- def GetWord(filename, targetcol, delim):
- n = 0
- while n < targetcol:
- x = filename.read(1)
- while x != delim:
- x = filename.read(1)
- n = n+1
- ch = filename.read(1)
- word = [ ch, ]
- while ch != delim:
- ch = filename.read(1)
- if ch != delim:
- word = word + [ ch, ]
- return word
- def PrintList(filename, wordlist):
- n = len(wordlist)
- x = 0
- while x < n:
- filename.write(wordlist[x])
- x = x+1
- def EqualLine(filename, col, delim, word):
- filename.seek(0, 0)
- while filename.read(1) == "#":
- NextLine(filename)
- filename.seek(-1,1)
- x = GetWord(filename, col, delim)
- n = 0
- while GetWord(filename, col, delim) != word:
- NextLine(filename)
- n = n+1
- return n
- def StartPrintLine(filename, i):
- filename.seek(0, 0)
- while filename.read(1) == "#":
- NextLine(filename)
- filename.seek(-1,1)
- x = 0
- while x < i:
- NextLine(filename)
- x = x+1
- ch = filename.read(1)
- word = [ ch, ]
- while ch != "\n":
- ch = filename.read(1)
- if ch != "\n":
- word = word + [ ch, ]
- return word
- def PrintLine(filename, i, col, amount):
- filename.seek(0, 0)
- while filename.read(1) == "#":
- NextLine(filename)
- filename.seek(-1,1)
- x = 0
- while x < i:
- NextLine(filename)
- x = x+1
- GoToCol(filename, col, "\t")
- word = GetWord(filename, 0, "\t")
- word = word + [ ";", ]
- x = 1
- while x < amount:
- word = word + GetWord(filename, 0, "\t") + [ ";", ]
- x = x+1
- return word
- print "Vocab file is", source1, ", and the deliminator is", delim1, "\b."
- print "Audio library is", source2, ", and the deliminator is", delim2, "\b."
- print "Output file is", output, ", and the deliminator is", delim1, "\b."
- print "The number of words is", number_of_words, "\b."
- print "\nMake sure that the end of Vocab file is \\n."
- raw_input("\nPress the enter key to continue.")
- s1 = open(source1, "r")
- s2 = open(source2, "r")
- fout = open(output, "w")
- while s1.read(1) == "#":
- NextLine(s1)
- s1.seek(-1,1)
- n = 0
- while n < number_of_words:
- Word = GetWord(s1, 2, delim1)
- #source1
- PrintList(fout, StartPrintLine(s1, n))
- fout.write(";")
- #source2
- i = EqualLine(s2, 1, delim2, Word)
- print "Printing line", n+1, "\b, matched with audio line", i, "\b."
- PrintList(fout, PrintLine(s2, i, 14, 3))
- fout.write("\n")
- n = n+1
- s1.close()
- s2.close()
- fout.close()
Advertisement
Add Comment
Please, Sign In to add comment