Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created September 28, 2018 14:47
Show Gist options
  • Save CapsAdmin/f80d1fb3333cb4fe05fd706680c58661 to your computer and use it in GitHub Desktop.
Save CapsAdmin/f80d1fb3333cb4fe05fd706680c58661 to your computer and use it in GitHub Desktop.
local excluded = {["<para>"]=true,
["<eod>"]=true}
local function write_table(data, fname)
local file = io.open(fname, "w")
io.output(file)
io.write(table.concat(data, " "))
io.close(file)
end
local function get_second_column(line, separator)
local start_pos, end_pos = line:find(separator, 1, true)
if not start_pos then error("unable to find separator") end
local sub_pos = end_pos + 1
start_pos, end_pos = line:find(separator, sub_pos, true)
if not start_pos then error("unable to find separator") end
return line:sub(sub_pos, start_pos - 1)
end
local excluded = {["<para>"]=true,
["<eod>"]=true}
function read_lines(fname, separator)
print(fname)
local cols = {}
local i = 1
for line in io.lines(fname) do
local res = get_second_column(line, separator)
if not excluded[res] then
cols[i] = res
i = i + 1
end
end
return cols
end
function write_table(data, fname)
local file = io.open(fname, "w")
io.output(file)
io.write(table.concat(data, " "))
io.close(file)
end
local separator = ";"
local column2 = read_lines(arg[1], separator)
write_table(column2, "glove_corpus.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment