#!/usr/bin/env python3 """ Tab1内容生成器 - 结构化内容库 包含:选题信息表、模型信息表、层级标签树 """ import html as html_module from typing import Dict, Any, List def render_topic_info_card(topic_info: Dict[str, Any]) -> str: """渲染选题信息表卡片""" macro_topic = topic_info.get("宏观母题", "") sub_topics = topic_info.get("高潜子题列表", []) html = '
\n' html += '
\n' html += '选题信息表\n' html += '\n' html += '
\n' html += '
\n' if macro_topic: html += '
\n' html += '宏观母题:\n' html += f'
{html_module.escape(macro_topic)}
\n' html += '
\n' if sub_topics: html += '
\n' html += '高潜子题列表:\n' html += '
    \n' for sub_topic in sub_topics: html += f'
  • {html_module.escape(str(sub_topic))}
  • \n' html += '
\n' html += '
\n' else: html += '
\n' html += '高潜子题列表: 暂无\n' html += '
\n' html += '
\n' html += '
\n' return html def render_model_info_card(model_info: Dict[str, Any]) -> str: """渲染模型信息表卡片""" logic_models = model_info.get("抽象逻辑模型列表", []) html = '
\n' html += '
\n' html += '模型信息表\n' html += '\n' html += '
\n' html += '
\n' if logic_models: html += '
\n' html += '抽象逻辑模型列表:\n' html += '
    \n' for model in logic_models: html += f'
  • {html_module.escape(str(model))}
  • \n' html += '
\n' html += '
\n' else: html += '
\n' html += '抽象逻辑模型列表: 暂无\n' html += '
\n' html += '
\n' html += '
\n' return html def render_label_tree_card(label_tree: Dict[str, Any]) -> str: """渲染层级标签树卡片""" html = '
\n' html += '
\n' html += '层级标签树\n' html += '\n' html += '
\n' html += '
\n' # L1_实例名词 l1_nouns = label_tree.get("L1_实例名词", []) if l1_nouns: html += '
\n' html += 'L1_实例名词:\n' html += '
\n' for noun in l1_nouns: html += f'{html_module.escape(str(noun))}\n' html += '
\n' html += '
\n' # L1_限定词 l1_qualifiers = label_tree.get("L1_限定词", []) if l1_qualifiers: html += '
\n' html += 'L1_限定词:\n' html += '
\n' for qualifier in l1_qualifiers: html += f'{html_module.escape(str(qualifier))}\n' html += '
\n' html += '
\n' # L2_具体品类 l2_categories = label_tree.get("L2_具体品类", []) if l2_categories: html += '
\n' html += 'L2_具体品类:\n' html += '
\n' for category in l2_categories: html += f'{html_module.escape(str(category))}\n' html += '
\n' html += '
\n' # L3_兴趣领域 l3_interests = label_tree.get("L3_兴趣领域", []) if l3_interests: html += '
\n' html += 'L3_兴趣领域:\n' html += '
\n' for interest in l3_interests: html += f'{html_module.escape(str(interest))}\n' html += '
\n' html += '
\n' # L4_情绪价值 l4_emotions = label_tree.get("L4_情绪价值", []) if l4_emotions: html += '
\n' html += 'L4_情绪价值:\n' html += '
\n' for emotion in l4_emotions: html += f'{html_module.escape(str(emotion))}\n' html += '
\n' html += '
\n' html += '
\n' html += '
\n' return html def generate_tab1_content(data: Dict[str, Any]) -> str: """生成Tab1内容:结构化内容库""" html = '
\n' html += '
\n' html += '

结构化内容库

\n' structured_content = data.get("结构化内容库", {}) if not structured_content: html += '

暂无数据

\n' else: # 选题信息表 topic_info = structured_content.get("选题信息表", {}) if topic_info: html += render_topic_info_card(topic_info) # 模型信息表 model_info = structured_content.get("模型信息表", {}) if model_info: html += render_model_info_card(model_info) # 层级标签树 label_tree = structured_content.get("层级标签树", {}) if label_tree: html += render_label_tree_card(label_tree) html += '
\n' html += '
\n' return html