Refactor: Improve Consistency in Function Signatures and Regex Usage in compute_ism_pm_score.py (#9145)

This commit is contained in:
Maxim Evtush 2025-06-17 23:22:16 +03:00 committed by GitHub
parent 3591c7a79f
commit 653a8a7ce2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -116,7 +116,7 @@ def get_token_per_line(code: str):
return identifiers_per_line return identifiers_per_line
def get_ISM(answer_code: str, model_output_list: list, asnwer_name: str) -> list: def get_ISM(answer_code: str, model_output_list: list, answer_name: str) -> list:
""" """
计算ISM返回一个有序的得分列表 计算ISM返回一个有序的得分列表
:return: :return:
@ -126,13 +126,13 @@ def get_ISM(answer_code: str, model_output_list: list, asnwer_name: str) -> list
if '```python' in code: if '```python' in code:
code = code.replace('```python', '') code = code.replace('```python', '')
code = code.replace('```', '') code = code.replace('```', '')
if not re.search(rf'\b{re.escape(asnwer_name)}\b', code) or not is_code_valid( if not re.search(rf'\b{re.escape(answer_name)}\b', code) or not is_code_valid(
code code
): ):
score_list.append(0) score_list.append(0)
continue continue
# if asnwer_name not in code: # if answer_name not in code:
# score_list.append(0) # score_list.append(0)
# continue # continue
@ -155,7 +155,7 @@ def get_ISM(answer_code: str, model_output_list: list, asnwer_name: str) -> list
def get_ISM_without_verification( def get_ISM_without_verification(
answer_code: str, model_output_list: list, asnwer_name: str answer_code: str, model_output_list: list, answer_name: str
) -> list: ) -> list:
""" """
计算ISM返回一个有序的得分列表 计算ISM返回一个有序的得分列表
@ -163,11 +163,11 @@ def get_ISM_without_verification(
""" """
score_list = [] score_list = []
for code in model_output_list: for code in model_output_list:
if asnwer_name not in code: if answer_name not in code:
score_list.append(0) score_list.append(0)
continue continue
# if asnwer_name not in code: # if answer_name not in code:
# score_list.append(0) # score_list.append(0)
# continue # continue
@ -215,7 +215,7 @@ def longest_common_prefix_with_lengths(list1, list2):
return max_length, len_list1, len_list2 return max_length, len_list1, len_list2
def get_PM(answer_code: str, model_output_list: list, asnwer_name: str) -> list: def get_PM(answer_code: str, model_output_list: list, answer_name: str) -> list:
""" """
计算PM返回一个有序的得分列表 计算PM返回一个有序的得分列表
:return: :return:
@ -225,14 +225,14 @@ def get_PM(answer_code: str, model_output_list: list, asnwer_name: str) -> list:
if '```python' in code: if '```python' in code:
code = code.replace('```python', '') code = code.replace('```python', '')
code = code.replace('```', '') code = code.replace('```', '')
if not re.search(rf'\b{re.escape(asnwer_name)}\b', code) or not is_code_valid( if not re.search(rf'\b{re.escape(answer_name)}\b', code) or not is_code_valid(
code code
): ):
# if asnwer_name not in code or is_code_valid(code) == False: # if answer_name not in code or is_code_valid(code) == False:
score_list.append(0) score_list.append(0)
continue continue
# if asnwer_name not in code: # if answer_name not in code:
# score_list.append(0) # score_list.append(0)
# continue # continue