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)
def read_questions(self, filepath): #0问题 1回答 2业务 3意图 4上级意图 5等价描述 book = xlrd.open_workbook(filepath) for sheet in book.sheets(): for i in range(1, sheet.nrows): if sheet.row(i)[0].value == '': continue line = [clean_str(x.value) for x in sheet.row(i)] questions = split_pro(line[0], '/') + split_pro(line[5], '/') key = line[2]+'#'+line[3]+ '#' + line[4] self.q2i[key] = self.q2i.setdefault(key, []) + questions
def read_data(self, filepath): #0问题 1回答 2表情 3图片 4超时时间 book = xlrd.open_workbook(filepath) for sheet in book.sheets(): for i in range(1, sheet.nrows): row = sheet.row(i) if row[0].value != '' and row[1].value != '': d = [clean_str(x.value) for x in row] if d[2] == '': d[2] = 'null' if d[3] == '': d[3] = 'null' if len(d) > 4: if d[4] == '': timeout = 'null' else: timeout = d[4] else: timeout = 'null' data = {} data['group'] = '情感' data['label'] = d[0] data['equal_questions'] = ['null'] data['answers'] = split_pro(d[1], '/') data['emotion_name'] = d[2] data['emotion_url'] = Emotion[d[2]] data['media'] = d[3] data['timeout'] = timeout self.data.append(data)
def read_data(filepath): #label questions book = xlrd.open_workbook(filepath) for sheet in book.sheets(): for i in range(1, sheet.nrows): if sheet.row(i)[0].value == '': continue line = [clean_str(x.value) for x in sheet.row(i)] questions = split_pro(line[1], '/') if line[0] not in Data.keys(): Data[line[0]] = questions else: Data[line[0]] += questions
def read_intention2answer(self, filepath): #0意图 1回答 2表情名称 3图片 4超时时间 book = xlrd.open_workbook(filepath) for sheet in book.sheets(): for i in range(1, sheet.nrows): if sheet.row(i)[0].value == '': continue line = [clean_str(x.value) for x in sheet.row(i)] if line[2] == '': line[2] = 'null' if line[3] == '': line[3] = 'null' if len(line) > 4: if line[4] == '': timeout = 'null' else: timeout = line[4] else: timeout = 'null' self.i2a[line[0]] = [split_pro(line[1], '/'), line[2], line[3], timeout] self.II = set(self.i2a.keys())