数据分析技能 data-analysis

Empathy Ledger平台AI数据分析技能,提供主题提取、引文分析、情感分析、故事推荐等核心功能。通过标准化分析流程和Supabase最佳实践,实现文化故事内容的智能处理、主题匹配和内容关联,提升用户体验和内容发现效率。关键词:AI数据分析、主题提取、引文分析、故事推荐、Supabase查询、文化内容分析、情感分析、内容关联算法。

AI应用 0 次安装 0 次浏览 更新于 3/1/2026

name: data-analysis description: 为Empathy Ledger提供AI驱动的数据分析。适用于处理主题、引文、故事建议、转录分析、讲述者关联或任何需要提取洞察的功能。确保平台内一致的分析模式。

数据分析技能

本技能为Empathy Ledger平台提供AI驱动的数据分析模式和最佳实践,确保引文、主题、摘要和建议在平台各处呈现一致。

核心数据模型

分析流程

转录文本(原始音频/文本)
    ↓ AI分析
主题提取 → themes[] 数组
引文提取 → key_quotes[] 数组
摘要生成 → ai_summary 文本
情感分析 → sentiment_scores{}
    ↓ 故事创作
故事(创作内容)
    ↓ 关联
相关故事 ← 主题匹配
建议内容 ← AI推荐

关键分析表

表名 分析字段 用途
transcripts themes, key_quotes, ai_summary, ai_processing_status 原始访谈分析
stories themes, cultural_tags, featured_quote 已发布故事元数据
storytellers expertise_themes, connection_strength 讲述者洞察
story_suggestions reason, confidence_score, theme_overlap AI推荐

主题系统

标准主题分类

const THEME_CATEGORIES = {
  cultural: ['identity', 'heritage', 'tradition', 'language', 'ceremony'],
  family: ['kinship', 'elders', 'children', 'ancestors', 'community'],
  land: ['country', 'connection', 'seasons', 'wildlife', 'sacred-sites'],
  resilience: ['survival', 'adaptation', 'strength', 'healing', 'hope'],
  knowledge: ['wisdom', 'teaching', 'learning', 'stories', 'dreams']
}

主题提取模式

// 从内容提取主题时:
interface ThemeExtraction {
  themes: string[]           // 最多5-7个主要主题
  theme_confidence: number   // 0-1置信度分数
  cultural_relevance: 'high' | 'medium' | 'low'
}

// 基于主题匹配的Supabase查询
const { data } = await supabase
  .from('stories')
  .select('*')
  .overlaps('themes', ['identity', 'heritage'])
  .order('view_count', { ascending: false })
  .limit(5)

引文系统

引文提取标准

interface ExtractedQuote {
  text: string              // 引文本体(理想长度50-300字符)
  context?: string          // 上下文环境
  themes: string[]          // 引文相关主题
  significance: 'highlight' | 'supporting' | 'context'
  speaker_attribution?: string
}

// 在转录中存储引文
UPDATE transcripts SET key_quotes = ARRAY[
  '当我行走在故土上,我能感受到祖先与我同在。',
  '我们的语言承载着数千年的智慧。'
]

引文显示模式

// 故事卡片应显示特色引文
<StoryCard
  story={story}
  featuredQuote={story.key_quotes?.[0]}
  showThemes={true}
/>

// 引文高亮组件
<QuoteHighlight
  quote={quote}
  attribution={storyteller.display_name}
  themes={quote.themes}
/>

AI分析集成

转录分析流程

// 1. 触发分析
POST /api/transcripts/{id}/analyze

// 2. AI提取:
{
  themes: ['identity', 'land-connection', 'healing'],
  key_quotes: [
    "河流教会了我耐心...",
    "我们的故事是我们的生存之道..."
  ],
  ai_summary: "此转录探讨了文化...主题",
  sentiment: { positive: 0.7, reflective: 0.8 }
}

// 3. 存储和索引
UPDATE transcripts SET
  themes = $themes,
  key_quotes = $key_quotes,
  ai_summary = $ai_summary,
  ai_processing_status = 'completed'

故事推荐算法

// 基于主题重叠查找相关内容
async function getSuggestedStories(storyId: string) {
  const { data: story } = await supabase
    .from('stories')
    .select('themes, storyteller_id')
    .eq('id', storyId)
    .single()

  // 查找具有重叠主题的故事
  const { data: related } = await supabase
    .from('stories')
    .select('*, storytellers!inner(display_name)')
    .neq('id', storyId)
    .overlaps('themes', story.themes)
    .limit(5)

  return related.map(r => ({
    ...r,
    theme_overlap: calculateOverlap(story.themes, r.themes),
    reason: generateReason(story.themes, r.themes)
  }))
}

Supabase最佳实践

主题数组操作

-- 查找具有任意匹配主题的故事
SELECT * FROM stories WHERE themes && ARRAY['identity', 'heritage'];

-- 查找具有所有主题的故事
SELECT * FROM stories WHERE themes @> ARRAY['identity', 'heritage'];

-- 统计主题出现次数
SELECT unnest(themes) as theme, count(*)
FROM stories
GROUP BY theme
ORDER BY count DESC;

全文搜索集成

-- 为引文添加搜索向量
ALTER TABLE transcripts ADD COLUMN
  quote_search tsvector GENERATED ALWAYS AS (
    to_tsvector('english', array_to_string(key_quotes, ' '))
  ) STORED;

CREATE INDEX idx_quote_search ON transcripts USING GIN(quote_search);

-- 搜索引文
SELECT * FROM transcripts
WHERE quote_search @@ to_tsquery('english', 'ancestor & wisdom');

分析物化视图

-- 平台主题分析
CREATE MATERIALIZED VIEW theme_analytics AS
SELECT
  unnest(themes) as theme,
  count(*) as story_count,
  count(DISTINCT storyteller_id) as storyteller_count,
  avg(view_count) as avg_views
FROM stories
WHERE status = 'published'
GROUP BY theme;

-- 定期刷新
REFRESH MATERIALIZED VIEW theme_analytics;

组件集成点

分析应出现的位置

位置 显示内容 数据源
故事卡片 特色引文,前3个主题 stories.key_quotes[0], stories.themes
故事详情 所有引文,完整主题列表 完整数组
讲述者档案 专业主题,引文数量 从故事聚合
世界巡游地图 主题聚类,引文高亮 theme_analytics 视图
搜索结果 主题徽章,引文片段 全文搜索
相关故事 主题重叠率,推荐原因 查询时计算
仪表板 主题趋势,热门引文 分析视图

分析React组件

// 带文化着色的主题徽章
<ThemeBadge theme="identity" variant="cultural" />

// 带归属的引文卡片
<QuoteCard
  quote={quote}
  storyteller={storyteller}
  showThemes
  linkToStory
/>

// 主题云可视化
<ThemeCloud
  themes={allThemes}
  onThemeClick={handleFilter}
  highlightActive={activeThemes}
/>

// 故事推荐面板
<SuggestedStories
  currentStory={story}
  maxSuggestions={5}
  showReason
/>

分析API端点

端点 用途
POST /api/transcripts/{id}/analyze 触发AI分析
GET /api/transcripts/{id}/analyze 检查分析状态
GET /api/stories/{id}/suggestions 获取相关故事
GET /api/themes 列出所有主题及计数
GET /api/themes/{theme}/stories 按主题获取故事
GET /api/quotes/search 跨引文搜索
GET /api/storytellers/{id}/themes 讲述者专业主题

何时使用此技能

在以下情况调用:

  • 向故事卡片或显示添加引文
  • 实现故事建议/相关内容
  • 构建基于主题的筛选或搜索
  • 创建分析仪表板
  • 集成AI分析结果
  • 设计数据可视化组件
  • 优化分析数据的Supabase查询

参考文件