Notes Pdf — Urban Planning Lecture

def _show_case_studies(self): print("\nšŸ“‹ CASE STUDIES:") for i, case in enumerate(self.analyzer.case_studies[:5], 1): print(f"\ni. case['title']") print(f" case['description'][:200]...")

def _extract_principles(self) -> List[str]: """Extract core urban planning principles""" principle_patterns = [ r'(?i)principle[s]? of (.+?)[\.\n]', r'(?i)core (?:concept|principle)[s]?: (.+?)[\.\n]', r'(?i)([^.]*?(?:should|must|requires|essential|crucial|important)[^.]*?\.)' ] principles = [] for pattern in principle_patterns: matches = re.findall(pattern, self.full_text) principles.extend(matches[:5]) return principles[:10]

def extract_text_from_pdf(self) -> str: """Extract text from PDF file""" text = "" with open(self.pdf_path, 'rb') as file: pdf_reader = PyPDF2.PdfReader(file) for page_num, page in enumerate(pdf_reader.pages): page_text = page.extract_text() self.pages_text.append( 'page_num': page_num + 1, 'text': page_text ) text += page_text + "\n" self.full_text = text return text

def extract_case_studies(self) -> List[Dict]: """Identify and extract case studies from lecture notes""" case_patterns = [ r'(?i)case study[:]\s*(.+?)(?:\n\n|\n\s*\n|$)', r'(?i)example[:]\s*(.+?)(?:\n\n|\n\s*\n|$)', r'(?i)([A-Z][a-z]+(?:[-\s][A-Z][a-z]+)*)\s+(?:is\s+an\s+example|demonstrates|illustrates)', ] case_studies = [] sentences = sent_tokenize(self.full_text) for i, sentence in enumerate(sentences): for pattern in case_patterns: matches = re.findall(pattern, sentence) for match in matches: # Get surrounding context start_idx = max(0, i - 2) end_idx = min(len(sentences), i + 3) context = ' '.join(sentences[start_idx:end_idx]) case_studies.append( 'title': match if isinstance(match, str) else match[0], 'description': sentence, 'context': context ) self.case_studies = case_studies return case_studies urban planning lecture notes pdf

def _show_summary(self): summary = self.analyzer.create_summary() print("\nšŸ“Š LECTURE SUMMARY:") print(f" Pages: summary['total_pages']") print(f" Total Words: summary['total_words']:,") print(f" Case Studies: summary['case_studies_count']") print(f"\n Main Topics: ', '.join(summary['key_topics'][:10])") print(f"\n Key Sections: ', '.join(summary['main_sections'][:5])")

def export_to_json(self, output_path: str): """Export all analysis results to JSON file""" output = 'metadata': 'source_file': self.pdf_path, 'total_pages': len(self.pages_text), 'total_words': len(self.full_text.split()) , 'summary': self.create_summary(), 'sections': self.sections, 'key_concepts': self.key_concepts, 'case_studies': self.case_studies, 'study_questions': self.generate_study_questions(), 'full_text_excerpt': self.full_text[:5000] # First 5000 chars with open(output_path, 'w', encoding='utf-8') as f: json.dump(output, f, indent=2, ensure_ascii=False) print(f"Analysis exported to output_path") class UrbanPlanningStudyAssistant: def init (self, analyzer: UrbanPlanningNotesAnalyzer): self.analyzer = analyzer

def _take_quiz(self): questions = self.analyzer.generate_study_questions()[:5] score = 0 print("\nšŸ“ QUICK QUIZ (5 questions)") print("Answer in your own words, then press Enter for sample answer\n") for i, q in enumerate(questions, 1): print(f"\ni. q['question']") input("Press Enter to see sample answer...") print(f"\n Sample approach: q['hint']") print(" Review the relevant section for complete answer.\n") def main(): # Replace with your PDF path pdf_path = "urban_planning_lecture_notes.pdf" q['question']") input("Press Enter to see sample answer

def _show_questions(self): questions = self.analyzer.generate_study_questions() print("\nā“ STUDY QUESTIONS:") for i, q in enumerate(questions, 1): print(f"\ni. q['question']") print(f" šŸ’” Hint: q['hint']")

def interactive_session(self): """Run interactive study session""" print("\n" + "="*60) print("šŸ“š URBAN PLANNING STUDY ASSISTANT") print("="*60) print("\nCommands:") print(" 'concepts' - Show key concepts") print(" 'questions' - Generate study questions") print(" 'cases' - Show case studies") print(" 'summary' - Show lecture summary") print(" 'search [term]' - Search for specific topics") print(" 'quiz' - Take a quick quiz") print(" 'export' - Export analysis to JSON") print(" 'quit' - Exit") while True: command = input("\nšŸ“ Enter command: ").strip().lower() if command == 'quit': print("Happy studying! šŸ“–") break elif command == 'concepts': self._show_concepts() elif command == 'questions': self._show_questions() elif command == 'cases': self._show_case_studies() elif command == 'summary': self._show_summary() elif command.startswith('search'): term = command[7:].strip() if term: self._search(term) else: print("Please provide a search term (e.g., 'search zoning')") elif command == 'quiz': self._take_quiz() elif command == 'export': self.analyzer.export_to_json('urban_planning_analysis.json') else: print("Unknown command. Try 'concepts', 'questions', 'cases', 'summary', 'search [term]', 'quiz', or 'quit'")

def search_similar_content(self, query: str, top_k: int = 3) -> List[Dict]: """Search for content similar to query using TF-IDF""" # Prepare documents (each page as a document) documents = [page['text'] for page in self.pages_text] documents.append(query) # Create TF-IDF matrix vectorizer = TfidfVectorizer(stop_words='english') tfidf_matrix = vectorizer.fit_transform(documents) # Calculate similarity cosine_similarities = cosine_similarity(tfidf_matrix[-1:], tfidf_matrix[:-1]) # Get top similar pages similar_indices = cosine_similarities.argsort()[0][-top_k:][::-1] results = [] for idx in similar_indices: if cosine_similarities[0][idx] > 0: results.append( 'page_number': self.pages_text[idx]['page_num'], 'similarity_score': float(cosine_similarities[0][idx]), 'excerpt': self.pages_text[idx]['text'][:500] ) return results or 'quit'") def search_similar_content(self

def identify_sections(self) -> Dict[str, str]: """Identify and extract major sections from lecture notes""" lines = self.full_text.split('\n') current_section = "Introduction" sections = current_section: [] # Common urban planning section headers section_patterns = [ r'(?i)^(?:chapter|section|part)\s+\d+[:.\s]+(.+)$', r'(?i)^(\d+\.\d+)\s+(.+)$', r'(?i)^([A-Z][A-Z\s]5,)$', # ALL CAPS headers r'(?i)^(introduction|background|methodology|analysis|conclusion|references)$', r'(?i)^(zoning|transportation|land use|environmental|housing|infrastructure|sustainability)', r'(?i)^(smart growth|new urbanism|urban design|public participation|economic development)' ] for line in lines: line = line.strip() if not line: continue section_found = False for pattern in section_patterns: if re.match(pattern, line): current_section = line[:50] # Limit section name length sections[current_section] = [] section_found = True break if not section_found and current_section: sections[current_section].append(line) # Convert lists to strings self.sections = k: ' '.join(v) for k, v in sections.items() if v return self.sections

import PyPDF2 import re from typing import List, Dict, Tuple import json from collections import Counter import nltk from nltk.corpus import stopwords from nltk.tokenize import sent_tokenize, word_tokenize from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity import pandas as pd import spacy Download required NLTK data nltk.download('punkt') nltk.download('stopwords') nltk.download('averaged_perceptron_tagger') Load spaCy model (run: python -m spacy download en_core_web_sm) nlp = spacy.load('en_core_web_sm')

class UrbanPlanningNotesAnalyzer: def (self, pdf_path: str): self.pdf_path = pdf_path self.full_text = "" self.pages_text = [] self.sections = {} self.key_concepts = [] self.case_studies = []