1 Star 1 Fork 0

nlp天眼/mathematics_practical_problems

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fifth_step.py 5.45 KB
一键复制 编辑 原始数据 按行查看 历史
import json
def number_choose(s):
try:
return float(s)
except ValueError:
if "/" in s:
s = s.split("/")
try:
return float(s[0]) / float(s[1])
except ValueError:
return False
return False
new_question = json.load(open("new_question.json", encoding="utf-8"))
print(len(new_question))
calculation_symbols = ["+", "-", "*", "/", "//", "%"]
revert_symbols = ["-", "/", "//", "%"]
three_calculation_symbols = []
for calculation_symbol in calculation_symbols:
for calculation_second in calculation_symbols:
three_calculation_symbols.append([calculation_symbol, calculation_second])
third_mathematics_practical_problems = []
def add(a, b):
return a + b
def remove(a, b):
return a - b
def division(a, b):
return a / b
def multiplication(a, b):
return a * b
def division_int(a, b):
return a // b
def five(a, b):
return a % b
def three_calculation_compute(number, three_calculation_label):
computer_answer = None
if number[0] and number[1]:
if three_calculation_label[0] == "+":
computer_answer = add(number[0], number[1])
if three_calculation_label[0] == "-":
computer_answer = remove(number[0], number[1])
if three_calculation_label[0] == "*":
computer_answer = multiplication(number[0], number[1])
if three_calculation_label[0] == "/":
computer_answer = division(number[0], number[1])
if three_calculation_label[0] == "//":
computer_answer = division_int(number[0], number[1])
if three_calculation_label[0] == "%":
computer_answer = five(number[0], number[1])
return computer_answer
slot_question = []
unbelived_data = []
for new_question in new_question:
if new_question in slot_question:
continue
else:
slot_question.append(new_question)
match_answer = number_choose(new_question["answer"])
new_question["compute_answer"] = match_answer
new_question["compute_answers"] = []
new_question["label"] = []
if len(new_question["number"]) == 1:
continue
if len(new_question["number"]) == 2:
calculation = new_question["number"]
for calculation_label in range(len(calculation_symbols)):
first_answer = three_calculation_compute(calculation, calculation_symbols[calculation_label])
if first_answer == match_answer:
new_question["label"].append({str(calculation_label + 1): calculation_symbols[calculation_label]})
if new_question not in third_mathematics_practical_problems:
third_mathematics_practical_problems.append(new_question)
break
else:
new_question["compute_answers"].append({str(calculation_label + 1): first_answer})
for revert_index in range(len(revert_symbols)):
first_answer = three_calculation_compute([calculation[1], calculation[0]],
revert_symbols[revert_index])
if first_answer == match_answer:
new_question["label"].append({str(revert_index + len(calculation_symbols) + 1): revert_symbols[revert_index]})
if new_question not in third_mathematics_practical_problems:
third_mathematics_practical_problems.append(new_question)
break
else:
new_question["compute_answers"].append({str(revert_index + len(calculation_symbols) + 1): first_answer})
if len(new_question["number"]) == 3:
for three_calculation_index in range(len(three_calculation_symbols)):
compute_answer = three_calculation_compute([new_question["number"][0], new_question["number"][1]],
three_calculation_symbols[three_calculation_index][0])
second_compute_answer = three_calculation_compute([compute_answer, new_question["number"][2]],
three_calculation_symbols[three_calculation_index][1])
if second_compute_answer == match_answer:
new_question["label"].append({str(
three_calculation_index + len(calculation_symbols) + 1 + len(revert_symbols)):
three_calculation_symbols[three_calculation_index]}
)
if new_question not in third_mathematics_practical_problems:
third_mathematics_practical_problems.append(new_question)
break
else:
new_question["compute_answers"].append({str(
three_calculation_index + len(calculation_symbols) + 1 + len(
revert_symbols)): second_compute_answer})
if not new_question["label"]:
unbelived_data.append(new_question)
print(len(third_mathematics_practical_problems))
json.dump(third_mathematics_practical_problems,
open("fifth_mathematics_practical_problem.json", "w", encoding="utf-8"), ensure_ascii=False, indent=3)
json.dump(third_mathematics_practical_problems[:20],
open("fifth_mathematics_practical_part.json", "w", encoding="utf-8"), ensure_ascii=False, indent=3)
json.dump(unbelived_data,
open("fifth_unbelieved_data.json", "w", encoding="utf-8"), ensure_ascii=False, indent=3)
print(len(third_mathematics_practical_problems) / len(slot_question))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/swner/mathematics_practical_problems.git
git@gitee.com:swner/mathematics_practical_problems.git
swner
mathematics_practical_problems
mathematics_practical_problems
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385