HugoVoxx commited on
Commit
33c3023
·
verified ·
1 Parent(s): b48a21c

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +21 -15
utils.py CHANGED
@@ -11,18 +11,24 @@ def translate(input:str) -> str:
11
  def run_ag():
12
  subprocess.run(["ag4masses/utils/run.sh"])
13
  def read_solution():
14
- with open('ag4mout/solution.out', 'r', encoding='utf-8') as f:
15
- lines = f.readlines()
16
- paragraphs = ''.join(lines).split('\n\n')
17
- theorem_premises = paragraphs[0].strip()
18
- auxiliary_constructions = paragraphs[1].strip()
19
- proof_steps = paragraphs[2].strip()
20
- proof_steps = re.sub(r'\d+\. ', '- Ta có:\n', proof_steps)
21
- proof_steps = re.sub(r' & ', '\n', proof_steps)
22
- proof_steps = re.sub(r' ', '\n', proof_steps)
23
- result = {
24
- theorem_premises.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(theorem_premises.split('\n')[1:])),
25
- auxiliary_constructions.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(auxiliary_constructions.split('\n')[1:])),
26
- proof_steps.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(proof_steps.split('\n')[1:]))
27
- }
28
- return result
 
 
 
 
 
 
 
11
  def run_ag():
12
  subprocess.run(["ag4masses/utils/run.sh"])
13
  def read_solution():
14
+ if os.path.exists('ag4mout/solution.out'):
15
+ with open('ag4mout/solution.out', 'r', encoding='utf-8') as f:
16
+ lines = f.readlines()
17
+ paragraphs = ''.join(lines).split('\n\n')
18
+ theorem_premises = paragraphs[0].strip()
19
+ auxiliary_constructions = paragraphs[1].strip()
20
+ proof_steps = paragraphs[2].strip()
21
+ proof_steps = re.sub(r'\d+\. ', '- Ta có:\n', proof_steps)
22
+ proof_steps = re.sub(r' & ', '\n', proof_steps)
23
+ proof_steps = re.sub(r' ⇒ ', '\n⇒ ', proof_steps)
24
+ result = {
25
+ theorem_premises.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(theorem_premises.split('\n')[1:])),
26
+ auxiliary_constructions.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(auxiliary_constructions.split('\n')[1:])),
27
+ proof_steps.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(proof_steps.split('\n')[1:]))
28
+ }
29
+ return result
30
+ else:
31
+ return {"key_1": "Bài toán không thể giải được/Đề bài bị lỗi",
32
+ "key_2": "Bài toán không thể giải được/Đề bài bị lỗi",
33
+ "key_3": "Bài toán không thể giải được/Đề bài bị lỗi",
34
+ }