-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetailed_content_viewer.py
More file actions
242 lines (193 loc) · 8.45 KB
/
detailed_content_viewer.py
File metadata and controls
242 lines (193 loc) · 8.45 KB
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
#!/usr/bin/env python3
"""
AutoFire Detailed Content Viewer
Shows exact text content and specific fire protection details extracted from PDFs
"""
import re
from pathlib import Path
import fitz # PyMuPDF
class DetailedContentViewer:
"""
Shows the actual text content AutoFire reads from construction drawings
Displays specific fire protection specifications, room details, and hazard information
"""
def __init__(self):
self.detailed_patterns = {
"fire_specifications": [
r"FIRE\s+RATING\s*:\s*[\d\w\s-]+",
r"FIRE\s+RESISTANT\s*[\d\w\s-]+",
r"UL\s+LISTED\s*[\d\w\s-]+",
r"NFPA\s+\d+\s*[\w\s-]*",
r"SPRINKLER\s+HEAD\s*[\w\s\d-]*",
r"SMOKE\s+DETECTOR\s*[\w\s\d-]*",
],
"room_specifications": [
r"OCCUPANCY\s*:\s*[\w\s\d-]+",
r"OCCUPANT\s+LOAD\s*:\s*\d+",
r"EGRESS\s*[\w\s\d-]*",
r"ROOM\s+\d+\s*[\w\s-]*",
r"AREA\s*:\s*[\d,\s]+\s*SF",
r"CEILING\s+HEIGHT\s*:\s*[\d\'-\"]+",
],
"fire_protection_details": [
r"FIRE\s+EXTINGUISHER\s+TYPE\s*[\w\s\d-]*",
r"SPRINKLER\s+COVERAGE\s*[\w\s\d-]*",
r"ALARM\s+SYSTEM\s*[\w\s\d-]*",
r"EMERGENCY\s+LIGHTING\s*[\w\s\d-]*",
r"EXIT\s+SIGN\s*[\w\s\d-]*",
r"FIRE\s+DOOR\s*[\w\s\d-]*",
],
"hazardous_materials": [
r"CHEMICAL\s+STORAGE\s*[\w\s\d-]*",
r"FLAMMABLE\s*[\w\s\d-]*",
r"COMBUSTIBLE\s*[\w\s\d-]*",
r"HAZARDOUS\s*[\w\s\d-]*",
r"POOL\s+CHEMICALS\s*[\w\s\d-]*",
r"CHLORINE\s*[\w\s\d-]*",
],
}
def show_detailed_extraction(self, pdf_path: str, max_pages: int = 3):
"""Show detailed content extraction from a specific PDF"""
path = Path(pdf_path)
print("\n📋 DETAILED CONTENT EXTRACTION")
print("=" * 50)
print(f"File: {path.name}")
print(f"Path: {pdf_path}")
print()
try:
doc = fitz.open(pdf_path)
total_pages = len(doc)
print(f"📄 Total Pages: {total_pages}")
print(f"🔍 Analyzing first {min(max_pages, total_pages)} pages in detail")
print()
for page_num in range(min(max_pages, total_pages)):
print(f"--- PAGE {page_num + 1} ANALYSIS ---")
page = doc.load_page(page_num)
text = page.get_text()
# Show raw text sample
self._show_raw_text_sample(text)
# Extract and show specific details
self._extract_and_show_details(text)
print()
doc.close()
except Exception as e:
print(f"❌ Error: {str(e)}")
def _show_raw_text_sample(self, text: str):
"""Show a sample of the raw text extracted"""
print("📝 RAW TEXT SAMPLE (first 300 characters):")
print("-" * 40)
sample = text[:300].replace("\n", " ").strip()
print(f'"{sample}..."')
print()
def _extract_and_show_details(self, text: str):
"""Extract and display specific fire protection details"""
for category, patterns in self.detailed_patterns.items():
matches = []
for pattern in patterns:
found = re.finditer(pattern, text, re.IGNORECASE)
for match in found:
# Get full line context
lines = text.split("\n")
match_line = None
for line in lines:
if match.group() in line:
match_line = line.strip()
break
if match_line:
matches.append({"match": match.group(), "full_line": match_line})
if matches:
category_name = category.replace("_", " ").title()
print(f"🎯 {category_name}:")
# Remove duplicates and show unique matches
unique_matches = []
seen = set()
for match in matches:
key = match["full_line"]
if key not in seen and len(key.strip()) > 5:
unique_matches.append(match)
seen.add(key)
for i, match in enumerate(unique_matches[:5]): # Show first 5
print(f" {i+1}. {match['full_line']}")
if len(unique_matches) > 5:
print(f" ... and {len(unique_matches) - 5} more")
print()
def analyze_specific_file(self, project_path: str, filename_pattern: str):
"""Analyze a specific file matching the pattern"""
path = Path(project_path)
# Find files matching pattern
matching_files = []
for pdf_file in path.glob("**/*.pdf"):
if filename_pattern.lower() in pdf_file.name.lower():
matching_files.append(pdf_file)
if not matching_files:
print(f"❌ No files found matching pattern: {filename_pattern}")
return
print(f"🔍 Found {len(matching_files)} files matching '{filename_pattern}':")
for i, file in enumerate(matching_files[:3]): # Show first 3
print(f" {i+1}. {file.name}")
# Analyze the first matching file in detail
if matching_files:
self.show_detailed_extraction(str(matching_files[0]), max_pages=2)
def show_fire_protection_summary(self, project_path: str):
"""Show a summary of fire protection information across multiple files"""
path = Path(project_path)
print("\n🔥 FIRE PROTECTION SUMMARY")
print("=" * 35)
print(f"Project: {path.name}")
print()
# Look for fire protection specific files
fire_files = []
for pdf_file in path.glob("**/*.pdf"):
filename_lower = pdf_file.name.lower()
if any(term in filename_lower for term in ["fire", "fp", "life safety", "alarm"]):
fire_files.append(pdf_file)
print(f"📄 Fire Protection Files Found: {len(fire_files)}")
if fire_files:
print("\nFire Protection Drawings:")
for i, file in enumerate(fire_files[:10]):
print(f" {i+1}. {file.name}")
# Analyze first fire protection file
if fire_files:
print(f"\n🔍 Detailed Analysis of: {fire_files[0].name}")
self.show_detailed_extraction(str(fire_files[0]), max_pages=1)
else:
print("Looking in general files for fire protection content...")
# Analyze general files for fire content
all_files = list(path.glob("**/*.pdf"))
if all_files:
self.show_detailed_extraction(str(all_files[0]), max_pages=1)
def main():
"""Interactive content viewer"""
viewer = DetailedContentViewer()
print("🔍 AUTOFIRE DETAILED CONTENT VIEWER")
print("=" * 40)
print("Shows exactly what AutoFire extracts from your construction drawings")
print()
# Available projects
projects = {
"1": ("C:/Dev/diventures full", "Diventures Aquatic Center"),
"2": ("C:/Dev/hilton full spec", "Hilton Hotel Project"),
}
print("Available Projects:")
for key, (path, name) in projects.items():
if Path(path).exists():
print(f" {key}. {name}")
print()
# For demonstration, show detailed analysis of both projects
# 1. Show fire protection summary for Diventures
print("🏊 DIVENTURES AQUATIC CENTER - FIRE PROTECTION ANALYSIS")
viewer.show_fire_protection_summary("C:/Dev/diventures full")
# 2. Show specific file analysis for Hilton
print("\n" + "=" * 60)
print("🏨 HILTON HOTEL - FIRE PROTECTION ANALYSIS")
viewer.show_fire_protection_summary("C:/Dev/hilton full spec")
# 3. Show specific pattern analysis
print("\n" + "=" * 60)
print("🎯 SPECIFIC FILE ANALYSIS")
print("Looking for electrical fire protection in Diventures...")
viewer.analyze_specific_file("C:/Dev/diventures full", "electrical")
print("\n✅ EXTRACTION COMPLETE!")
print("This shows the actual text content and specifications")
print("that AutoFire processes to generate fire protection designs.")
if __name__ == "__main__":
main()