#!/usr/bin/env python3 """ Tab1内容生成器 - 选题点(灵感点、目的点、关键点) """ import html as html_module from typing import Dict, Any, List def render_inspiration_card(item: Dict[str, Any], idx: int) -> str: """渲染灵感点卡片""" point_text = item.get('灵感点', '') description = item.get('描述', '') category = item.get('分类', '') features = item.get('提取的特征', []) scoring = item.get('scoring', {}) reasoning = item.get('推理', '') derivation = item.get('推导说明', '') card_id = f'inspiration-{idx}' has_details = description or features or scoring or reasoning or derivation html = f'
\n' html += '
\n' html += f'#{idx}\n' html += f'{html_module.escape(point_text)}\n' if category: html += f'{html_module.escape(category)}\n' if has_details: html += '\n' html += '
\n' if has_details: html += f'
\n' if description: html += '
\n' html += '描述:\n' html += f'
{html_module.escape(description)}
\n' html += '
\n' if reasoning: html += '
\n' html += '推理:\n' html += f'
{html_module.escape(reasoning)}
\n' html += '
\n' if derivation: html += '
\n' html += '推导说明:\n' html += f'
{html_module.escape(derivation)}
\n' html += '
\n' if features: html += '
\n' html += '提取的特征:\n' html += '
\n' for feature in features: feature_name = feature.get('特征名称', '') weight = feature.get('权重', 0) dimension = feature.get('维度分类', '') html += f'{html_module.escape(feature_name)} ' if dimension: html += f'({html_module.escape(dimension)}) ' html += f'权重:{weight}\n' html += '
\n' html += '
\n' if scoring: html += '
\n' html += '评分:\n' html += '
\n' if '人设契合度' in scoring: html += f'人设契合度: {scoring["人设契合度"]}/10\n' if '触发可能性' in scoring: html += f'触发可能性: {scoring["触发可能性"]}/10\n' if '内容解释力' in scoring: html += f'内容解释力: {scoring["内容解释力"]}/10\n' if '总分' in scoring: html += f'总分: {scoring["总分"]}\n' if '评分说明' in scoring: html += f'
{html_module.escape(scoring["评分说明"])}
\n' html += '
\n' html += '
\n' html += '
\n' html += '
\n' return html def render_purpose_card(item: Dict[str, Any], idx: int) -> str: """渲染目的点卡片""" point_text = item.get('目的点', '') description = item.get('描述', '') dimension = item.get('维度', {}) features = item.get('提取的特征', []) reasoning = item.get('推理', '') card_id = f'purpose-{idx}' has_details = description or features or reasoning html = f'
\n' html += '
\n' html += f'#{idx}\n' html += f'{html_module.escape(point_text)}\n' # 显示维度标签 if dimension: html += '
\n' if '一级分类' in dimension: html += f'{html_module.escape(dimension["一级分类"])}\n' if '二级分类' in dimension: html += f'{html_module.escape(dimension["二级分类"])}\n' html += '
\n' if has_details: html += '\n' html += '
\n' if has_details: html += f'
\n' if description: html += '
\n' html += '描述:\n' html += f'
{html_module.escape(description)}
\n' html += '
\n' if reasoning: html += '
\n' html += '推理:\n' html += f'
{html_module.escape(reasoning)}
\n' html += '
\n' if features: html += '
\n' html += '提取的特征:\n' html += '
\n' for feature in features: feature_name = feature.get('特征名称', '') weight = feature.get('权重', 0) feature_class = feature.get('特征分类', '') html += f'{html_module.escape(feature_name)} ' if feature_class: html += f'({html_module.escape(feature_class)}) ' html += f'权重:{weight}\n' html += '
\n' html += '
\n' html += '
\n' html += '
\n' return html def render_keypoint_card(item: Dict[str, Any], idx: int, level: int = 0) -> str: """渲染关键点卡片(支持嵌套)""" point_text = item.get('关键点', '') description = item.get('描述', '') dimension = item.get('维度', '') or item.get('维度细分', '') dimension_category = item.get('维度大类', '') features = item.get('提取的特征', []) children = item.get('children', []) child_reason = item.get('作为子节点的原因', '') card_id = f'keypoint-{idx}-l{level}' has_details = description or features or child_reason has_children = len(children) > 0 indent_class = f'keypoint-level-{level}' if level > 0 else '' html = f'
\n' html += '
\n' html += f'#{item.get("候选编号", idx)}\n' html += f'{html_module.escape(point_text)}\n' # 显示维度大类标签(实质类/形式类) if dimension_category: category_label = '形式类' if dimension_category == '形式' else '实质类' category_class = 'dimension-category-form' if dimension_category == '形式' else 'dimension-category-substance' html += f'{html_module.escape(category_label)}\n' # 显示维度标签(维度细分) if dimension: html += f'{html_module.escape(dimension)}\n' if has_details or has_children: html += '\n' html += '
\n' if has_details or has_children: html += f'
\n' if description: html += '
\n' html += '描述:\n' html += f'
{html_module.escape(description)}
\n' html += '
\n' if child_reason: html += '
\n' html += '作为子节点的原因:\n' html += f'
{html_module.escape(child_reason)}
\n' html += '
\n' if features: html += '
\n' html += '提取的特征:\n' html += '
\n' for feature in features: feature_name = feature.get('特征名称', '') weight = feature.get('权重', 0) feature_dimension = feature.get('维度', '') html += f'{html_module.escape(feature_name)} ' if feature_dimension: html += f'({html_module.escape(feature_dimension)}) ' html += f'权重:{weight}\n' html += '
\n' html += '
\n' # 递归渲染子关键点 if has_children: html += '
\n' html += '子关键点:\n' html += '
\n' for child_idx, child in enumerate(children, 1): html += render_keypoint_card(child, child_idx, level + 1) html += '
\n' html += '
\n' html += '
\n' html += '
\n' return html def generate_tab1_content(data: Dict[str, Any]) -> str: """生成Tab1内容:选题、灵感点、目的点、关键点""" html = '
\n' # 添加CSS样式 html += ''' ''' # 添加JavaScript html += ''' ''' # 选题描述 if '选题描述' in data: topic = data['选题描述'] html += '
\n' html += '

选题描述

\n' if '主题' in topic: html += f'
主题:{html_module.escape(topic["主题"])}
\n' if '描述' in topic: html += f'
描述:{html_module.escape(topic["描述"])}
\n' html += '
\n' # 灵感点 if '灵感点' in data: inspiration = data['灵感点'] html += '
\n' html += '

灵感点

\n' html += '
\n' if isinstance(inspiration, list): for idx, item in enumerate(inspiration, 1): html += render_inspiration_card(item, idx) html += '
\n' html += '
\n' # 目的点 if '目的点' in data: purpose = data['目的点'] html += '
\n' html += '

目的点

\n' html += '
\n' if isinstance(purpose, dict) and 'purposes' in purpose: purpose_list = purpose['purposes'] elif isinstance(purpose, list): purpose_list = purpose else: purpose_list = [] if isinstance(purpose_list, list): for idx, item in enumerate(purpose_list, 1): html += render_purpose_card(item, idx) html += '
\n' html += '
\n' # 关键点 if '关键点' in data: keypoint = data['关键点'] html += '
\n' html += '

关键点

\n' html += '
\n' # 处理关键点数据:可能是列表,也可能是包含key_points的对象 keypoint_list = keypoint if isinstance(keypoint, dict) and 'key_points' in keypoint: keypoint_list = keypoint['key_points'] if isinstance(keypoint_list, list): for idx, item in enumerate(keypoint_list, 1): html += render_keypoint_card(item, idx, 0) html += '
\n' html += '
\n' html += '
\n' return html