You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.7 KiB

import re
# 输入文本
text = """
2002.09--2006.07  曲阜师范大学历史文化学院旅游管理专业学习
2006.07--2007.01  待业
2007.01--2008.01  滕州市旅游局见习期人员
2008.01--2017.07  滕州市旅游和服务业发展局科员
2017.07--2019.10  滕州市环境监察大队科员
2019.10--2020.12  滕州市生态环境保护综合执法大队科员
2020.12--2021.04  滕州市生态环境保护综合执法大队一级行政执法员
2021.04--         枣庄市生态环境保护综合执法支队滕州市生态环境保护综合执法大队一级行政执法员
"""
# 正则表达式匹配每段经历
pattern = r"(\d{4}\.\d{2})--(\d{4}\.\d{2}|至今)\s*([^\n]+)"
# 查找所有匹配项
matches = re.findall(pattern, text)
# 定义标签规则
def get_label_and_details(content):
if "学习" in content:
# 匹配学校、学院、专业
school_pattern = r"([\u4e00-\u9fa5]+大学|学院)([\u4e00-\u9fa5]+学院)?([\u4e00-\u9fa5]+专业)?"
school_match = re.search(school_pattern, content)
if school_match:
school = school_match.group(1) or ""
college = school_match.group(2) or ""
major = school_match.group(3) or ""
details = {
"学校": school,
"学院": college,
"专业": major
}
else:
details = {}
return "教育经历", details
elif "待业" in content:
return "待业", {}
elif "见习" in content:
# 匹配单位名称
unit_pattern = r"([\u4e00-\u9fa5]+[局|队|公司|集团])"
unit_match = re.search(unit_pattern, content)
if unit_match:
unit = unit_match.group(1)
details = {
"单位": unit
}
else:
details = {}
return "见习经历", details
else:
# 匹配单位名称
unit_pattern = r"([\u4e00-\u9fa5]+[局|队|公司|集团])"
unit_match = re.search(unit_pattern, content)
if unit_match:
unit = unit_match.group(1)
details = {
"单位": unit
}
else:
details = {}
return "工作经历", details
# 整理结果
results = []
for match in matches:
start_time, end_time, content = match
label, details = get_label_and_details(content)
result = {
"开始时间": start_time,
"结束时间": end_time,
"主要内容": content.strip(),
"标签": label,
**details # 将具体名称合并到结果中
}
results.append(result)
# 输出结果
for result in results:
print(result)