MCPcopy Create free account
hub / github.com/elena-luo/SODE / split_refine

Method split_refine

pattern_extraction.py:87–348  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

85 return len(intersection) / len(union)
86
87 def split_refine(self, data):
88 Solution_Explore_save = []
89 Verify_Explore_save = []
90 split_dic_save = []
91 for d in tqdm(data):
92 try:
93 # dict_keys(['id', 'prompt', 'task_l1', 'task_l2', 'ground_truth', 'result', 'split_result'])
94 # get_response(d)
95 result = d['result']
96 result_list = result.split(".")
97 split_result = d["split_result"]
98 if self.part == "basic_structure":
99 split_dic = self.part1_split(split_result)
100 pre_key = None
101 for k, v in split_dic.items():
102 # dict_keys(['Question_Repeat', 'Problem_Understand', 'Solution_Explore', 'Verify', 'Conclusion'])
103 v_list = v.split(".")
104 if ((v_list[0] in result_list) or ("\n" + v_list[0] in result_list) or (
105 "\n\n" + v_list[0] in result_list)) and pre_key is not None:
106 if (v_list[0] in result_list):
107 start = result_list.index(v_list[0])
108 elif "\n" + v_list[0] in result_list:
109 start = result_list.index("\n" + v_list[0])
110 else:
111 start = result_list.index("\n\n" + v_list[0])
112 if start > 0:
113 v_real = split_dic[pre_key] + ".".join(result_list[: start]) + "."
114 split_dic[pre_key] = v_real
115 result_list = result_list[start:]
116 else:
117 a1 = self.find_str_in_list(v_list[0], result_list)
118 a2 = self.find_str_in_list("\n\n" + v_list[0], result_list)
119 if a2 >= 0 and pre_key is not None:
120 if a2 > 0 or (a2 == 0 and not result_list[0].startswith("\n\n" + v_list[0])):
121 v_real = split_dic[pre_key] + ".".join(result_list[: a2]) + result_list[
122 a2].replace("\n\n" + v_list[0], "")
123 split_dic[pre_key] = v_real
124 result_list[a2] = "\n\n" + v_list[0]
125 result_list = result_list[a2:]
126 elif a1 >= 0 and pre_key is not None:
127 if a1 > 0 or (a1 == 0 and not result_list[0].startswith(v_list[0])):
128 v_real = split_dic[pre_key] + ".".join(result_list[: a1]) + result_list[
129 a1].replace(v_list[0], "")
130 split_dic[pre_key] = v_real
131 result_list[a1] = v_list[0]
132 result_list = result_list[a1:]
133 if v_list[-1] == "":
134 v_list = v_list[:-1]
135 for i in range(len(v_list)):
136 flag = -i - 1
137 if v_list[flag] in result_list:
138 end = result_list.index(v_list[flag])
139 v_real = ".".join(result_list[: end + 1]) + "."
140 split_dic[k] = v_real
141 result_list = result_list[end + 1:]
142 break
143 elif "\n\n" + v_list[flag] in result_list:
144 end = result_list.index("\n\n" + v_list[flag])

Callers 1

runMethod · 0.95

Calls 3

part1_splitMethod · 0.95
find_str_in_listMethod · 0.95

Tested by

no test coverage detected