File size: 20,066 Bytes
1b4b6d2 8682034 1b4b6d2 8682034 1b4b6d2 8682034 1b4b6d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | """
ูู ู
ุฎุทุท ุจูุณุชุฎุฑุฌ ุจุณ ุงููู ู
ุนุงุฏูุงุชู ู
ุญุชุงุฌุงู
ู
ุจูู ุนูู equations_and_pages_detections.txt ุจุงูุธุจุท
"""
import re
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# ูู drawing โ ุงูู
ุนุงุฏูุงุช ุงููู ููู โ ุงูู inputs ุงูู
ุทููุจุฉ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
DRAWING_REQUIRED_INPUTS = {
"foundations": {
"label": "Foundations | ุงูุฃุณุงุณุงุช",
"formulas_and_inputs": {
"excavation": ["longest_length", "longest_width"],
"foundation_concrete": ["footing_width", "footing_length", "footing_depth", "footing_count"],
"foundation_pcc": ["footing_width", "footing_length", "footing_count"],
"foundation_bitumen": ["footing_width", "footing_length", "footing_depth", "footing_count"],
"anti_termite_found": ["longest_length", "longest_width"],
"road_base": ["longest_length", "longest_width"],
"polyethylene_found": ["footing_width", "footing_length", "footing_count"],
"backfill": ["longest_length", "longest_width",
"footing_width", "footing_length", "footing_depth", "footing_count"],
},
"extract_only": [
"longest_length",
"longest_width",
"footing_width",
"footing_length",
"footing_depth",
"footing_count",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "floor_heights",
"areas", "perimeters",
],
"ai_instruction": """
Extract ONLY:
1. The overall building footprint: longest_length and longest_width (full extent of all footings combined)
2. For each footing type (F1, F2, etc.): width, length, depth, count
DO NOT extract:
- Floor heights, column dimensions, beam dimensions
- Areas or perimeters
- Any dates, sheet numbers, scale ratios, revision marks
""",
},
"tie_beam": {
"label": "Tie Beam | ุงูู
ูุฏุฉ",
"formulas_and_inputs": {
"tie_beam_concrete": ["tb_width", "tb_depth", "tb_total_length"],
"tie_beam_pcc": ["tb_width", "tb_total_length"],
"tie_beam_bitumen": ["tb_total_length", "tb_depth"],
"slab_on_grade": ["gf_area"],
"solid_block_work": ["ext_perimeter"],
"block_work_bitumen": ["ext_perimeter"],
"anti_termite_tb": ["gf_area"],
"polyethylene_tb": ["gf_area", "tb_width", "tb_total_length"],
},
"extract_only": [
"tb_width",
"tb_depth",
"tb_total_length",
"gf_area",
"ext_perimeter",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"footing_dimensions", "column_dimensions", "beam_dimensions",
"floor_heights", "individual_segment_lengths",
],
"ai_instruction": """
Extract ONLY:
1. Tie beam cross-section: width and depth
2. Total tie beam length (sum of ALL segments โ not individual spans)
3. Ground floor total area (inside the tie beams)
4. External perimeter of the building
DO NOT extract:
- Individual tie beam segment lengths
- Footing, column, or beam dimensions
- Floor heights
- Any dates, sheet numbers, scale ratios
""",
},
"ground_columns": {
"label": "Ground Columns (Neck) | ุฃุนู
ุฏุฉ ุงูุฑูุจุฉ",
"formulas_and_inputs": {
"neck_column_concrete": ["nc_width", "nc_length", "nc_count"],
"neck_column_bitumen": ["nc_width", "nc_length", "nc_count"],
},
"extract_only": [
"nc_width",
"nc_length",
"nc_count",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"footing_dimensions", "beam_dimensions", "floor_heights",
"areas", "perimeters", "slab_dimensions",
],
"ai_instruction": """
Extract ONLY:
For each neck column type (NC1, NC2, etc.): width, length, count
DO NOT extract:
- Footing or upper column dimensions
- Beam or slab dimensions
- Heights, areas, perimeters
- Any dates, sheet numbers, scale ratios
""",
},
"upper_columns": {
"label": "Upper Columns | ุงูุฃุนู
ุฏุฉ ุงูุนูููุฉ",
"formulas_and_inputs": {
"col_concrete_1st": ["col_width", "col_length", "col_count"],
"col_concrete_2nd": ["col_width", "col_length", "col_count"],
"col_concrete_roof": ["col_width", "col_length", "col_count"],
},
"extract_only": [
"col_width",
"col_length",
"col_count",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"footing_dimensions", "beam_dimensions", "floor_heights",
"areas", "perimeters", "slab_thickness",
"column_heights", # fixed in formulas: 4.0m floors, 3.5m roof
],
"ai_instruction": """
Extract ONLY from the column schedule:
For each column type (C1, C2, etc.): width, length, and count per floor
DO NOT extract:
- Column heights (fixed: 4.0m for floors, 3.5m for roof)
- Footing, beam, or slab dimensions
- Floor heights, areas, perimeters
- Any dates, sheet numbers, scale ratios, revision marks
""",
},
"slab_1st": {
"label": "1st Floor Slab | ุจูุงุทุฉ ุงูุฃูู",
"formulas_and_inputs": {
"slab_concrete": ["slab_area", "slab_thickness"],
"beam_concrete": ["beam_length", "beam_width", "beam_depth"],
"staircase_concrete": ["structural_levels"],
},
"extract_only": [
"slab_area",
"slab_thickness",
"beam_length",
"beam_width",
"beam_depth",
"structural_levels",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "footing_dimensions",
"floor_heights", "perimeters", "reinforcement_details",
],
"ai_instruction": """
Extract ONLY:
1. Slab total area and thickness
2. For each beam (B1, B2, etc.): length, width, depth
3. Number of structural levels (G+1=1, G+2=2, G+3=3)
DO NOT extract:
- Column or footing dimensions
- Floor heights or perimeters
- Reinforcement bar details
- Any dates, sheet numbers, scale ratios
""",
},
"slab_2nd": {
"label": "2nd Floor Slab | ุจูุงุทุฉ ุงูุซุงูู",
"formulas_and_inputs": {
"slab_concrete": ["slab_area", "slab_thickness"],
"beam_concrete": ["beam_length", "beam_width", "beam_depth"],
},
"extract_only": [
"slab_area", "slab_thickness",
"beam_length", "beam_width", "beam_depth",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "footing_dimensions",
"floor_heights", "perimeters", "reinforcement_details",
],
"ai_instruction": """
Extract ONLY:
1. Slab total area and thickness
2. For each beam: length, width, depth
DO NOT extract:
- Column or footing dimensions
- Floor heights, perimeters, reinforcement details
- Dates, sheet numbers, scale ratios
""",
},
"roof_slab": {
"label": "Roof Slab | ุจูุงุทุฉ ุงูุณุทุญ",
"formulas_and_inputs": {
"slab_concrete": ["slab_area", "slab_thickness"],
"beam_concrete": ["beam_length", "beam_width", "beam_depth"],
"parapet_block_work": ["roof_perimeter"],
"parapet_concrete": ["roof_perimeter"],
},
"extract_only": [
"slab_area", "slab_thickness",
"beam_length", "beam_width", "beam_depth",
"roof_perimeter",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "footing_dimensions",
"floor_heights", "reinforcement_details",
],
"ai_instruction": """
Extract ONLY:
1. Roof slab area and thickness
2. For each roof beam: length, width, depth
3. Roof slab perimeter (for parapet calculation)
DO NOT extract:
- Column or footing dimensions
- Floor heights, reinforcement details
- Dates, sheet numbers, scale ratios
""",
},
"setting_out": {
"label": "Setting Out | ู
ุฎุทุท ุงูู
ููุน",
"formulas_and_inputs": {
"interlock_paving": ["plot_area", "gf_area"],
"compound_wall": ["compound_length"],
},
"extract_only": [
"plot_area",
"gf_area",
"compound_length",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions",
"floor_heights", "individual_room_areas",
],
"ai_instruction": """
Extract ONLY:
1. "plot_area": Total plot/land area (If not explicitly written, calculate it mathematically by multiplying the outer boundary dimensions: Length ร Width)
2. "gf_area": Ground floor building footprint area
3. "compound_length": Total compound/boundary wall length (This is the PERIMETER of the plot. CRITICAL: If there is no explicit "total length" text, YOU MUST VISUALLY ESTIMATE OR CALCULATE the perimeter by summing the boundary lines you see (Top + Right + Bottom + Left). Do NOT return null if you can estimate the boundary length from the drawing scale or grid.)
DO NOT extract:
- Individual room areas
- Column or beam dimensions
- Floor heights
- Dates, sheet numbers, scale ratios
""",
},
"ground_floor_plan": {
"label": "Ground Floor Plan | ู
ุณูุท ุงูุฃุฑุถู",
"formulas_and_inputs": {
"thermal_block_external": ["ext_perimeter", "floor_height"],
"block_20_internal": ["int_walls_length", "floor_height"],
"internal_plaster": ["int_walls_length", "ext_perimeter", "floor_height"],
"dry_area_flooring": ["total_floor_area", "wet_area"],
"wet_area_flooring": ["wet_area"],
"wall_tiles": ["wet_perimeter", "floor_height"],
"skirting": ["dry_perimeter"],
"paint_int": ["dry_perimeter", "floor_height"],
"dry_area_ceiling": ["total_floor_area", "wet_area"],
"wet_area_ceiling": ["wet_area"],
"balcony_waterproofing": ["balcony_area"],
},
"extract_only": [
"total_floor_area",
"wet_area",
"wet_perimeter",
"dry_perimeter",
"ext_perimeter",
"int_walls_length",
"floor_height",
"balcony_area",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "footing_dimensions",
"individual_room_names", "furniture_dimensions",
"door_dimensions", "window_dimensions", "reinforcement_details",
],
"ai_instruction": """
Extract ONLY:
1. Total floor area
2. Total wet area (bathrooms + toilets + kitchen + laundry combined)
3. Total wet rooms perimeter
4. Total dry areas perimeter
5. External perimeter of floor
6. Total internal partition walls length
7. Floor to ceiling height
8. Balcony/terrace area (0 if none)
DO NOT extract:
- Individual room dimensions or names
- Door or window dimensions
- Column, beam, footing dimensions
- Furniture dimensions
- Dates, sheet numbers, scale ratios
""",
},
"first_floor_plan": {
"label": "1st Floor Plan | ู
ุณูุท ุงูุฃูู",
"formulas_and_inputs": {
"thermal_block_external": ["ext_perimeter", "floor_height"],
"block_20_internal": ["int_walls_length", "floor_height"],
"internal_plaster": ["int_walls_length", "ext_perimeter", "floor_height"],
"dry_area_flooring": ["total_floor_area", "wet_area"],
"wet_area_flooring": ["wet_area"],
"wall_tiles": ["wet_perimeter", "floor_height"],
"skirting": ["dry_perimeter"],
"paint_int": ["dry_perimeter", "floor_height"],
"dry_area_ceiling": ["total_floor_area", "wet_area"],
"wet_area_ceiling": ["wet_area"],
"wet_area_waterproofing": ["wet_area"],
"balcony_waterproofing": ["balcony_area"],
},
"extract_only": [
"total_floor_area", "wet_area", "wet_perimeter",
"dry_perimeter", "ext_perimeter",
"int_walls_length", "floor_height", "balcony_area",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "footing_dimensions",
"individual_room_dimensions", "door_dimensions", "window_dimensions",
],
"ai_instruction": """
Extract ONLY:
1. Total floor area
2. Total wet area (all wet rooms combined)
3. Total wet rooms perimeter
4. Total dry areas perimeter
5. External perimeter
6. Total internal walls length
7. Floor height
8. Balcony area (0 if none)
DO NOT extract:
- Individual room dimensions
- Door or window dimensions
- Column, beam, footing dimensions
- Dates, sheet numbers, scale ratios
""",
},
"second_floor_plan": {
"label": "2nd Floor Plan | ู
ุณูุท ุงูุซุงูู",
"formulas_and_inputs": {
"thermal_block_external": ["ext_perimeter", "floor_height"],
"block_20_internal": ["int_walls_length", "floor_height"],
"internal_plaster": ["int_walls_length", "ext_perimeter", "floor_height"],
"dry_area_flooring": ["total_floor_area", "wet_area"],
"wet_area_flooring": ["wet_area"],
"wall_tiles": ["wet_perimeter", "floor_height"],
"skirting": ["dry_perimeter"],
"paint_int": ["dry_perimeter", "floor_height"],
"wet_area_waterproofing": ["wet_area"],
"balcony_waterproofing": ["balcony_area"],
},
"extract_only": [
"total_floor_area", "wet_area", "wet_perimeter",
"dry_perimeter", "ext_perimeter",
"int_walls_length", "floor_height", "balcony_area",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "individual_room_dimensions",
],
"ai_instruction": """
Extract ONLY:
1. Total floor area
2. Total wet area
3. Wet rooms perimeter
4. Dry areas perimeter
5. External perimeter
6. Internal walls length
7. Floor height
8. Balcony area (0 if none)
DO NOT extract:
- Individual room dimensions
- Column or beam dimensions
- Dates, sheet numbers, scale ratios
""",
},
"roof_floor_plan": {
"label": "Roof Floor Plan | ู
ุณูุท ุงูุณุทุญ",
"formulas_and_inputs": {
"roof_waterproofing": ["roof_slab_area"],
},
"extract_only": [
"roof_slab_area",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "perimeters",
"parapet_dimensions", "heights",
],
"ai_instruction": """
Extract ONLY:
1. Total roof slab area
Nothing else. No perimeters, no heights, no column dims, no dates.
""",
},
"elevations": {
"label": "Elevations | ุงููุงุฌูุงุช",
"formulas_and_inputs": {
"external_plaster": ["ext_perimeter", "total_villa_height"],
"finish_ext": ["ext_perimeter", "total_villa_height"],
},
"extract_only": [
"ext_perimeter",
"total_villa_height_m",
"floor_to_floor_heights_m",
"parapet_height_m"
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "footing_dimensions",
"individual_wall_lengths",
"window_dimensions", "door_dimensions", "room_dimensions",
],
"ai_instruction": """
Extract ONLY:
1. Total external perimeter of the villa (if shown)
2. "total_villa_height_m" (overall height from ground level to top of parapet/roof in meters)
3. "floor_to_floor_heights_m" (an array of heights per floor in order: GF, 1F, 2F... in meters)
4. "parapet_height_m" (height of parapet wall in meters)
DO NOT extract:
- Individual wall lengths
- Column, beam, footing, window, door dimensions
- Dates, sheet numbers, scale ratios
""",
},
"schedules": {
"label": "Door & Window Schedules | ุงูุฌุฏุงูู",
"formulas_and_inputs": {
"openings_doors": ["door_count"],
"openings_windows": ["win_width", "win_height", "win_count"],
},
"extract_only": [
"door_count",
"win_width",
"win_height",
"win_count",
],
"ignore_completely": [
"dates", "sheet_numbers", "revision_marks", "scale_ratios",
"column_dimensions", "beam_dimensions", "footing_dimensions",
"floor_heights", "areas", "perimeters",
"door_dimensions", # only count needed for doors
"frame_dimensions", "threshold_dimensions",
],
"ai_instruction": """
Extract ONLY:
1. Total door count (all types combined)
2. For each window type: width, height, count
DO NOT extract:
- Door dimensions (only count needed)
- Column, beam, footing dimensions
- Floor heights, areas, perimeters
- Dates, sheet numbers, scale ratios
""",
},
}
def get_ai_prompt_for_drawing(drawing_type: str) -> str:
"""Builds a focused prompt telling the AI exactly what to extract."""
config = DRAWING_REQUIRED_INPUTS.get(drawing_type)
if not config:
return "Extract all visible dimensions and return as JSON."
lines = "\n".join(f" - {inp}" for inp in config["extract_only"])
return (
f"Drawing type: {config['label']}\n"
f"{config['ai_instruction']}\n"
f"Required outputs (ONLY these keys):\n{lines}\n\n"
"Return ONLY valid JSON with these exact keys. Use null for anything not found."
)
def filter_ocr_by_drawing_inputs(raw_dims: list, drawing_type: str) -> list:
"""
Keeps only OCR-extracted numbers that could be formula inputs for this drawing.
Drops dates, scale ratios, revision marks, and noise.
"""
config = DRAWING_REQUIRED_INPUTS.get(drawing_type)
if not config:
return raw_dims
filtered = []
for dim in raw_dims:
txt = str(dim.get("original_text", "")).lower()
skip = False
# Date pattern
if re.search(r'\d{1,2}[-/]\d{1,2}[-/]\d{2,4}', txt):
skip = True
# Scale ratio
if re.search(r'1\s*[:/]\s*\d+', txt):
skip = True
# Revision mark
if re.search(r'\brev\s*\d+\b|r\d+\s*$', txt, re.IGNORECASE):
skip = True
# Sheet / drawing number patterns (e.g. "S-01", "A03")
if re.search(r'\b[a-zA-Z]{1,2}-?\d{2,3}\b', txt) and not re.search(r'\d+\.\d+', txt):
skip = True
if not skip:
filtered.append(dim)
return filtered
|