Skip to content

Instantly share code, notes, and snippets.

@moustaki
Created October 10, 2009 17:26
Show Gist options
  • Save moustaki/206966 to your computer and use it in GitHub Desktop.
Save moustaki/206966 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'rqommend'
DEFAULT_OPTIONS = {
'certificate' => 'cert.ca',
'key' => 'cert.pem'
}
DEFAULT_ENDPOINT = 'https://server11.incubator.bbc.co.uk/sparql/'
Rqommend::Can.new "
SELECT *
WHERE {
@INPUT <http://www.w3.org/2002/07/owl#sameAs> ?dbpedia_artist .
@INPUT <http://xmlns.com/foaf/0.1/name> ?input_name .
?dbpedia_artist <http://dbpedia.org/ontology/homeTown> <http://dbpedia.org/resource/Detroit> .
?dbpedia_artist_2 <http://dbpedia.org/ontology/homeTown> <http://dbpedia.org/resource/Detroit> .
?OUTPUT <http://www.w3.org/2002/07/owl#sameAs> ?dbpedia_artist_2 .
?OUTPUT <http://xmlns.com/foaf/0.1/name> ?output_name .
FILTER (@INPUT != ?OUTPUT && regex(str(?OUTPUT), '^http://www\.bbc\.co\.uk'))
}",
'<%= result["input_name"] %> and <a href="<%= result["OUTPUT"] %>"><%= result["output_name"] %></a> are both based in Detroit'
Rqommend::Can.new "
SELECT *
WHERE {
@INPUT <http://purl.org/vocab/relationship/siblingOf> ?OUTPUT .
@INPUT <http://xmlns.com/foaf/0.1/name> ?input_name .
?OUTPUT <http://xmlns.com/foaf/0.1/name> ?output_name .
FILTER (@INPUT != ?OUTPUT && regex(str(?OUTPUT), '^http://www\.bbc\.co\.uk'))
}
",
'<%= result["input_name"] %> is the sibling of <a href="<%= result["OUTPUT"] %>"><%= result["output_name"] %></a>'
Rqommend::Can.new "
SELECT *
WHERE {
@INPUT <http://purl.org/ontology/mo/member> ?member .
?OUTPUT <http://purl.org/ontology/mo/member> ?member .
@INPUT <http://xmlns.com/foaf/0.1/name> ?input_name .
?OUTPUT <http://xmlns.com/foaf/0.1/name> ?output_name .
?member <http://xmlns.com/foaf/0.1/name> ?member_name .
FILTER (@INPUT != ?OUTPUT && regex(str(?OUTPUT), '^http://www\.bbc\.co\.uk'))
}
",
'<%= result["member_name"] %> played in <%= result["input_name"] %> and also in <a href="<%= result["OUTPUT"] %>"><%= result["output_name"] %></a>'
Rqommend::Can.new "
SELECT * WHERE {
@INPUT
<http://www.w3.org/2002/07/owl#sameAs> ?dbpedia_artist ;
<http://xmlns.com/foaf/0.1/name> ?input_name .
?dbpedia_artist
<http://dbpedia.org/ontology/label> ?label .
?dbpedia_artist_2
<http://dbpedia.org/ontology/label> ?label .
?label
<http://xmlns.com/foaf/0.1/name> ?label_name ;
a <http://dbpedia.org/class/yago/IndependentRecordLabels> ;
<http://dbpedia.org/property/abstract> ?abstract .
?OUTPUT
<http://www.w3.org/2002/07/owl#sameAs> ?dbpedia_artist_2 ;
<http://xmlns.com/foaf/0.1/name> ?output_name .
FILTER (
(@INPUT != ?OUTPUT) &&
regex(str(?OUTPUT), '^http://www\.bbc\.co\.uk') &&
(langMatches(lang(?abstract), 'en') || lang(?abstract) = '' )
)
}
",
'<%= result["input_name"] %> and <a href="<%= result["OUTPUT"] %>"><%= result["output_name"] %></a> were both signed on <a href="<%= result["label"] %>"><%= result["label_name"] %></a>. <%= result["abstract"] %>'
get '/recommendations/:artist' do
artist_guid = params[:artist]
resource = Rqommend::Resource.new "http://www.bbc.co.uk/music/artists/#{artist_guid}#artist"
recommendation = resource.recommendation
"<div id=\"recommendations\">#{recommendation['explanation']}</div>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment