MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / parse_user_reply

Function parse_user_reply

agents/feedback-agent/main.py:234–305  ·  view source on GitHub ↗

解析用户回复,提取选中的论文编号 支持格式: - "1 2 4 6 7 9 11" (空格分隔) - "1-5 6 9 11" (范围 + 单个编号) - "1,2,4,6,7,9,11" (逗号分隔) - 混合格式:"1-3 5 7-9 11" - 快捷命令:"all lock"(所有必读)、"all red"(所有高度相关) Args: reply: 用户回复文本 papers: 论文列表(用于快捷命令) Returns: 选中的编号集合

(reply: str, papers: List[Dict] = None)

Source from the content-addressed store, hash-verified

232def parse_user_reply(reply: str, papers: List[Dict] = None) -> Set[int]:
233 """
234 解析用户回复,提取选中的论文编号
235
236 支持格式:
237 - "1 2 4 6 7 9 11" (空格分隔)
238 - "1-5 6 9 11" (范围 + 单个编号)
239 - "1,2,4,6,7,9,11" (逗号分隔)
240 - 混合格式:"1-3 5 7-9 11"
241 - 快捷命令:"all lock"(所有必读)、"all red"(所有高度相关)
242
243 Args:
244 reply: 用户回复文本
245 papers: 论文列表(用于快捷命令)
246
247 Returns:
248 选中的编号集合
249 """
250 selected: Set[int] = set()
251 max_paper_num = len(papers) if papers else 200
252
253 # 快捷命令处理
254 reply_lower = reply.lower().strip()
255
256 if reply_lower == "all lock":
257 # 选择必读清单论文
258 if papers:
259 for i, paper in enumerate(papers):
260 if paper.get("category") == "must_read":
261 selected.add(i + 1) # 编号从 1 开始
262 return selected
263
264 if reply_lower == "all red":
265 # 选择所有高度相关论文
266 if papers:
267 for i, paper in enumerate(papers):
268 if paper.get("category") == "high_relevant":
269 selected.add(i + 1) # 编号从 1 开始
270 return selected
271
272 if reply_lower == "none":
273 # 都不选
274 return selected
275
276 # 规范化:将逗号、顿号等替换为空格
277 normalized = re.sub(r"[,,、;;]", " ", reply)
278
279 # 提取所有 token(由空格分隔的部分)
280 tokens = normalized.split()
281
282 for token in tokens:
283 token = token.strip()
284 if not token:
285 continue
286
287 # 检查是否是范围格式(如 "1-5")
288 range_match = re.match(r"^(\d+)-(\d+)$", token)
289 if range_match:
290 start = int(range_match.group(1))
291 end = int(range_match.group(2))

Callers 2

mainFunction · 0.85
process_feedbackFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected