mavi88 commited on
Commit
eebb93b
·
1 Parent(s): 775108e

add data for IMO, USA_TST, USA_TSTST, USAJMO, USAMO

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. IMO/md/en-IMO2006SL.md +0 -0
  2. IMO/md/en-IMO2007SL.md +0 -0
  3. IMO/md/en-IMO2008SL.md +0 -0
  4. IMO/md/en-IMO2009SL.md +0 -0
  5. IMO/md/en-IMO2010SL.md +0 -0
  6. IMO/md/en-IMO2011SL.md +0 -0
  7. IMO/md/en-IMO2012SL.md +0 -0
  8. IMO/md/en-IMO2013SL.md +0 -0
  9. IMO/md/en-IMO2014SL.md +0 -0
  10. IMO/md/en-IMO2015SL.md +0 -0
  11. IMO/md/en-IMO2016SL.md +0 -0
  12. IMO/md/en-IMO2017SL.md +0 -0
  13. IMO/md/en-IMO2018SL.md +0 -0
  14. IMO/md/en-IMO2019SL.md +0 -0
  15. IMO/md/en-IMO2020SL.md +0 -0
  16. IMO/md/en-IMO2021SL.md +0 -0
  17. IMO/md/en-IMO2022SL.md +0 -0
  18. IMO/md/en-compendium.md +0 -0
  19. IMO/raw/en-IMO2006SL.pdf +3 -0
  20. IMO/raw/en-IMO2007SL.pdf +3 -0
  21. IMO/raw/en-IMO2008SL.pdf +3 -0
  22. IMO/raw/en-IMO2009SL.pdf +3 -0
  23. IMO/raw/en-IMO2010SL.pdf +3 -0
  24. IMO/raw/en-IMO2011SL.pdf +3 -0
  25. IMO/raw/en-IMO2012SL.pdf +3 -0
  26. IMO/raw/en-IMO2013SL.pdf +3 -0
  27. IMO/raw/en-IMO2014SL.pdf +3 -0
  28. IMO/raw/en-IMO2015SL.pdf +3 -0
  29. IMO/raw/en-IMO2016SL.pdf +3 -0
  30. IMO/raw/en-IMO2017SL.pdf +3 -0
  31. IMO/raw/en-IMO2018SL.pdf +3 -0
  32. IMO/raw/en-IMO2019SL.pdf +3 -0
  33. IMO/raw/en-IMO2020SL.pdf +3 -0
  34. IMO/raw/en-IMO2021SL.pdf +3 -0
  35. IMO/raw/en-IMO2022SL.pdf +3 -0
  36. IMO/raw/en-compendium.pdf +3 -0
  37. IMO/segment_script/fixtures/test-case-1.md +17 -0
  38. IMO/segment_script/fixtures/test-case-2.md +35 -0
  39. IMO/segment_script/fixtures/test-case-3.md +35 -0
  40. IMO/segment_script/fixtures/test-case-4.md +44 -0
  41. IMO/segment_script/fixtures/test-case-5.md +37 -0
  42. IMO/segment_script/fixtures/test-out-1234.jsonl +4 -0
  43. IMO/segment_script/fixtures/test-out-5.jsonl +4 -0
  44. IMO/segment_script/segment.py +96 -0
  45. IMO/segment_script/segment_compendium.py +155 -0
  46. IMO/segmented/en-IMO2006SL.jsonl +0 -0
  47. IMO/segmented/en-IMO2007SL.jsonl +0 -0
  48. IMO/segmented/en-IMO2008SL.jsonl +0 -0
  49. IMO/segmented/en-IMO2009SL.jsonl +0 -0
  50. IMO/segmented/en-IMO2010SL.jsonl +0 -0
IMO/md/en-IMO2006SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2007SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2008SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2009SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2010SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2011SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2012SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2013SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2014SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2015SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2016SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2017SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2018SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2019SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2020SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2021SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-IMO2022SL.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/md/en-compendium.md ADDED
The diff for this file is too large to render. See raw diff
 
IMO/raw/en-IMO2006SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df9f97f299b7ae8ad3cf0614a50804c3f4709c9c78215bd5bc1618e7a5e447fe
3
+ size 523498
IMO/raw/en-IMO2007SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a874eb812eacc3d2732fb9e8f803ab45f8fd2d3a05aec7e665ae0fee6adbaf79
3
+ size 550183
IMO/raw/en-IMO2008SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef610b4fead4865d6cadbcea7ff7586553d1e1c4ba074b0c9f67a5694820b4fc
3
+ size 525713
IMO/raw/en-IMO2009SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bfdee720406220b62aa274de2fa3149bc08afe1dd6affc6f91cf29fb2b44d726
3
+ size 1954803
IMO/raw/en-IMO2010SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b22e58d9559699baa1adcd2d2ddbadb3b5f3a4fc8ef75d5d0e2d4864597783d
3
+ size 1683818
IMO/raw/en-IMO2011SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f7fae0cc74dba95dc556b5f78a5b429a8ecd70acbf7a5ffeb3018ea92331ab8
3
+ size 713524
IMO/raw/en-IMO2012SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22b018a851a4b17a628563964a02649db15052d523d5371e0dbe42b537ef119d
3
+ size 411332
IMO/raw/en-IMO2013SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ea75d998c6d67962c59011b8f8c81da253b0090dfef2d003e80cf2fc0e5468b
3
+ size 538224
IMO/raw/en-IMO2014SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74c54060408e2598482e6db44afa1a3c5226a74383113f9add5a053667986495
3
+ size 1196532
IMO/raw/en-IMO2015SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf6cdda0ff82cee99b2eed34d213f699aa9ef5c22be33b0b0a51eb8bd9e18716
3
+ size 1628652
IMO/raw/en-IMO2016SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:881095ca836abdd044373fbce409e0ef2696de7d815bbc32783397cad2c7874f
3
+ size 1012241
IMO/raw/en-IMO2017SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ba525cc74014f0b74d5bd018374dc96dbce467eaaa67fe4a79cf005043e781d
3
+ size 1605265
IMO/raw/en-IMO2018SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92b6a2fde1ba8cc85ec5d6bc5c0adbd4d2b576653a4c9c257df85a2c31599332
3
+ size 981255
IMO/raw/en-IMO2019SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f112cbaa7abf1a4139dbba9e29e8fa1e4d73258708ba558388ae144db222e725
3
+ size 3107272
IMO/raw/en-IMO2020SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a42248a040d7d011b1c1ad58351207350af9dd8bd8f2ac347ba4e216323081f4
3
+ size 2406391
IMO/raw/en-IMO2021SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c02d9f0d68fd38fb3b3136b19004d09fb8ee421a0f4da0c325e28b42a086ff45
3
+ size 2052151
IMO/raw/en-IMO2022SL.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ed31c9e5efecfcc796940719da86ec47edca41b7f7df75811d2269453dc86f5
3
+ size 4760328
IMO/raw/en-compendium.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c69aa00c85ffc60d815081d1eb6ca65b8e27ed26700c0c8741a04e40755d42d1
3
+ size 5946928
IMO/segment_script/fixtures/test-case-1.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Algebra
2
+
3
+ A1. Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
4
+
5
+ Solution. The equation simplifies to \((x - 2)^2 = 0\), so the root is \(x = 2\).
6
+
7
+ A2. Determine the value of \(y\) in the equation \(2y + 3 = 7\).
8
+
9
+ Solution 1. Subtracting 3 from both sides gives \(2y = 4\).
10
+
11
+ Solution 2. Dividing both sides by 2 gives \(y = 2\).
12
+
13
+ ## Combinatorics
14
+
15
+ C1. How many ways can 3 objects be arranged in a line?
16
+
17
+ Solution. The number of permutations of 3 objects is \(3! = 6\).
IMO/segment_script/fixtures/test-case-2.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Algebra
2
+
3
+ ## A1
4
+
5
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
6
+
7
+ ## A2
8
+
9
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
10
+
11
+ ## Combinatorics
12
+
13
+ ## C1
14
+
15
+ How many ways can 3 objects be arranged in a line?
16
+
17
+ ## A1
18
+
19
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
20
+
21
+ Solution. The equation simplifies to \((x - 2)^2 = 0\), so the root is \(x = 2\).
22
+
23
+ ## A2
24
+
25
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
26
+
27
+ Solution 1. Subtracting 3 from both sides gives \(2y = 4\).
28
+
29
+ Solution 2. Dividing both sides by 2 gives \(y = 2\).
30
+
31
+ ## C1
32
+
33
+ How many ways can 3 objects be arranged in a line?
34
+
35
+ Solution. The number of permutations of 3 objects is \(3! = 6\).
IMO/segment_script/fixtures/test-case-3.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Algebra
2
+
3
+ ## A1
4
+
5
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
6
+
7
+ ## A2
8
+
9
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
10
+
11
+ ## Combinatorics
12
+
13
+ ## C1
14
+
15
+ How many ways can 3 objects be arranged in a line?
16
+
17
+ ## A 1
18
+
19
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
20
+
21
+ Solution. The equation simplifies to \((x - 2)^2 = 0\), so the root is \(x = 2\).
22
+
23
+ ## A2
24
+
25
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
26
+
27
+ Solution 1. Subtracting 3 from both sides gives \(2y = 4\).
28
+
29
+ Solution 2. Dividing both sides by 2 gives \(y = 2\).
30
+
31
+ ## C1
32
+
33
+ How many ways can 3 objects be arranged in a line?
34
+
35
+ Solution. The number of permutations of 3 objects is \(3! = 6\).
IMO/segment_script/fixtures/test-case-4.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # $5^{\text {nd }}$ International Mathematical Olympiad
2
+
3
+ 12 - 24 July 2011 Amsterdam The Netherlands
4
+
5
+ ![](https://cdn.mathpix.com/cropped/2024_04_17_481ddb3576adc2313a2eg-01.jpg?height=2070&width=1902&top_left_y=744&top_left_x=-3)
6
+
7
+ ## 52nd International <br> Mathematical Olympiad <br> 12-24 July 2011 <br> Amsterdam <br> The Netherlands
8
+
9
+ Problem shortlist with solutions
10
+
11
+ ## IMO regulation: <br> these shortlist problems have to be kept strictly confidential until IMO 2012.
12
+
13
+ The problem selection committee
14
+
15
+ Bart de Smit (chairman), Ilya Bogdanov, Johan Bosman,
16
+
17
+ Andries Brouwer, Gabriele Dalla Torre, Géza Kós,
18
+
19
+ Hendrik Lenstra, Charles Leytem, Ronald van Luijk,
20
+
21
+ Christian Reiher, Eckard Specht, Hans Sterk, Lenny Taelman
22
+
23
+ The committee gratefully acknowledges the receipt of 142 problem proposals by the following 46 countries:
24
+
25
+ Armenia, Australia, Austria, Belarus, Belgium, Bosnia and Herzegovina, Brazil, Bulgaria, Canada, Colombia, Cyprus, Denmark, Estonia, Finland, France, Germany, Greece, Hong Kong, Hungary, India, Islamic Republic of Iran, Ireland, Israel, Japan, Kazakhstan, Republic of Korea, Luxembourg, Malaysia, Mexico, Mongolia, Montenegro, Pakistan, Poland, Romania, Russian Federation, Saudi Arabia, Serbia, Slovakia, Slovenia, Sweden, Taiwan, Thailand, Turkey, Ukraine, United Kingdom, United States of America
26
+
27
+
28
+ ## Algebra
29
+
30
+ A1. Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
31
+
32
+ Solution. The equation simplifies to \((x - 2)^2 = 0\), so the root is \(x = 2\).
33
+
34
+ A2. Determine the value of \(y\) in the equation \(2y + 3 = 7\).
35
+
36
+ Solution 1. Subtracting 3 from both sides gives \(2y = 4\).
37
+
38
+ Solution 2. Dividing both sides by 2 gives \(y = 2\).
39
+
40
+ ## Combinatorics
41
+
42
+ C1. How many ways can 3 objects be arranged in a line?
43
+
44
+ Solution. The number of permutations of 3 objects is \(3! = 6\).
IMO/segment_script/fixtures/test-case-5.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Algebra
2
+
3
+ ## A1
4
+
5
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
6
+
7
+ ## A2
8
+
9
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
10
+
11
+ ## Combinatorics
12
+
13
+ ## C1
14
+
15
+ How many ways can 3 objects be arranged in a line?
16
+
17
+ ## A1
18
+
19
+ Find the roots of the quadratic equation \(x^2 - 4x + 4 = 0\).
20
+
21
+ Solution. The equation simplifies to \((x - 2)^2 = 0\), so the root is:
22
+
23
+ ## $\(x = 2\)$
24
+
25
+ ## A2
26
+
27
+ Determine the value of \(y\) in the equation \(2y + 3 = 7\).
28
+
29
+ Solution 1. Subtracting 3 from both sides gives \(2y = 4\).
30
+
31
+ Solution 2. Dividing both sides by 2 gives \(y = 2\).
32
+
33
+ ## C1
34
+
35
+ How many ways can 3 objects be arranged in a line?
36
+
37
+ Solution. The number of permutations of 3 objects is \(3! = 6\).
IMO/segment_script/fixtures/test-out-1234.jsonl ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {"problem_type":"Algebra","problem_label":"A1","problem":"Find the roots of the quadratic equation \\(x^2 - 4x + 4 = 0\\).","solution":"The equation simplifies to \\((x - 2)^2 = 0\\), so the root is \\(x = 2\\).","tier":0}
2
+ {"problem_type":"Algebra","problem_label":"A2","problem":"Determine the value of \\(y\\) in the equation \\(2y + 3 = 7\\).","solution":"Subtracting 3 from both sides gives \\(2y = 4\\).","tier":0}
3
+ {"problem_type":"Algebra","problem_label":"A2","problem":"Determine the value of \\(y\\) in the equation \\(2y + 3 = 7\\).","solution":"Dividing both sides by 2 gives \\(y = 2\\).","tier":0}
4
+ {"problem_type":"Combinatorics","problem_label":"C1","problem":"How many ways can 3 objects be arranged in a line?","solution":"The number of permutations of 3 objects is \\(3! = 6\\).","tier":0}
IMO/segment_script/fixtures/test-out-5.jsonl ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {"problem_type":"Algebra","problem_label":"A1","problem":"Find the roots of the quadratic equation \\(x^2 - 4x + 4 = 0\\).","solution":"The equation simplifies to \\((x - 2)^2 = 0\\), so the root is: ## $\\(x = 2\\)$","tier":0}
2
+ {"problem_type":"Algebra","problem_label":"A2","problem":"Determine the value of \\(y\\) in the equation \\(2y + 3 = 7\\).","solution":"Subtracting 3 from both sides gives \\(2y = 4\\).","tier":0}
3
+ {"problem_type":"Algebra","problem_label":"A2","problem":"Determine the value of \\(y\\) in the equation \\(2y + 3 = 7\\).","solution":"Dividing both sides by 2 gives \\(y = 2\\).","tier":0}
4
+ {"problem_type":"Combinatorics","problem_label":"C1","problem":"How many ways can 3 objects be arranged in a line?","solution":"The number of permutations of 3 objects is \\(3! = 6\\).","tier":0}
IMO/segment_script/segment.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Marina
3
+ # Date: 2024-11-15
4
+ # -----------------------------------------------------------------------------
5
+ ''' Script to segment IMO shortlist md files using regex. It takes as input
6
+ files in en-shortlist and outputs en-shortlist-seg
7
+ To run:
8
+ `python segment_script/segment.py`
9
+ To debug (or see covered use cases listed in fixtures/):
10
+ `pytest test_segment`
11
+ '''
12
+
13
+ from collections import defaultdict
14
+ import os
15
+ import re
16
+ import pandas as pd
17
+ import json
18
+
19
+
20
+ base = 'md'
21
+ seg_base = 'segmented'
22
+
23
+ section_re = re.compile(r'##\s+([A-Za-z]\w.*)')
24
+ problem_re = re.compile(
25
+ r'^(?:##\s*)?((?:[AGNC]\s*\d+))\.*\s*(.*?)(?:\((.*?)\))?$',
26
+ re.MULTILINE
27
+ )
28
+ solution_re = re.compile(
29
+ r'^(?:##\s*)?(Solution(?: \d+)?\.)\s*(.*?)(?=(?:Solution|Comment|A\d+|G\d+|N\d+|C\d+|##|$))',
30
+ re.MULTILINE | re.DOTALL
31
+ )
32
+
33
+ def add_content(section, label, text_class, text, problems, solutions):
34
+ text_str = " ".join(text).strip()
35
+ if text_class == "problem":
36
+ # print(f"ADD PROBLEM {section} {label} ")
37
+ problems.append({"section": section, "label": label, "problem": text_str})
38
+ elif text_class == "solution":
39
+ # print(f"ADD SOLUTION {section} {label}")
40
+ solutions.append({"label": label, "solution": text_str})
41
+
42
+ def parse(file):
43
+ with open(file, 'r') as file:
44
+ content = file.read()
45
+ problems, solutions = [], []
46
+ current_section, current_label, current_class = None, None, None
47
+ current_lines = []
48
+ for line in content.splitlines():
49
+ if match := problem_re.match(line):
50
+ label, text, country = match.groups()
51
+ label = label.replace(" ", "") # clean the label
52
+ add_content(current_section, current_label, current_class, current_lines, problems, solutions)
53
+ current_class = "problem"
54
+ current_label = label
55
+ current_lines = [text]
56
+ elif match := solution_re.match(line):
57
+ label, text = match.groups()
58
+ add_content(current_section, current_label, current_class, current_lines, problems, solutions)
59
+ current_class = "solution"
60
+ current_lines = [text]
61
+ elif match := section_re.match(line):
62
+ add_content(current_section, current_label, current_class, current_lines, problems, solutions)
63
+ current_class = "section"
64
+ text, = match.groups()
65
+ current_section = text
66
+ else:
67
+ current_lines.append(line)
68
+ add_content(current_section, current_label, current_class, current_lines, problems, solutions)
69
+ problems_df = pd.DataFrame(problems).drop_duplicates(subset=["label", "problem"])
70
+ solutions_df = pd.DataFrame(solutions)
71
+ return problems_df, solutions_df
72
+
73
+ def join(problems_df, solutions_df):
74
+ pairs_df = problems_df.merge(solutions_df, on=["label"], how="left")
75
+ return pairs_df
76
+
77
+ def add_metadata(pairs_df):
78
+ pairs_df.rename(columns={"section": "problem_type", "label": "problem_label"}, inplace=True)
79
+ pairs_df['tier'] = 0 # according to omnimath
80
+ return pairs_df
81
+
82
+ def write_pairs(filename, pairs_df):
83
+ pairs_df.to_json(filename, orient="records", lines=True)
84
+
85
+
86
+ os.makedirs(seg_base, exist_ok=True)
87
+ for name in os.listdir(base):
88
+ if "compendium" not in name: # en-compendium is segmented in segment_compendium.py
89
+ print(name)
90
+ problems, solutions = parse(os.path.join(base, name))
91
+ pairs_df = join(problems, solutions)
92
+ pairs_df = add_metadata(pairs_df)
93
+ print(pairs_df)
94
+ basename = os.path.splitext(name)[0]
95
+ print(f"{seg_base}/{basename}.jsonl")
96
+ write_pairs(f"{seg_base}/{basename}.jsonl", pairs_df)
IMO/segment_script/segment_compendium.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Marina
3
+ # Date: 2024-11-15
4
+ # -----------------------------------------------------------------------------
5
+ ''' Script to segment IMO shortlist md files using regex. It takes as input
6
+ the file en-compendium.md in en-shortlist and outputs the segmentation
7
+ (problem/solution pairs) in en-shortlist-seg
8
+ To run:
9
+ `python segment_compendium.py`
10
+ To debug (or see covered use cases by regex):
11
+ `pytest test_segment_compendium`
12
+ '''
13
+
14
+ import os
15
+ import re
16
+ import pandas as pd
17
+
18
+
19
+ base = 'en-shortlist'
20
+ seg_base = 'en-shortlist-seg'
21
+ basename = 'en-compendium'
22
+
23
+
24
+ level1_re = re.compile(r"^##\s+(Problems|Solutions|Notation and Abbreviations)$")
25
+ year_re = re.compile(r"^[^=]*,\s+(\d{4})\s*$")
26
+ problem_section_re = re.compile(r"^###\s+(\d+\.\d+\.\d+)\s+(.+)$")
27
+ solution_section_re = re.compile(r"^###\s+(\d+\.\d+)\s+([\w\s]+)\s+(\d{4})$")
28
+ problem_or_solution_re = re.compile(r"^(?:\[.*?\])?\s*(\d+)\s*\.\s*(.+)$")
29
+
30
+
31
+ def add_content(current_dict):
32
+ required_keys = ["year", "category", "section_label", "label", "lines"]
33
+ if not all(current_dict[key] for key in required_keys):
34
+ return
35
+ text_str = " ".join(current_dict["lines"]).strip()
36
+ entry = {
37
+ "year": current_dict["year"],
38
+ "category": current_dict["category"],
39
+ "section": current_dict["section_label"],
40
+ "label": current_dict["label"],
41
+ }
42
+ if current_dict["class"] == "problem":
43
+ entry["problem"] = text_str
44
+ current_dict["problems"].append(entry)
45
+ elif current_dict["class"] == "solution":
46
+ entry["solution"] = text_str
47
+ current_dict["solutions"].append(entry)
48
+
49
+
50
+ def get_category(s:str):
51
+ cat = None
52
+ if 'contest' in s.lower():
53
+ cat = 'contest'
54
+ elif 'shortlisted' in s.lower():
55
+ cat = 'shortlisted'
56
+ elif 'longlisted' in s.lower():
57
+ cat = 'longlisted'
58
+ return cat
59
+
60
+
61
+ def get_matching_section_label(s:str):
62
+ """
63
+ extracts the section number to be used a a join key to pair a problem and solution
64
+ for problems: 3.44.1 -> 44
65
+ for solutions: 4.20 -> 20
66
+ """
67
+ return s.split('.')[1]
68
+
69
+
70
+ def parse(file):
71
+ with open(file, 'r') as file:
72
+ content = file.read()
73
+ # problems, solutions = [], []
74
+ current = {
75
+ "year": None,
76
+ "category": None,
77
+ "section_label": None,
78
+ "label": None,
79
+ "class": None,
80
+ "lines": [],
81
+ "problems": [],
82
+ "solutions": []
83
+ }
84
+ for line in content.splitlines():
85
+ if match := level1_re.match(line):
86
+ add_content(current)
87
+ title, = match.groups()
88
+ current["class"] = {
89
+ "Problems": "problem",
90
+ "Solutions": "solution",
91
+ }.get(title, "other")
92
+ current["lines"] = []
93
+ elif match := year_re.match(line):
94
+ add_content(current)
95
+ current["year"] = match.group(1)
96
+ current["lines"] = []
97
+ elif match := problem_section_re.match(line):
98
+ add_content(current)
99
+ number, title = match.groups()
100
+ current["section_label"] = get_matching_section_label(number)
101
+ current["category"] = get_category(title)
102
+ current["lines"] = []
103
+ elif match := solution_section_re.match(line):
104
+ add_content(current)
105
+ number, title, year = match.groups()
106
+ current["section_label"] = get_matching_section_label(number)
107
+ current["category"] = get_category(title)
108
+ current["year"] = year
109
+ current["lines"] = []
110
+ elif match := problem_or_solution_re.match(line):
111
+ add_content(current)
112
+ current["label"] = match.group(1)
113
+ current["lines"] = [line]
114
+ else:
115
+ if current["lines"]:
116
+ current["lines"].append(line)
117
+ problems_df = pd.DataFrame(current["problems"])
118
+ solutions_df = pd.DataFrame(current["solutions"])
119
+ return problems_df, solutions_df
120
+
121
+ def join(problems_df, solutions_df):
122
+ pairs_df = problems_df.merge(solutions_df, on=["year", "category", "section", "label"], how="outer")
123
+ return pairs_df
124
+
125
+ def add_metadata(pairs_df):
126
+ problem_type_mapping = {
127
+ "A": "Algebra",
128
+ "C": "Combinatorics",
129
+ "G": "Geometry",
130
+ "N": "Number Theory"
131
+ }
132
+ pairs_df['problem_type'] = pairs_df['problem'].str.extract(r'^\d+\.\s*([ACGN])\d*')[0]
133
+ pairs_df['problem_type'] = pairs_df['problem_type'] .map(problem_type_mapping)
134
+ pairs_df['tier'] = 0 # according to omnimath
135
+ pairs_df.rename(columns={"category": "problem_phase"}, inplace=True)
136
+ pairs_df = pairs_df.drop(columns=['section', 'label'])
137
+ return pairs_df
138
+
139
+ def write_pairs(filename, pairs_df):
140
+ pairs_df.to_json(filename, orient="records", lines=True)
141
+
142
+
143
+ problems, solutions = parse(f"{base}/{basename}.md")
144
+ pairs_df = join(problems, solutions)
145
+ pairs_df = pairs_df[pairs_df.notnull().all(axis=1)]
146
+ pairs_df = add_metadata(pairs_df)
147
+ write_pairs(f"{seg_base}/{basename}.jsonl", pairs_df)
148
+
149
+ # problems contains duplicate problems (since problem in Shortlist appears in Contest, and problem in Longlist appeasr in Shortlist)
150
+ # >>>print(len(problems))
151
+ # 2460
152
+ # >>>print(len(solutions))
153
+ # 961
154
+ # print(len(pairs_df))
155
+ # 960
IMO/segmented/en-IMO2006SL.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
IMO/segmented/en-IMO2007SL.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
IMO/segmented/en-IMO2008SL.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
IMO/segmented/en-IMO2009SL.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
IMO/segmented/en-IMO2010SL.jsonl ADDED
The diff for this file is too large to render. See raw diff