test
Browse files
__pycache__/contents_extractor_v2.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/contents_extractor_v2.cpython-310.pyc and b/__pycache__/contents_extractor_v2.cpython-310.pyc differ
|
|
|
__pycache__/inference_svm_model.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/inference_svm_model.cpython-310.pyc and b/__pycache__/inference_svm_model.cpython-310.pyc differ
|
|
|
contents_extractor_v2.py
CHANGED
|
@@ -44,8 +44,8 @@ class ContentsExtractor:
|
|
| 44 |
|
| 45 |
Instructions:
|
| 46 |
1. Identify the "Contents" section, which lists all topics, subtopics, and their corresponding pages.
|
| 47 |
-
2. Extract only the **highest-level, subject-related
|
| 48 |
-
3.
|
| 49 |
4. Return the output in the following JSON format:
|
| 50 |
|
| 51 |
{{
|
|
@@ -53,58 +53,87 @@ class ContentsExtractor:
|
|
| 53 |
}}
|
| 54 |
|
| 55 |
Important Notes:
|
| 56 |
-
- Ignore non-subject-related sections (e.g., "Introduction", "Exam Guidelines", "Appendices").
|
| 57 |
-
-
|
| 58 |
-
-
|
| 59 |
-
- Only extract main topics without sub-topic numeration. Any topic with additional numbering (e.g., '3.1 Some Topic')
|
| 60 |
-
should be ignored, as it is a sub-topic rather than a primary subject-related topic.
|
| 61 |
-
- Make sure that all of the pages for a topic are included, end page should be the start page of the topic
|
| 62 |
that comes next after the extracted one in contents section.
|
| 63 |
|
| 64 |
Examples:
|
| 65 |
1. Given this table of contents:
|
| 66 |
-
|
| 67 |
-
1
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
The correct output should be:
|
| 79 |
|
| 80 |
{{
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
}}
|
| 84 |
|
| 85 |
2. Given this table of contents:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
The correct output should be:
|
| 100 |
|
| 101 |
{{
|
| 102 |
"Biology": [5, 22],
|
| 103 |
"Chemistry": [22, 43]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}}
|
| 105 |
|
| 106 |
Now, extract topics from this text: {content}
|
| 107 |
"""],
|
| 108 |
config=types.GenerateContentConfig(temperature=0.)
|
| 109 |
)
|
| 110 |
-
return response.text.strip().replace("```json", "").replace("```", "")
|
|
|
|
| 44 |
|
| 45 |
Instructions:
|
| 46 |
1. Identify the "Contents" section, which lists all topics, subtopics, and their corresponding pages.
|
| 47 |
+
2. Extract only the **highest-level, subject-related subtopics** (ignore organizational or administrative sections).
|
| 48 |
+
3. For subtopics, include the full range of pages from the first to the last subtopic.
|
| 49 |
4. Return the output in the following JSON format:
|
| 50 |
|
| 51 |
{{
|
|
|
|
| 53 |
}}
|
| 54 |
|
| 55 |
Important Notes:
|
| 56 |
+
- Ignore non-subject-related sections (e.g., "Introduction", "Exam Guidelines", "Appendices", "Assessment, Qualification at a glance").
|
| 57 |
+
- The extracted subtopics should represent major academic areas, not organizational or structural elements.
|
| 58 |
+
- Make sure that all of the pages for a subtopic are included, end page should be the start page of the topic
|
|
|
|
|
|
|
|
|
|
| 59 |
that comes next after the extracted one in contents section.
|
| 60 |
|
| 61 |
Examples:
|
| 62 |
1. Given this table of contents:
|
| 63 |
+
|
| 64 |
+
1 Introduction β 2
|
| 65 |
+
Why choose Edexcel A Level Mathematics? - 2
|
| 66 |
+
Supporting you in planning and implementing this qualification - 3
|
| 67 |
+
Qualification at a glance - 5
|
| 68 |
+
2 Subject content and assessment information β 7
|
| 69 |
+
Paper 1 and Paper 2: Pure Mathematics - 11
|
| 70 |
+
Paper 3: Statistics and Mechanics - 30
|
| 71 |
+
Assessment Objectives - 40
|
| 72 |
+
3 Administration and general information β 42
|
| 73 |
+
Entries - 42
|
| 74 |
+
Access arrangements, reasonable adjustments, special consideration and malpractice - 42
|
| 75 |
+
Student recruitment and progression - 45
|
| 76 |
+
Appendix 1: Formulae β 49
|
| 77 |
+
Appendix 2: Notation β 53
|
| 78 |
+
Appendix 3: Use of calculators β 59
|
| 79 |
+
Appendix 4: Assessment Objectives β 60
|
| 80 |
+
Appendix 5: The context for the development of this qualification β 62
|
| 81 |
+
Appendix 6: Transferable skills β 64
|
| 82 |
+
Appendix 7: Level 3 Extended Project qualification β 65
|
| 83 |
+
Appendix 8: Codes β 67
|
| 84 |
|
| 85 |
The correct output should be:
|
| 86 |
|
| 87 |
{{
|
| 88 |
+
"Paper 1 and Paper 2: Pure Mathematics": [11, 29],
|
| 89 |
+
"Paper 3: Statistics and Mechanics": [30, 42]
|
| 90 |
}}
|
| 91 |
|
| 92 |
2. Given this table of contents:
|
| 93 |
+
|
| 94 |
+
Qualification at a glance β 1
|
| 95 |
+
Assessment Objectives and weightings - 4
|
| 96 |
+
Knowledge, skills and understanding β 5
|
| 97 |
+
Theme 1: Introduction to markets and market failure - 5
|
| 98 |
+
Theme 2: The UK economy β performance and policies - 11
|
| 99 |
+
Theme 3: Business behaviour and the labour market - 21
|
| 100 |
+
Theme 4: A global perspective - 29
|
| 101 |
+
Assessment β 39
|
| 102 |
+
Assessment summary - 39
|
| 103 |
+
Assessment objectives - 41
|
| 104 |
+
Assessment overview - 42
|
| 105 |
+
Breakdown of assessment objectives - 42
|
| 106 |
+
Synoptic assessment - 43
|
| 107 |
+
Discount code and performance tables - 43
|
| 108 |
+
Access arrangements, reasonable adjustments and special consideration - 44
|
| 109 |
+
Malpractice - 45
|
| 110 |
+
Equality Act 2010 and Pearson equality policy - 45
|
| 111 |
+
Synoptic assessment - 46
|
| 112 |
+
Awarding and reporting - 47
|
| 113 |
+
Other information β 49
|
| 114 |
+
Student recruitment -49
|
| 115 |
+
Prior learning and other requirements -49
|
| 116 |
+
Progression - 49
|
| 117 |
+
Appendix 1: Transferable skills β 53
|
| 118 |
+
Appendix 2: Level 3 Extended Project qualification β 55
|
| 119 |
+
Appendix 3: Quantitative skills β 59
|
| 120 |
+
Appendix 4: Codes β 61
|
| 121 |
+
Appendix 5: Index β 63
|
| 122 |
|
| 123 |
The correct output should be:
|
| 124 |
|
| 125 |
{{
|
| 126 |
"Biology": [5, 22],
|
| 127 |
"Chemistry": [22, 43]
|
| 128 |
+
|
| 129 |
+
"Theme 1: Introduction to markets and market failure": [5, 10]
|
| 130 |
+
"Theme 2: The UK economy β performance and policies": - [11, 20]
|
| 131 |
+
"Theme 3: Business behaviour and the labour market": [21, 28]
|
| 132 |
+
"Theme 4: A global perspective": [29, 38]
|
| 133 |
}}
|
| 134 |
|
| 135 |
Now, extract topics from this text: {content}
|
| 136 |
"""],
|
| 137 |
config=types.GenerateContentConfig(temperature=0.)
|
| 138 |
)
|
| 139 |
+
return response.text.strip().replace("```json", "").replace("```", "")
|
selective_pdf_extractor.log
DELETED
|
File without changes
|
topic_extraction.py
CHANGED
|
@@ -15,20 +15,13 @@ logging.basicConfig(
|
|
| 15 |
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
| 16 |
handlers=[
|
| 17 |
logging.StreamHandler(),
|
| 18 |
-
logging.FileHandler('selective_pdf_extractor.log')
|
| 19 |
]
|
| 20 |
)
|
| 21 |
logger = logging.getLogger(__name__)
|
| 22 |
logger.setLevel(logging.INFO)
|
| 23 |
|
| 24 |
class SelectivePDFProcessor:
|
| 25 |
-
"""
|
| 26 |
-
Uses Gemini to identify:
|
| 27 |
-
- The '2 Subject content...' section from the Contents
|
| 28 |
-
- Each subtopic name + page range
|
| 29 |
-
Then extracts only those subtopic pages, processes them with LocalPDFProcessor,
|
| 30 |
-
and removes all text except the final table rows from the output markdown.
|
| 31 |
-
"""
|
| 32 |
|
| 33 |
def __init__(self, output_folder: str, api_key: str):
|
| 34 |
self.output_folder = output_folder
|
|
@@ -100,7 +93,6 @@ class SelectivePDFProcessor:
|
|
| 100 |
raw_json = raw_json.replace("```json", "").replace("```", "").strip()
|
| 101 |
data = json.loads(raw_json)
|
| 102 |
|
| 103 |
-
# data might look like:
|
| 104 |
# {
|
| 105 |
# "1 Introduction": [1, 5],
|
| 106 |
# "2 Subject content and assessment information": {
|
|
|
|
| 15 |
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
| 16 |
handlers=[
|
| 17 |
logging.StreamHandler(),
|
| 18 |
+
# logging.FileHandler('selective_pdf_extractor.log')
|
| 19 |
]
|
| 20 |
)
|
| 21 |
logger = logging.getLogger(__name__)
|
| 22 |
logger.setLevel(logging.INFO)
|
| 23 |
|
| 24 |
class SelectivePDFProcessor:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def __init__(self, output_folder: str, api_key: str):
|
| 27 |
self.output_folder = output_folder
|
|
|
|
| 93 |
raw_json = raw_json.replace("```json", "").replace("```", "").strip()
|
| 94 |
data = json.loads(raw_json)
|
| 95 |
|
|
|
|
| 96 |
# {
|
| 97 |
# "1 Introduction": [1, 5],
|
| 98 |
# "2 Subject content and assessment information": {
|