1
0

models.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. """数据模型定义"""
  2. from typing import List, Dict, Any, Optional
  3. from dataclasses import dataclass, field
  4. from enum import Enum
  5. class ContentLevel(Enum):
  6. """内容层级"""
  7. TOPIC = 1 # 子话题层级
  8. SECTION = 2 # 小节层级
  9. DETAIL = 3 # 细节层级
  10. @dataclass
  11. class ContentNode:
  12. """内容树节点"""
  13. id: str # 节点唯一标识
  14. title: str # 节点标题
  15. level: ContentLevel # 内容层级
  16. description: str # 节点描述
  17. content: Optional[str] = None # 实际内容(markdown)
  18. children: List['ContentNode'] = field(default_factory=list) # 子节点列表
  19. metadata: Dict[str, Any] = field(default_factory=dict) # 元数据
  20. revision_history: List[Dict[str, Any]] = field(default_factory=list) # 修改历史
  21. def add_child(self, child: 'ContentNode'):
  22. """添加子节点"""
  23. self.children.append(child)
  24. def get_all_nodes(self) -> List['ContentNode']:
  25. """获取所有节点(深度优先)"""
  26. nodes = [self]
  27. for child in self.children:
  28. nodes.extend(child.get_all_nodes())
  29. return nodes
  30. def count_words(self) -> int:
  31. """统计节点及其子节点的总字数"""
  32. total = len(self.content) if self.content else 0
  33. for child in self.children:
  34. total += child.count_words()
  35. return total
  36. @dataclass
  37. class ReviewResult:
  38. """评审结果"""
  39. score: int # 总分 (0-100)
  40. grade: str # 评级(优秀/良好/需改进/不合格)
  41. dimension_scores: Dict[str, int] # 各维度得分
  42. detailed_feedback: Dict[str, Any] # 详细反馈
  43. revision_plan: Dict[str, Any] # 修改计划
  44. needs_revision: bool # 是否需要修改
  45. estimated_effort: str = "" # 预估修改工作量
  46. reviewer_notes: str = "" # 评审者备注
  47. @classmethod
  48. def from_dict(cls, data: Dict[str, Any]) -> 'ReviewResult':
  49. """从字典创建评审结果"""
  50. return cls(
  51. score=data.get('score', 0),
  52. grade=data.get('grade', '未知'),
  53. dimension_scores=data.get('dimension_scores', {}),
  54. detailed_feedback=data.get('detailed_feedback', {}),
  55. revision_plan=data.get('revision_plan', {}),
  56. needs_revision=data.get('needs_revision', False),
  57. estimated_effort=data.get('estimated_revision_effort', ''),
  58. reviewer_notes=data.get('reviewer_notes', '')
  59. )
  60. @dataclass
  61. class ColumnPlan:
  62. """专栏规划"""
  63. column_title: str # 专栏标题
  64. column_description: str # 专栏描述
  65. target_audience: str # 目标读者
  66. topics: List[Dict[str, Any]] # 子话题列表
  67. @classmethod
  68. def from_dict(cls, data: Dict[str, Any]) -> 'ColumnPlan':
  69. """从字典创建专栏规划"""
  70. return cls(
  71. column_title=data.get('column_title', ''),
  72. column_description=data.get('column_description', ''),
  73. target_audience=data.get('target_audience', ''),
  74. topics=data.get('topics', [])
  75. )
  76. def get_topic_count(self) -> int:
  77. """获取话题数量"""
  78. return len(self.topics)
  79. def to_dict(self) -> Dict[str, Any]:
  80. """转换为字典(用于缓存)"""
  81. return {
  82. 'column_title': self.column_title,
  83. 'column_description': self.column_description,
  84. 'target_audience': self.target_audience,
  85. 'topics': self.topics
  86. }