Advertisement
polv

marked-vocab

Dec 25th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. #! /usr/bin/python3
  2.  
  3. #Universal parameters
  4. delim1 = ";"
  5. delim2 = "\t"
  6. number_of_words = 183
  7. vocab_list = "marked.txt"
  8. source1 = "vocabulary.txt"
  9. output = "vocab_marked.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 list is", vocab_list ", and the deliminator is", delim1, "\b."
  108. print "Full vocab file is", source1, ", and the deliminator is", delim1, "\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 the vocab list is ';', and the vocab is separated by ';'."
  113. raw_input("\nPress the enter key to continue.")
  114.  
  115. f1 = open(vocab_list, "r")
  116. s1 = open(source1, "r")
  117. f2 = 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(f1, 0, delim1)
  126.    
  127.     #source1
  128.     i = EqualLine(s1, 2, delim1, Word)
  129.     PrintList(f2, StartPrintLine(s1, i))
  130.     print "Printing line", n+1, "\b,matched with line", i
  131.     f2.write("\n")
  132.     n = n+1
  133.  
  134. f1.close()
  135. f2.close()
  136. s1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement