Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created September 28, 2018 14:28
Show Gist options
  • Save CapsAdmin/643a3b0e529a2e27c31367e1f3d25a91 to your computer and use it in GitHub Desktop.
Save CapsAdmin/643a3b0e529a2e27c31367e1f3d25a91 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 split_string(self, separator, max)
local tbl = {}
local current_pos = 1
for i = 1, max or #self do
local start_pos, end_pos = self:find(separator, current_pos, true)
if not start_pos then break end
tbl[i] = self:sub(current_pos, start_pos - 1)
current_pos = end_pos + 1
end
if current_pos > 1 then
tbl[#tbl + 1] = self:sub(current_pos)
else
tbl[1] = self
end
return tbl
end
local excluded = {["<para>"]=true,
["<eod>"]=true}
function read_lines(fname, separator)
local cols = {}
local i = 1
for line in io.lines(fname) do
local res = split_string(line, separator, 2)
if not excluded[res[2]] then
cols[i] = res[2]
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