-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_executor.py
More file actions
219 lines (181 loc) · 8.55 KB
/
main_executor.py
File metadata and controls
219 lines (181 loc) · 8.55 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
"""
코드 ID: MAIN_EXECUTOR_001
연결 요구사항: AI-REQ-F-001 (문서 분석 및 요구사항 자동 추출)
작성자: AI System
작성일: 2025-09-01
설명: 모든 모듈을 통합하여 실행하는 메인 모듈
"""
import logging
import sys
from typing import Dict, Any, List
from datetime import datetime
# 사용자 정의 모듈 임포트
from document_parser import DocumentParser # DOC_PARSER_001
from nlp_processor import NLPProcessor # NLP_PROCESSOR_001
from requirement_extractor import RequirementExtractor # REQ_EXTRACTOR_001
from requirement_classifier import RequirementClassifier # REQ_CLASSIFIER_001
from output_generator import OutputGenerator # OUTPUT_GENERATOR_001
# 코드 ID: MAIN_EXECUTOR_001
class RequirementAnalysisSystem:
"""
요구사항 분석 시스템 메인 클래스
- 모든 모듈 통합 실행
- 요구사항 ID: AI-REQ-F-001과 연결
"""
def __init__(self, openai_api_key: str = None):
"""
시스템 초기화
Args:
openai_api_key: OpenAI API 키 (선택사항)
"""
# 로깅 설정
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
self.logger = logging.getLogger(__name__)
# 각 모듈 초기화
self.document_parser = DocumentParser() # DOC_PARSER_001
self.nlp_processor = NLPProcessor() # NLP_PROCESSOR_001
self.requirement_extractor = RequirementExtractor(openai_api_key) # REQ_EXTRACTOR_001
self.requirement_classifier = RequirementClassifier() # REQ_CLASSIFIER_001
self.output_generator = OutputGenerator() # OUTPUT_GENERATOR_001
self.logger.info("요구사항 분석 시스템 초기화 완료")
self.logger.info("연결 요구사항: AI-REQ-F-001")
self.logger.info("활성 모듈: DOC_PARSER_001, NLP_PROCESSOR_001, REQ_EXTRACTOR_001, REQ_CLASSIFIER_001, OUTPUT_GENERATOR_001")
def analyze_document(self, file_path: str, max_requirements: int = 20) -> Dict[str, Any]:
"""
문서 분석 전체 프로세스 실행
Args:
file_path: 분석할 문서 경로
max_requirements: 최대 추출 요구사항 수
Returns:
Dict: 분석 결과
"""
try:
self.logger.info(f"문서 분석 시작: {file_path}")
# 1단계: 문서 파싱 (DOC_PARSER_001)
self.logger.info("1단계: 문서 파싱 (DOC_PARSER_001)")
parsed_doc = self.document_parser.parse_document(file_path)
# 2단계: NLP 처리 (NLP_PROCESSOR_001)
self.logger.info("2단계: 자연어 처리 (NLP_PROCESSOR_001)")
preprocessed_text = self.nlp_processor.preprocess_text(parsed_doc['text'])
sentences = self.nlp_processor.extract_sentences(preprocessed_text)
entities = self.nlp_processor.extract_entities(preprocessed_text)
keywords = self.nlp_processor.extract_keywords(preprocessed_text)
candidates = self.nlp_processor.identify_requirement_candidates(sentences)
# 3단계: 요구사항 추출 (REQ_EXTRACTOR_001)
self.logger.info("3단계: 요구사항 추출 (REQ_EXTRACTOR_001)")
extracted_reqs = self.requirement_extractor.extract_requirements(
preprocessed_text, max_requirements
)
validated_reqs = self.requirement_extractor.validate_requirements(extracted_reqs)
# 4단계: 요구사항 분류 (REQ_CLASSIFIER_001)
self.logger.info("4단계: 요구사항 분류 (REQ_CLASSIFIER_001)")
req_data = [{"id": req.id, "text": req.text} for req in validated_reqs]
classified_reqs = self.requirement_classifier.classify_batch(req_data)
# 5단계: 결과 통합
self.logger.info("5단계: 결과 통합")
analysis_results = {
"document_info": parsed_doc,
"nlp_analysis": {
"total_sentences": len(sentences),
"entities": entities,
"top_keywords": keywords,
"requirement_candidates": len(candidates)
},
"requirements": self._merge_extraction_and_classification(
validated_reqs, classified_reqs
),
"statistics": self._calculate_statistics(validated_reqs, classified_reqs),
"processing_info": {
"processed_at": datetime.now().isoformat(),
"linked_requirement": "AI-REQ-F-001",
"modules_used": [
"DOC_PARSER_001", "NLP_PROCESSOR_001",
"REQ_EXTRACTOR_001", "REQ_CLASSIFIER_001"
]
}
}
self.logger.info(f"문서 분석 완료: {len(validated_reqs)}개 요구사항 추출")
return analysis_results
except Exception as e:
self.logger.error(f"문서 분석 오류: {e}")
raise
def generate_reports(self, analysis_results: Dict[str, Any]) -> Dict[str, str]:
"""
분석 결과 보고서 생성
Args:
analysis_results: 분석 결과
Returns:
Dict: 생성된 파일 경로들
"""
try:
self.logger.info("보고서 생성 시작 (OUTPUT_GENERATOR_001)")
# 모든 형식의 보고서 생성
file_paths = self.output_generator.generate_comprehensive_report(analysis_results)
self.logger.info(f"보고서 생성 완료: {len(file_paths)}개 파일")
return file_paths
except Exception as e:
self.logger.error(f"보고서 생성 오류: {e}")
raise
def _merge_extraction_and_classification(self, extracted_reqs, classified_reqs) -> List[Dict[str, Any]]:
"""추출 결과와 분류 결과 병합"""
merged_results = []
for ext_req, cls_req in zip(extracted_reqs, classified_reqs):
merged_result = {
"id": ext_req.id,
"text": ext_req.text,
"type": cls_req.type.value,
"priority": cls_req.priority.value,
"category": cls_req.category,
"subcategory": cls_req.subcategory,
"confidence_score": ext_req.confidence_score,
"classification_confidence": cls_req.confidence,
"reasoning": cls_req.reasoning
}
merged_results.append(merged_result)
return merged_results
def _calculate_statistics(self, extracted_reqs, classified_reqs) -> Dict[str, Any]:
"""통계 계산"""
if not extracted_reqs:
return {}
functional_count = sum(1 for req in classified_reqs if req.type.value == "기능")
non_functional_count = len(classified_reqs) - functional_count
avg_confidence = sum(req.confidence_score for req in extracted_reqs) / len(extracted_reqs)
return {
"total_requirements": len(extracted_reqs),
"functional_count": functional_count,
"non_functional_count": non_functional_count,
"average_confidence": avg_confidence,
"high_confidence_count": sum(1 for req in extracted_reqs if req.confidence_score >= 0.8)
}
def main():
"""메인 실행 함수"""
if len(sys.argv) < 2:
print("사용법: python main_executor.py <문서_파일_경로>")
sys.exit(1)
file_path = sys.argv[1]
# 시스템 초기화 및 실행
system = RequirementAnalysisSystem()
try:
# 문서 분석
results = system.analyze_document(file_path)
# 보고서 생성
file_paths = system.generate_reports(results)
print("\n" + "="*60)
print("요구사항 분석 완료!")
print(f"연결 요구사항: AI-REQ-F-001")
print("="*60)
print(f"추출된 요구사항: {results['statistics']['total_requirements']}개")
print(f"기능 요구사항: {results['statistics']['functional_count']}개")
print(f"비기능 요구사항: {results['statistics']['non_functional_count']}개")
print(f"평균 신뢰도: {results['statistics']['average_confidence']:.2f}")
print("\n생성된 보고서:")
for format_type, file_path in file_paths.items():
print(f" - {format_type.upper()}: {file_path}")
except Exception as e:
print(f"오류 발생: {e}")
sys.exit(1)
if __name__ == "__main__":
main()