如何模拟说唱音乐的解释

Tom*_*man 27 activerecord model ruby-on-rails

我刚开始在一个网站上工作,这将帮助人们了解说唱歌手在谈论什么.用户将看到一首说唱歌曲的歌词,他们将能够点击某些歌词来查看解释.这是一个截图(你也可以在这里查看网站):

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

(原始歌词审查; 点击这里查看)

无论如何,我的问题是如何在我的应用程序中建模这些注释.现在,我将歌词和注释存储为这种格式的一大块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>
Run Code Online (Sandbox Code Playgroud)

然后使用此方法处理它以进行输出:

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
Run Code Online (Sandbox Code Playgroud)

其余的我使用jQuery和梦幻般的qTip插件.

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

另一方面,我真的不知道在ActiveRecord中表示这个的最佳方法.我想一首歌可以"has_many"注释,但我如何表示哪些歌词被注释?我可以存储开始和结束单词索引,但这似乎很痛苦,并且对歌词中的微小变化很敏感.

Chr*_*all 8

如何呈现这样的歌词(感谢人民冠军)?

Well it's that [grain grippa][1] from Houston, Tex
That bar sippa, that bar no plex
I'm straight up outta that [Swishahouse][2]
Where G. Dash write all the checks
So [check the neck, check the wrist][3]
I'm balla status from head to toe

[1]Referring to the wood grain steering wheel common to luxury cars
[2]Swisha House is the record label Paul Wall records for
[3]"Look at my watch and necklace because they are expensive"

只是一个想法,我受到了用于在此网站上添加评论的标记的启发.

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

这种格式应该很容易从数据库中生成,并且具有比XML更"人类可读"且可就地编辑的优点,因此您可以在开发整个UI之前更轻松地测试它.

我对这个问题很感兴趣,并期待看到网站的进展.有趣的工作!