-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
48 lines (36 loc) · 1.57 KB
/
utils.py
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
import re
import difflib
def get_cate(response):
line_list = response.split('\n')
cate_list = []
if len(line_list) == 1:
cate_list = [c.replace(" ", "").lower() for c in line_list[0].split(',')]
return cate_list
for line in line_list:
if line and line[0].isdigit():
cate_name = re.sub(r"[-:() ]", "", line.split(".", 1)[-1]).lower()
cate_list.append(cate_name)
return cate_list
def get_news_title(message):
return [line.split('.', 1)[-1].strip() for line in message.split('\n') if line.strip() and line[0].isdigit()]
def get_subcate(response):
line_list = response.split('\n')
subcate_list = []
for line in line_list:
if line and line[0].isdigit():
subcate_name = re.sub(r"[-:() ]", "", line.split(".", 1)[-1]).lower()
subcate_list.append(subcate_name)
return subcate_list
def get_pos_news(news_data, user_id, user_history):
user_impression = user_history[user_history["User ID"] == user_id]["Impression News"]
user_pos_news = set()
for impression in user_impression:
item_list = impression.split(' ')
for item in item_list:
newsid, label = item.split('-')
if label == '1':
news_title = news_data[news_data["NewsID"] == newsid]["NewsTitle"].iloc[0]
user_pos_news.add(news_title)
return user_pos_news
def get_answer_list(message):
return [line.split('.', 1)[-1].strip() for line in message.split('\n') if line.strip() and line[0].isdigit()]