| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import json
- import re
- def _looks_like_placeholder_text(text: str) -> bool:
- normalized = (text or "").strip()
- if not normalized:
- return False
- placeholder_patterns = [
- r"^题目内容$",
- r"^解析内容$",
- r"^参考措施$",
- r"^答题要点$",
- r"^具体选项内容$",
- r"^选项[ABCD]$",
- r"^.+工程相关(?:单选题|多选题|判断题|简答题)\d+$",
- r"^.+相关(?:单选题|多选题|判断题|简答题)\d+$",
- r"^第?\d+题$",
- r"^题目\d+$",
- ]
- return any(re.search(pattern, normalized) for pattern in placeholder_patterns)
- def _exam_payload_has_placeholders(payload) -> bool:
- if isinstance(payload, dict):
- return any(_exam_payload_has_placeholders(value) for value in payload.values())
- if isinstance(payload, list):
- return any(_exam_payload_has_placeholders(item) for item in payload)
- if isinstance(payload, str):
- if _looks_like_placeholder_text(payload):
- print(f"Match found for: {payload}")
- return True
- return False
- return False
- # we can simulate the generated JSON to see which field triggers the placeholder
- mock_payload = {
- "title": "隧道工程施工技术考核",
- "totalScore": 100,
- "totalQuestions": 10,
- "singleChoice": {"scorePerQuestion": 2, "totalScore": 20, "count": 10, "questions": [{"text": "这是一个单选题题干", "options": [{"key": "A", "text": "选项A具体内容"}, {"key": "B", "text": "选项B具体内容"}], "answer": "A", "analysis": "解析内容"}]},
- }
- print("Has placeholder:", _exam_payload_has_placeholders(mock_payload))
|