comparison.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import json
  2. import pandas as pd
  3. keyword2id_dict = dict()
  4. # 求解类型
  5. solution_type_list = ["概念辨析","规律理解","现象解释","物理学史","计算分析","实验操作","连线作图","实验读数"]
  6. solving_type2id = dict()
  7. for i, ele in enumerate(solution_type_list):
  8. solving_type2id[ele] = 1 + i
  9. keyword2id_dict["solving_type2id"] = solving_type2id
  10. # 物理量
  11. excel_path = r"data/物理量.xlsx"
  12. df = pd.read_excel(excel_path)
  13. quantity2id = dict()
  14. count_index = 0
  15. for i in range(len(df)):
  16. if not pd.isna(df['类别'][i]):
  17. count_index += 1
  18. sign_index = count_index * 100
  19. knowledge = df['物理量'][i]
  20. if not pd.isna(knowledge):
  21. sign_index += 1
  22. quantity2id[knowledge] = sign_index
  23. keyword2id_dict["quantity2id"] = quantity2id
  24. # 物理场景
  25. excel_path = r"data/物理情景.xlsx"
  26. df = pd.read_excel(excel_path)
  27. scene2id = dict()
  28. count_index = 0
  29. for i in range(len(df)):
  30. if not pd.isna(df['知识点'][i]):
  31. count_index += 1
  32. sign_index = 10000 + count_index * 10
  33. knowledge = df['情景'][i]
  34. if not pd.isna(knowledge):
  35. sign_index += 1
  36. scene2id[knowledge] = sign_index
  37. keyword2id_dict["scene2id"] = scene2id
  38. # 知识点
  39. excel_path = r"data/物理知识点.xlsx"
  40. df = pd.read_excel(excel_path)
  41. knowledge2id = dict()
  42. init_id2max_id = dict()
  43. count_index = 0
  44. for i in range(len(df)):
  45. if not pd.isna(df['2级知识点'][i]):
  46. count_index += 1
  47. if not pd.isna(df['3级知识点'][i]):
  48. sign = df['3级知识点'][i].split(' ')[0].split('.')
  49. # sign_index = 10000 + int(sign[0]) * 100 + int(sign[1]) * 10
  50. sign_index = 10000 + count_index * 100 + int(sign[1]) * 10
  51. init_id = sign_index
  52. init_id2max_id[init_id] = sign_index
  53. knowledge = df['4级知识点'][i]
  54. if not pd.isna(knowledge):
  55. sign_index += 1
  56. knowledge2id[knowledge] = sign_index
  57. init_id2max_id[init_id] = sign_index
  58. keyword2id_dict["knowledge2id"] = knowledge2id
  59. keyword2id_dict["init_id2max_id"] = init_id2max_id
  60. # 映射转换
  61. with open("data/keyword_mapping.json", 'w', encoding="utf8") as f:
  62. json.dump(keyword2id_dict, f, ensure_ascii=False, indent=2)