1. 拼接子串技健,每個(gè)新子串長(zhǎng)度不大于max_len
# split_ids是一個(gè)二維list(針對(duì)每一條評(píng)論), 每個(gè)元素是一個(gè)以mask為結(jié)尾(或者評(píng)論結(jié)尾為結(jié)尾)的list
# 拼接子句句子
si = 0
while si < len(split_ids):
tmp_list = []
while si < len(split_ids) and len(tmp_list) + len(split_ids[si]) <= max_len:
tmp_list += split_ids[si]
si += 1
# 循環(huán)結(jié)束后判斷語(yǔ)句
if si < len(split_ids):
if len(tmp_list) == 0: # 第一個(gè)子句長(zhǎng)度就超過(guò)max_len了踢涌,按尾句截?cái)? sub_ids_list.append(split_ids[si][-max_len:])
si += 1
else:
sub_ids_list.append(tmp_list)
elif len(tmp_list) != 0:
sub_ids_list.append(tmp_list)
2. flask傳遞前端有Null值時(shí),為了不顯示None
{{ result or '' }}