Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created October 18, 2010 20:13
Show Gist options
  • Save tommorris/632955 to your computer and use it in GitHub Desktop.
Save tommorris/632955 to your computer and use it in GitHub Desktop.
evolution of RDFa on OpenPlaques.org
I've been slowly adding bits of RDFa into OpenPlaques. Here's how.
Really, it isn't that difficult.
It also isn't complete yet. There's loads more to do.
This is just to show people that RDFa isn't very difficult! ;-)
commit 10c517dd4a0e6505583c4e41d0f678d11dc02f20
Author: bbtommorris <bbtommorris@a70bfd38-3ca5-11de-a81c-fde7d73ceb89>
Date: Sat Sep 25 22:16:50 2010 +0000
Initial support for RDFa
added FOAF RDFa on person/show
- Uses foaf:Agent, foaf:Person, vcard:VCard and rdfs/owl properties to link back people with dbpedia etc.
update issue #244 - http://code.google.com/p/openplaques/issues/detail?id=244
- if this gets changed, then the code introduced by this update will need to be changed too
the doctype is now XHTML+RDFa 1.0 and has xmlns attributes for rdfs, vcard, foaf and owl.
git-svn-id: https://openplaques.googlecode.com/svn/trunk/www@595 a70bfd38-3ca5-11de-a81c-fde7d73ceb89
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb
index 68e4f50..502e32c 100644
--- a/app/helpers/people_helper.rb
+++ b/app/helpers/people_helper.rb
@@ -47,6 +47,14 @@ module PeopleHelper
return "http://en.wikipedia.org/wiki/"+untitled_name
end
+ def dbpedia_url(person)
+ unless person.dbpedia_url.empty?
+ dbpedia_url
+ else
+ wikipedia_url(person).gsub(/[a-zA-Z]{0,2}\.wikipedia\.org\/wiki\//, "dbpedia.org/resource/")
+ end
+ end
+
def wikipedia_summary_p(person)
if person.wikipedia_paras && person.wikipedia_paras > ""
return wikipedia_summary_each(wikipedia_url(person), person.wikipedia_paras)
@@ -110,9 +118,9 @@ module PeopleHelper
dates =""
end
if options[:links] == :none
- return content_tag("span", person.name, {:class => "fn"}) + dates.html_safe
+ return content_tag("span", person.name, {:class => "fn", :property => "rdfs:label foaf:name vcard:fn"}) + dates.html_safe
else
- return link_to(person.name, person, {:class => "fn url"}) + dates.html_safe
+ return link_to(person.name, person, {:class => "fn url", :property => "rdfs:label foaf:name vcard:fn", :rel => "foaf:homepage vcard:url"}) + dates.html_safe
end
end
diff --git a/app/models/person.rb b/app/models/person.rb
index e2debb0..59c402f 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -88,6 +88,12 @@ class Person < ActiveRecord::Base
return self
end
+ def person?
+ false if roles.member?(Role.find_by_name("dog"))
+ true
+ # TODO: add 'not human' property to role and abstract.
+ end
+
private
def update_index
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index b84d8e6..76ae95e 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,7 +1,11 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+ "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:vcard="http://www.w3.org/2006/vcard/ns#"
+ xmlns:owl="http://www.w3.org/2002/07/owl#">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= @page_title + " - " if @page_title %>Open Plaques</title>
diff --git a/app/views/people/show.html.erb b/app/views/people/show.html.erb
index f9f51d2..519d31d 100644
--- a/app/views/people/show.html.erb
+++ b/app/views/people/show.html.erb
@@ -1,5 +1,5 @@
<% @page_title = @person.name %>
-<div class="vcard person">
+<div class="vcard person" typeof="<%= if (@person.person?) then "foaf:Person" else "foaf:Agent" end %> vcard:VCard" about="#person">
<h1><%= dated_person(@person, {:links => :none}) %></h1>
<%= render :partial => 'plaques/map.html.erb' %>
@@ -36,7 +36,7 @@
<% @wiki = wikipedia_summary_p(@person) %>
<% if @wiki != nil %>
<div id="wikipedia">
- <p>"<%= @wiki %>...", according to Wikipedia. See <a href="<%= wikipedia_url(@person) %>">full article</a> for more. Content reused under <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution ShareAlike</a> licence.</p>
+ <p>"<%= @wiki %>...", according to Wikipedia. See <a href="<%= wikipedia_url(@person) %>" resource="<%= wikipedia_url(@person).gsub(/en\.wikipedia\.org\/wiki\//, "dbpedia.org/resource/") %>" rel="owl:sameAs">full article</a> for more. Content reused under <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution ShareAlike</a> licence.</p>
</div>
<% end %>
</div>
commit fb7d41e7dd30bd60867f2633afc03cc77c4d95b3
Author: bbtommorris <bbtommorris@a70bfd38-3ca5-11de-a81c-fde7d73ceb89>
Date: Sun Sep 26 12:57:33 2010 +0000
people/show RDFa includes birth and death dates
added dbpprop (dbpedia properties ontology) to xmlns headers.
git-svn-id: https://openplaques.googlecode.com/svn/trunk/www@596 a70bfd38-3ca5-11de-a81c-fde7d73ceb89
diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb
index 502e32c..8faae2c 100644
--- a/app/helpers/people_helper.rb
+++ b/app/helpers/people_helper.rb
@@ -111,7 +111,7 @@ module PeopleHelper
if (person.born_on? and person.died_on?)
dates = " (" + linked_birth_date(person) + "&#8202;–&#8202;" + linked_death_date(person) + ")"
elsif (person.born_on?)
- dates = " (born " + linked_birth_date(person) + ")"
+ dates = " (born " + linked_birth_date(person) + "<span property=\"foaf:age\" content=\"#{Time.now.year - person.born_on.year}\" />)"
elsif (person.died_on?)
dates = " (died " + linked_death_date(person) + ")"
else
@@ -130,7 +130,7 @@ module PeopleHelper
if person.died_on_is_circa
birth_date = circa_tag
end
- birth_date += link_to(person.died_on.year.to_s, people_died_on_path(person.died_on.year.to_s))
+ birth_date += link_to(person.died_on.year.to_s, people_died_on_path(person.died_on.year.to_s), {:about => "/people/#{person.id}#person", :property => "dbpprop:dateOfDeath", :datatype => "xsd:date", :content => person.died_on.year.to_s})
end
end
@@ -140,7 +140,7 @@ module PeopleHelper
if person.born_on_is_circa
birth_date = circa_tag
end
- birth_date += link_to(person.born_on.year.to_s, people_born_on_path(person.born_on.year.to_s), {:class => "bday"})
+ birth_date += link_to(person.born_on.year.to_s, people_born_on_path(person.born_on.year.to_s), {:class => "bday", :about => "/people/#{person.id}#person", :property => "dbpprop:dateOfBirth vcard:bday", :datatype => "xsd:date", :content => person.born_on.year.to_s})
end
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 76ae95e..8b75cb7 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -5,7 +5,9 @@
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:vcard="http://www.w3.org/2006/vcard/ns#"
- xmlns:owl="http://www.w3.org/2002/07/owl#">
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:dbpprop="http://dbpedia.org/property/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= @page_title + " - " if @page_title %>Open Plaques</title>
commit 28b507b1647661a30f79b81b0a38c495b368db0e
Author: bbtommorris <bbtommorris@a70bfd38-3ca5-11de-a81c-fde7d73ceb89>
Date: Mon Oct 18 19:25:45 2010 +0000
RDFa support for organisations
I've used foaf:Organization to model organisations. I've used dc:title,
rdfs:label and foaf:name for the name of the organisations, and used
foaf:homepage and vcard:url for linking to the organisation's homepage.
This seems pretty uncontroversial FOAF usage to me.
Where I've gone a bit strange is I'm using foaf:made to relate the orgs
to the plaques. This is slightly strange to me as it is really used to
link to documents one has made like, say, blog posts or maybe academic
articles etc.
To say that a plaque is 'made' by a particular body like English
Heritage or a particular local council is stretching it a bit. They are
commissioned, perhaps. There are better English words for the
relationship between the organisation and the plaque than the predicate
'to make'. But 'foaf:made' isn't English, it's RDF. The FOAF
specification doesn't specify exactly what situations one should use
foaf:maker or foaf:made, except to say that it follows the same
semantics (but not the same domain/range restrictions) as dc:creator. In
the Dublin Core spec, it states that dc:creator is used to indicate an
"entity primarily responsible for making the resource". Commissioning a
plaque seems to count in my book. I'd rather reuse this than end up
having to define some kind of spooky new relationship between plaque
commissioner and plaque.
git-svn-id: https://openplaques.googlecode.com/svn/trunk/www@603 a70bfd38-3ca5-11de-a81c-fde7d73ceb89
diff --git a/app/helpers/plaques_helper.rb b/app/helpers/plaques_helper.rb
index 77bbbe3..aec12fb 100644
--- a/app/helpers/plaques_helper.rb
+++ b/app/helpers/plaques_helper.rb
@@ -173,7 +173,6 @@ module PlaquesHelper
url_for(:controller => "PersonalConnections", :action => :new, :plaque_id => plaque.id)
end
-
# def plaque_list(plaques)
# @listy = ""
# @add = ""
@@ -201,7 +200,7 @@ module PlaquesHelper
# end
# end
- def plaque_list(plaques)
+ def plaque_list(plaques, context = nil)
@listy = ""
@add = ""
@add += content_tag("p", link_to("add one?", new_plaque_path)) if authorized?
@@ -214,12 +213,21 @@ module PlaquesHelper
# icon from http://www.iconarchive.com/show/canon-digital-camera-icons-by-newformula.org/
camera_icon = image_tag("/images/EOS-300D-32x32.png", {:alt => "Photo of plaque"})
end
- @listy << content_tag("tr",
+
+ # RDFa: because plaques have different relationships with the current page.
+ # in the context of an organisation page, it is a list of plaques made by that organisation
+ # in the context of, say, colour it is a 'has primary colour of' relationship.
+ args = case context
+ when :organsation then {:rel => "foaf:made"}
+ else {}
+ end
+
+ @listy << content_tag("tr",
content_tag("td", link_to("#" + plaque.id.to_s, plaque_path(plaque)), :class => :photo) +
content_tag("td", @loc, :class => "geo") +
content_tag("td", camera_icon, :class => :photo)+
content_tag("td", new_linked_inscription(plaque)),
- :id => "openplaques:id:" + plaque.id.to_s, :class => plaque.colour && plaque.colour.name.downcase)
+ {:id => "openplaques:id:" + plaque.id.to_s, :class => plaque.colour && plaque.colour.name.downcase} + args)
end
@ul = content_tag("table", @listy, :class => :plaque_list)
out = ""
diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb
index 3b24722..18b5818 100644
--- a/app/views/organisations/show.html.erb
+++ b/app/views/organisations/show.html.erb
@@ -1,5 +1,6 @@
+<div typeof="foaf:Organization">
<% @page_title = @organisation.name %>
-<h1><%= h @organisation.name %></h1>
+<h1 property="dc:title rdfs:label foaf:name" about="#this"><%= h @organisation.name %></h1>
<div class="info">
<%= link_to("Edit", edit_organisation_path(@organisation), {:class => :edit, :title => "edit location"}) if logged_in? %>
@@ -8,9 +9,10 @@
<div class="info">
<%= link_to("Edit", edit_organisation_path(@organisation), {:class => :edit, :title => "edit location"}) if logged_in? %>
- <%= content_tag("p", "Website: " + link_to(h(@organisation.website),@organisation.website)) if @organisation.website %>
+ <%= content_tag("p", "Website: " + link_to(h(@organisation.website),@organisation.website), {:rel => "foaf:homepage vcard:url"}) if @organisation.website %>
</div>
<%= render :partial => 'plaques/map.html.erb' %>
-<%= plaque_list(@plaques) %>
\ No newline at end of file
+<%= plaque_list(@plaques, :organisation) %>
+</div>
commit 285f610648e4a1f572c4d8c9f78357ae894dc802
Author: bbtommorris <bbtommorris@a70bfd38-3ca5-11de-a81c-fde7d73ceb89>
Date: Mon Oct 18 19:26:21 2010 +0000
started RDFa for plaques/show.
started working on /ontology too.
git-svn-id: https://openplaques.googlecode.com/svn/trunk/www@604 a70bfd38-3ca5-11de-a81c-fde7d73ceb89
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 8b75cb7..77f489c 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -7,6 +7,7 @@
xmlns:vcard="http://www.w3.org/2006/vcard/ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dbpprop="http://dbpedia.org/property/"
+ xmlns:op="http://openplaques.org/ontology/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
diff --git a/app/views/plaques/show.html.erb b/app/views/plaques/show.html.erb
index bb9fd8b..62b421e 100644
--- a/app/views/plaques/show.html.erb
+++ b/app/views/plaques/show.html.erb
@@ -2,7 +2,7 @@
<iframe src="http://www.facebook.com/plugins/like.php?href=<%= request.url %>&amp;layout=button_count&amp;show_faces=false&amp;width=260&amp;action=like&amp;font&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60px; height:35px; text-align:right;" allowTransparency="true"></iframe>
</div>
-<div<%= " class=\"" + @plaque.colour.name + "plaque\"" if @plaque.colour %>>
+<div<%= " class=\"" + @plaque.colour.name + "plaque\"" if @plaque.colour %> about="#this" typeof="op:Plaque">
<div class="info">
<%= link_to "Edit", edit_plaque_path(@plaque), {:class => :edit, :title => "Edit plaque"} if logged_in?%>
<h1>Plaque #<%= @plaque.id %></h1>
diff --git a/public/ontology/index.n3 b/public/ontology/index.n3
new file mode 100644
index 0000000..9debc27
--- /dev/null
+++ b/public/ontology/index.n3
@@ -0,0 +1,11 @@
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+@prefix wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
+@prefix dc: <http://purl.org/dc/terms/> .
+@prefix op: <http://openplaques.org/ontology/> .
+
+op:Plaque a owl:Class;
+ rdfs:label "Plaque"@en;
+ rdfs:comment "A commemorative plaque affixed at a particular geographical location, often of a person."@en
+.
\ No newline at end of file
commit a1761bd22fc313bc89bbfcbe697810948e2d8a2d
Author: bbtommorris <bbtommorris@a70bfd38-3ca5-11de-a81c-fde7d73ceb89>
Date: Mon Oct 18 19:26:45 2010 +0000
RDFa: added dc:language to language helper
uses DC-RDF and an xsd:language datatype.
git-svn-id: https://openplaques.googlecode.com/svn/trunk/www@605 a70bfd38-3ca5-11de-a81c-fde7d73ceb89
diff --git a/app/helpers/languages_helper.rb b/app/helpers/languages_helper.rb
index 3444400..287fdb9 100644
--- a/app/helpers/languages_helper.rb
+++ b/app/helpers/languages_helper.rb
@@ -6,7 +6,7 @@ module LanguagesHelper
def language_if_known(plaque, text = "unknown")
if plaque.language
- link_to(plaque.language.name, language_path(plaque.language))
+ link_to(plaque.language.name, language_path(plaque.language), {:property => "dc:language", :content => plaque.language.alpha2, :datatype => "xsd:language"})
else
unknown(text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment