ruby-on-rails - 如何模拟说唱音乐的诠释

标签 ruby-on-rails activerecord model

我刚刚开始在一个网站上工作,该网站将帮助人们了解说唱歌手在谈论什么。用户将看到一首说唱歌曲的歌词,他们将能够单击某些歌词以查看解释。这是屏幕截图(您也可以查看网站本身 here):

alt text http://img146.imageshack.us/img146/6882/clocal.png

(原歌词已删;click here 可查看)

无论如何,我的问题是如何在我的应用程序中对这些注释进行建模。现在,我将歌词和注释以这种格式存储为一大块 HTML:

<div class="lyrics">
  With the goons I spy
  <a href="#note1">Stay in tune with ma</a>
  <a href="#note2">She like damn
  This the realest since 'Kumbaya'</a>
  Kumbayay Killa Cam my lord 
</div>

<div class="annotations">
  <div id="note1">
"Ma" refers to ladies, generally, and specifically also the woman singing the hook;  "Stay in tune" is a musical metaphor: he literally stays in tune with the singer and also in the sense that he has game.
  </div>
  <div id="note2">
Kumbaya is a campfire singalong.
  </div>
</div>

然后使用此方法处理它以进行输出:
class Song < ActiveRecord::Base
  include ActionView::Helpers

  def annotated_lyrics
    lyrics = read_attribute('annotated_lyrics')
    return if lyrics.blank?

    require 'hpricot'
    doc = Hpricot lyrics

    doc.at('.lyrics').inner_html = doc.at('.lyrics').inner_html.strip
    doc.search("a[@href^='#note']").set('class', 'tooltip').each do |t|
      t.inner_html = t.inner_html.strip
    end
    doc.search("div[@id^='note']").set('class', 'annotation').each do |a|
      a.inner_html = auto_link(a.inner_html.strip, :all, :target => '_blank')
    end
    simple_format doc.html.strip
  end
end

剩下的我用jQuery和奇妙的qTip做的插入。

这适用于显示,但由于我的应用程序不知道注释和歌词之间的关系,因此很难说,添加一个界面来更新单个注释内联(或根本,真的)。

另一方面,我真的不知道在 ActiveRecord 中表示它的最佳方式。我想一首歌可以“有_许多”注释,但我如何表示哪些歌词被注释了?我可以存储开始和结束词的索引,但这对于歌词中的微小变化似乎很痛苦并且很敏感。

最佳答案

像这样呈现歌词怎么样(感谢人民冠军)?

嗯,它是来自德克萨斯州休斯顿的 [grain grippa][1]
那个酒吧 sippa,那个酒吧没有 plex
我直接离开了[Swishahouse][2]
G. Dash 写所有支票的地方
所以[检查脖子,检查手腕][3]
我从头到脚都是巴拉状态

[1]引用豪华车通用的木纹方向盘
[2] Swisha House 是唱片公司 Paul Wall 为
[3]“看看我的 watch 和项链,因为它们很贵”

只是一个想法,我的灵感来自用于在此站点上添加评论的标记。

因此,对于数据库,创建 Lyric、LyricLine 和 Annotation 表。注释具有 LyricLineIds、StartChar 和 EndChar 值以及含义或说明字段。 LyricLines 是每行的文本,与 LyricIds 的 Lyric 实体相关。歌词存储歌曲信息、语言信息等。

这种格式应该很容易从数据库中生成,并且具有比 XML 更“人类可读”和可就地编辑的好处,因此您可以在开发整个 UI 之前更轻松地对其进行测试。

我收藏了这个问题,期待看到网站的进展。有趣的工作!

关于ruby-on-rails - 如何模拟说唱音乐的诠释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303495/

相关文章:

ruby-on-rails - Sprockets::Rails::Helper::AssetNotFound - Assets 管道中不存在 Assets "my_logo.jpeg"

ruby-on-rails - rails PG::InvalidDatetimeFormat:错误:时间戳类型的输入语法无效

ruby-on-rails - 有没有一种方法可以从现有的一组模型生成 Rails fixtures?

model-view-controller - 构建用于在多个服务之间共享数据层的 Play 框架模块

Java操作系统进程队列

mysql - Laravel 动态模型数据库

ruby-on-rails - "Expected string default value for ` --jbuilder `; got true (boolean)"新建rails项目出错

ruby-on-rails - 按月份编号查找特定月份的所有记录(例如 1 = 一月)

ruby-on-rails - 在 ActiveRecord 模型中设置默认随机列值

ruby-on-rails - 数据库/模型夹具和原始状态