a90f7adfa1
将 Markdown 源文件移入 md/,LaTeX 工作目录保留在 latex/, Word 导出移入 word/;删除临时脚本、调试截图和空 stub。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1323 lines
40 KiB
Markdown
1323 lines
40 KiB
Markdown
# 05.5 个人知识体系
|
||
|
||
## 核心问题
|
||
|
||
> 如何建立可持续的个人AI工具箱?
|
||
> 什么样的文档策略能有效支持长期学习?
|
||
> 如何通过社区参与加速成长?
|
||
|
||
---
|
||
|
||
## 概念讲解
|
||
|
||
### 个人知识体系的结构
|
||
|
||
一个有效的个人知识体系应该是有机的、可演进的:
|
||
|
||
```
|
||
个人知识体系结构
|
||
|
||
┌─────────────────────────────────────────────────────────────┐
|
||
│ │
|
||
│ 第一层:知识获取层 (Acquisition) │
|
||
│ ────────────────────────────────────────────────────── │
|
||
│ • 信息源管理(RSS、通讯、期刊) │
|
||
│ • 学习计划(短期、中期、长期) │
|
||
│ • 时间分配(阅读、实践、反思) │
|
||
│ │
|
||
│ 第二层:知识处理层 (Processing) │
|
||
│ ────────────────────────────────────────────────────── │
|
||
│ • 笔记系统(捕获、整理、归档) │
|
||
│ • 知识连接(建立概念间的关系) │
|
||
│ • 代码片段库(可复用的代码片段) │
|
||
│ │
|
||
│ 第三层:知识应用层 (Application) │
|
||
│ ────────────────────────────────────────────────────── │
|
||
│ • 项目实践(真实问题应用) │
|
||
│ • 工具箱(积累的AI工具和工作流) │
|
||
│ • 模板库(常用分析模板) │
|
||
│ │
|
||
│ 第四层:知识分享层 (Sharing) │
|
||
│ ────────────────────────────────────────────────────── │
|
||
│ • 写作(博客、论文、文档) │
|
||
│ • 演讲(会议、工作坊) │
|
||
│ • 开源(贡献代码和工具) │
|
||
│ │
|
||
│ 第五层:知识反思层 (Reflection) │
|
||
│ ────────────────────────────────────────────────────── │
|
||
│ • 定期回顾(月度、年度) │
|
||
│ • 知识审计(识别盲区和过时知识) │
|
||
│ • 体系优化(持续改进知识系统) │
|
||
│ │
|
||
└─────────────────────────────────────────────────────────────┘
|
||
|
||
关键特征:
|
||
• 开放性:可以不断添加和更新
|
||
• 连接性:知识之间相互关联
|
||
• 可检索性:快速找到所需信息
|
||
• 可维护性:低成本的维护和更新
|
||
```
|
||
|
||
### AI工具箱的构成
|
||
|
||
```
|
||
个人AI工具箱
|
||
|
||
┌─────────────────────────────────────────────────────────────┐
|
||
│ │
|
||
│ 1. 基础工具集 │
|
||
│ ─────────────────────────────────────────────────── │
|
||
│ • 通用AI助手(Claude, ChatGPT) │
|
||
│ • 代码助手(GitHub Copilot) │
|
||
│ • 图像生成(Midjourney, DALL-E) │
|
||
│ │
|
||
│ 2. 专业工具集 │
|
||
│ ─────────────────────────────────────────────────── │
|
||
│ • 空间分析AI(遥感解译、地理NLP) │
|
||
│ • 数据处理AI(数据清洗、转换) │
|
||
│ • 可视化AI(自动图表、地图生成) │
|
||
│ │
|
||
│ 3. 自定义工具集 │
|
||
│ ─────────────────────────────────────────────────── │
|
||
│ • 自定义Skills(Prompt集合) │
|
||
│ • 专用工作流(针对特定任务) │
|
||
│ • 集成系统(API整合) │
|
||
│ │
|
||
│ 4. 辅助资源集 │
|
||
│ ─────────────────────────────────────────────────── │
|
||
│ • Prompt模板库 │
|
||
│ • 示例案例集 │
|
||
│ • 最佳实践文档 │
|
||
│ │
|
||
└─────────────────────────────────────────────────────────────┘
|
||
```
|
||
|
||
### 文档化策略
|
||
|
||
```
|
||
有效的文档化
|
||
|
||
金字塔模型:
|
||
|
||
┌──────────────┐
|
||
│ 即时笔记 │ ← 捕获想法,最小开销
|
||
└──────┬───────┘
|
||
│
|
||
┌──────┴───────┐
|
||
│ 项目笔记 │ ← 项目上下文,详细记录
|
||
└──────┬───────┘
|
||
│
|
||
┌──────┴───────┐
|
||
│ 知识笔记 │ ← 提炼知识,建立连接
|
||
└──────┬───────┘
|
||
│
|
||
┌──────┴───────┐
|
||
│ 指南文档 │ ← 结构化输出,可分享
|
||
└──────────────┘
|
||
|
||
不同文档的特点:
|
||
|
||
即时笔记:
|
||
• 快速捕获
|
||
• 原始想法
|
||
• 待整理
|
||
|
||
项目笔记:
|
||
• 项目特定
|
||
• 决策记录
|
||
• 问题解决
|
||
|
||
知识笔记:
|
||
• 跨项目
|
||
• 概念理解
|
||
• 最佳实践
|
||
|
||
指南文档:
|
||
• 面向读者
|
||
• 结构完整
|
||
• 可独立使用
|
||
```
|
||
|
||
---
|
||
|
||
## 设计原理
|
||
|
||
### 知识管理系统实现
|
||
|
||
```python
|
||
"""
|
||
个人知识管理系统
|
||
"""
|
||
from typing import Dict, List, Set, Optional, Any
|
||
from dataclasses import dataclass, field
|
||
from datetime import datetime
|
||
from pathlib import Path
|
||
import json
|
||
from enum import Enum
|
||
|
||
class NoteType(Enum):
|
||
"""笔记类型"""
|
||
QUICK = "quick" # 即时笔记
|
||
PROJECT = "project" # 项目笔记
|
||
KNOWLEDGE = "knowledge" # 知识笔记
|
||
GUIDE = "guide" # 指南文档
|
||
|
||
class Tag(Enum):
|
||
"""常用标签分类"""
|
||
SKILL = "skill"
|
||
CONCEPT = "concept"
|
||
TOOL = "tool"
|
||
WORKFLOW = "workflow"
|
||
PROBLEM = "problem"
|
||
SOLUTION = "solution"
|
||
REFERENCE = "reference"
|
||
|
||
@dataclass
|
||
class Note:
|
||
"""知识条目"""
|
||
id: str
|
||
title: str
|
||
content: str
|
||
note_type: NoteType
|
||
tags: Set[str] = field(default_factory=set)
|
||
created: str = ""
|
||
modified: str = ""
|
||
related_notes: Set[str] = field(default_factory=set)
|
||
metadata: Dict = field(default_factory=dict)
|
||
|
||
def __post_init__(self):
|
||
if not self.created:
|
||
self.created = datetime.now().isoformat()
|
||
self.modified = self.created
|
||
|
||
@dataclass
|
||
class CodeSnippet:
|
||
"""代码片段"""
|
||
id: str
|
||
name: str
|
||
description: str
|
||
code: str
|
||
language: str
|
||
tags: Set[str] = field(default_factory=set)
|
||
dependencies: List[str] = field(default_factory=list)
|
||
created: str = ""
|
||
|
||
def __post_init__(self):
|
||
if not self.created:
|
||
self.created = datetime.now().isoformat()
|
||
|
||
@dataclass
|
||
class ToolEntry:
|
||
"""工具条目"""
|
||
name: str
|
||
category: str
|
||
url: str
|
||
description: str
|
||
use_cases: List[str]
|
||
pros: List[str]
|
||
cons: List[str]
|
||
last_used: str = ""
|
||
proficiency: str = "beginner" # beginner, intermediate, advanced
|
||
|
||
class PersonalKnowledgeSystem:
|
||
"""个人知识系统"""
|
||
|
||
def __init__(self, base_path: str):
|
||
self.base_path = Path(base_path)
|
||
self.notes: Dict[str, Note] = {}
|
||
self.snippets: Dict[str, CodeSnippet] = {}
|
||
self.tools: Dict[str, ToolEntry] = {}
|
||
self.connections: Dict[str, Set[str]] = {} # 知识关联图
|
||
|
||
self._load()
|
||
|
||
def add_note(self, title: str, content: str,
|
||
note_type: NoteType, tags: List[str] = None) -> Note:
|
||
"""添加笔记"""
|
||
note_id = self._generate_id()
|
||
note = Note(
|
||
id=note_id,
|
||
title=title,
|
||
content=content,
|
||
note_type=note_type,
|
||
tags=set(tags or [])
|
||
)
|
||
self.notes[note_id] = note
|
||
self._save_note(note)
|
||
return note
|
||
|
||
def add_code_snippet(self, name: str, code: str, language: str,
|
||
description: str = "") -> CodeSnippet:
|
||
"""添加代码片段"""
|
||
snippet_id = self._generate_id()
|
||
snippet = CodeSnippet(
|
||
id=snippet_id,
|
||
name=name,
|
||
description=description,
|
||
code=code,
|
||
language=language
|
||
)
|
||
self.snippets[snippet_id] = snippet
|
||
self._save_snippet(snippet)
|
||
return snippet
|
||
|
||
def add_tool(self, name: str, category: str, url: str,
|
||
description: str, use_cases: List[str]) -> ToolEntry:
|
||
"""添加工具"""
|
||
tool = ToolEntry(
|
||
name=name,
|
||
category=category,
|
||
url=url,
|
||
description=description,
|
||
use_cases=use_cases,
|
||
pros=[],
|
||
cons=[]
|
||
)
|
||
self.tools[name] = tool
|
||
self._save_tools()
|
||
return tool
|
||
|
||
def connect_notes(self, note_id1: str, note_id2: str, relation: str = ""):
|
||
"""连接两个笔记"""
|
||
if note_id1 in self.notes and note_id2 in self.notes:
|
||
self.notes[note_id1].related_notes.add(note_id2)
|
||
self.notes[note_id2].related_notes.add(note_id1)
|
||
|
||
# 更新关联图
|
||
if note_id1 not in self.connections:
|
||
self.connections[note_id1] = set()
|
||
if note_id2 not in self.connections:
|
||
self.connections[note_id2] = set()
|
||
self.connections[note_id1].add(note_id2)
|
||
self.connections[note_id2].add(note_id1)
|
||
|
||
self._save_note(self.notes[note_id1])
|
||
self._save_note(self.notes[note_id2])
|
||
|
||
def search(self, query: str) -> List[Note]:
|
||
"""搜索笔记"""
|
||
results = []
|
||
query_lower = query.lower()
|
||
|
||
for note in self.notes.values():
|
||
if (query_lower in note.title.lower() or
|
||
query_lower in note.content.lower() or
|
||
any(query_lower in tag.lower() for tag in note.tags)):
|
||
results.append(note)
|
||
|
||
return sorted(results, key=lambda n: n.modified, reverse=True)
|
||
|
||
def get_related_notes(self, note_id: str) -> List[Note]:
|
||
"""获取相关笔记"""
|
||
if note_id not in self.notes:
|
||
return []
|
||
|
||
related_ids = self.notes[note_id].related_notes
|
||
return [self.notes[nid] for nid in related_ids if nid in self.notes]
|
||
|
||
def get_knowledge_graph(self) -> Dict[str, List[str]]:
|
||
"""获取知识图谱"""
|
||
graph = {}
|
||
for note_id, note in self.notes.items():
|
||
graph[note.title] = [
|
||
self.notes[rid].title
|
||
for rid in note.related_notes
|
||
if rid in self.notes
|
||
]
|
||
return graph
|
||
|
||
def review_periodic(self, days: int = 30) -> Dict[str, List[Note]]:
|
||
"""定期回顾:获取需要复习的笔记"""
|
||
from datetime import timedelta
|
||
|
||
cutoff = datetime.now() - timedelta(days=days)
|
||
to_review = {
|
||
'stale': [], # 长时间未更新的笔记
|
||
'orphan': [], # 没有关联的笔记
|
||
'valuable': [] # 高价值笔记
|
||
}
|
||
|
||
for note in self.notes.values():
|
||
modified = datetime.fromisoformat(note.modified)
|
||
|
||
# 识别陈旧笔记
|
||
if modified < cutoff:
|
||
to_review['stale'].append(note)
|
||
|
||
# 识别孤立笔记
|
||
if not note.related_notes:
|
||
to_review['orphan'].append(note)
|
||
|
||
# 识别高价值笔记(知识型和指南型)
|
||
if note.note_type in [NoteType.KNOWLEDGE, NoteType.GUIDE]:
|
||
to_review['valuable'].append(note)
|
||
|
||
return to_review
|
||
|
||
def export_markdown(self, note_id: str, output_path: str):
|
||
"""导出为Markdown"""
|
||
if note_id not in self.notes:
|
||
return
|
||
|
||
note = self.notes[note_id]
|
||
|
||
md_content = f"""# {note.title}
|
||
|
||
**类型**: {note.note_type.value}
|
||
**标签**: {', '.join(note.tags)}
|
||
**创建**: {note.created}
|
||
**修改**: {note.modified}
|
||
|
||
---
|
||
|
||
{note.content}
|
||
"""
|
||
|
||
if note.related_notes:
|
||
md_content += "\n\n## 相关笔记\n\n"
|
||
for rid in note.related_notes:
|
||
if rid in self.notes:
|
||
related = self.notes[rid]
|
||
md_content += f"- [{related.title}](notes/{rid}.md)\n"
|
||
|
||
Path(output_path).write_text(md_content, encoding='utf-8')
|
||
|
||
def _generate_id(self) -> str:
|
||
"""生成唯一ID"""
|
||
import uuid
|
||
return str(uuid.uuid4())[:8]
|
||
|
||
def _save_note(self, note: Note):
|
||
"""保存笔记"""
|
||
note_dir = self.base_path / "notes"
|
||
note_dir.mkdir(parents=True, exist_ok=True)
|
||
note_file = note_dir / f"{note.id}.json"
|
||
note_file.write_text(json.dumps(note.__dict__, default=str), encoding='utf-8')
|
||
|
||
def _save_snippet(self, snippet: CodeSnippet):
|
||
"""保存代码片段"""
|
||
snippet_dir = self.base_path / "snippets"
|
||
snippet_dir.mkdir(parents=True, exist_ok=True)
|
||
snippet_file = snippet_dir / f"{snippet.id}.json"
|
||
snippet_file.write_text(json.dumps(snippet.__dict__, default=str), encoding='utf-8')
|
||
|
||
def _save_tools(self):
|
||
"""保存工具列表"""
|
||
tools_file = self.base_path / "tools.json"
|
||
tools_data = {name: tool.__dict__ for name, tool in self.tools.items()}
|
||
tools_file.write_text(json.dumps(tools_data, default=str, ensure_ascii=False), encoding='utf-8')
|
||
|
||
def _load(self):
|
||
"""加载数据"""
|
||
# 加载笔记
|
||
note_dir = self.base_path / "notes"
|
||
if note_dir.exists():
|
||
for note_file in note_dir.glob("*.json"):
|
||
data = json.loads(note_file.read_text(encoding='utf-8'))
|
||
data['note_type'] = NoteType(data['note_type'])
|
||
data['tags'] = set(data.get('tags', []))
|
||
data['related_notes'] = set(data.get('related_notes', []))
|
||
note = Note(**data)
|
||
self.notes[note.id] = note
|
||
|
||
# 加载代码片段
|
||
snippet_dir = self.base_path / "snippets"
|
||
if snippet_dir.exists():
|
||
for snippet_file in snippet_dir.glob("*.json"):
|
||
data = json.loads(snippet_file.read_text(encoding='utf-8'))
|
||
data['tags'] = set(data.get('tags', []))
|
||
snippet = CodeSnippet(**data)
|
||
self.snippets[snippet.id] = snippet
|
||
|
||
# 加载工具
|
||
tools_file = self.base_path / "tools.json"
|
||
if tools_file.exists():
|
||
data = json.loads(tools_file.read_text(encoding='utf-8'))
|
||
for name, tool_data in data.items():
|
||
self.tools[name] = ToolEntry(**tool_data)
|
||
|
||
# === 空间AI工具箱 ===
|
||
|
||
class SpatialAIToolkit:
|
||
"""空间AI工具箱"""
|
||
|
||
def __init__(self, knowledge_system: PersonalKnowledgeSystem):
|
||
self.knowledge = knowledge_system
|
||
self.categories = {
|
||
'llm': '大语言模型',
|
||
'vision': '计算机视觉',
|
||
'gis_ai': 'GIS AI工具',
|
||
'remote_sensing': '遥感AI',
|
||
'data': '数据处理',
|
||
'visualization': '可视化'
|
||
}
|
||
|
||
def register_tool(self, name: str, category: str, url: str,
|
||
description: str, use_cases: List[str],
|
||
pros: List[str] = None, cons: List[str] = None):
|
||
"""注册工具"""
|
||
tool = self.knowledge.add_tool(
|
||
name=name,
|
||
category=category,
|
||
url=url,
|
||
description=description,
|
||
use_cases=use_cases
|
||
)
|
||
if pros:
|
||
tool.pros = pros
|
||
if cons:
|
||
tool.cons = cons
|
||
|
||
# 添加对应的笔记
|
||
self.knowledge.add_note(
|
||
title=f"工具: {name}",
|
||
content=f"""
|
||
## {name}
|
||
|
||
**类别**: {self.categories.get(category, category)}
|
||
**链接**: {url}
|
||
|
||
### 描述
|
||
{description}
|
||
|
||
### 适用场景
|
||
{chr(10).join(f'- {uc}' for uc in use_cases)}
|
||
|
||
### 优点
|
||
{chr(10).join(f'- {p}' for p in (pros or ['']))}
|
||
|
||
### 缺点
|
||
{chr(10).join(f'- {c}' for c in (cons or ['']))}
|
||
""",
|
||
note_type=NoteType.QUICK,
|
||
tags=[Tag.TOOL.value, category]
|
||
)
|
||
|
||
return tool
|
||
|
||
def add_workflow(self, name: str, description: str,
|
||
steps: List[str], tools: List[str],
|
||
code_example: str = None):
|
||
"""添加工作流"""
|
||
# 添加工作流笔记
|
||
content = f"""## {name}
|
||
|
||
### 描述
|
||
{description}
|
||
|
||
### 步骤
|
||
{chr(10).join(f'{i+1}. {step}' for i, step in enumerate(steps))}
|
||
|
||
### 所需工具
|
||
{chr(10).join(f'- {t}' for t in tools)}
|
||
"""
|
||
|
||
if code_example:
|
||
content += f"\n### 代码示例\n\n```python\n{code_example}\n```\n"
|
||
|
||
note = self.knowledge.add_note(
|
||
title=f"工作流: {name}",
|
||
content=content,
|
||
note_type=NoteType.GUIDE,
|
||
tags=[Tag.WORKFLOW.value]
|
||
)
|
||
|
||
# 如果有代码,添加代码片段
|
||
if code_example:
|
||
self.knowledge.add_code_snippet(
|
||
name=name,
|
||
description=description,
|
||
code=code_example,
|
||
language="python"
|
||
)
|
||
|
||
return note
|
||
|
||
# === 使用示例 ===
|
||
|
||
def initialize_knowledge_system(base_path: str) -> PersonalKnowledgeSystem:
|
||
"""初始化知识系统"""
|
||
print("=== 初始化个人知识系统 ===\n")
|
||
|
||
pks = PersonalKnowledgeSystem(base_path)
|
||
toolkit = SpatialAIToolkit(pks)
|
||
|
||
# 注册常用工具
|
||
print("注册AI工具...")
|
||
|
||
toolkit.register_tool(
|
||
name="Claude",
|
||
category="llm",
|
||
url="https://claude.ai",
|
||
description="Anthropic的大语言模型,擅长分析和写作",
|
||
use_cases=["代码生成", "文档写作", "问题分析", "代码审查"],
|
||
pros=["上下文窗口大", "安全性好", "输出质量高"],
|
||
cons=["无法实时联网", "不能运行代码"]
|
||
)
|
||
|
||
toolkit.register_tool(
|
||
name="ChatGPT",
|
||
category="llm",
|
||
url="https://chat.openai.com",
|
||
description="OpenAI的对话式AI",
|
||
use_cases=["对话交流", "知识问答", "创意生成"],
|
||
pros=["响应快速", "知识广博", "有插件生态"],
|
||
cons=["上下文限制", "可能有幻觉"]
|
||
)
|
||
|
||
toolkit.register_tool(
|
||
name="GitHub Copilot",
|
||
category="llm",
|
||
url="https://github.com/features/copilot",
|
||
description="AI代码助手",
|
||
use_cases=["代码补全", "函数生成", "代码解释"],
|
||
pros=["集成在编辑器中", "学习代码模式", "提高效率"],
|
||
cons=["需要订阅", "可能生成不安全代码"]
|
||
)
|
||
|
||
toolkit.register_tool(
|
||
name="QGIS",
|
||
category="gis_ai",
|
||
url="https://qgis.org",
|
||
description="开源GIS软件,支持Python插件",
|
||
use_cases=["空间分析", "地图制作", "数据处理"],
|
||
pros=["免费开源", "功能强大", "社区活跃"],
|
||
cons=["学习曲线陡峭", "大数据处理慢"]
|
||
)
|
||
|
||
# 添加工作流
|
||
print("添加工作流...")
|
||
|
||
toolkit.add_workflow(
|
||
name="遥感影像分类工作流",
|
||
description="使用深度学习进行遥感影像分类",
|
||
steps=[
|
||
"准备训练数据和标签",
|
||
"数据预处理和增强",
|
||
"训练深度学习模型",
|
||
"模型评估和调优",
|
||
"对全图进行预测",
|
||
"后处理和结果导出"
|
||
],
|
||
tools=["Python", "TensorFlow/PyTorch", "GDAL"],
|
||
code_example="""
|
||
# 简化的遥感分类示例
|
||
import rasterio
|
||
from sklearn.ensemble import RandomForestClassifier
|
||
|
||
# 读取影像
|
||
with rasterio.open('image.tif') as src:
|
||
image = src.read()
|
||
profile = src.profile
|
||
|
||
# 训练分类器
|
||
# clf = RandomForestClassifier()
|
||
# clf.fit(train_samples, train_labels)
|
||
|
||
# 预测
|
||
# prediction = clf.predict(image_pixels)
|
||
"""
|
||
)
|
||
|
||
# 添加核心概念笔记
|
||
print("添加核心概念...")
|
||
|
||
pks.add_note(
|
||
title="空间自相关",
|
||
content="""
|
||
## 空间自相关 (Spatial Autocorrelation)
|
||
|
||
### 定义
|
||
空间上相近的事物往往比随机分布的事物更相似。
|
||
|
||
### 度量指标
|
||
- **Moran's I**: 全局空间自相关
|
||
- **Geary's C**: 另一种全局指标
|
||
- **LISA**: 局部空间关联指标
|
||
|
||
### 应用
|
||
- 生态格局分析
|
||
- 疾病传播研究
|
||
- 房地产价格分析
|
||
|
||
### Python实现
|
||
```python
|
||
from libpysal.weights import Queen
|
||
from esda.moran import Moran
|
||
|
||
# 创建空间权重
|
||
w = Queen.from_dataframe(gdf)
|
||
|
||
# 计算Moran's I
|
||
moran = Moran(values, w)
|
||
```
|
||
""",
|
||
note_type=NoteType.KNOWLEDGE,
|
||
tags=[Tag.CONCEPT.value, "statistics", "spatial"]
|
||
)
|
||
|
||
print(f"\n知识系统初始化完成!")
|
||
print(f"- 笔记: {len(pks.notes)}")
|
||
print(f"- 代码片段: {len(pks.snippets)}")
|
||
print(f"- 工具: {len(pks.tools)}")
|
||
|
||
return pks
|
||
|
||
if __name__ == "__main__":
|
||
# 初始化知识系统
|
||
pks = initialize_knowledge_system("./knowledge_base")
|
||
|
||
# 示例:搜索
|
||
print("\n=== 搜索示例 ===")
|
||
results = pks.search("空间")
|
||
for note in results[:3]:
|
||
print(f"- {note.title} ({note.note_type.value})")
|
||
|
||
# 示例:知识图谱
|
||
print("\n=== 知识图谱 ===")
|
||
graph = pks.get_knowledge_graph()
|
||
for title, related in list(graph.items())[:3]:
|
||
if related:
|
||
print(f"{title} → {', '.join(related)}")
|
||
|
||
# 示例:定期回顾
|
||
print("\n=== 需要回顾的内容 ===")
|
||
review = pks.review_periodic(days=30)
|
||
print(f"陈旧笔记: {len(review['stale'])}")
|
||
print(f"孤立笔记: {len(review['orphan'])}")
|
||
print(f"高价值笔记: {len(review['valuable'])}")
|
||
```
|
||
|
||
### 社区参与策略
|
||
|
||
```
|
||
社区参与的层次
|
||
|
||
┌─────────────────┐
|
||
│ 贡献者 │ ← 创建新价值
|
||
│ - 开源项目 │
|
||
│ - 发表论文 │
|
||
│ - 开发工具 │
|
||
└────────┬────────┘
|
||
│
|
||
┌────────┴────────┐
|
||
│ 分享者 │ ← 分享知识
|
||
│ - 写博客 │
|
||
│ - 做演讲 │
|
||
│ - 回答问题 │
|
||
└────────┬────────┘
|
||
│
|
||
┌────────┴────────┐
|
||
│ 参与者 │ ← 参与讨论
|
||
│ - 参加会议 │
|
||
│ - 社区讨论 │
|
||
│ - 提问互动 │
|
||
└────────┬────────┘
|
||
│
|
||
┌────────┴────────┐
|
||
│ 观察者 │ ← 获取信息
|
||
│ - 阅读文档 │
|
||
│ - 关注动态 │
|
||
│ - 收集资源 │
|
||
└─────────────────┘
|
||
|
||
各层次的行动建议:
|
||
|
||
观察者:
|
||
• 订阅精选博客和通讯
|
||
• 关注领域专家
|
||
• 收集优质资源
|
||
|
||
参与者:
|
||
• 加入相关社区(Discord, Slack, 邮件列表)
|
||
• 参加线上/线下活动
|
||
• 积极提问和讨论
|
||
|
||
分享者:
|
||
• 写学习笔记和博客
|
||
• 在会议上分享经验
|
||
• 回答社区问题
|
||
|
||
贡献者:
|
||
• 提交PR到开源项目
|
||
• 发布自己的工具
|
||
• 参与学术研究
|
||
```
|
||
|
||
---
|
||
|
||
## 案例分析
|
||
|
||
### 案例1:建立个人Prompt库
|
||
|
||
```python
|
||
"""
|
||
个人Prompt管理系统
|
||
"""
|
||
from typing import Dict, List
|
||
from dataclasses import dataclass
|
||
|
||
@dataclass
|
||
class PromptTemplate:
|
||
"""Prompt模板"""
|
||
name: str
|
||
description: str
|
||
category: str
|
||
template: str
|
||
variables: List[str] # 模板中的变量
|
||
examples: List[Dict] # 使用示例
|
||
tags: List[str]
|
||
|
||
class PromptLibrary:
|
||
"""Prompt库"""
|
||
|
||
def __init__(self):
|
||
self.prompts: Dict[str, PromptTemplate] = {}
|
||
|
||
def add_prompt(self, prompt: PromptTemplate):
|
||
"""添加Prompt模板"""
|
||
self.prompts[prompt.name] = prompt
|
||
|
||
def get_prompt(self, name: str, **kwargs) -> str:
|
||
"""获取填充后的Prompt"""
|
||
if name not in self.prompts:
|
||
raise ValueError(f"Prompt '{name}' not found")
|
||
|
||
template = self.prompts[name]
|
||
result = template.template
|
||
|
||
# 替换变量
|
||
for var, value in kwargs.items():
|
||
result = result.replace(f"{{{var}}}", str(value))
|
||
|
||
return result
|
||
|
||
def list_by_category(self, category: str) -> List[PromptTemplate]:
|
||
"""按类别列出"""
|
||
return [p for p in self.prompts.values() if p.category == category]
|
||
|
||
# === 空间AI专用Prompt ===
|
||
|
||
spatial_prompts = [
|
||
PromptTemplate(
|
||
name="spatial_analysis_explain",
|
||
description="解释空间分析方法的原理和实现",
|
||
category="analysis",
|
||
template="""
|
||
你是一个空间分析专家。请解释以下空间分析方法:
|
||
|
||
**方法名称**: {method}
|
||
|
||
请包括:
|
||
1. 方法的核心原理
|
||
2. 数学基础(如果有)
|
||
3. 适用场景
|
||
4. 局限性
|
||
5. Python实现示例
|
||
6. 与其他方法的比较
|
||
""",
|
||
variables=["method"],
|
||
examples=[
|
||
{"method": "Moran's I"},
|
||
{"method": "最小累积阻力模型"}
|
||
],
|
||
tags=["解释", "分析"]
|
||
),
|
||
|
||
PromptTemplate(
|
||
name="code_review_spatial",
|
||
description="审查空间分析代码",
|
||
category="code",
|
||
template="""
|
||
请审查以下空间分析代码:
|
||
|
||
```python
|
||
{code}
|
||
```
|
||
|
||
请检查:
|
||
1. 空间数据处理是否正确(坐标系、投影等)
|
||
2. 算法选择是否合适
|
||
3. 效率问题
|
||
4. 潜在的错误
|
||
5. 改进建议
|
||
""",
|
||
variables=["code"],
|
||
examples=[{"code": "# 空间分析代码"}],
|
||
tags=["代码审查", "质量"]
|
||
),
|
||
|
||
PromptTemplate(
|
||
name="gis_choice_advice",
|
||
description="获取工具选择建议",
|
||
category="advice",
|
||
template="""
|
||
我需要为以下项目选择合适的GIS工具:
|
||
|
||
**项目描述**: {project_description}
|
||
**主要任务**: {tasks}
|
||
**数据量**: {data_size}
|
||
**团队情况**: {team_info}
|
||
**预算**: {budget}
|
||
|
||
请比较:
|
||
1. QGIS
|
||
2. ArcGIS
|
||
3. 其他相关工具
|
||
|
||
给出推荐和理由。
|
||
""",
|
||
variables=["project_description", "tasks", "data_size", "team_info", "budget"],
|
||
examples=[],
|
||
tags=["工具选择", "建议"]
|
||
),
|
||
|
||
PromptTemplate(
|
||
name="spatial_data_cleaning",
|
||
description="空间数据清洗指导",
|
||
category="data",
|
||
template="""
|
||
我需要清洗以下空间数据:
|
||
|
||
**数据描述**: {data_description}
|
||
**当前问题**: {problems}
|
||
|
||
请提供:
|
||
1. 诊断步骤
|
||
2. 清洗方法
|
||
3. Python代码示例
|
||
4. 质量检查方法
|
||
""",
|
||
variables=["data_description", "problems"],
|
||
examples=[],
|
||
tags=["数据清洗", "质量"]
|
||
),
|
||
|
||
PromptTemplate(
|
||
name="landscape_pattern_analysis",
|
||
description="景观格局分析",
|
||
category="ecology",
|
||
template="""
|
||
请帮我进行景观格局分析:
|
||
|
||
**研究区域**: {study_area}
|
||
**数据**: {data_description}
|
||
**研究问题**: {research_question}
|
||
|
||
请提供:
|
||
1. 合适的景观指数
|
||
2. 分析流程
|
||
3. 代码实现
|
||
4. 结果解释框架
|
||
""",
|
||
variables=["study_area", "data_description", "research_question"],
|
||
examples=[],
|
||
tags=["景观", "生态"]
|
||
),
|
||
]
|
||
|
||
# 初始化Prompt库
|
||
prompt_lib = PromptLibrary()
|
||
for prompt in spatial_prompts:
|
||
prompt_lib.add_prompt(prompt)
|
||
|
||
# 使用示例
|
||
if __name__ == "__main__":
|
||
print("=== 空间AI Prompt库 ===\n")
|
||
|
||
# 使用Prompt
|
||
prompt = prompt_lib.get_prompt(
|
||
"spatial_analysis_explain",
|
||
method="最小累积阻力模型"
|
||
)
|
||
print("生成的Prompt:")
|
||
print(prompt[:200] + "...\n")
|
||
|
||
# 列出某类别
|
||
analysis_prompts = prompt_lib.list_by_category("analysis")
|
||
print(f"分析类Prompt: {[p.name for p in analysis_prompts]}")
|
||
```
|
||
|
||
### 案例2:项目文档化策略
|
||
|
||
```python
|
||
"""
|
||
项目文档化模板系统
|
||
"""
|
||
|
||
class ProjectDocumentation:
|
||
"""项目文档化"""
|
||
|
||
@staticmethod
|
||
def create_readme_template() -> str:
|
||
"""README模板"""
|
||
return """# {project_name}
|
||
|
||
## 简介
|
||
{description}
|
||
|
||
## 背景
|
||
{background}
|
||
|
||
## 目标
|
||
{goals}
|
||
|
||
## 数据
|
||
- 数据来源: {data_sources}
|
||
- 数据格式: {data_formats}
|
||
- 数据质量: {data_quality}
|
||
|
||
## 方法
|
||
{methods}
|
||
|
||
## 结果
|
||
{results}
|
||
|
||
## 运行
|
||
```bash
|
||
{run_commands}
|
||
```
|
||
|
||
## 依赖
|
||
{dependencies}
|
||
|
||
## 作者
|
||
{authors}
|
||
|
||
## 许可
|
||
{license}
|
||
"""
|
||
|
||
@staticmethod
|
||
def create_methodology_section(method: str, data: Dict) -> str:
|
||
"""方法学文档"""
|
||
return f"""
|
||
## {method}
|
||
|
||
### 原理
|
||
{data.get('principle', '')}
|
||
|
||
### 实现
|
||
```python
|
||
{data.get('code', '')}
|
||
```
|
||
|
||
### 参数
|
||
{chr(10).join(f"- **{k}**: {v}" for k, v in data.get('parameters', {}).items())}
|
||
|
||
### 参考文献
|
||
{chr(10).join(f"- [{ref}]({ref})" for ref in data.get('references', []))}
|
||
"""
|
||
|
||
@staticmethod
|
||
def create_decision_log_template() -> str:
|
||
"""决策日志模板"""
|
||
return """# 项目决策日志
|
||
|
||
## 决策记录
|
||
|
||
| 日期 | 决策 | 理由 | 替代方案 | 状态 |
|
||
|------|------|------|----------|------|
|
||
| {date} | {decision} | {rationale} | {alternatives} | {status} |
|
||
|
||
## 重要决策详情
|
||
|
||
### {decision_title}
|
||
**日期**: {date}
|
||
**决策者**: {decision_maker}
|
||
|
||
**问题**:
|
||
{problem}
|
||
|
||
**选项**:
|
||
1. {option1}
|
||
2. {option2}
|
||
3. {option3}
|
||
|
||
**选择**: {chosen_option}
|
||
|
||
**理由**:
|
||
{rationale}
|
||
|
||
**预期影响**:
|
||
{expected_impact}
|
||
"""
|
||
|
||
# === 自动文档生成 ===
|
||
|
||
class AutoDocumentation:
|
||
"""自动文档生成器"""
|
||
|
||
@staticmethod
|
||
def generate_code_documentation(code: str, ai_assistant) -> Dict:
|
||
"""使用AI生成代码文档"""
|
||
prompt = f"""
|
||
请为以下代码生成文档:
|
||
|
||
```python
|
||
{code}
|
||
```
|
||
|
||
返回JSON格式:
|
||
{{
|
||
"description": "代码描述",
|
||
"parameters": "参数说明",
|
||
"returns": "返回值说明",
|
||
"example": "使用示例",
|
||
"notes": "注意事项"
|
||
}}
|
||
"""
|
||
response = ai_assistant.query(prompt)
|
||
return response
|
||
|
||
@staticmethod
|
||
def generate_workflow_diagram(steps: List[str]) -> str:
|
||
"""生成工作流图(Mermaid格式)"""
|
||
mermaid = ["graph TD"]
|
||
for i, step in enumerate(steps):
|
||
node_id = f"S{i}"
|
||
mermaid.append(f" {node_id}[{step}]")
|
||
if i > 0:
|
||
mermaid.append(f" S{i-1} --> {node_id}")
|
||
return "\n".join(mermaid)
|
||
```
|
||
|
||
### 案例3:学习路径规划
|
||
|
||
```python
|
||
"""
|
||
个人学习路径规划器
|
||
"""
|
||
from typing import List, Dict, Optional
|
||
from dataclasses import dataclass
|
||
from datetime import datetime, timedelta
|
||
|
||
@dataclass
|
||
class LearningGoal:
|
||
"""学习目标"""
|
||
name: str
|
||
description: str
|
||
priority: str # high, medium, low
|
||
estimated_hours: float
|
||
dependencies: List[str] # 前置要求
|
||
resources: List[str] # 学习资源
|
||
status: str = "planned" # planned, in_progress, completed
|
||
start_date: Optional[str] = None
|
||
completed_date: Optional[str] = None
|
||
|
||
class LearningPathPlanner:
|
||
"""学习路径规划器"""
|
||
|
||
def __init__(self):
|
||
self.goals: Dict[str, LearningGoal] = {}
|
||
self.completed: List[str] = []
|
||
|
||
def add_goal(self, goal: LearningGoal):
|
||
"""添加学习目标"""
|
||
self.goals[goal.name] = goal
|
||
|
||
def get_recommended_order(self) -> List[str]:
|
||
"""获取推荐的学习顺序(拓扑排序)"""
|
||
# 简化的拓扑排序
|
||
ordered = []
|
||
remaining = set(self.goals.keys())
|
||
|
||
while remaining:
|
||
# 找到没有未满足依赖的目标
|
||
ready = [
|
||
name for name in remaining
|
||
if all(dep in self.completed for dep in self.goals[name].dependencies)
|
||
]
|
||
|
||
if not ready:
|
||
# 循环依赖,按优先级选一个
|
||
ready = [min(remaining, key=lambda n: self.goals[n].priority)]
|
||
|
||
# 按优先级排序
|
||
ready.sort(key=lambda n: {'high': 0, 'medium': 1, 'low': 2}[self.goals[n].priority])
|
||
|
||
next_goal = ready[0]
|
||
ordered.append(next_goal)
|
||
remaining.remove(next_goal)
|
||
|
||
return ordered
|
||
|
||
def create_schedule(self, weekly_hours: float, start_date: str = None) -> Dict:
|
||
"""创建学习计划"""
|
||
if start_date is None:
|
||
start_date = datetime.now()
|
||
else:
|
||
start_date = datetime.fromisoformat(start_date)
|
||
|
||
schedule = {}
|
||
current = start_date
|
||
ordered = self.get_recommended_order()
|
||
|
||
for goal_name in ordered:
|
||
goal = self.goals[goal_name]
|
||
|
||
# 计算需要周数
|
||
weeks_needed = goal.estimated_hours / weekly_hours
|
||
|
||
schedule[goal_name] = {
|
||
'start': current.isoformat(),
|
||
'end': (current + timedelta(weeks=weeks_needed)).isoformat(),
|
||
'weeks': weeks_needed,
|
||
'hours_per_week': weekly_hours
|
||
}
|
||
|
||
current += timedelta(weeks=weeks_needed)
|
||
|
||
return schedule
|
||
|
||
def mark_completed(self, goal_name: str):
|
||
"""标记目标完成"""
|
||
if goal_name in self.goals:
|
||
self.goals[goal_name].status = "completed"
|
||
self.goals[goal_name].completed_date = datetime.now().isoformat()
|
||
self.completed.append(goal_name)
|
||
|
||
# === 空间AI学习路径 ===
|
||
|
||
def create_spatial_ai_learning_path() -> LearningPathPlanner:
|
||
"""创建空间AI学习路径"""
|
||
planner = LearningPathPlanner()
|
||
|
||
# 基础
|
||
planner.add_goal(LearningGoal(
|
||
name="Python基础",
|
||
description="掌握Python编程基础",
|
||
priority="high",
|
||
estimated_hours=40,
|
||
dependencies=[],
|
||
resources=["Python官方教程", "Automate the Boring Stuff"]
|
||
))
|
||
|
||
planner.add_goal(LearningGoal(
|
||
name="GIS基础",
|
||
description="理解地理信息系统基本概念",
|
||
priority="high",
|
||
estimated_hours=30,
|
||
dependencies=[],
|
||
resources=["QGIS官方教程", "Geocomputation with R"]
|
||
))
|
||
|
||
# 核心
|
||
planner.add_goal(LearningGoal(
|
||
name="空间数据处理",
|
||
description="使用Python处理空间数据",
|
||
priority="high",
|
||
estimated_hours=50,
|
||
dependencies=["Python基础", "GIS基础"],
|
||
resources=["GeoPandas文档", "PyTutoria"]
|
||
))
|
||
|
||
planner.add_goal(LearningGoal(
|
||
name="空间统计分析",
|
||
description="空间统计方法和实践",
|
||
priority="high",
|
||
estimated_hours=60,
|
||
dependencies=["空间数据处理"],
|
||
resources=["PySAL文档", "Spatial Statistics"]
|
||
))
|
||
|
||
planner.add_goal(LearningGoal(
|
||
name="机器学习基础",
|
||
description="机器学习算法和原理",
|
||
priority="medium",
|
||
estimated_hours=80,
|
||
dependencies=["Python基础"],
|
||
resources=["Hands-On ML", "Scikit-learn文档"]
|
||
))
|
||
|
||
# 进阶
|
||
planner.add_goal(LearningGoal(
|
||
name="深度学习",
|
||
description="深度学习和神经网络",
|
||
priority="medium",
|
||
estimated_hours=100,
|
||
dependencies=["机器学习基础"],
|
||
resources=["Deep Learning", "Fast.ai"]
|
||
))
|
||
|
||
planner.add_goal(LearningGoal(
|
||
name="遥感AI",
|
||
description="遥感影像的深度学习应用",
|
||
priority="medium",
|
||
estimated_hours=60,
|
||
dependencies=["深度学习", "空间数据处理"],
|
||
resources=["深度学习与遥感", "torchgeo"]
|
||
))
|
||
|
||
planner.add_goal(LearningGoal(
|
||
name="LLM应用",
|
||
description="大语言模型在空间分析中的应用",
|
||
priority="low",
|
||
estimated_hours=40,
|
||
dependencies=["机器学习基础", "空间数据处理"],
|
||
resources=["Claude文档", "LangChain文档"]
|
||
))
|
||
|
||
return planner
|
||
|
||
if __name__ == "__main__":
|
||
print("=== 空间AI学习路径 ===\n")
|
||
|
||
planner = create_spatial_ai_learning_path()
|
||
|
||
print("推荐学习顺序:")
|
||
order = planner.get_recommended_order()
|
||
for i, goal_name in enumerate(order, 1):
|
||
goal = planner.goals[goal_name]
|
||
print(f"{i}. {goal_name} ({goal.estimated_hours}h) - {goal.priority}")
|
||
|
||
print("\n学习计划 (每周10小时):")
|
||
schedule = planner.create_schedule(weekly_hours=10)
|
||
for goal_name, info in schedule.items():
|
||
start = info['start'][:10]
|
||
end = info['end'][:10]
|
||
print(f"{goal_name}: {start} → {end} ({info['weeks']:.1f}周)")
|
||
|
||
total_hours = sum(g.estimated_hours for g in planner.goals.values())
|
||
total_weeks = total_hours / 10
|
||
print(f"\n总计: {total_hours}小时, 约{total_weeks:.1f}周")
|
||
```
|
||
|
||
---
|
||
|
||
## 反思与延伸
|
||
|
||
### 思考问题
|
||
|
||
1. **知识审计**:你当前的知识体系有哪些空白?
|
||
|
||
2. **工具评估**:你的AI工具箱中有多少工具是真正常用的?
|
||
|
||
3. **文档习惯**:你目前的文档化习惯有什么问题?
|
||
|
||
4. **社区参与**:你在哪个层次的社区参与?如何提升?
|
||
|
||
### 实践练习
|
||
|
||
1. **建立知识库**:使用文中代码创建你的个人知识系统
|
||
|
||
2. **整理Prompt**:收集并整理你常用的Prompt模板
|
||
|
||
3. **规划学习**:为未来6个月创建详细的学习计划
|
||
|
||
### 延伸阅读
|
||
|
||
- **"Building a Second Brain"** (Tiago Forte) - 个人知识管理
|
||
- **"How to Take Smart Notes"** (Sönke Ahrens) - 卡片笔记法
|
||
- **"Digital Minimalism"** (Cal Newport) - 数字工具的选择
|
||
|
||
---
|
||
|
||
## 关键要点
|
||
|
||
1. **个人知识体系应该是分层的**,从捕获到分享
|
||
2. **AI工具箱需要分类管理**,包括基础、专业、自定义工具
|
||
3. **文档化应该遵循金字塔模型**,不同类型文档有不同目的
|
||
4. **社区参与是多层次的**,从观察到贡献逐步深入
|
||
5. **持续优化是关键**,定期回顾和调整你的知识系统
|