Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- # 读取 JSON 文件
- def read_json_file(file_path):
- try:
- with open(file_path, 'r', encoding='utf-8') as file:
- data = json.load(file)
- return data
- except FileNotFoundError:
- print(f"错误: 文件 {file_path} 未找到。")
- return []
- except json.JSONDecodeError:
- print(f"错误: 无法解析 {file_path} 中的 JSON 数据。")
- return []
- # 添加误导性字段
- def add_misleading_field(data):
- # misleading_fields = [
- # "The weather on that day was sunny with a gentle breeze.",
- # "A nearby observer was wearing a red hat.",
- # "There was a small bird flying overhead during the experiment.",
- # "The temperature in the room was 25 degrees Celsius.",
- # "A clock on the wall showed 3:15 PM.",
- # "A car passed by on the road outside.",
- # "There was a faint smell of flowers in the air.",
- # "A sign on the wall read 'Keep Quiet'.",
- # "A child was playing with a ball nearby.",
- # "The table where the experiment was conducted was made of wood."
- # ]
- misleading_fields = [
- "The spring was slightly rusted, which might affect its elastic coefficient, but it was assumed to be negligible in the experiment.",
- "There was a slight air resistance during the free - fall motion, although it was considered to have no significant impact on the result.",
- "The road surface where the cars were moving had a small coefficient of friction, but it was ignored in this problem.",
- "During the particle collision, there was a very small amount of energy loss due to a brief magnetic field interference, which was not accounted for in the calculations.",
- "The lunar surface has a thin layer of dust, which might cause a small change in the gravitational field, but it was not considered in this model.",
- "There was a weak magnetic field around the charged ball, which could potentially affect its motion, but was assumed to be insignificant.",
- "The toll station area had a very slight slope, but it was assumed to be a flat road in the analysis.",
- "The magnetic field around the coil had a small non - uniformity, but it was considered uniform for simplicity in this problem.",
- "The AC generator had a small amount of mechanical friction in its rotation, which was not considered in the power calculations.",
- "The transmission line had a small capacitance effect, but it was ignored in the power transmission analysis."
- ]
- # misleading_fields = [
- # "The weather on that day was sunny with a gentle breeze.",
- # "A nearby observer was wearing a red hat.",
- # "There was a small bird flying overhead during the experiment.",
- # "The temperature in the room was 25 degrees Celsius.",
- # "A clock on the wall showed 3:15 PM.",
- # "A car passed by on the road outside.",
- # "There was a faint smell of flowers in the air.",
- # "A sign on the wall read 'Keep Quiet'.",
- # "A child was playing with a ball nearby.",
- # "The table where the experiment was conducted was made of wood."
- # ]
- for i, item in enumerate(data):
- context = item["question_structure"]["context"]
- misleading_field = misleading_fields[i % len(misleading_fields)]
- new_context = f"{context} {misleading_field}"
- item["question_structure"]["context"] = new_context
- return data
- # 保存 JSON 文件
- def save_json_file(data, file_path):
- try:
- with open(file_path, 'w', encoding='utf-8') as file:
- json.dump(data, file, ensure_ascii=False, indent=4)
- print(f"文件已成功保存到 {file_path}。")
- except Exception as e:
- print(f"错误: 保存文件时出现问题: {e}")
- if __name__ == "__main__":
- input_file_path = '/home/xie.zhongwei/extracted_data.json'
- output_file_path = '/home/xie.zhongwei/modified_extracted_data.json'
- # 读取文件
- data = read_json_file(input_file_path)
- if data:
- # 添加误导性字段
- modified_data = add_misleading_field(data)
- # 保存修改后的文件
- save_json_file(modified_data, output_file_path)
Add Comment
Please, Sign In to add comment