Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python3
- #Universal parameters
- delim1 = ";"
- delim2 = "\t"
- number_of_words = 183
- vocab_list = "marked.txt"
- source1 = "vocabulary.txt"
- output = "vocab_marked.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 list is", vocab_list ", and the deliminator is", delim1, "\b."
- print "Full vocab file is", source1, ", and the deliminator is", delim1, "\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 the vocab list is ';', and the vocab is separated by ';'."
- raw_input("\nPress the enter key to continue.")
- f1 = open(vocab_list, "r")
- s1 = open(source1, "r")
- f2 = open(output, "w")
- while s1.read(1) == "#":
- NextLine(s1)
- s1.seek(-1,1)
- n = 0
- while n < number_of_words:
- Word = GetWord(f1, 0, delim1)
- #source1
- i = EqualLine(s1, 2, delim1, Word)
- PrintList(f2, StartPrintLine(s1, i))
- print "Printing line", n+1, "\b,matched with line", i
- f2.write("\n")
- n = n+1
- f1.close()
- f2.close()
- s1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement