tab1.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/usr/bin/env python3
  2. """
  3. Tab1内容生成器 - 结构化内容库
  4. 包含:选题信息表、模型信息表、层级标签树
  5. """
  6. import html as html_module
  7. from typing import Dict, Any, List
  8. def render_topic_info_card(topic_info: Dict[str, Any]) -> str:
  9. """渲染选题信息表卡片"""
  10. macro_topic = topic_info.get("宏观母题", "")
  11. sub_topics = topic_info.get("高潜子题列表", [])
  12. html = '<div class="point-card topic-card" data-card-id="topic-info">\n'
  13. html += '<div class="point-card-header" onclick="toggleCardDetails(\'topic-info\')">\n'
  14. html += '<span class="point-text">选题信息表</span>\n'
  15. html += '<span class="toggle-icon">▼</span>\n'
  16. html += '</div>\n'
  17. html += '<div class="point-card-details" id="topic-info-details">\n'
  18. if macro_topic:
  19. html += '<div class="detail-section">\n'
  20. html += '<strong>宏观母题:</strong>\n'
  21. html += f'<div class="detail-text">{html_module.escape(macro_topic)}</div>\n'
  22. html += '</div>\n'
  23. if sub_topics:
  24. html += '<div class="detail-section">\n'
  25. html += '<strong>高潜子题列表:</strong>\n'
  26. html += '<ul class="detail-list">\n'
  27. for sub_topic in sub_topics:
  28. html += f'<li>{html_module.escape(str(sub_topic))}</li>\n'
  29. html += '</ul>\n'
  30. html += '</div>\n'
  31. else:
  32. html += '<div class="detail-section">\n'
  33. html += '<strong>高潜子题列表:</strong> 暂无\n'
  34. html += '</div>\n'
  35. html += '</div>\n'
  36. html += '</div>\n'
  37. return html
  38. def render_model_info_card(model_info: Dict[str, Any]) -> str:
  39. """渲染模型信息表卡片"""
  40. logic_models = model_info.get("抽象逻辑模型列表", [])
  41. html = '<div class="point-card model-card" data-card-id="model-info">\n'
  42. html += '<div class="point-card-header" onclick="toggleCardDetails(\'model-info\')">\n'
  43. html += '<span class="point-text">模型信息表</span>\n'
  44. html += '<span class="toggle-icon">▼</span>\n'
  45. html += '</div>\n'
  46. html += '<div class="point-card-details" id="model-info-details">\n'
  47. if logic_models:
  48. html += '<div class="detail-section">\n'
  49. html += '<strong>抽象逻辑模型列表:</strong>\n'
  50. html += '<ul class="detail-list">\n'
  51. for model in logic_models:
  52. html += f'<li class="model-item">{html_module.escape(str(model))}</li>\n'
  53. html += '</ul>\n'
  54. html += '</div>\n'
  55. else:
  56. html += '<div class="detail-section">\n'
  57. html += '<strong>抽象逻辑模型列表:</strong> 暂无\n'
  58. html += '</div>\n'
  59. html += '</div>\n'
  60. html += '</div>\n'
  61. return html
  62. def render_label_tree_card(label_tree: Dict[str, Any]) -> str:
  63. """渲染层级标签树卡片"""
  64. html = '<div class="point-card label-tree-card" data-card-id="label-tree">\n'
  65. html += '<div class="point-card-header" onclick="toggleCardDetails(\'label-tree\')">\n'
  66. html += '<span class="point-text">层级标签树</span>\n'
  67. html += '<span class="toggle-icon">▼</span>\n'
  68. html += '</div>\n'
  69. html += '<div class="point-card-details" id="label-tree-details">\n'
  70. # L1_实例名词
  71. l1_nouns = label_tree.get("L1_实例名词", [])
  72. if l1_nouns:
  73. html += '<div class="detail-section">\n'
  74. html += '<strong>L1_实例名词:</strong>\n'
  75. html += '<div class="tag-group">\n'
  76. for noun in l1_nouns:
  77. html += f'<span class="label-tag l1-tag">{html_module.escape(str(noun))}</span>\n'
  78. html += '</div>\n'
  79. html += '</div>\n'
  80. # L1_限定词
  81. l1_qualifiers = label_tree.get("L1_限定词", [])
  82. if l1_qualifiers:
  83. html += '<div class="detail-section">\n'
  84. html += '<strong>L1_限定词:</strong>\n'
  85. html += '<div class="tag-group">\n'
  86. for qualifier in l1_qualifiers:
  87. html += f'<span class="label-tag l1-tag">{html_module.escape(str(qualifier))}</span>\n'
  88. html += '</div>\n'
  89. html += '</div>\n'
  90. # L2_具体品类
  91. l2_categories = label_tree.get("L2_具体品类", [])
  92. if l2_categories:
  93. html += '<div class="detail-section">\n'
  94. html += '<strong>L2_具体品类:</strong>\n'
  95. html += '<div class="tag-group">\n'
  96. for category in l2_categories:
  97. html += f'<span class="label-tag l2-tag">{html_module.escape(str(category))}</span>\n'
  98. html += '</div>\n'
  99. html += '</div>\n'
  100. # L3_兴趣领域
  101. l3_interests = label_tree.get("L3_兴趣领域", [])
  102. if l3_interests:
  103. html += '<div class="detail-section">\n'
  104. html += '<strong>L3_兴趣领域:</strong>\n'
  105. html += '<div class="tag-group">\n'
  106. for interest in l3_interests:
  107. html += f'<span class="label-tag l3-tag">{html_module.escape(str(interest))}</span>\n'
  108. html += '</div>\n'
  109. html += '</div>\n'
  110. # L4_情绪价值
  111. l4_emotions = label_tree.get("L4_情绪价值", [])
  112. if l4_emotions:
  113. html += '<div class="detail-section">\n'
  114. html += '<strong>L4_情绪价值:</strong>\n'
  115. html += '<div class="tag-group">\n'
  116. for emotion in l4_emotions:
  117. html += f'<span class="label-tag l4-tag">{html_module.escape(str(emotion))}</span>\n'
  118. html += '</div>\n'
  119. html += '</div>\n'
  120. html += '</div>\n'
  121. html += '</div>\n'
  122. return html
  123. def generate_tab1_content(data: Dict[str, Any]) -> str:
  124. """生成Tab1内容:结构化内容库"""
  125. html = '<div class="tab-content" id="tab1">\n'
  126. html += '<div class="section">\n'
  127. html += '<h3>结构化内容库</h3>\n'
  128. structured_content = data.get("结构化内容库", {})
  129. if not structured_content:
  130. html += '<p>暂无数据</p>\n'
  131. else:
  132. # 选题信息表
  133. topic_info = structured_content.get("选题信息表", {})
  134. if topic_info:
  135. html += render_topic_info_card(topic_info)
  136. # 模型信息表
  137. model_info = structured_content.get("模型信息表", {})
  138. if model_info:
  139. html += render_model_info_card(model_info)
  140. # 层级标签树
  141. label_tree = structured_content.get("层级标签树", {})
  142. if label_tree:
  143. html += render_label_tree_card(label_tree)
  144. html += '</div>\n'
  145. html += '</div>\n'
  146. return html