polv

concat-new

Dec 24th, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.19 KB | None | 0 0
  1. #! /usr/bin/python3
  2.  
  3. #Universal parameters
  4. delim1 = ";"
  5. delim2 = "\t"
  6. number_of_words = 113
  7. source1 = "vocabulary.txt"
  8. source2 = "WK_sen.txt"
  9. output = "vsound.txt"
  10.  
  11. #Actual coding
  12. def NextLine(filename):
  13.     y = filename.read(1)
  14.     while y != "\n":
  15.         y = filename.read(1)
  16.  
  17. def NextCol(filename,delim):
  18.     y = filename.read(1)
  19.     while y != delim:
  20.         y = filename.read(1)
  21.  
  22. def GoToCol(filename, n, delim):
  23.     x = 0
  24.     while x < n:
  25.         y = filename.read(1)
  26.         while y != delim:
  27.             y = filename.read(1)
  28.         x = x+1
  29.  
  30. def GetWord(filename, targetcol, delim):
  31.     n = 0
  32.     while n < targetcol:
  33.         x = filename.read(1)
  34.         while x != delim:
  35.             x = filename.read(1)
  36.         n = n+1
  37.    
  38.     ch = filename.read(1)
  39.     word = [ ch, ]
  40.     while ch != delim:
  41.         ch = filename.read(1)
  42.         if ch != delim:
  43.             word = word + [ ch, ]
  44.     return word
  45.  
  46. def PrintList(filename, wordlist):
  47.     n = len(wordlist)
  48.     x = 0
  49.     while x < n:
  50.         filename.write(wordlist[x])
  51.         x = x+1
  52.  
  53. def EqualLine(filename, col, delim, word):
  54.     filename.seek(0, 0)
  55.     while filename.read(1) == "#":
  56.         NextLine(filename)
  57.     filename.seek(-1,1)
  58.    
  59.     x = GetWord(filename, col, delim)
  60.     n = 0
  61.     while GetWord(filename, col, delim) != word:
  62.         NextLine(filename)
  63.         n = n+1
  64.     return n
  65.  
  66. def StartPrintLine(filename, i):
  67.     filename.seek(0, 0)
  68.     while filename.read(1) == "#":
  69.         NextLine(filename)
  70.     filename.seek(-1,1)
  71.    
  72.     x = 0
  73.     while x < i:
  74.         NextLine(filename)
  75.         x = x+1
  76.    
  77.     ch = filename.read(1)
  78.     word = [ ch, ]
  79.     while ch != "\n":
  80.         ch = filename.read(1)
  81.         if ch != "\n":
  82.             word = word + [ ch, ]
  83.     return word
  84.  
  85. def PrintLine(filename, i, col, amount):
  86.     filename.seek(0, 0)
  87.     while filename.read(1) == "#":
  88.         NextLine(filename)
  89.     filename.seek(-1,1)
  90.    
  91.     x = 0
  92.     while x < i:
  93.         NextLine(filename)
  94.         x = x+1
  95.    
  96.     GoToCol(filename, col, "\t")
  97.    
  98.     word = GetWord(filename, 0, "\t")
  99.     word = word + [ ";", ]
  100.     x = 1
  101.     while x < amount:
  102.         word = word + GetWord(filename, 0, "\t") + [ ";", ]
  103.         x = x+1
  104.    
  105.     return word
  106.  
  107. print "Vocab file is", source1, ", and the deliminator is", delim1, "\b."
  108. print "Audio library is", source2, ", and the deliminator is", delim2, "\b."
  109. print "Output file is", output, ", and the deliminator is", delim1, "\b."
  110. print "The number of words is", number_of_words, "\b."
  111.  
  112. print "\nMake sure that the end of Vocab file is \\n."
  113. raw_input("\nPress the enter key to continue.")
  114.  
  115. s1 = open(source1, "r")
  116. s2 = open(source2, "r")
  117. fout = open(output, "w")
  118.  
  119. while s1.read(1) == "#":
  120.     NextLine(s1)
  121. s1.seek(-1,1)
  122.  
  123. n = 0
  124. while n < number_of_words:
  125.     Word = GetWord(s1, 2, delim1)
  126.    
  127.     #source1
  128.     PrintList(fout, StartPrintLine(s1, n))
  129.     fout.write(";")
  130.    
  131.     #source2
  132.     i = EqualLine(s2, 1, delim2, Word)
  133.     print "Printing line", n+1, "\b, matched with audio line", i, "\b."
  134.     PrintList(fout, PrintLine(s2, i, 14, 3))
  135.     fout.write("\n")
  136.    
  137.     n = n+1
  138.  
  139. s1.close()
  140. s2.close()
  141. fout.close()
Advertisement
Add Comment
Please, Sign In to add comment