# user_prompt = f"""You are an advanced semantic analyzer. For the given question, perform the following tasks step-by-step: # 1. **Domain Identification**: # - Determine the broad subject category (domain) this question belongs to. # - Examples: film, history, biology, geography, politics, technology, etc (or any other suitable domain) # 2. **Key Point Extraction**: # - Identify 2-4 core semantic components that are crucial for answering # - Include: # • Key entities (e.g., films, people, locations) # • Critical attributes (e.g., age, duration, population) # • Core relationships (e.g., comparison, causality) # • Measurement dimensions (e.g., time, quantity) # - Exclude filler words and non-essential descriptors # **Output Requirements**: # - Use JSON format: {{"domain": "...", "key_points": [...]}} # - Keep key_points concise (1-2 words each) # - Use lowercase for all outputs # - Separate multiple key_points with commas # **Examples**: # Question: "Which film whose director is younger, Charge It To Me or Danger: Diabolik?" # Output: {{"domain": "film", "key_points": ["director", "age"]}} # **Now process this question:** # {{Question}}""" # print(user_prompt.replace('{Question}', 'Which film whose director is younger, Charge It To Me or Danger: Diabolik?')) # import json # txt = "{'domain': 'film', 'key_points': ['directors', 'country', 'same']}" # print(json.loads(txt)) # 使用ast.literal_eval解析Python风格字符串(需import ast) # import ast # py_style_txt = "{'domain': 'film', 'key_points': ['directors', 'country', 'same']}" # print(ast.literal_eval(py_style_txt)) # 输出解析后的字典 import re def extract_last_braced_content(s): """ 提取字符串中被 {} 包裹的内容,如果有多个则返回最后一个。 :param s: 输入字符串 :return: 最后一个被 {} 包裹的内容,如果没有则返回 None """ # 使用正则表达式匹配所有被 {} 包裹的内容 # matches = re.findall(r'\{(.*?)\}', s) matches = re.findall(r'\{.*?\}', s) # 如果有匹配的内容,返回最后一个;否则返回 None return matches[-1] if matches else None # import json # input_file_path = "/share/project/sunshuang/deep_search/data_syn/data/mixed_data/splits/tagged_domain_keypoints/final_selected_dataset.json" # with open(input_file_path, 'r') as f: # data = json.load(f) # print(len(data)) text = '{"domain": "development", "key_points": ["human development index", "adopted", "time", "employer"]} \n*Note: The key point "human development index" exceeds the 1-2 word limit. To comply strictly, "hdi" (abbreviation) could be used instead for conciseness, but the original term is more precise. Adjusting for the requirement:* \n{"domain": "development", "key_points": ["hdi", "adopted", "time", "employer"]}' print(extract_last_braced_content(text))