Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to model interpretations of rap music
    text
    copied!<p>I just started working on a website that will help people understand what rappers are talking about. Users will see the lyrics to a rap song and they'll be able to click certain lyrics to see an explanation. Here's a screenshot (you can also check out the site itself <a href="http://rapexegesis.com/songs/Cam-ron/Killa-cam" rel="nofollow noreferrer">here</a>):</p> <p><a href="http://img146.imageshack.us/img146/6882/clocal.png" rel="nofollow noreferrer">alt text http://img146.imageshack.us/img146/6882/clocal.png</a></p> <p>(Original lyrics censored; <a href="http://img44.imageshack.us/img44/650/picture10vwr.png" rel="nofollow noreferrer">click here</a> to see them)</p> <p>Anyway, my question is how to model these annotations in my application. Right now, I'm storing the lyrics and annotations as one big blob of HTML in this format:</p> <pre><code>&lt;div class="lyrics"&gt; With the goons I spy &lt;a href="#note1"&gt;Stay in tune with ma&lt;/a&gt; &lt;a href="#note2"&gt;She like damn This the realest since 'Kumbaya'&lt;/a&gt; Kumbayay Killa Cam my lord &lt;/div&gt; &lt;div class="annotations"&gt; &lt;div id="note1"&gt; "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. &lt;/div&gt; &lt;div id="note2"&gt; Kumbaya is a campfire singalong. &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and then processing it with this method for output:</p> <pre><code>class Song &lt; 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 =&gt; '_blank') end simple_format doc.html.strip end end </code></pre> <p>and the rest I do with jQuery and the fantastic <a href="http://craigsworks.com/projects/qtip/" rel="nofollow noreferrer">qTip</a> plugin.</p> <p>This works fine for display, but since my application doesn't know about the relationship between annotations and lyrics, it will be hard to, say, add an interface for updating an individual annotation inline (or at all, really).</p> <p>On the other hand, I don't really know the best way to represent this in ActiveRecord. I suppose a song could "have_many" annotations, but how would I represent which lyrics were annotated? I could store the start and end word index, but this seems painful and sensitive to minor changes in the lyrics.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload