Update handlers/doc/custom_doc_type.py
This commit is contained in:
@@ -1,3 +1,80 @@
|
|||||||
# 커스텀 문서 유형 정의
|
# -*- coding: utf-8 -*-
|
||||||
class CustomDocType:
|
"""
|
||||||
pass
|
Custom Doc Type Handler
|
||||||
|
- 사용자가 업로드한 HWPX를 분석하여 새로운 '문서 유형' 생성
|
||||||
|
- Phase 1~3 전체 프로세스 오케스트레이션
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# 도구들
|
||||||
|
from .doc_type_analyzer import DocTypeAnalyzer
|
||||||
|
from ..template.doc_template_analyzer import DocTemplateAnalyzer
|
||||||
|
from ..template.semantic_mapper import SemanticMapper
|
||||||
|
from .content_analyzer import generate as generate_content_prompt
|
||||||
|
|
||||||
|
|
||||||
|
class CustomDocTypeHandler:
|
||||||
|
def __init__(self):
|
||||||
|
self.doc_analyzer = DocTypeAnalyzer()
|
||||||
|
self.temp_analyzer = DocTemplateAnalyzer()
|
||||||
|
self.semantic_mapper = SemanticMapper()
|
||||||
|
|
||||||
|
def create_from_hwpx(self, file_path: str, doc_name: str,
|
||||||
|
description: str = "") -> dict:
|
||||||
|
"""
|
||||||
|
HWPX 파일을 분석하여 새로운 유저 문서 유형 생성
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# 1. HWPX 파싱 (구조/텍스트/XML 추출)
|
||||||
|
print(f"[Phase 1] Parsing HWPX: {file_path}")
|
||||||
|
parsed = self.doc_analyzer.parse(file_path)
|
||||||
|
|
||||||
|
# 2. 문서 구조 분석 (디자인/레이아웃 추출)
|
||||||
|
print("[Phase 2] Analyzing Template Layout...")
|
||||||
|
template_info = self.temp_analyzer.analyze(parsed)
|
||||||
|
|
||||||
|
# 3. 시맨틱 맵핑 (섹션 의미/역할 분석)
|
||||||
|
print("[Phase 3] Semantic Mapping...")
|
||||||
|
semantic_map = self.semantic_mapper.map_parsed(parsed)
|
||||||
|
|
||||||
|
# 4. 콘텐츠 프롬프트 생성 (Placeholder 추출)
|
||||||
|
print("[Phase 4] Generating Content Prompt...")
|
||||||
|
content_prompt = generate_content_prompt(
|
||||||
|
template_info, semantic_map, parsed)
|
||||||
|
|
||||||
|
# 5. 결과 조합
|
||||||
|
result = {
|
||||||
|
"template_id": None, # 유저 커스텀은 ID 없음
|
||||||
|
"layout": template_info,
|
||||||
|
"context": semantic_map.get("context", {}),
|
||||||
|
"structure": semantic_map.get("structure", {}),
|
||||||
|
"content_prompt": content_prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
# 6. 설정 파일 생성
|
||||||
|
config = self.doc_analyzer._generate_config(
|
||||||
|
doc_name, description, result)
|
||||||
|
|
||||||
|
# 7. 파일 시스템 저장
|
||||||
|
# (이 부분은 실제 환경에 맞춰 조정 필요)
|
||||||
|
save_dir = self.doc_analyzer.save_doc_type(
|
||||||
|
config, template=None)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"doc_id": config["id"],
|
||||||
|
"save_path": save_dir,
|
||||||
|
"config": config
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
import traceback
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"error": str(e),
|
||||||
|
"trace": traceback.format_exc()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user