예제 #1
0
 def read_data(self, filepath):
     #0分组 1问题标签 2回答 3等价描述 4表情 5图片 6超时时间
     book = xlrd.open_workbook(filepath)
     for sheet in book.sheets():
         for i in range(1, sheet.nrows):
             row = sheet.row(i)
             if row[1].value != '' and row[2].value != '':
                 d = [clean_str(x.value) for x in row]
                 if d[4] == '':
                     d[4] = 'null'
                 if d[5] == '':
                     d[5] = 'null'
                 if len(d) > 6:
                     if d[6] == '':
                         timeout = 'null'
                     else:
                         timeout = d[6]
                 else:
                     timeout = 'null'
                 data = {}
                 data['group'] = d[0]
                 data['label'] = d[1]
                 data['answers'] = split_pro(d[2], '/')
                 data['equal_questions'] = list(set(split_pro(d[1], '/') + \
                         split_pro(d[3], '/')))
                 data['equal_questions'] = \
                         list(set(questions_pro(data['equal_questions'])))
                 data['emotion_name'] = d[4]
                 data['emotion_url'] = Emotion[d[4]]
                 data['media'] = d[5]
                 data['timeout'] = timeout
                 self.data.append(data)
예제 #2
0
 def write_data2mongodb(self):
     for key in self.q2i.keys():
         i = key.split('#')
         self.I.add(i[1])
         dic = {}
         dic['equal_questions'] = list(set(questions_pro(list(set(self.q2i[key])))))
         dic['business'] = i[0]
         dic['intention'] = i[1]
         dic['super_intention'] = i[2]
         dic['answers'] = self.i2a[i[1]][0]
         dic['emotion_name'] = self.i2a[i[1]][1]
         dic['emotion_url'] = Emotion[self.i2a[i[1]][1]]
         dic['media'] = self.i2a[i[1]][2]
         dic['timeout'] = self.i2a[i[1]][3]
         self.data.append(dic)
     self.db['dialogue'].drop()
     self.db['dialogue'].insert(self.data)
     self.db['dialogue'].create_index('intention')