从聊天记录中提取物流价格和时效信息
Author:匿名用户
2026/01/05 09:12
Description
从客服聊天记录中精确提取物流报价数据,输出JSON格式结构化信息,包含完整上下文引用和时间戳标记。
Tags
代码编程提取信息内容生成
Content
### 从聊天记录中提取物流价格和时效信息
- **核心主题**:从聊天记录中提取物流价格和时效信息
- **用户意图**:自动化处理客服聊天记录,提取关键物流数据
- **内容特点**:需要精确的数据提取和时效计算,涉及中英文单位转换
###生成的提示词
```
你是一位专业的物流数据处理专家,擅长从聊天记录中提取结构化物流信息。你的任务是分析客服聊天记录,准确提取以下关键信息:
1. 物流报价数据:
- 出发地
- 目的地
- 体积/重量参数
- 价格
- 时效估算
2. 具体要求:
- 完全剔除无关对话内容
- 识别并统一处理中英文物流单位(plt/pcs/件/个等)
- 通过对话时间戳计算合理时效
- 确保数据提取无遗漏
3. 输出格式要求:
- 结构化JSON格式
- 包含完整引用上下文
- 附带数据提取时间标记
4. 数据处理规则:
- 时效计算示例:"今天提,21号交货"=4天时效
- 单位标准化:plt→托盘,pcs→件
- 空运/海运等运输方式需明确标注
5. 质量检查标准:
- 100%数据提取准确率
- 无无关内容混入
- 单位转换正确无误
- 时效计算合理
请先生成Python代码框架,确认无误后再继续填充具体实现逻辑。
```
### 💡 使用建议
- **适用场景**:客服聊天记录分析、物流数据统计、运输时效监控
- **优化方向**:可增加异常数据检测功能,自动标记可疑报价
### 第一阶段Python代码框架
```python
import re
from datetime import datetime
import json
def parse_logistics_chat(chat_log):
"""
分析物流客服聊天记录,提取关键报价信息
参数:
chat_log: str - 原始聊天记录文本
返回:
list - 结构化报价信息列表
"""
# 初始化结果容器
quotations = []
# 单位标准化映射表
UNIT_MAPPING = {
'plt': '托盘',
'pcs': '件',
'个': '件',
# 可扩展其他单位
}
# 第一步:按消息分割聊天记录
messages = chat_log.split('\n') # 根据实际换行符调整
# TODO: 添加具体解析逻辑
return json.dumps(quotations, ensure_ascii=False, indent=2)
```
### 第二阶段代码实现
```python
# 消息处理逻辑(接上一部分代码)
current_quotation = None
for msg in messages:
# 跳过空消息和非客服消息
if not msg.strip() or '斯比特客服' not in msg:
continue
# 提取消息时间和内容
try:
time_str, content = re.match(r'.*?(\d+/\d+ \d+:\d+:\d+)(.*)', msg).groups()
msg_time = datetime.strptime(time_str, '%m/%d %H:%M:%S')
except:
continue
# 识别报价信息
price_match = re.search(r'价格[::]\s*(\d+(?:\.\d+)?)', content)
if price_match:
if current_quotation:
quotations.append(current_quotation)
current_quotation = {
'price': float(price_match.group(1)),
'timestamp': time_str,
'details': {}
}
# 提取出发地/目的地
loc_match = re.search(r'从(.+?)到(.+?)[,,]', content)
if loc_match and current_quotation:
current_quotation['details'].update({
'origin': loc_match.group(1).strip(),
'destination': loc_match.group(2).strip()
})
# 处理时效信息
eta_match = re.search(r'(\d+)天到|(\d+号)交货', content)
if eta_match and current_quotation:
days = eta_match.group(1) or str((datetime.strptime(eta_match.group(2), '%d号') - msg_time).days)
current_quotation['eta_days'] = int(days)
# 添加最后一个报价
if current_quotation:
quotations.append(current_quotation)
return json.dumps(quotations, ensure_ascii=False, indent=2)
```
### 使用示例代码
```python
# 示例用法
chat_log = """
[无关对话]...
斯比特客服 5/17 13:52:52 从上海到北京,2plt货物,价格:3500元
Mandy 5/17 14:00:23 什么时候能到?
斯比特客服 5/17 14:01:15 今天提货,21号交货
[其他对话]...
"""
print(parse_logistics_chat(chat_log))
```
### 代码优化建议
1. 可添加正则表达式模式缓存提升性能
2. 增加异常处理防止解析失败
3. 可扩展支持更多物流参数提取
4. 建议添加数据验证逻辑
需要我继续完善任何部分吗?