(s:str)
| 70 | logger.warning("No complete JSON object found in the input string.") |
| 71 | return None |
| 72 | def extract_json_from_cluster(s:str): |
| 73 | import re |
| 74 | s=s.replace('*', '') |
| 75 | entity_name = re.search(r"Aggregate Entity Name:\s*(.+)", s).group(1).strip() |
| 76 | entity_description = re.search( |
| 77 | r"Aggregate Entity Description:\s*(.+?)\n\nFindings:", s, re.DOTALL |
| 78 | ).group(1).strip() |
| 79 | |
| 80 | # 提取 findings |
| 81 | pattern = r"<summary_(\d+)>:\s*(.*?)\s*<explanation_\1>:\s*(.*?)(?=\n<summary_\d+>:|\Z)" |
| 82 | matches = re.findall(pattern, s, re.DOTALL) |
| 83 | |
| 84 | findings = [] |
| 85 | for _, summary, explanation in matches: |
| 86 | findings.append({ |
| 87 | "summary": summary.strip().replace('\n', ' '), |
| 88 | "explanation": explanation.strip().replace('\n', ' ') |
| 89 | }) |
| 90 | |
| 91 | # 构造最终 JSON |
| 92 | result = { |
| 93 | "entity_name": entity_name, |
| 94 | "entity_description": entity_description, |
| 95 | "findings": findings |
| 96 | } |
| 97 | |
| 98 | # 输出 JSON 字符串(可选择写入文件) |
| 99 | return result |
| 100 | def parse_value(value: str): |
| 101 | """Convert a string value to its appropriate type (int, float, bool, None, or keep as string). Work as a more broad 'eval()'""" |
| 102 | value = value.strip() |
nothing calls this directly
no outgoing calls
no test coverage detected