forked from aceimnorstuvwxz/chatbot-zh-torch7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cornell_movie_dialogs.lua
executable file
·64 lines (48 loc) · 1.29 KB
/
cornell_movie_dialogs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local CornellMovieDialogs = torch.class("neuralconvo.CornellMovieDialogs")
local stringx = require "pl.stringx"
local xlua = require "xlua"
function CornellMovieDialogs:__init(dir)
self.dir = dir
end
function CornellMovieDialogs:load()
local lines = {}
local conversations = {}
local count = 1
print("-- Parsing Cornell movie dialogs data set ...")
local f = assert(io.open('../xiaohuangji50w_fenciA.conv', 'r'))
while true do
local line = f:read("*line")
if line == nil then
f:close()
break
end
lines[count] = line
count = count + 1
end
print("Total lines = "..count)
local tmpconv = nil
local TOTAL = #lines
local count = 0
for i, line in ipairs(lines) do
--print(i..' '..line)
if string.sub(line, 0, 1) == "E" then
if tmpconv ~= nil then
--print('new conv'..#tmpconv)
table.insert(conversations, tmpconv)
end
--print('e make the tmpconv')
tmpconv = {}
end
if string.sub(line, 0, 1) == "M" then
--print('insert into conv')
local tmpl = string.sub(line, 3, #line)
--print(tmpl)
table.insert(tmpconv, tmpl)
end
count = count + 1
if count%1000 == 0 then
xlua.progress(count, TOTAL)
end
end
return conversations
end