Add files using upload-large-folder tool
Browse files- derived/Source/circuit_generation_code/DC/00056.eps +0 -2
- derived/Source/circuit_generation_code/DC/00057.eps +0 -2
- derived/Source/circuit_generation_code/DC/00058.eps +0 -2
- derived/Source/circuit_generation_code/DC/00059.eps +0 -2
- derived/Source/circuit_generation_code/DC/00060.eps +0 -4
- derived/Source/circuit_generation_code/DC/00061.eps +0 -4
- derived/Source/circuit_generation_code/DC/00069.eps +0 -1
- derived/Source/hf_dataset/state.json +1 -1
- derived/Source/metadata/pruned_figures.jsonl +33 -0
- derived/Source/metadata/structure_summary.json +27 -6
- derived/Source/metadata/verification_summary.json +45 -45
- derived/Source/scripts/build_circuit_dataset.py +618 -19
- derived/Source/scripts/build_sheet_pdf.py +19 -4
- derived/Source/scripts/generate_visual_sheets.py +37 -6
- derived/Source/sheets/sheet_manifest.csv +0 -0
- derived/Source/sheets/sheet_manifest_no_text.csv +0 -0
derived/Source/circuit_generation_code/DC/00056.eps
CHANGED
|
@@ -303,9 +303,7 @@ endgate
|
|
| 303 |
1.00 30 672 656 arrowhead90
|
| 304 |
1 1.00 672 656 752 704 2 polygon
|
| 305 |
1.00 0 288 368 gnd
|
| 306 |
-
1.00 0 840 592 person_shocked
|
| 307 |
1 1.00 704 608 784 608 2 polygon
|
| 308 |
-
1.00 0 864 512 gnd
|
| 309 |
3 1.00 304 320 864 320 864 448 3 polygon
|
| 310 |
(path for current through the dirt) {/Helvetica 1.000 cf} 2 16 0 304 256 label
|
| 311 |
1.00 -1 688 304 arrowhead90
|
|
|
|
| 303 |
1.00 30 672 656 arrowhead90
|
| 304 |
1 1.00 672 656 752 704 2 polygon
|
| 305 |
1.00 0 288 368 gnd
|
|
|
|
| 306 |
1 1.00 704 608 784 608 2 polygon
|
|
|
|
| 307 |
3 1.00 304 320 864 320 864 448 3 polygon
|
| 308 |
(path for current through the dirt) {/Helvetica 1.000 cf} 2 16 0 304 256 label
|
| 309 |
1.00 -1 688 304 arrowhead90
|
derived/Source/circuit_generation_code/DC/00057.eps
CHANGED
|
@@ -284,8 +284,6 @@ endgate
|
|
| 284 |
1.00 30 672 700 arrowhead90
|
| 285 |
1 1.00 672 700 752 748 2 polygon
|
| 286 |
1.00 0 288 412 gnd
|
| 287 |
-
1.00 0 880 316 gnd
|
| 288 |
-
1.00 0 848 396 person
|
| 289 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 896 460 label
|
| 290 |
1 1.00 704 412 784 412 2 polygon
|
| 291 |
3 1.00 304 364 864 268 2 polygon
|
|
|
|
| 284 |
1.00 30 672 700 arrowhead90
|
| 285 |
1 1.00 672 700 752 748 2 polygon
|
| 286 |
1.00 0 288 412 gnd
|
|
|
|
|
|
|
| 287 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 896 460 label
|
| 288 |
1 1.00 704 412 784 412 2 polygon
|
| 289 |
3 1.00 304 364 864 268 2 polygon
|
derived/Source/circuit_generation_code/DC/00058.eps
CHANGED
|
@@ -284,8 +284,6 @@ endgate
|
|
| 284 |
1.00 30 672 548 arrowhead90
|
| 285 |
1 1.00 672 548 752 596 2 polygon
|
| 286 |
1 1.00 704 500 784 500 2 polygon
|
| 287 |
-
1.00 0 864 404 gnd
|
| 288 |
-
1.00 0 832 484 person
|
| 289 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 880 548 label
|
| 290 |
1.00 0 704 500 dot
|
| 291 |
pgsave restore showpage
|
|
|
|
| 284 |
1.00 30 672 548 arrowhead90
|
| 285 |
1 1.00 672 548 752 596 2 polygon
|
| 286 |
1 1.00 704 500 784 500 2 polygon
|
|
|
|
|
|
|
| 287 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 880 548 label
|
| 288 |
1.00 0 704 500 dot
|
| 289 |
pgsave restore showpage
|
derived/Source/circuit_generation_code/DC/00059.eps
CHANGED
|
@@ -325,9 +325,7 @@ endgate
|
|
| 325 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 819 1024 label
|
| 326 |
1.00 30 787 960 arrowhead90
|
| 327 |
1 1.00 787 960 867 1008 2 polygon
|
| 328 |
-
1.00 0 955 896 person_shocked
|
| 329 |
1 1.00 819 912 899 912 2 polygon
|
| 330 |
-
1.00 0 979 816 gnd
|
| 331 |
1.00 -1 791 404 arrowhead90
|
| 332 |
1 1.00 791 404 551 404 2 polygon
|
| 333 |
1.00 0 1011 656 arrowhead
|
|
|
|
| 325 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 819 1024 label
|
| 326 |
1.00 30 787 960 arrowhead90
|
| 327 |
1 1.00 787 960 867 1008 2 polygon
|
|
|
|
| 328 |
1 1.00 819 912 899 912 2 polygon
|
|
|
|
| 329 |
1.00 -1 791 404 arrowhead90
|
| 330 |
1 1.00 791 404 551 404 2 polygon
|
| 331 |
1.00 0 1011 656 arrowhead
|
derived/Source/circuit_generation_code/DC/00060.eps
CHANGED
|
@@ -326,9 +326,7 @@ endgate
|
|
| 326 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 867 1024 label
|
| 327 |
1.00 30 835 960 arrowhead90
|
| 328 |
1 1.00 835 960 915 1008 2 polygon
|
| 329 |
-
1.00 0 1003 656 person_shocked
|
| 330 |
1 1.00 867 672 947 672 2 polygon
|
| 331 |
-
1.00 0 1027 576 gnd
|
| 332 |
1.00 0 599 404 arrowhead90
|
| 333 |
1 1.00 839 404 599 404 2 polygon
|
| 334 |
1.00 -181 1075 432 arrowhead
|
|
@@ -341,9 +339,7 @@ endgate
|
|
| 341 |
(for shock current through the victim.) {/Helvetica-Oblique 1.000 cf} 2 16 0 419 256 label
|
| 342 |
3 1.00 435 432 339 432 339 736 3 polygon
|
| 343 |
3 1.00 435 432 1027 432 1027 512 3 polygon
|
| 344 |
-
1.00 0 995 896 person
|
| 345 |
1 1.00 867 912 947 912 2 polygon
|
| 346 |
-
1.00 0 1021 824 gnd
|
| 347 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 1043 960 label
|
| 348 |
1.00 0 451 912 dot
|
| 349 |
1.00 0 867 912 dot
|
|
|
|
| 326 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 867 1024 label
|
| 327 |
1.00 30 835 960 arrowhead90
|
| 328 |
1 1.00 835 960 915 1008 2 polygon
|
|
|
|
| 329 |
1 1.00 867 672 947 672 2 polygon
|
|
|
|
| 330 |
1.00 0 599 404 arrowhead90
|
| 331 |
1 1.00 839 404 599 404 2 polygon
|
| 332 |
1.00 -181 1075 432 arrowhead
|
|
|
|
| 339 |
(for shock current through the victim.) {/Helvetica-Oblique 1.000 cf} 2 16 0 419 256 label
|
| 340 |
3 1.00 435 432 339 432 339 736 3 polygon
|
| 341 |
3 1.00 435 432 1027 432 1027 512 3 polygon
|
|
|
|
| 342 |
1 1.00 867 912 947 912 2 polygon
|
|
|
|
| 343 |
(person \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 1043 960 label
|
| 344 |
1.00 0 451 912 dot
|
| 345 |
1.00 0 867 912 dot
|
derived/Source/circuit_generation_code/DC/00061.eps
CHANGED
|
@@ -302,13 +302,9 @@ endgate
|
|
| 302 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 704 796 label
|
| 303 |
1.00 30 672 732 arrowhead90
|
| 304 |
1 1.00 672 732 752 780 2 polygon
|
| 305 |
-
1.00 0 840 428 person_shocked
|
| 306 |
1 1.00 704 444 784 444 2 polygon
|
| 307 |
-
1.00 0 864 348 gnd
|
| 308 |
(person \(SHOCKED!\)) {/Helvetica 1.000 cf} 2 16 0 896 476 label
|
| 309 |
1 1.00 704 684 784 684 2 polygon
|
| 310 |
-
1.00 0 858 596 gnd
|
| 311 |
-
1.00 0 824 668 person_shocked
|
| 312 |
(person \(SHOCKED!\)) {/Helvetica 1.000 cf} 2 16 0 880 716 label
|
| 313 |
3 1.00 864 556 1312 556 1312 300 880 300 4 polygon
|
| 314 |
1.00 -1 1024 268 arrowhead90
|
|
|
|
| 302 |
(bird \(not shocked\)) {/Helvetica 1.000 cf} 2 16 0 704 796 label
|
| 303 |
1.00 30 672 732 arrowhead90
|
| 304 |
1 1.00 672 732 752 780 2 polygon
|
|
|
|
| 305 |
1 1.00 704 444 784 444 2 polygon
|
|
|
|
| 306 |
(person \(SHOCKED!\)) {/Helvetica 1.000 cf} 2 16 0 896 476 label
|
| 307 |
1 1.00 704 684 784 684 2 polygon
|
|
|
|
|
|
|
| 308 |
(person \(SHOCKED!\)) {/Helvetica 1.000 cf} 2 16 0 880 716 label
|
| 309 |
3 1.00 864 556 1312 556 1312 300 880 300 4 polygon
|
| 310 |
1.00 -1 1024 268 arrowhead90
|
derived/Source/circuit_generation_code/DC/00069.eps
CHANGED
|
@@ -315,7 +315,6 @@ endgate
|
|
| 315 |
1 1.00 1498 1114 1146 1242 2 polygon
|
| 316 |
5 1.00 458 602 458 458 2 polygon
|
| 317 |
5 1.00 1834 602 1834 458 2 polygon
|
| 318 |
-
1.00 0 1338 682 person_shocked
|
| 319 |
5 1.00 1306 602 1306 506 2 polygon
|
| 320 |
5 1.00 1370 602 1370 506 2 polygon
|
| 321 |
1.00 270 1274 522 arrow
|
|
|
|
| 315 |
1 1.00 1498 1114 1146 1242 2 polygon
|
| 316 |
5 1.00 458 602 458 458 2 polygon
|
| 317 |
5 1.00 1834 602 1834 458 2 polygon
|
|
|
|
| 318 |
5 1.00 1306 602 1306 506 2 polygon
|
| 319 |
5 1.00 1370 602 1370 506 2 polygon
|
| 320 |
1.00 270 1274 522 arrow
|
derived/Source/hf_dataset/state.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
"filename": "data-00000-of-00001.arrow"
|
| 5 |
}
|
| 6 |
],
|
| 7 |
-
"_fingerprint": "
|
| 8 |
"_format_columns": null,
|
| 9 |
"_format_kwargs": {},
|
| 10 |
"_format_type": null,
|
|
|
|
| 4 |
"filename": "data-00000-of-00001.arrow"
|
| 5 |
}
|
| 6 |
],
|
| 7 |
+
"_fingerprint": "545a5d8fc5886e81",
|
| 8 |
"_format_columns": null,
|
| 9 |
"_format_kwargs": {},
|
| 10 |
"_format_type": null,
|
derived/Source/metadata/pruned_figures.jsonl
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"book": "DC", "figure_id": "00017", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS OF ELECTRICITY", "line": 390, "raw_reference": "00017.png", "reference_source": "basiccon.sml", "section": "Voltage and current"}]}
|
| 2 |
+
{"book": "DC", "figure_id": "00019", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS OF ELECTRICITY", "line": 406, "raw_reference": "00019.png", "reference_source": "basiccon.sml", "section": "Voltage and current"}]}
|
| 3 |
+
{"book": "DC", "figure_id": "00022", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS OF ELECTRICITY", "line": 467, "raw_reference": "00022.png", "reference_source": "basiccon.sml", "section": "Voltage and current"}]}
|
| 4 |
+
{"book": "DC", "figure_id": "00023", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS OF ELECTRICITY", "line": 477, "raw_reference": "00023.png", "reference_source": "basiccon.sml", "section": "Voltage and current"}]}
|
| 5 |
+
{"book": "DC", "figure_id": "00031", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS OF ELECTRICITY", "line": 663, "raw_reference": "00031.png", "reference_source": "basiccon.sml", "section": "Voltage and current in a practical circuit"}]}
|
| 6 |
+
{"book": "DC", "figure_id": "00146", "reason": "meter illustration section", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 47, "raw_reference": "00146.png", "reference_source": "dcmeter.sml", "section": "What is a meter?"}]}
|
| 7 |
+
{"book": "DC", "figure_id": "00148", "reason": "meter illustration section", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 78, "raw_reference": "00148.png", "reference_source": "dcmeter.sml", "section": "What is a meter?"}]}
|
| 8 |
+
{"book": "DC", "figure_id": "00149", "reason": "meter illustration section", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 91, "raw_reference": "00149.png", "reference_source": "dcmeter.sml", "section": "What is a meter?"}]}
|
| 9 |
+
{"book": "DC", "figure_id": "00152", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 224, "raw_reference": "00152.png", "reference_source": "dcmeter.sml", "section": "Voltmeter design"}]}
|
| 10 |
+
{"book": "DC", "figure_id": "00181", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 1397, "raw_reference": "00181.png", "reference_source": "dcmeter.sml", "section": "Wattmeter design"}]}
|
| 11 |
+
{"book": "DC", "figure_id": "00182", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "DC METERING CIRCUITS", "line": 1403, "raw_reference": "00182.png", "reference_source": "dcmeter.sml", "section": "Wattmeter design"}]}
|
| 12 |
+
{"book": "DC", "figure_id": "00202", "reason": "chemical cell illustration", "references": [{"caption": null, "chapter": "ELECTRICAL INSTRUMENTATION SIGNALS", "line": 474, "raw_reference": "00202.png", "reference_source": "dcsignal.sml", "section": "pH measurement"}]}
|
| 13 |
+
{"book": "DC", "figure_id": "00203", "reason": "chemical cell illustration", "references": [{"caption": null, "chapter": "ELECTRICAL INSTRUMENTATION SIGNALS", "line": 487, "raw_reference": "00203.png", "reference_source": "dcsignal.sml", "section": "pH measurement"}]}
|
| 14 |
+
{"book": "DC", "figure_id": "00259", "reason": "chemical cell illustration", "references": [{"caption": null, "chapter": "BATTERIES AND POWER SYSTEMS", "line": 82, "raw_reference": "00259.png", "reference_source": "batt.sml", "section": "Electron activity in chemical reactions"}]}
|
| 15 |
+
{"book": "DC", "figure_id": "00271", "reason": "chemical cell illustration", "references": [{"caption": null, "chapter": "BATTERIES AND POWER SYSTEMS", "line": 377, "raw_reference": "00271.png", "reference_source": "batt.sml", "section": "Special-purpose batteries"}]}
|
| 16 |
+
{"book": "AC", "figure_id": "02157", "reason": "instrument or device illustration", "references": [{"caption": "Short-circuit switch allows ammeter to be removed from an active current transformer circuit.", "chapter": "TRANSFORMERS", "line": 1233, "raw_reference": "02157.png", "reference_source": "trans.sml", "section": "Special transformers and applications"}]}
|
| 17 |
+
{"book": "AC", "figure_id": "02224", "reason": "instrument or device illustration", "references": [{"caption": "Passing AC through this D'Arsonval meter movement causes useless flutter of the needle.", "chapter": "AC METERING CIRCUITS", "line": 18, "raw_reference": "02224.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 18 |
+
{"book": "AC", "figure_id": "02225", "reason": "instrument or device illustration", "references": [{"caption": "Passing AC through this Rectified AC meter movement will drive it in one direction.", "chapter": "AC METERING CIRCUITS", "line": 28, "raw_reference": "02225.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 19 |
+
{"book": "AC", "figure_id": "02246", "reason": "instrument or device illustration", "references": [{"caption": "Iron-vane electromechanical meter movement.", "chapter": "AC METERING CIRCUITS", "line": 34, "raw_reference": "02246.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 20 |
+
{"book": "AC", "figure_id": "02250", "reason": "instrument or device illustration", "references": [{"caption": "Resonant frequency meter ``peaks'' as L-C resonant frequency is tuned to test frequency.", "chapter": "AC METERING CIRCUITS", "line": 189, "raw_reference": "02250.png", "reference_source": "acmeter.sml", "section": "Frequency and phase measurement"}]}
|
| 21 |
+
{"book": "AC", "figure_id": "02315", "reason": "instrument or device illustration", "references": [{"caption": "Multiplier resistor (a) or resistive divider (b) scales the range of the basic meter movement.", "chapter": "AC METERING CIRCUITS", "line": 47, "raw_reference": "02315.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 22 |
+
{"book": "AC", "figure_id": "02316", "reason": "instrument or device illustration", "references": [{"caption": "AC voltmeter with capacitive divider.", "chapter": "AC METERING CIRCUITS", "line": 55, "raw_reference": "02316.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 23 |
+
{"book": "AC", "figure_id": "02317", "reason": "instrument or device illustration", "references": [{"caption": "An electrostatic meter movement may use a capacitive multiplier to multiply the scale of the basic meter movement..", "chapter": "AC METERING CIRCUITS", "line": 61, "raw_reference": "02317.png", "reference_source": "acmeter.sml", "section": "AC voltmeters and ammeters"}]}
|
| 24 |
+
{"book": "AC", "figure_id": "12148", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "TRANSMISSION LINES", "line": 186, "raw_reference": "12148.png", "reference_source": "lines.sml", "section": "Characteristic impedance"}]}
|
| 25 |
+
{"book": "SEMI", "figure_id": "03015", "reason": "chemical cell illustration", "references": [{"caption": null, "chapter": "ELECTRON TUBES", "line": 418, "raw_reference": "03015.png", "reference_source": "tubes.sml", "section": "Ionization (gas-filled) tubes"}]}
|
| 26 |
+
{"book": "SEMI", "figure_id": "03492", "reason": "instrument or device illustration", "references": [{"caption": "TR One, one transistor radio. No-bias-resistor causes operation as a detector. After Stoner, Figure 4.4A. <cite>DLS</cite>", "chapter": "PRACTICAL ANALOG SEMICONDUCTOR CIRCUITS", "line": 707, "raw_reference": "03492.png", "reference_source": "analog.sml", "section": "Radio circuits -- INCOMPLETE"}]}
|
| 27 |
+
{"book": "SEMI", "figure_id": "03493", "reason": "instrument or device illustration", "references": [{"caption": "Crystal radio with one transistor audio amplifer, base-bias. After Stoner, Figure 4.3A. <cite>DLS</cite>", "chapter": "PRACTICAL ANALOG SEMICONDUCTOR CIRCUITS", "line": 718, "raw_reference": "03493.png", "reference_source": "analog.sml", "section": "Radio circuits -- INCOMPLETE"}]}
|
| 28 |
+
{"book": "REF", "figure_id": "01056", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "CIRCUIT SCHEMATIC SYMBOLS", "line": 133, "raw_reference": "01056.png", "reference_source": "symbol.sml", "section": "Diodes"}]}
|
| 29 |
+
{"book": "EXP", "figure_id": "05036", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS AND TEST EQUIPMENT", "line": 78, "raw_reference": "05036.png", "reference_source": "basic.sml", "section": "Voltmeter usage"}]}
|
| 30 |
+
{"book": "EXP", "figure_id": "05069", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "BASIC CONCEPTS AND TEST EQUIPMENT", "line": 1233, "raw_reference": "05069.png", "reference_source": "basic.sml", "section": "Electromagnetism"}]}
|
| 31 |
+
{"book": "LIII", "figure_id": "motor_16", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "Variable-speed motor controls", "line": 43100, "line_excerpt": "$$\\includegraphics{motor_16.eps}$$", "reference_source": "liii_2v16.latex", "section": "DC motor speed control", "subsection": null}]}
|
| 32 |
+
{"book": "LIII", "figure_id": "optical_27", "reason": "instrument or device illustration", "references": [{"caption": null, "chapter": "Continuous analytical measurement", "line": 35788, "line_excerpt": "$$\\includegraphics{optical_27.eps}$$", "reference_source": "liii_2v16.latex", "section": "Fluorescence", "subsection": null}]}
|
| 33 |
+
{"book": "LIII", "figure_id": "pressure04", "reason": "hydraulic analogy illustration", "references": [{"caption": null, "chapter": "Physics", "line": 4353, "line_excerpt": "$$\\includegraphics{pressure04.eps}$$", "reference_source": "liii_2v16.latex", "section": "Fluid mechanics", "subsection": "Pressure"}]}
|
derived/Source/metadata/structure_summary.json
CHANGED
|
@@ -1,66 +1,81 @@
|
|
| 1 |
{
|
| 2 |
"books": {
|
| 3 |
"AC": {
|
| 4 |
-
"circuit_rows":
|
|
|
|
| 5 |
"display_name": "Lessons In Electric Circuits, Volume II \u2013 AC",
|
| 6 |
"pdf_name": "AC.pdf",
|
| 7 |
"pdf_origin": "bundled",
|
| 8 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/AC.pdf",
|
| 9 |
"pdf_url_used": null,
|
| 10 |
"pdf_version_sync": true,
|
|
|
|
| 11 |
"referenced_figures": 727,
|
|
|
|
| 12 |
"source_kind": "sml",
|
| 13 |
"source_notes": [],
|
| 14 |
"source_version": null
|
| 15 |
},
|
| 16 |
"DC": {
|
| 17 |
-
"circuit_rows":
|
|
|
|
| 18 |
"display_name": "Lessons In Electric Circuits, Volume I \u2013 DC",
|
| 19 |
"pdf_name": "DC.pdf",
|
| 20 |
"pdf_origin": "bundled",
|
| 21 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/DC.pdf",
|
| 22 |
"pdf_url_used": null,
|
| 23 |
"pdf_version_sync": true,
|
|
|
|
| 24 |
"referenced_figures": 787,
|
|
|
|
| 25 |
"source_kind": "sml",
|
| 26 |
"source_notes": [],
|
| 27 |
"source_version": null
|
| 28 |
},
|
| 29 |
"DIGI": {
|
| 30 |
"circuit_rows": 358,
|
|
|
|
| 31 |
"display_name": "Lessons In Electric Circuits, Volume IV \u2013 Digital",
|
| 32 |
"pdf_name": "DIGI.pdf",
|
| 33 |
"pdf_origin": "bundled",
|
| 34 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/DIGI.pdf",
|
| 35 |
"pdf_url_used": null,
|
| 36 |
"pdf_version_sync": true,
|
|
|
|
| 37 |
"referenced_figures": 674,
|
|
|
|
| 38 |
"source_kind": "sml",
|
| 39 |
"source_notes": [],
|
| 40 |
"source_version": null
|
| 41 |
},
|
| 42 |
"EXP": {
|
| 43 |
-
"circuit_rows":
|
|
|
|
| 44 |
"display_name": "Lessons In Electric Circuits, Volume VI \u2013 Experiments",
|
| 45 |
"pdf_name": "EXP.pdf",
|
| 46 |
"pdf_origin": "bundled",
|
| 47 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/EXP.pdf",
|
| 48 |
"pdf_url_used": null,
|
| 49 |
"pdf_version_sync": true,
|
|
|
|
| 50 |
"referenced_figures": 396,
|
|
|
|
| 51 |
"source_kind": "sml",
|
| 52 |
"source_notes": [],
|
| 53 |
"source_version": null
|
| 54 |
},
|
| 55 |
"LIII": {
|
| 56 |
-
"circuit_rows":
|
|
|
|
| 57 |
"display_name": "Lessons In Industrial Instrumentation",
|
| 58 |
"pdf_name": "liii_2v16.pdf",
|
| 59 |
"pdf_origin": "downloaded",
|
| 60 |
"pdf_path_used": "/workspace/SchemID/derived/Source/work/cache/pdfs/liii_2v16.pdf",
|
| 61 |
"pdf_url_used": "https://www.ibiblio.org/kuphaldt/socratic/sinst/book/liii_2v16.pdf",
|
| 62 |
"pdf_version_sync": true,
|
|
|
|
| 63 |
"referenced_figures": 2714,
|
|
|
|
| 64 |
"source_kind": "latex",
|
| 65 |
"source_notes": [
|
| 66 |
"Using the source-matched Lessons in Industrial Instrumentation version 2.16 PDF downloaded from ibiblio for verification."
|
|
@@ -68,27 +83,33 @@
|
|
| 68 |
"source_version": "2.16"
|
| 69 |
},
|
| 70 |
"REF": {
|
| 71 |
-
"circuit_rows":
|
|
|
|
| 72 |
"display_name": "Lessons In Electric Circuits, Volume V \u2013 Reference",
|
| 73 |
"pdf_name": "REF.pdf",
|
| 74 |
"pdf_origin": "bundled",
|
| 75 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/REF.pdf",
|
| 76 |
"pdf_url_used": null,
|
| 77 |
"pdf_version_sync": true,
|
|
|
|
| 78 |
"referenced_figures": 164,
|
|
|
|
| 79 |
"source_kind": "sml",
|
| 80 |
"source_notes": [],
|
| 81 |
"source_version": null
|
| 82 |
},
|
| 83 |
"SEMI": {
|
| 84 |
-
"circuit_rows":
|
|
|
|
| 85 |
"display_name": "Lessons In Electric Circuits, Volume III \u2013 Semiconductors",
|
| 86 |
"pdf_name": "SEMI.pdf",
|
| 87 |
"pdf_origin": "bundled",
|
| 88 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/SEMI.pdf",
|
| 89 |
"pdf_url_used": null,
|
| 90 |
"pdf_version_sync": true,
|
|
|
|
| 91 |
"referenced_figures": 630,
|
|
|
|
| 92 |
"source_kind": "sml",
|
| 93 |
"source_notes": [],
|
| 94 |
"source_version": null
|
|
|
|
| 1 |
{
|
| 2 |
"books": {
|
| 3 |
"AC": {
|
| 4 |
+
"circuit_rows": 294,
|
| 5 |
+
"cropped_rows": 19,
|
| 6 |
"display_name": "Lessons In Electric Circuits, Volume II \u2013 AC",
|
| 7 |
"pdf_name": "AC.pdf",
|
| 8 |
"pdf_origin": "bundled",
|
| 9 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/AC.pdf",
|
| 10 |
"pdf_url_used": null,
|
| 11 |
"pdf_version_sync": true,
|
| 12 |
+
"pruned_rows": 9,
|
| 13 |
"referenced_figures": 727,
|
| 14 |
+
"sanitized_rows": 0,
|
| 15 |
"source_kind": "sml",
|
| 16 |
"source_notes": [],
|
| 17 |
"source_version": null
|
| 18 |
},
|
| 19 |
"DC": {
|
| 20 |
+
"circuit_rows": 353,
|
| 21 |
+
"cropped_rows": 14,
|
| 22 |
"display_name": "Lessons In Electric Circuits, Volume I \u2013 DC",
|
| 23 |
"pdf_name": "DC.pdf",
|
| 24 |
"pdf_origin": "bundled",
|
| 25 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/DC.pdf",
|
| 26 |
"pdf_url_used": null,
|
| 27 |
"pdf_version_sync": true,
|
| 28 |
+
"pruned_rows": 15,
|
| 29 |
"referenced_figures": 787,
|
| 30 |
+
"sanitized_rows": 13,
|
| 31 |
"source_kind": "sml",
|
| 32 |
"source_notes": [],
|
| 33 |
"source_version": null
|
| 34 |
},
|
| 35 |
"DIGI": {
|
| 36 |
"circuit_rows": 358,
|
| 37 |
+
"cropped_rows": 6,
|
| 38 |
"display_name": "Lessons In Electric Circuits, Volume IV \u2013 Digital",
|
| 39 |
"pdf_name": "DIGI.pdf",
|
| 40 |
"pdf_origin": "bundled",
|
| 41 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/DIGI.pdf",
|
| 42 |
"pdf_url_used": null,
|
| 43 |
"pdf_version_sync": true,
|
| 44 |
+
"pruned_rows": 0,
|
| 45 |
"referenced_figures": 674,
|
| 46 |
+
"sanitized_rows": 0,
|
| 47 |
"source_kind": "sml",
|
| 48 |
"source_notes": [],
|
| 49 |
"source_version": null
|
| 50 |
},
|
| 51 |
"EXP": {
|
| 52 |
+
"circuit_rows": 279,
|
| 53 |
+
"cropped_rows": 9,
|
| 54 |
"display_name": "Lessons In Electric Circuits, Volume VI \u2013 Experiments",
|
| 55 |
"pdf_name": "EXP.pdf",
|
| 56 |
"pdf_origin": "bundled",
|
| 57 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/EXP.pdf",
|
| 58 |
"pdf_url_used": null,
|
| 59 |
"pdf_version_sync": true,
|
| 60 |
+
"pruned_rows": 2,
|
| 61 |
"referenced_figures": 396,
|
| 62 |
+
"sanitized_rows": 0,
|
| 63 |
"source_kind": "sml",
|
| 64 |
"source_notes": [],
|
| 65 |
"source_version": null
|
| 66 |
},
|
| 67 |
"LIII": {
|
| 68 |
+
"circuit_rows": 114,
|
| 69 |
+
"cropped_rows": 11,
|
| 70 |
"display_name": "Lessons In Industrial Instrumentation",
|
| 71 |
"pdf_name": "liii_2v16.pdf",
|
| 72 |
"pdf_origin": "downloaded",
|
| 73 |
"pdf_path_used": "/workspace/SchemID/derived/Source/work/cache/pdfs/liii_2v16.pdf",
|
| 74 |
"pdf_url_used": "https://www.ibiblio.org/kuphaldt/socratic/sinst/book/liii_2v16.pdf",
|
| 75 |
"pdf_version_sync": true,
|
| 76 |
+
"pruned_rows": 3,
|
| 77 |
"referenced_figures": 2714,
|
| 78 |
+
"sanitized_rows": 0,
|
| 79 |
"source_kind": "latex",
|
| 80 |
"source_notes": [
|
| 81 |
"Using the source-matched Lessons in Industrial Instrumentation version 2.16 PDF downloaded from ibiblio for verification."
|
|
|
|
| 83 |
"source_version": "2.16"
|
| 84 |
},
|
| 85 |
"REF": {
|
| 86 |
+
"circuit_rows": 42,
|
| 87 |
+
"cropped_rows": 1,
|
| 88 |
"display_name": "Lessons In Electric Circuits, Volume V \u2013 Reference",
|
| 89 |
"pdf_name": "REF.pdf",
|
| 90 |
"pdf_origin": "bundled",
|
| 91 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/REF.pdf",
|
| 92 |
"pdf_url_used": null,
|
| 93 |
"pdf_version_sync": true,
|
| 94 |
+
"pruned_rows": 1,
|
| 95 |
"referenced_figures": 164,
|
| 96 |
+
"sanitized_rows": 0,
|
| 97 |
"source_kind": "sml",
|
| 98 |
"source_notes": [],
|
| 99 |
"source_version": null
|
| 100 |
},
|
| 101 |
"SEMI": {
|
| 102 |
+
"circuit_rows": 336,
|
| 103 |
+
"cropped_rows": 34,
|
| 104 |
"display_name": "Lessons In Electric Circuits, Volume III \u2013 Semiconductors",
|
| 105 |
"pdf_name": "SEMI.pdf",
|
| 106 |
"pdf_origin": "bundled",
|
| 107 |
"pdf_path_used": "/workspace/SchemID/SchemSourceAvailable/SEMI.pdf",
|
| 108 |
"pdf_url_used": null,
|
| 109 |
"pdf_version_sync": true,
|
| 110 |
+
"pruned_rows": 3,
|
| 111 |
"referenced_figures": 630,
|
| 112 |
+
"sanitized_rows": 0,
|
| 113 |
"source_kind": "sml",
|
| 114 |
"source_notes": [],
|
| 115 |
"source_version": null
|
derived/Source/metadata/verification_summary.json
CHANGED
|
@@ -1,81 +1,81 @@
|
|
| 1 |
{
|
| 2 |
"books": {
|
| 3 |
"AC": {
|
| 4 |
-
"html_png_exact_false":
|
| 5 |
"html_png_exact_missing": 0,
|
| 6 |
-
"html_png_exact_true":
|
| 7 |
-
"pdf_proxy_verified_false":
|
| 8 |
-
"pdf_proxy_verified_true":
|
| 9 |
-
"reference_png_exact_false":
|
| 10 |
"reference_png_exact_missing": 0,
|
| 11 |
-
"reference_png_exact_true":
|
| 12 |
-
"rows":
|
| 13 |
},
|
| 14 |
"DC": {
|
| 15 |
-
"html_png_exact_false":
|
| 16 |
"html_png_exact_missing": 0,
|
| 17 |
-
"html_png_exact_true":
|
| 18 |
-
"pdf_proxy_verified_false":
|
| 19 |
-
"pdf_proxy_verified_true":
|
| 20 |
-
"reference_png_exact_false":
|
| 21 |
"reference_png_exact_missing": 0,
|
| 22 |
-
"reference_png_exact_true":
|
| 23 |
-
"rows":
|
| 24 |
},
|
| 25 |
"DIGI": {
|
| 26 |
-
"html_png_exact_false":
|
| 27 |
"html_png_exact_missing": 0,
|
| 28 |
-
"html_png_exact_true":
|
| 29 |
-
"pdf_proxy_verified_false":
|
| 30 |
-
"pdf_proxy_verified_true":
|
| 31 |
-
"reference_png_exact_false":
|
| 32 |
"reference_png_exact_missing": 0,
|
| 33 |
-
"reference_png_exact_true":
|
| 34 |
"rows": 358
|
| 35 |
},
|
| 36 |
"EXP": {
|
| 37 |
-
"html_png_exact_false":
|
| 38 |
"html_png_exact_missing": 0,
|
| 39 |
-
"html_png_exact_true":
|
| 40 |
-
"pdf_proxy_verified_false":
|
| 41 |
-
"pdf_proxy_verified_true":
|
| 42 |
-
"reference_png_exact_false":
|
| 43 |
"reference_png_exact_missing": 0,
|
| 44 |
-
"reference_png_exact_true":
|
| 45 |
-
"rows":
|
| 46 |
},
|
| 47 |
"LIII": {
|
| 48 |
"html_png_exact_false": 0,
|
| 49 |
-
"html_png_exact_missing":
|
| 50 |
"html_png_exact_true": 0,
|
| 51 |
-
"pdf_proxy_verified_false":
|
| 52 |
"pdf_proxy_verified_true": 0,
|
| 53 |
"reference_png_exact_false": 0,
|
| 54 |
-
"reference_png_exact_missing":
|
| 55 |
"reference_png_exact_true": 0,
|
| 56 |
-
"rows":
|
| 57 |
},
|
| 58 |
"REF": {
|
| 59 |
-
"html_png_exact_false":
|
| 60 |
"html_png_exact_missing": 0,
|
| 61 |
-
"html_png_exact_true":
|
| 62 |
-
"pdf_proxy_verified_false":
|
| 63 |
-
"pdf_proxy_verified_true":
|
| 64 |
-
"reference_png_exact_false":
|
| 65 |
"reference_png_exact_missing": 0,
|
| 66 |
-
"reference_png_exact_true":
|
| 67 |
-
"rows":
|
| 68 |
},
|
| 69 |
"SEMI": {
|
| 70 |
-
"html_png_exact_false":
|
| 71 |
"html_png_exact_missing": 0,
|
| 72 |
-
"html_png_exact_true":
|
| 73 |
-
"pdf_proxy_verified_false":
|
| 74 |
-
"pdf_proxy_verified_true":
|
| 75 |
-
"reference_png_exact_false":
|
| 76 |
"reference_png_exact_missing": 0,
|
| 77 |
-
"reference_png_exact_true":
|
| 78 |
-
"rows":
|
| 79 |
}
|
| 80 |
}
|
| 81 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"books": {
|
| 3 |
"AC": {
|
| 4 |
+
"html_png_exact_false": 247,
|
| 5 |
"html_png_exact_missing": 0,
|
| 6 |
+
"html_png_exact_true": 47,
|
| 7 |
+
"pdf_proxy_verified_false": 247,
|
| 8 |
+
"pdf_proxy_verified_true": 47,
|
| 9 |
+
"reference_png_exact_false": 247,
|
| 10 |
"reference_png_exact_missing": 0,
|
| 11 |
+
"reference_png_exact_true": 47,
|
| 12 |
+
"rows": 294
|
| 13 |
},
|
| 14 |
"DC": {
|
| 15 |
+
"html_png_exact_false": 27,
|
| 16 |
"html_png_exact_missing": 0,
|
| 17 |
+
"html_png_exact_true": 326,
|
| 18 |
+
"pdf_proxy_verified_false": 27,
|
| 19 |
+
"pdf_proxy_verified_true": 326,
|
| 20 |
+
"reference_png_exact_false": 27,
|
| 21 |
"reference_png_exact_missing": 0,
|
| 22 |
+
"reference_png_exact_true": 326,
|
| 23 |
+
"rows": 353
|
| 24 |
},
|
| 25 |
"DIGI": {
|
| 26 |
+
"html_png_exact_false": 6,
|
| 27 |
"html_png_exact_missing": 0,
|
| 28 |
+
"html_png_exact_true": 352,
|
| 29 |
+
"pdf_proxy_verified_false": 6,
|
| 30 |
+
"pdf_proxy_verified_true": 352,
|
| 31 |
+
"reference_png_exact_false": 6,
|
| 32 |
"reference_png_exact_missing": 0,
|
| 33 |
+
"reference_png_exact_true": 352,
|
| 34 |
"rows": 358
|
| 35 |
},
|
| 36 |
"EXP": {
|
| 37 |
+
"html_png_exact_false": 5,
|
| 38 |
"html_png_exact_missing": 0,
|
| 39 |
+
"html_png_exact_true": 274,
|
| 40 |
+
"pdf_proxy_verified_false": 5,
|
| 41 |
+
"pdf_proxy_verified_true": 274,
|
| 42 |
+
"reference_png_exact_false": 5,
|
| 43 |
"reference_png_exact_missing": 0,
|
| 44 |
+
"reference_png_exact_true": 274,
|
| 45 |
+
"rows": 279
|
| 46 |
},
|
| 47 |
"LIII": {
|
| 48 |
"html_png_exact_false": 0,
|
| 49 |
+
"html_png_exact_missing": 114,
|
| 50 |
"html_png_exact_true": 0,
|
| 51 |
+
"pdf_proxy_verified_false": 114,
|
| 52 |
"pdf_proxy_verified_true": 0,
|
| 53 |
"reference_png_exact_false": 0,
|
| 54 |
+
"reference_png_exact_missing": 114,
|
| 55 |
"reference_png_exact_true": 0,
|
| 56 |
+
"rows": 114
|
| 57 |
},
|
| 58 |
"REF": {
|
| 59 |
+
"html_png_exact_false": 1,
|
| 60 |
"html_png_exact_missing": 0,
|
| 61 |
+
"html_png_exact_true": 41,
|
| 62 |
+
"pdf_proxy_verified_false": 1,
|
| 63 |
+
"pdf_proxy_verified_true": 41,
|
| 64 |
+
"reference_png_exact_false": 1,
|
| 65 |
"reference_png_exact_missing": 0,
|
| 66 |
+
"reference_png_exact_true": 41,
|
| 67 |
+
"rows": 42
|
| 68 |
},
|
| 69 |
"SEMI": {
|
| 70 |
+
"html_png_exact_false": 29,
|
| 71 |
"html_png_exact_missing": 0,
|
| 72 |
+
"html_png_exact_true": 307,
|
| 73 |
+
"pdf_proxy_verified_false": 29,
|
| 74 |
+
"pdf_proxy_verified_true": 307,
|
| 75 |
+
"reference_png_exact_false": 29,
|
| 76 |
"reference_png_exact_missing": 0,
|
| 77 |
+
"reference_png_exact_true": 307,
|
| 78 |
+
"rows": 336
|
| 79 |
}
|
| 80 |
}
|
| 81 |
}
|
derived/Source/scripts/build_circuit_dataset.py
CHANGED
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
| 4 |
|
| 5 |
import argparse
|
| 6 |
import json
|
|
|
|
| 7 |
import os
|
| 8 |
import re
|
| 9 |
import shutil
|
|
@@ -17,6 +18,7 @@ from dataclasses import dataclass
|
|
| 17 |
from pathlib import Path
|
| 18 |
from typing import Any
|
| 19 |
|
|
|
|
| 20 |
import pyarrow as pa
|
| 21 |
import pyarrow.parquet as pq
|
| 22 |
from datasets import Dataset, Features, Image as HFImage, Value
|
|
@@ -65,9 +67,87 @@ CIRCUIT_PROCEDURE_WHITELIST = {
|
|
| 65 |
"source",
|
| 66 |
"transistor2",
|
| 67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
XCIRCUIT_CREATOR_RE = re.compile(r"^%%Creator:\s*(.+)$", re.M)
|
| 70 |
EPS_PROC_RE = re.compile(r"^/([A-Za-z][A-Za-z0-9_-]*)\s*\{", re.M)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
SML_TOKEN_RE = re.compile(
|
| 72 |
r"(?P<chapter><chaptertitle>(?P<chapter_text>.*?)</chaptertitle>)"
|
| 73 |
r"|(?P<section><sectiontitle>(?P<section_text>.*?)</sectiontitle>)"
|
|
@@ -391,6 +471,456 @@ def parse_eps_metadata(eps_path: Path) -> dict[str, Any]:
|
|
| 391 |
}
|
| 392 |
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
def write_no_text_eps(source_code: str, output_path: Path) -> None:
|
| 395 |
needle = "%%EndComments\n"
|
| 396 |
if needle in source_code:
|
|
@@ -441,21 +971,41 @@ def render_task(task: dict[str, Any]) -> dict[str, Any]:
|
|
| 441 |
output_png = Path(task["output_png"])
|
| 442 |
no_text_png = Path(task["no_text_png"])
|
| 443 |
temp_no_text_eps = Path(task["temp_no_text_eps"])
|
|
|
|
|
|
|
| 444 |
reference_png = Path(task["reference_png"]) if task["reference_png"] else None
|
| 445 |
html_png = Path(task["html_png"]) if task["html_png"] else None
|
| 446 |
pdf_text_path = Path(task["pdf_text_path"]) if task["pdf_text_path"] else None
|
| 447 |
captions = task["captions"]
|
| 448 |
source_code = task["source_code"]
|
|
|
|
|
|
|
| 449 |
render_device = "pnggray"
|
| 450 |
reference_png_exact = None
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
render_device = "pngalpha"
|
| 453 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 454 |
-
reference_png_exact = images_equal_rgba(output_png,
|
| 455 |
if not reference_png_exact:
|
| 456 |
render_device = "pnggray"
|
| 457 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 458 |
-
reference_png_exact = images_equal_rgba(output_png,
|
| 459 |
else:
|
| 460 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 461 |
|
|
@@ -465,8 +1015,8 @@ def render_task(task: dict[str, Any]) -> dict[str, Any]:
|
|
| 465 |
no_text_status = "rendered"
|
| 466 |
|
| 467 |
html_exact = None
|
| 468 |
-
if
|
| 469 |
-
html_exact = images_equal_rgba(output_png,
|
| 470 |
|
| 471 |
pdf_caption_pages: list[int] = []
|
| 472 |
if pdf_text_path.exists() and captions:
|
|
@@ -538,15 +1088,13 @@ def main() -> None:
|
|
| 538 |
parquet_path = derived_root / "circuits.parquet"
|
| 539 |
payload_root = Path("/workspace/hf_upload_payload")
|
| 540 |
|
| 541 |
-
for path in [
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
metadata_root,
|
| 549 |
-
]:
|
| 550 |
path.mkdir(parents=True, exist_ok=True)
|
| 551 |
|
| 552 |
ensure_inputs(repo_root, extracted_root)
|
|
@@ -563,6 +1111,7 @@ def main() -> None:
|
|
| 563 |
|
| 564 |
records: list[dict[str, Any]] = []
|
| 565 |
render_jobs: list[dict[str, Any]] = []
|
|
|
|
| 566 |
structure_summary: dict[str, Any] = {"books": {}}
|
| 567 |
|
| 568 |
for book in BOOKS:
|
|
@@ -584,6 +1133,9 @@ def main() -> None:
|
|
| 584 |
"pdf_version_sync": pdf_source["pdf_version_sync"],
|
| 585 |
"referenced_figures": len(figure_refs),
|
| 586 |
"circuit_rows": 0,
|
|
|
|
|
|
|
|
|
|
| 587 |
"source_notes": list(pdf_source["notes"]),
|
| 588 |
}
|
| 589 |
if not pdf_source["pdf_version_sync"]:
|
|
@@ -601,16 +1153,40 @@ def main() -> None:
|
|
| 601 |
if not eps_meta["is_circuit"]:
|
| 602 |
continue
|
| 603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
book_summary["circuit_rows"] += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
book_code_dir = code_root / book.slug
|
| 606 |
book_code_dir.mkdir(parents=True, exist_ok=True)
|
| 607 |
code_copy_path = book_code_dir / eps_path.name
|
| 608 |
-
|
| 609 |
-
shutil.copy2(eps_path, code_copy_path)
|
| 610 |
|
| 611 |
rendered_png = rendered_root / "original" / book.slug / f"{figure_stem}.png"
|
| 612 |
no_text_png = rendered_root / "no_text" / book.slug / f"{figure_stem}.png"
|
| 613 |
temp_no_text_eps = temp_root / "no_text_eps" / book.slug / f"{figure_stem}.eps"
|
|
|
|
|
|
|
| 614 |
|
| 615 |
captions = sorted(
|
| 616 |
{
|
|
@@ -645,12 +1221,19 @@ def main() -> None:
|
|
| 645 |
"eps_path": str(code_copy_path.relative_to(derived_root)),
|
| 646 |
"eps_creator": eps_meta["creator"],
|
| 647 |
"circuit_tokens": eps_meta["circuit_tokens"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
"references": refs,
|
| 649 |
"verification": {},
|
| 650 |
}
|
| 651 |
|
| 652 |
record = {
|
| 653 |
-
"Circuit Generation Code":
|
| 654 |
"Circuit generated image": str(rendered_png),
|
| 655 |
"Circuit Generated image with no text": str(no_text_png),
|
| 656 |
"Source": source_payload,
|
|
@@ -661,15 +1244,19 @@ def main() -> None:
|
|
| 661 |
{
|
| 662 |
"book": book.slug,
|
| 663 |
"figure_id": figure_stem,
|
| 664 |
-
"eps_path": str(
|
| 665 |
"output_png": str(rendered_png),
|
| 666 |
"no_text_png": str(no_text_png),
|
| 667 |
"temp_no_text_eps": str(temp_no_text_eps),
|
|
|
|
|
|
|
| 668 |
"reference_png": str(reference_png) if reference_png else None,
|
| 669 |
"html_png": str(html_png) if html_png else None,
|
| 670 |
"pdf_text_path": str(pdf_text_cache_paths[book.slug]),
|
| 671 |
"captions": captions,
|
| 672 |
-
"source_code":
|
|
|
|
|
|
|
| 673 |
}
|
| 674 |
)
|
| 675 |
|
|
@@ -723,6 +1310,15 @@ def main() -> None:
|
|
| 723 |
verification["notes"].append(
|
| 724 |
"Archived HTML PNG comparison was also recorded."
|
| 725 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
|
| 727 |
source_payload["verification"] = verification
|
| 728 |
|
|
@@ -778,6 +1374,9 @@ def main() -> None:
|
|
| 778 |
with (metadata_root / "rows.jsonl").open("w") as handle:
|
| 779 |
for row in dataset_rows:
|
| 780 |
handle.write(json.dumps(row, sort_keys=True) + "\n")
|
|
|
|
|
|
|
|
|
|
| 781 |
|
| 782 |
features = Features(
|
| 783 |
{
|
|
|
|
| 4 |
|
| 5 |
import argparse
|
| 6 |
import json
|
| 7 |
+
import math
|
| 8 |
import os
|
| 9 |
import re
|
| 10 |
import shutil
|
|
|
|
| 18 |
from pathlib import Path
|
| 19 |
from typing import Any
|
| 20 |
|
| 21 |
+
import numpy as np
|
| 22 |
import pyarrow as pa
|
| 23 |
import pyarrow.parquet as pq
|
| 24 |
from datasets import Dataset, Features, Image as HFImage, Value
|
|
|
|
| 67 |
"source",
|
| 68 |
"transistor2",
|
| 69 |
}
|
| 70 |
+
PRIMARY_SEED_PROCEDURES = {
|
| 71 |
+
"LED",
|
| 72 |
+
"acsource",
|
| 73 |
+
"battery",
|
| 74 |
+
"capacitor",
|
| 75 |
+
"diode",
|
| 76 |
+
"fuse_blown",
|
| 77 |
+
"inductor",
|
| 78 |
+
"npn",
|
| 79 |
+
"opamp",
|
| 80 |
+
"pnp",
|
| 81 |
+
"potentiometer",
|
| 82 |
+
"resistor",
|
| 83 |
+
"source",
|
| 84 |
+
}
|
| 85 |
+
PROC_BBOX_CATALOG: dict[str, tuple[int, int, int, int]] = {
|
| 86 |
+
"LED": (-16, -32, 32, 59),
|
| 87 |
+
"acsource": (-32, -64, 64, 128),
|
| 88 |
+
"battery": (-32, -64, 64, 128),
|
| 89 |
+
"capacitor": (-32, -64, 64, 128),
|
| 90 |
+
"diode": (-8, -48, 36, 96),
|
| 91 |
+
"fuse_blown": (-16, -32, 32, 62),
|
| 92 |
+
"gnd": (-32, -60, 64, 68),
|
| 93 |
+
"inductor": (-14, -64, 29, 112),
|
| 94 |
+
"npn": (-64, -64, 72, 128),
|
| 95 |
+
"opamp": (-80, -80, 160, 160),
|
| 96 |
+
"pnp": (-64, -64, 72, 128),
|
| 97 |
+
"potentiometer": (-46, -64, 78, 128),
|
| 98 |
+
"resistor": (-14, -64, 28, 128),
|
| 99 |
+
"source": (-32, -64, 64, 128),
|
| 100 |
+
}
|
| 101 |
+
STRIP_INVOCATION_PROCEDURES = {"person", "person_shocked"}
|
| 102 |
+
NON_CIRCUIT_SOURCE_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = (
|
| 103 |
+
(
|
| 104 |
+
re.compile(r"\breservoir\b|\bpond\b|\bpump\b|water flow", re.I),
|
| 105 |
+
"hydraulic analogy illustration",
|
| 106 |
+
),
|
| 107 |
+
(
|
| 108 |
+
re.compile(
|
| 109 |
+
r"lead-acid|fuel cell|electrolyte|electrode|hydrogen|oxygen|membranes?\b",
|
| 110 |
+
re.I,
|
| 111 |
+
),
|
| 112 |
+
"chemical cell illustration",
|
| 113 |
+
),
|
| 114 |
+
(
|
| 115 |
+
re.compile(
|
| 116 |
+
r"meter movement|moving coil|electron gun|view-screen|vacuum|needle|magnet\b",
|
| 117 |
+
re.I,
|
| 118 |
+
),
|
| 119 |
+
"instrument or device illustration",
|
| 120 |
+
),
|
| 121 |
+
)
|
| 122 |
|
| 123 |
XCIRCUIT_CREATOR_RE = re.compile(r"^%%Creator:\s*(.+)$", re.M)
|
| 124 |
EPS_PROC_RE = re.compile(r"^/([A-Za-z][A-Za-z0-9_-]*)\s*\{", re.M)
|
| 125 |
+
PROC_BBOX_RE = re.compile(
|
| 126 |
+
r"^/(?P<name>[A-Za-z][A-Za-z0-9_-]*)\s*\{\n%\s*"
|
| 127 |
+
r"(?P<x>-?\d+)\s+(?P<y>-?\d+)\s+(?P<w>-?\d+)\s+(?P<h>-?\d+)\s+bbox",
|
| 128 |
+
re.M,
|
| 129 |
+
)
|
| 130 |
+
PAGE_BODY_RE = re.compile(
|
| 131 |
+
r"(?P<prefix>^%%Page:.*?^/pgsave save def bop\n)(?P<body>.*?)(?P<suffix>^pgsave restore showpage.*?\Z)",
|
| 132 |
+
re.S | re.M,
|
| 133 |
+
)
|
| 134 |
+
PROC_CALL_RE = re.compile(
|
| 135 |
+
r"(?P<scale>-?\d+(?:\.\d+)?)\s+(?P<rot>-?\d+(?:\.\d+)?)\s+"
|
| 136 |
+
r"(?P<x>-?\d+(?:\.\d+)?)\s+(?P<y>-?\d+(?:\.\d+)?)\s+"
|
| 137 |
+
r"(?P<name>[A-Za-z][A-Za-z0-9_]*)\b"
|
| 138 |
+
)
|
| 139 |
+
PAGE_SCALE_RE = re.compile(r"(?P<scale>[0-9.]+)\s+(?P<kind>inchscale|cmscale)")
|
| 140 |
+
PAGE_TRANSLATE_RE = re.compile(
|
| 141 |
+
r"(?P<x>-?\d+(?:\.\d+)?)\s+(?P<y>-?\d+(?:\.\d+)?)\s+translate"
|
| 142 |
+
)
|
| 143 |
+
INVOCATION_LINE_RE = re.compile(
|
| 144 |
+
r"^\s*-?\d+(?:\.\d+)?\s+-?\d+(?:\.\d+)?\s+-?\d+(?:\.\d+)?\s+-?\d+(?:\.\d+)?\s+(?P<name>[A-Za-z][A-Za-z0-9_]*)\s*$"
|
| 145 |
+
)
|
| 146 |
+
FULL_INVOCATION_LINE_RE = re.compile(
|
| 147 |
+
r"^\s*(?P<scale>-?\d+(?:\.\d+)?)\s+(?P<rot>-?\d+(?:\.\d+)?)\s+"
|
| 148 |
+
r"(?P<x>-?\d+(?:\.\d+)?)\s+(?P<y>-?\d+(?:\.\d+)?)\s+"
|
| 149 |
+
r"(?P<name>[A-Za-z][A-Za-z0-9_]*)\s*$"
|
| 150 |
+
)
|
| 151 |
SML_TOKEN_RE = re.compile(
|
| 152 |
r"(?P<chapter><chaptertitle>(?P<chapter_text>.*?)</chaptertitle>)"
|
| 153 |
r"|(?P<section><sectiontitle>(?P<section_text>.*?)</sectiontitle>)"
|
|
|
|
| 471 |
}
|
| 472 |
|
| 473 |
|
| 474 |
+
def parse_eps_bounding_box(source_code: str) -> tuple[float, float, float, float]:
|
| 475 |
+
match = re.search(
|
| 476 |
+
r"^%%BoundingBox:\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)", source_code, re.M
|
| 477 |
+
)
|
| 478 |
+
if not match:
|
| 479 |
+
raise ValueError("Missing EPS bounding box")
|
| 480 |
+
return tuple(float(value) for value in match.groups())
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def split_page_body(source_code: str) -> tuple[str, str, str] | None:
|
| 484 |
+
match = PAGE_BODY_RE.search(source_code)
|
| 485 |
+
if not match:
|
| 486 |
+
return None
|
| 487 |
+
return match.group("prefix"), match.group("body"), match.group("suffix")
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def replace_page_body(source_code: str, new_body: str) -> str:
|
| 491 |
+
page_parts = split_page_body(source_code)
|
| 492 |
+
if not page_parts:
|
| 493 |
+
return source_code
|
| 494 |
+
prefix, _, suffix = page_parts
|
| 495 |
+
return source_code[: PAGE_BODY_RE.search(source_code).start()] + prefix + new_body + suffix
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
def strip_forbidden_invocations(source_code: str) -> tuple[str, list[str]]:
|
| 499 |
+
page_parts = split_page_body(source_code)
|
| 500 |
+
if not page_parts:
|
| 501 |
+
return source_code, []
|
| 502 |
+
|
| 503 |
+
prefix, body, suffix = page_parts
|
| 504 |
+
kept_lines: list[str] = []
|
| 505 |
+
removed: list[str] = []
|
| 506 |
+
for line in body.splitlines():
|
| 507 |
+
match = INVOCATION_LINE_RE.match(line)
|
| 508 |
+
if match and match.group("name") in STRIP_INVOCATION_PROCEDURES:
|
| 509 |
+
removed.append(match.group("name"))
|
| 510 |
+
continue
|
| 511 |
+
kept_lines.append(line)
|
| 512 |
+
|
| 513 |
+
rewritten = source_code[: PAGE_BODY_RE.search(source_code).start()] + prefix
|
| 514 |
+
if kept_lines:
|
| 515 |
+
rewritten += "\n".join(kept_lines) + "\n"
|
| 516 |
+
rewritten += suffix
|
| 517 |
+
return rewritten, sorted(set(removed))
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
def strip_trailing_ground_invocations(source_code: str) -> tuple[str, int]:
|
| 521 |
+
page_parts = split_page_body(source_code)
|
| 522 |
+
if not page_parts:
|
| 523 |
+
return source_code, 0
|
| 524 |
+
|
| 525 |
+
prefix, body, suffix = page_parts
|
| 526 |
+
anchor_x: float | None = None
|
| 527 |
+
for line in body.splitlines():
|
| 528 |
+
match = FULL_INVOCATION_LINE_RE.match(line)
|
| 529 |
+
if not match:
|
| 530 |
+
continue
|
| 531 |
+
name = match.group("name")
|
| 532 |
+
if name in PRIMARY_SEED_PROCEDURES:
|
| 533 |
+
x = float(match.group("x"))
|
| 534 |
+
anchor_x = x if anchor_x is None else max(anchor_x, x)
|
| 535 |
+
|
| 536 |
+
if anchor_x is None:
|
| 537 |
+
return source_code, 0
|
| 538 |
+
|
| 539 |
+
kept_lines: list[str] = []
|
| 540 |
+
removed = 0
|
| 541 |
+
for line in body.splitlines():
|
| 542 |
+
match = FULL_INVOCATION_LINE_RE.match(line)
|
| 543 |
+
if match and match.group("name") == "gnd" and float(match.group("x")) > anchor_x + 64.0:
|
| 544 |
+
removed += 1
|
| 545 |
+
continue
|
| 546 |
+
kept_lines.append(line)
|
| 547 |
+
|
| 548 |
+
rewritten = source_code[: PAGE_BODY_RE.search(source_code).start()] + prefix
|
| 549 |
+
if kept_lines:
|
| 550 |
+
rewritten += "\n".join(kept_lines) + "\n"
|
| 551 |
+
rewritten += suffix
|
| 552 |
+
return rewritten, removed
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
def reject_reason_for_figure(
|
| 556 |
+
book: BookConfig,
|
| 557 |
+
refs: list[dict[str, Any]],
|
| 558 |
+
source_code: str,
|
| 559 |
+
) -> str | None:
|
| 560 |
+
chapter = normalize_space(refs[0].get("chapter") or "").lower() if refs else ""
|
| 561 |
+
section = normalize_space(refs[0].get("section") or "").lower() if refs else ""
|
| 562 |
+
if (
|
| 563 |
+
book.slug == "DC"
|
| 564 |
+
and chapter == "dc metering circuits"
|
| 565 |
+
and section == "what is a meter?"
|
| 566 |
+
):
|
| 567 |
+
return "meter illustration section"
|
| 568 |
+
|
| 569 |
+
for pattern, reason in NON_CIRCUIT_SOURCE_PATTERNS:
|
| 570 |
+
if pattern.search(source_code):
|
| 571 |
+
return reason
|
| 572 |
+
return None
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
def parse_page_transform(source_code: str) -> tuple[tuple[float, float, float, float], float, float, float]:
|
| 576 |
+
bbox = parse_eps_bounding_box(source_code)
|
| 577 |
+
page_parts = split_page_body(source_code)
|
| 578 |
+
if not page_parts:
|
| 579 |
+
return bbox, 1.0, 0.0, 0.0
|
| 580 |
+
|
| 581 |
+
_, body, _ = page_parts
|
| 582 |
+
scale_match = PAGE_SCALE_RE.search(body)
|
| 583 |
+
scale = 1.0
|
| 584 |
+
if scale_match:
|
| 585 |
+
unit_scale = 0.375 if scale_match.group("kind") == "inchscale" else 0.35433071
|
| 586 |
+
scale = float(scale_match.group("scale")) * unit_scale
|
| 587 |
+
|
| 588 |
+
translate_match = PAGE_TRANSLATE_RE.search(body)
|
| 589 |
+
tx = float(translate_match.group("x")) if translate_match else 0.0
|
| 590 |
+
ty = float(translate_match.group("y")) if translate_match else 0.0
|
| 591 |
+
return bbox, scale, tx, ty
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
def placed_seed_boxes(source_code: str, image_size: tuple[int, int]) -> list[tuple[str, int, int, int, int]]:
|
| 595 |
+
bbox, page_scale, tx, ty = parse_page_transform(source_code)
|
| 596 |
+
page_parts = split_page_body(source_code)
|
| 597 |
+
if not page_parts:
|
| 598 |
+
return []
|
| 599 |
+
|
| 600 |
+
definitions = {
|
| 601 |
+
match.group("name"): (
|
| 602 |
+
int(match.group("x")),
|
| 603 |
+
int(match.group("y")),
|
| 604 |
+
int(match.group("w")),
|
| 605 |
+
int(match.group("h")),
|
| 606 |
+
)
|
| 607 |
+
for match in PROC_BBOX_RE.finditer(source_code)
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
_, body, _ = page_parts
|
| 611 |
+
llx, lly, urx, ury = bbox
|
| 612 |
+
width, height = image_size
|
| 613 |
+
seeds: list[tuple[str, int, int, int, int]] = []
|
| 614 |
+
|
| 615 |
+
for match in PROC_CALL_RE.finditer(body):
|
| 616 |
+
name = match.group("name")
|
| 617 |
+
if name not in PRIMARY_SEED_PROCEDURES:
|
| 618 |
+
continue
|
| 619 |
+
local_bbox = definitions.get(name) or PROC_BBOX_CATALOG.get(name)
|
| 620 |
+
if not local_bbox:
|
| 621 |
+
continue
|
| 622 |
+
|
| 623 |
+
scale = abs(float(match.group("scale")))
|
| 624 |
+
rotation = math.radians(float(match.group("rot")))
|
| 625 |
+
x = float(match.group("x"))
|
| 626 |
+
y = float(match.group("y"))
|
| 627 |
+
bx, by, bw, bh = local_bbox
|
| 628 |
+
corners = [
|
| 629 |
+
(bx, by),
|
| 630 |
+
(bx + bw, by),
|
| 631 |
+
(bx, by + bh),
|
| 632 |
+
(bx + bw, by + bh),
|
| 633 |
+
]
|
| 634 |
+
page_points: list[tuple[float, float]] = []
|
| 635 |
+
for cx, cy in corners:
|
| 636 |
+
sx = cx * scale
|
| 637 |
+
sy = cy * scale
|
| 638 |
+
rx = sx * math.cos(rotation) - sy * math.sin(rotation)
|
| 639 |
+
ry = sx * math.sin(rotation) + sy * math.cos(rotation)
|
| 640 |
+
page_points.append((page_scale * (tx + x + rx), page_scale * (ty + y + ry)))
|
| 641 |
+
|
| 642 |
+
xs = [point[0] for point in page_points]
|
| 643 |
+
ys = [point[1] for point in page_points]
|
| 644 |
+
left = max(0, int((min(xs) - llx) / (urx - llx) * width))
|
| 645 |
+
right = min(width - 1, int((max(xs) - llx) / (urx - llx) * width))
|
| 646 |
+
top = max(0, int((ury - max(ys)) / (ury - lly) * height))
|
| 647 |
+
bottom = min(height - 1, int((ury - min(ys)) / (ury - lly) * height))
|
| 648 |
+
seeds.append((name, left, top, right, bottom))
|
| 649 |
+
|
| 650 |
+
return seeds
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
def widest_low_ink_run(values: np.ndarray, max_dark: int) -> tuple[int, int] | None:
|
| 654 |
+
best: tuple[int, int] | None = None
|
| 655 |
+
run_start: int | None = None
|
| 656 |
+
for index, value in enumerate(values):
|
| 657 |
+
if int(value) <= max_dark:
|
| 658 |
+
if run_start is None:
|
| 659 |
+
run_start = index
|
| 660 |
+
continue
|
| 661 |
+
if run_start is not None:
|
| 662 |
+
candidate = (run_start, index - 1)
|
| 663 |
+
if not best or (candidate[1] - candidate[0]) > (best[1] - best[0]):
|
| 664 |
+
best = candidate
|
| 665 |
+
run_start = None
|
| 666 |
+
if run_start is not None:
|
| 667 |
+
candidate = (run_start, len(values) - 1)
|
| 668 |
+
if not best or (candidate[1] - candidate[0]) > (best[1] - best[0]):
|
| 669 |
+
best = candidate
|
| 670 |
+
return best
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
def pixel_bbox_from_mask(mask: np.ndarray) -> tuple[int, int, int, int] | None:
|
| 674 |
+
ys, xs = np.where(mask)
|
| 675 |
+
if xs.size == 0 or ys.size == 0:
|
| 676 |
+
return None
|
| 677 |
+
return int(xs.min()), int(ys.min()), int(xs.max()), int(ys.max())
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
def connected_components(mask: np.ndarray) -> tuple[np.ndarray, list[tuple[int, int, int, int, int, int]]]:
|
| 681 |
+
height, width = mask.shape
|
| 682 |
+
seen = np.zeros((height, width), dtype=np.uint8)
|
| 683 |
+
labels = np.full((height, width), -1, dtype=np.int32)
|
| 684 |
+
components: list[tuple[int, int, int, int, int, int]] = []
|
| 685 |
+
label = 0
|
| 686 |
+
|
| 687 |
+
for y in range(height):
|
| 688 |
+
for x in range(width):
|
| 689 |
+
if not mask[y, x] or seen[y, x]:
|
| 690 |
+
continue
|
| 691 |
+
stack = [(x, y)]
|
| 692 |
+
seen[y, x] = 1
|
| 693 |
+
area = 0
|
| 694 |
+
min_x = max_x = x
|
| 695 |
+
min_y = max_y = y
|
| 696 |
+
while stack:
|
| 697 |
+
cx, cy = stack.pop()
|
| 698 |
+
labels[cy, cx] = label
|
| 699 |
+
area += 1
|
| 700 |
+
min_x = min(min_x, cx)
|
| 701 |
+
max_x = max(max_x, cx)
|
| 702 |
+
min_y = min(min_y, cy)
|
| 703 |
+
max_y = max(max_y, cy)
|
| 704 |
+
for ny in range(max(0, cy - 1), min(height, cy + 2)):
|
| 705 |
+
for nx in range(max(0, cx - 1), min(width, cx + 2)):
|
| 706 |
+
if mask[ny, nx] and not seen[ny, nx]:
|
| 707 |
+
seen[ny, nx] = 1
|
| 708 |
+
stack.append((nx, ny))
|
| 709 |
+
components.append((label, area, min_x, min_y, max_x, max_y))
|
| 710 |
+
label += 1
|
| 711 |
+
|
| 712 |
+
return labels, components
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
def crop_pixels_to_eps_points(
|
| 716 |
+
pixel_bbox: tuple[int, int, int, int],
|
| 717 |
+
image_size: tuple[int, int],
|
| 718 |
+
eps_bbox: tuple[float, float, float, float],
|
| 719 |
+
) -> tuple[float, float, float, float]:
|
| 720 |
+
left, top, right, bottom = pixel_bbox
|
| 721 |
+
width, height = image_size
|
| 722 |
+
llx, lly, urx, ury = eps_bbox
|
| 723 |
+
eps_left = llx + (left / width) * (urx - llx)
|
| 724 |
+
eps_right = llx + ((right + 1) / width) * (urx - llx)
|
| 725 |
+
eps_top = ury - (top / height) * (ury - lly)
|
| 726 |
+
eps_bottom = ury - ((bottom + 1) / height) * (ury - lly)
|
| 727 |
+
return eps_left, eps_bottom, eps_right, eps_top
|
| 728 |
+
|
| 729 |
+
|
| 730 |
+
def crop_eps_points_to_pixels(
|
| 731 |
+
crop_bbox: tuple[float, float, float, float],
|
| 732 |
+
image_size: tuple[int, int],
|
| 733 |
+
eps_bbox: tuple[float, float, float, float],
|
| 734 |
+
) -> tuple[int, int, int, int]:
|
| 735 |
+
crop_llx, crop_lly, crop_urx, crop_ury = crop_bbox
|
| 736 |
+
llx, lly, urx, ury = eps_bbox
|
| 737 |
+
width, height = image_size
|
| 738 |
+
left = max(0, math.floor((crop_llx - llx) / (urx - llx) * width))
|
| 739 |
+
right = min(width, math.ceil((crop_urx - llx) / (urx - llx) * width))
|
| 740 |
+
top = max(0, math.floor((ury - crop_ury) / (ury - lly) * height))
|
| 741 |
+
bottom = min(height, math.ceil((ury - crop_lly) / (ury - lly) * height))
|
| 742 |
+
return left, top, right, bottom
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
def apply_clip_bbox(
|
| 746 |
+
source_code: str, crop_bbox: tuple[float, float, float, float]
|
| 747 |
+
) -> str:
|
| 748 |
+
page_parts = split_page_body(source_code)
|
| 749 |
+
if not page_parts:
|
| 750 |
+
return source_code
|
| 751 |
+
|
| 752 |
+
clip_llx, clip_lly, clip_urx, clip_ury = crop_bbox
|
| 753 |
+
prefix, body, suffix = page_parts
|
| 754 |
+
clip_ps = (
|
| 755 |
+
f"newpath {clip_llx:.3f} {clip_lly:.3f} moveto "
|
| 756 |
+
f"{clip_urx:.3f} {clip_lly:.3f} lineto "
|
| 757 |
+
f"{clip_urx:.3f} {clip_ury:.3f} lineto "
|
| 758 |
+
f"{clip_llx:.3f} {clip_ury:.3f} lineto closepath clip newpath\n"
|
| 759 |
+
)
|
| 760 |
+
rewritten = source_code[: PAGE_BODY_RE.search(source_code).start()] + prefix + clip_ps + body + suffix
|
| 761 |
+
|
| 762 |
+
bbox_line = "%%BoundingBox: {} {} {} {}".format(
|
| 763 |
+
math.floor(clip_llx),
|
| 764 |
+
math.floor(clip_lly),
|
| 765 |
+
math.ceil(clip_urx),
|
| 766 |
+
math.ceil(clip_ury),
|
| 767 |
+
)
|
| 768 |
+
rewritten = re.sub(r"^%%BoundingBox:.*$", bbox_line, rewritten, count=1, flags=re.M)
|
| 769 |
+
return rewritten
|
| 770 |
+
|
| 771 |
+
|
| 772 |
+
def render_source_code_to_png(
|
| 773 |
+
source_code: str,
|
| 774 |
+
eps_path: Path,
|
| 775 |
+
png_path: Path,
|
| 776 |
+
*,
|
| 777 |
+
device: str,
|
| 778 |
+
) -> None:
|
| 779 |
+
eps_path.parent.mkdir(parents=True, exist_ok=True)
|
| 780 |
+
eps_path.write_text(source_code)
|
| 781 |
+
render_eps_to_png(eps_path, png_path, device=device)
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
def derive_crop_bbox(
|
| 785 |
+
source_code: str,
|
| 786 |
+
analysis_png_path: Path,
|
| 787 |
+
) -> tuple[int, int, int, int] | None:
|
| 788 |
+
with Image.open(analysis_png_path) as image:
|
| 789 |
+
gray = np.array(image.convert("L"))
|
| 790 |
+
|
| 791 |
+
mask = gray < 220
|
| 792 |
+
full_bbox = pixel_bbox_from_mask(mask)
|
| 793 |
+
if not full_bbox:
|
| 794 |
+
return None
|
| 795 |
+
|
| 796 |
+
seeds = placed_seed_boxes(source_code, (gray.shape[1], gray.shape[0]))
|
| 797 |
+
if not seeds:
|
| 798 |
+
return None
|
| 799 |
+
|
| 800 |
+
seed_left = min(seed[1] for seed in seeds)
|
| 801 |
+
seed_top = min(seed[2] for seed in seeds)
|
| 802 |
+
seed_right = max(seed[3] for seed in seeds)
|
| 803 |
+
seed_bottom = max(seed[4] for seed in seeds)
|
| 804 |
+
|
| 805 |
+
full_left, _, full_right, _ = full_bbox
|
| 806 |
+
column_sums = mask.sum(axis=0)
|
| 807 |
+
gap_dark_max = 1
|
| 808 |
+
gap_min_width = max(24, int(gray.shape[1] * 0.08))
|
| 809 |
+
left_gap_abs: tuple[int, int] | None = None
|
| 810 |
+
right_gap_abs: tuple[int, int] | None = None
|
| 811 |
+
|
| 812 |
+
if seed_left - full_left >= gap_min_width:
|
| 813 |
+
left_gap = widest_low_ink_run(column_sums[full_left:seed_left], gap_dark_max)
|
| 814 |
+
if left_gap and (left_gap[1] - left_gap[0] + 1) >= gap_min_width:
|
| 815 |
+
left_gap_abs = (full_left + left_gap[0], full_left + left_gap[1])
|
| 816 |
+
|
| 817 |
+
if full_right - seed_right >= gap_min_width:
|
| 818 |
+
right_gap = widest_low_ink_run(column_sums[seed_right + 1 : full_right + 1], gap_dark_max)
|
| 819 |
+
if right_gap and (right_gap[1] - right_gap[0] + 1) >= gap_min_width:
|
| 820 |
+
right_gap_abs = (seed_right + 1 + right_gap[0], seed_right + 1 + right_gap[1])
|
| 821 |
+
|
| 822 |
+
if not left_gap_abs and not right_gap_abs:
|
| 823 |
+
return None
|
| 824 |
+
|
| 825 |
+
labels, components = connected_components(mask)
|
| 826 |
+
component_ids: set[int] = set()
|
| 827 |
+
for _, left, top, right, bottom in seeds:
|
| 828 |
+
if right < left or bottom < top:
|
| 829 |
+
continue
|
| 830 |
+
sub = labels[top : bottom + 1, left : right + 1]
|
| 831 |
+
component_ids.update(int(value) for value in np.unique(sub) if value >= 0)
|
| 832 |
+
|
| 833 |
+
picked = [component for component in components if component[0] in component_ids]
|
| 834 |
+
if not picked:
|
| 835 |
+
return None
|
| 836 |
+
|
| 837 |
+
margin_x = max(8, int(gray.shape[1] * 0.02))
|
| 838 |
+
margin_y = max(8, int(gray.shape[0] * 0.05))
|
| 839 |
+
left = max(0, min(component[2] for component in picked) - margin_x)
|
| 840 |
+
top = max(0, min(component[3] for component in picked) - margin_y)
|
| 841 |
+
right = min(gray.shape[1] - 1, max(component[4] for component in picked) + margin_x)
|
| 842 |
+
bottom = min(gray.shape[0] - 1, max(component[5] for component in picked) + margin_y)
|
| 843 |
+
|
| 844 |
+
if left_gap_abs:
|
| 845 |
+
left = max(left, left_gap_abs[1] + 1)
|
| 846 |
+
if right_gap_abs:
|
| 847 |
+
right = min(right, right_gap_abs[0] - 1)
|
| 848 |
+
|
| 849 |
+
if right <= left or bottom <= top:
|
| 850 |
+
return None
|
| 851 |
+
|
| 852 |
+
cropped_area = (right - left + 1) * (bottom - top + 1)
|
| 853 |
+
full_area = gray.shape[0] * gray.shape[1]
|
| 854 |
+
if cropped_area >= full_area * 0.94:
|
| 855 |
+
return None
|
| 856 |
+
return left, top, right, bottom
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
def crop_image_to_bbox(
|
| 860 |
+
source_path: Path,
|
| 861 |
+
output_path: Path,
|
| 862 |
+
crop_bbox: tuple[float, float, float, float],
|
| 863 |
+
eps_bbox: tuple[float, float, float, float],
|
| 864 |
+
) -> None:
|
| 865 |
+
with Image.open(source_path) as image:
|
| 866 |
+
left, top, right, bottom = crop_eps_points_to_pixels(crop_bbox, image.size, eps_bbox)
|
| 867 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 868 |
+
image.crop((left, top, right, bottom)).save(output_path)
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
def prepare_figure_artifact(
|
| 872 |
+
book: BookConfig,
|
| 873 |
+
figure_stem: str,
|
| 874 |
+
refs: list[dict[str, Any]],
|
| 875 |
+
source_code: str,
|
| 876 |
+
temp_root: Path,
|
| 877 |
+
) -> dict[str, Any]:
|
| 878 |
+
reject_reason = reject_reason_for_figure(book, refs, source_code)
|
| 879 |
+
if reject_reason:
|
| 880 |
+
return {"keep": False, "reject_reason": reject_reason}
|
| 881 |
+
|
| 882 |
+
sanitized_code, removed_procedures = strip_forbidden_invocations(source_code)
|
| 883 |
+
removed_grounds = 0
|
| 884 |
+
if removed_procedures:
|
| 885 |
+
sanitized_code, removed_grounds = strip_trailing_ground_invocations(sanitized_code)
|
| 886 |
+
original_bbox = parse_eps_bounding_box(sanitized_code)
|
| 887 |
+
|
| 888 |
+
analysis_eps = temp_root / "analysis_eps" / book.slug / f"{figure_stem}.eps"
|
| 889 |
+
analysis_png = temp_root / "analysis_png" / book.slug / f"{figure_stem}.png"
|
| 890 |
+
analysis_eps.parent.mkdir(parents=True, exist_ok=True)
|
| 891 |
+
analysis_png.parent.mkdir(parents=True, exist_ok=True)
|
| 892 |
+
write_no_text_eps(sanitized_code, analysis_eps)
|
| 893 |
+
render_eps_to_png(analysis_eps, analysis_png, device="pnggray")
|
| 894 |
+
|
| 895 |
+
crop_bbox_px = None if removed_procedures else derive_crop_bbox(sanitized_code, analysis_png)
|
| 896 |
+
crop_bbox_eps = None
|
| 897 |
+
if crop_bbox_px:
|
| 898 |
+
with Image.open(analysis_png) as analysis_image:
|
| 899 |
+
crop_bbox_eps = crop_pixels_to_eps_points(
|
| 900 |
+
crop_bbox_px,
|
| 901 |
+
analysis_image.size,
|
| 902 |
+
original_bbox,
|
| 903 |
+
)
|
| 904 |
+
derived_code = apply_clip_bbox(sanitized_code, crop_bbox_eps) if crop_bbox_eps else sanitized_code
|
| 905 |
+
|
| 906 |
+
extraction_mode = "whole"
|
| 907 |
+
if crop_bbox_eps:
|
| 908 |
+
extraction_mode = "cropped"
|
| 909 |
+
elif removed_procedures:
|
| 910 |
+
extraction_mode = "sanitized"
|
| 911 |
+
|
| 912 |
+
return {
|
| 913 |
+
"keep": True,
|
| 914 |
+
"source_code": derived_code,
|
| 915 |
+
"original_eps_bbox": original_bbox,
|
| 916 |
+
"crop_bbox_eps": crop_bbox_eps,
|
| 917 |
+
"crop_bbox_px": crop_bbox_px,
|
| 918 |
+
"removed_procedures": removed_procedures,
|
| 919 |
+
"removed_auxiliary_grounds": removed_grounds,
|
| 920 |
+
"extraction_mode": extraction_mode,
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
|
| 924 |
def write_no_text_eps(source_code: str, output_path: Path) -> None:
|
| 925 |
needle = "%%EndComments\n"
|
| 926 |
if needle in source_code:
|
|
|
|
| 971 |
output_png = Path(task["output_png"])
|
| 972 |
no_text_png = Path(task["no_text_png"])
|
| 973 |
temp_no_text_eps = Path(task["temp_no_text_eps"])
|
| 974 |
+
temp_reference_png = Path(task["temp_reference_png"]) if task["temp_reference_png"] else None
|
| 975 |
+
temp_html_png = Path(task["temp_html_png"]) if task["temp_html_png"] else None
|
| 976 |
reference_png = Path(task["reference_png"]) if task["reference_png"] else None
|
| 977 |
html_png = Path(task["html_png"]) if task["html_png"] else None
|
| 978 |
pdf_text_path = Path(task["pdf_text_path"]) if task["pdf_text_path"] else None
|
| 979 |
captions = task["captions"]
|
| 980 |
source_code = task["source_code"]
|
| 981 |
+
crop_bbox_eps = tuple(task["crop_bbox_eps"]) if task["crop_bbox_eps"] else None
|
| 982 |
+
original_eps_bbox = tuple(task["original_eps_bbox"]) if task["original_eps_bbox"] else None
|
| 983 |
render_device = "pnggray"
|
| 984 |
reference_png_exact = None
|
| 985 |
+
reference_compare_path = reference_png
|
| 986 |
+
if (
|
| 987 |
+
reference_png
|
| 988 |
+
and reference_png.exists()
|
| 989 |
+
and crop_bbox_eps
|
| 990 |
+
and original_eps_bbox
|
| 991 |
+
and temp_reference_png
|
| 992 |
+
):
|
| 993 |
+
crop_image_to_bbox(reference_png, temp_reference_png, crop_bbox_eps, original_eps_bbox)
|
| 994 |
+
reference_compare_path = temp_reference_png
|
| 995 |
+
|
| 996 |
+
html_compare_path = html_png
|
| 997 |
+
if html_png and html_png.exists() and crop_bbox_eps and original_eps_bbox and temp_html_png:
|
| 998 |
+
crop_image_to_bbox(html_png, temp_html_png, crop_bbox_eps, original_eps_bbox)
|
| 999 |
+
html_compare_path = temp_html_png
|
| 1000 |
+
|
| 1001 |
+
if reference_compare_path and reference_compare_path.exists():
|
| 1002 |
render_device = "pngalpha"
|
| 1003 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 1004 |
+
reference_png_exact = images_equal_rgba(output_png, reference_compare_path)
|
| 1005 |
if not reference_png_exact:
|
| 1006 |
render_device = "pnggray"
|
| 1007 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 1008 |
+
reference_png_exact = images_equal_rgba(output_png, reference_compare_path)
|
| 1009 |
else:
|
| 1010 |
render_eps_to_png(eps_path, output_png, device=render_device)
|
| 1011 |
|
|
|
|
| 1015 |
no_text_status = "rendered"
|
| 1016 |
|
| 1017 |
html_exact = None
|
| 1018 |
+
if html_compare_path and html_compare_path.exists():
|
| 1019 |
+
html_exact = images_equal_rgba(output_png, html_compare_path)
|
| 1020 |
|
| 1021 |
pdf_caption_pages: list[int] = []
|
| 1022 |
if pdf_text_path.exists() and captions:
|
|
|
|
| 1088 |
parquet_path = derived_root / "circuits.parquet"
|
| 1089 |
payload_root = Path("/workspace/hf_upload_payload")
|
| 1090 |
|
| 1091 |
+
for path in [rendered_root, code_root, metadata_root, dataset_root, temp_root]:
|
| 1092 |
+
if path.exists():
|
| 1093 |
+
shutil.rmtree(path)
|
| 1094 |
+
if parquet_path.exists():
|
| 1095 |
+
parquet_path.unlink()
|
| 1096 |
+
|
| 1097 |
+
for path in [work_root, extracted_root, cache_root, temp_root, rendered_root, code_root, metadata_root]:
|
|
|
|
|
|
|
| 1098 |
path.mkdir(parents=True, exist_ok=True)
|
| 1099 |
|
| 1100 |
ensure_inputs(repo_root, extracted_root)
|
|
|
|
| 1111 |
|
| 1112 |
records: list[dict[str, Any]] = []
|
| 1113 |
render_jobs: list[dict[str, Any]] = []
|
| 1114 |
+
pruned_records: list[dict[str, Any]] = []
|
| 1115 |
structure_summary: dict[str, Any] = {"books": {}}
|
| 1116 |
|
| 1117 |
for book in BOOKS:
|
|
|
|
| 1133 |
"pdf_version_sync": pdf_source["pdf_version_sync"],
|
| 1134 |
"referenced_figures": len(figure_refs),
|
| 1135 |
"circuit_rows": 0,
|
| 1136 |
+
"cropped_rows": 0,
|
| 1137 |
+
"sanitized_rows": 0,
|
| 1138 |
+
"pruned_rows": 0,
|
| 1139 |
"source_notes": list(pdf_source["notes"]),
|
| 1140 |
}
|
| 1141 |
if not pdf_source["pdf_version_sync"]:
|
|
|
|
| 1153 |
if not eps_meta["is_circuit"]:
|
| 1154 |
continue
|
| 1155 |
|
| 1156 |
+
prepared = prepare_figure_artifact(
|
| 1157 |
+
book,
|
| 1158 |
+
figure_stem,
|
| 1159 |
+
refs,
|
| 1160 |
+
eps_meta["code"],
|
| 1161 |
+
temp_root,
|
| 1162 |
+
)
|
| 1163 |
+
if not prepared["keep"]:
|
| 1164 |
+
book_summary["pruned_rows"] += 1
|
| 1165 |
+
pruned_records.append(
|
| 1166 |
+
{
|
| 1167 |
+
"book": book.slug,
|
| 1168 |
+
"figure_id": figure_stem,
|
| 1169 |
+
"reason": prepared["reject_reason"],
|
| 1170 |
+
"references": refs,
|
| 1171 |
+
}
|
| 1172 |
+
)
|
| 1173 |
+
continue
|
| 1174 |
+
|
| 1175 |
book_summary["circuit_rows"] += 1
|
| 1176 |
+
if prepared["extraction_mode"] == "cropped":
|
| 1177 |
+
book_summary["cropped_rows"] += 1
|
| 1178 |
+
if prepared["removed_procedures"]:
|
| 1179 |
+
book_summary["sanitized_rows"] += 1
|
| 1180 |
book_code_dir = code_root / book.slug
|
| 1181 |
book_code_dir.mkdir(parents=True, exist_ok=True)
|
| 1182 |
code_copy_path = book_code_dir / eps_path.name
|
| 1183 |
+
code_copy_path.write_text(prepared["source_code"])
|
|
|
|
| 1184 |
|
| 1185 |
rendered_png = rendered_root / "original" / book.slug / f"{figure_stem}.png"
|
| 1186 |
no_text_png = rendered_root / "no_text" / book.slug / f"{figure_stem}.png"
|
| 1187 |
temp_no_text_eps = temp_root / "no_text_eps" / book.slug / f"{figure_stem}.eps"
|
| 1188 |
+
temp_reference_png = temp_root / "reference_png" / book.slug / f"{figure_stem}.png"
|
| 1189 |
+
temp_html_png = temp_root / "html_png" / book.slug / f"{figure_stem}.png"
|
| 1190 |
|
| 1191 |
captions = sorted(
|
| 1192 |
{
|
|
|
|
| 1221 |
"eps_path": str(code_copy_path.relative_to(derived_root)),
|
| 1222 |
"eps_creator": eps_meta["creator"],
|
| 1223 |
"circuit_tokens": eps_meta["circuit_tokens"],
|
| 1224 |
+
"extraction": {
|
| 1225 |
+
"mode": prepared["extraction_mode"],
|
| 1226 |
+
"crop_bbox_eps": prepared["crop_bbox_eps"],
|
| 1227 |
+
"crop_bbox_px": prepared["crop_bbox_px"],
|
| 1228 |
+
"removed_procedures": prepared["removed_procedures"],
|
| 1229 |
+
"removed_auxiliary_grounds": prepared["removed_auxiliary_grounds"],
|
| 1230 |
+
},
|
| 1231 |
"references": refs,
|
| 1232 |
"verification": {},
|
| 1233 |
}
|
| 1234 |
|
| 1235 |
record = {
|
| 1236 |
+
"Circuit Generation Code": prepared["source_code"],
|
| 1237 |
"Circuit generated image": str(rendered_png),
|
| 1238 |
"Circuit Generated image with no text": str(no_text_png),
|
| 1239 |
"Source": source_payload,
|
|
|
|
| 1244 |
{
|
| 1245 |
"book": book.slug,
|
| 1246 |
"figure_id": figure_stem,
|
| 1247 |
+
"eps_path": str(code_copy_path),
|
| 1248 |
"output_png": str(rendered_png),
|
| 1249 |
"no_text_png": str(no_text_png),
|
| 1250 |
"temp_no_text_eps": str(temp_no_text_eps),
|
| 1251 |
+
"temp_reference_png": str(temp_reference_png),
|
| 1252 |
+
"temp_html_png": str(temp_html_png),
|
| 1253 |
"reference_png": str(reference_png) if reference_png else None,
|
| 1254 |
"html_png": str(html_png) if html_png else None,
|
| 1255 |
"pdf_text_path": str(pdf_text_cache_paths[book.slug]),
|
| 1256 |
"captions": captions,
|
| 1257 |
+
"source_code": prepared["source_code"],
|
| 1258 |
+
"crop_bbox_eps": prepared["crop_bbox_eps"],
|
| 1259 |
+
"original_eps_bbox": prepared["original_eps_bbox"],
|
| 1260 |
}
|
| 1261 |
)
|
| 1262 |
|
|
|
|
| 1310 |
verification["notes"].append(
|
| 1311 |
"Archived HTML PNG comparison was also recorded."
|
| 1312 |
)
|
| 1313 |
+
extraction_mode = source_payload.get("extraction", {}).get("mode")
|
| 1314 |
+
if extraction_mode == "cropped":
|
| 1315 |
+
verification["notes"].append(
|
| 1316 |
+
"Verification used the cropped circuit-only region from the reference figure."
|
| 1317 |
+
)
|
| 1318 |
+
elif extraction_mode == "sanitized":
|
| 1319 |
+
verification["notes"].append(
|
| 1320 |
+
"Circuit-only rendering removed non-circuit procedural elements before verification."
|
| 1321 |
+
)
|
| 1322 |
|
| 1323 |
source_payload["verification"] = verification
|
| 1324 |
|
|
|
|
| 1374 |
with (metadata_root / "rows.jsonl").open("w") as handle:
|
| 1375 |
for row in dataset_rows:
|
| 1376 |
handle.write(json.dumps(row, sort_keys=True) + "\n")
|
| 1377 |
+
with (metadata_root / "pruned_figures.jsonl").open("w") as handle:
|
| 1378 |
+
for row in pruned_records:
|
| 1379 |
+
handle.write(json.dumps(row, sort_keys=True) + "\n")
|
| 1380 |
|
| 1381 |
features = Features(
|
| 1382 |
{
|
derived/Source/scripts/build_sheet_pdf.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
import csv
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
@@ -10,21 +11,35 @@ import img2pdf
|
|
| 10 |
|
| 11 |
SOURCE_ROOT = Path("/workspace/SchemID/derived/Source")
|
| 12 |
SHEETS_ROOT = SOURCE_ROOT / "sheets"
|
| 13 |
-
MANIFEST_PATH = SHEETS_ROOT / "sheet_manifest.csv"
|
| 14 |
-
OUTPUT_PDF = SHEETS_ROOT / "all_visualization_sheets.pdf"
|
| 15 |
FIXED_DPI = (300, 300)
|
| 16 |
|
| 17 |
|
| 18 |
def main() -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
image_paths: list[str] = []
|
| 20 |
-
with
|
| 21 |
reader = csv.DictReader(handle)
|
| 22 |
for row in reader:
|
| 23 |
image_path = SHEETS_ROOT / row["sheet_png"]
|
| 24 |
image_paths.append(str(image_path))
|
| 25 |
|
| 26 |
layout_fun = img2pdf.get_fixed_dpi_layout_fun(FIXED_DPI)
|
| 27 |
-
|
|
|
|
| 28 |
handle.write(img2pdf.convert(image_paths, layout_fun=layout_fun))
|
| 29 |
|
| 30 |
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
import argparse
|
| 6 |
import csv
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
|
|
| 11 |
|
| 12 |
SOURCE_ROOT = Path("/workspace/SchemID/derived/Source")
|
| 13 |
SHEETS_ROOT = SOURCE_ROOT / "sheets"
|
|
|
|
|
|
|
| 14 |
FIXED_DPI = (300, 300)
|
| 15 |
|
| 16 |
|
| 17 |
def main() -> None:
|
| 18 |
+
parser = argparse.ArgumentParser()
|
| 19 |
+
parser.add_argument(
|
| 20 |
+
"--manifest",
|
| 21 |
+
type=Path,
|
| 22 |
+
default=SHEETS_ROOT / "sheet_manifest.csv",
|
| 23 |
+
help="Sheet manifest CSV path.",
|
| 24 |
+
)
|
| 25 |
+
parser.add_argument(
|
| 26 |
+
"--output-pdf",
|
| 27 |
+
type=Path,
|
| 28 |
+
default=SHEETS_ROOT / "all_visualization_sheets.pdf",
|
| 29 |
+
help="Output PDF path.",
|
| 30 |
+
)
|
| 31 |
+
args = parser.parse_args()
|
| 32 |
+
|
| 33 |
image_paths: list[str] = []
|
| 34 |
+
with args.manifest.open(newline="") as handle:
|
| 35 |
reader = csv.DictReader(handle)
|
| 36 |
for row in reader:
|
| 37 |
image_path = SHEETS_ROOT / row["sheet_png"]
|
| 38 |
image_paths.append(str(image_path))
|
| 39 |
|
| 40 |
layout_fun = img2pdf.get_fixed_dpi_layout_fun(FIXED_DPI)
|
| 41 |
+
args.output_pdf.parent.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
with args.output_pdf.open("wb") as handle:
|
| 43 |
handle.write(img2pdf.convert(image_paths, layout_fun=layout_fun))
|
| 44 |
|
| 45 |
|
derived/Source/scripts/generate_visual_sheets.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
import csv
|
| 6 |
import html
|
| 7 |
import json
|
|
@@ -18,8 +19,6 @@ REPO_ROOT = Path("/workspace/SchemID")
|
|
| 18 |
SOURCE_ROOT = REPO_ROOT / "derived" / "Source"
|
| 19 |
ROWS_PATH = SOURCE_ROOT / "metadata" / "rows.jsonl"
|
| 20 |
SHEETS_ROOT = SOURCE_ROOT / "sheets"
|
| 21 |
-
SHEETS_ORIGINAL_ROOT = SHEETS_ROOT / "original"
|
| 22 |
-
MANIFEST_PATH = SHEETS_ROOT / "sheet_manifest.csv"
|
| 23 |
|
| 24 |
PAGE_W = 4200
|
| 25 |
PAGE_H = 5940
|
|
@@ -224,7 +223,31 @@ def build_page(rows: list[dict], display_name: str, book: str, page_number: int,
|
|
| 224 |
|
| 225 |
|
| 226 |
def main() -> None:
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
grouped: dict[str, list[dict]] = defaultdict(list)
|
| 230 |
display_names: dict[str, str] = {}
|
|
@@ -239,7 +262,7 @@ def main() -> None:
|
|
| 239 |
{
|
| 240 |
"book": book,
|
| 241 |
"figure_id": source_payload["figure_id"],
|
| 242 |
-
"image_path": Path(raw[
|
| 243 |
"primary_title": pick_primary_title(source_payload),
|
| 244 |
"context": pick_context(source_payload),
|
| 245 |
"source_line": pick_source_line(source_payload),
|
|
@@ -260,7 +283,7 @@ def main() -> None:
|
|
| 260 |
end = start + PER_PAGE
|
| 261 |
page_rows = rows[start:end]
|
| 262 |
output_path = (
|
| 263 |
-
|
| 264 |
/ book
|
| 265 |
/ f"{book}_sheet_{page_index + 1:03d}.png"
|
| 266 |
)
|
|
@@ -284,7 +307,15 @@ def main() -> None:
|
|
| 284 |
}
|
| 285 |
)
|
| 286 |
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
writer = csv.DictWriter(
|
| 289 |
handle,
|
| 290 |
fieldnames=[
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
import argparse
|
| 6 |
import csv
|
| 7 |
import html
|
| 8 |
import json
|
|
|
|
| 19 |
SOURCE_ROOT = REPO_ROOT / "derived" / "Source"
|
| 20 |
ROWS_PATH = SOURCE_ROOT / "metadata" / "rows.jsonl"
|
| 21 |
SHEETS_ROOT = SOURCE_ROOT / "sheets"
|
|
|
|
|
|
|
| 22 |
|
| 23 |
PAGE_W = 4200
|
| 24 |
PAGE_H = 5940
|
|
|
|
| 223 |
|
| 224 |
|
| 225 |
def main() -> None:
|
| 226 |
+
parser = argparse.ArgumentParser()
|
| 227 |
+
parser.add_argument(
|
| 228 |
+
"--image-field",
|
| 229 |
+
default="Circuit generated image",
|
| 230 |
+
choices=[
|
| 231 |
+
"Circuit generated image",
|
| 232 |
+
"Circuit Generated image with no text",
|
| 233 |
+
],
|
| 234 |
+
help="Dataset row field containing the image path to place on the sheets.",
|
| 235 |
+
)
|
| 236 |
+
parser.add_argument(
|
| 237 |
+
"--output-subdir",
|
| 238 |
+
default="original",
|
| 239 |
+
help="Subdirectory under derived/Source/sheets where the page PNGs will be written.",
|
| 240 |
+
)
|
| 241 |
+
parser.add_argument(
|
| 242 |
+
"--manifest-name",
|
| 243 |
+
default="sheet_manifest.csv",
|
| 244 |
+
help="Manifest filename written under derived/Source/sheets.",
|
| 245 |
+
)
|
| 246 |
+
args = parser.parse_args()
|
| 247 |
+
|
| 248 |
+
sheets_output_root = SHEETS_ROOT / args.output_subdir
|
| 249 |
+
manifest_path = SHEETS_ROOT / args.manifest_name
|
| 250 |
+
sheets_output_root.mkdir(parents=True, exist_ok=True)
|
| 251 |
|
| 252 |
grouped: dict[str, list[dict]] = defaultdict(list)
|
| 253 |
display_names: dict[str, str] = {}
|
|
|
|
| 262 |
{
|
| 263 |
"book": book,
|
| 264 |
"figure_id": source_payload["figure_id"],
|
| 265 |
+
"image_path": Path(raw[args.image_field]),
|
| 266 |
"primary_title": pick_primary_title(source_payload),
|
| 267 |
"context": pick_context(source_payload),
|
| 268 |
"source_line": pick_source_line(source_payload),
|
|
|
|
| 283 |
end = start + PER_PAGE
|
| 284 |
page_rows = rows[start:end]
|
| 285 |
output_path = (
|
| 286 |
+
sheets_output_root
|
| 287 |
/ book
|
| 288 |
/ f"{book}_sheet_{page_index + 1:03d}.png"
|
| 289 |
)
|
|
|
|
| 307 |
}
|
| 308 |
)
|
| 309 |
|
| 310 |
+
keep_paths = {
|
| 311 |
+
(SHEETS_ROOT / row["sheet_png"]).resolve()
|
| 312 |
+
for row in manifest_rows
|
| 313 |
+
}
|
| 314 |
+
for path in sheets_output_root.rglob("*.png"):
|
| 315 |
+
if path.resolve() not in keep_paths:
|
| 316 |
+
path.unlink()
|
| 317 |
+
|
| 318 |
+
with manifest_path.open("w", newline="") as handle:
|
| 319 |
writer = csv.DictWriter(
|
| 320 |
handle,
|
| 321 |
fieldnames=[
|
derived/Source/sheets/sheet_manifest.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
derived/Source/sheets/sheet_manifest_no_text.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|