Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Linked Data on Rails

5,809 views

Published on

Introduction to Linked Data for Ruby and Rails developers

Published in: Technology, Education
  • Follow the link, new dating source: ♥♥♥ http://bit.ly/39sFWPG ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39sFWPG ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Linked Data on Rails

  1. 1. Linked Data on Rails Patrick Sinclair LRUG 8th June 2009
  2. 2. http://dbtune.org/openhacklondon/London
  3. 3. BBC Music BBC Programmes Wikipedia
  4. 4. BBC Music BBC Programmes API Wikipedia
  5. 5. BBC Music BBC Programmes API API Wikipedia
  6. 6. BBC Music BBC Programmes API API Code Wikipedia
  7. 7. BBC Music BBC Programmes API Code API Code Wikipedia
  8. 8. BBC Music BBC Programmes API Code API Code Wikipedia API
  9. 9. BBC Music BBC Programmes API Code API Code Wikipedia API Code
  10. 10. BBC Music BBC Programmes API Code API Code Wikipedia ? API Code
  11. 11. what if there was a standard way of publishing and querying data on the web?
  12. 12. Information Management: A Proposal Tim Berners-Lee, CERN March 1989, May 1990 - http://www.w3.org/History/1989/proposal.html
  13. 13. http://www.flickr.com/photos/danbri/2415237566/
  14. 14. Linked Data http://linkeddata.org
  15. 15. 1. Use URIs as names for things
  16. 16. 2. Use HTTP URIs so that people can look up those names
  17. 17. 3. When someone looks up a URI, provide useful information
  18. 18. 4. Include links to other URIs, so that they can discover more things
  19. 19. RDF Resource Description Framework
  20. 20. RDF subject - predicate - object
  21. 21. RDF subject - predicate - object Ruby was designed by Matz
  22. 22. RDF subject - predicate - object Ruby was designed by Matz Ruby was designed by Matz
  23. 23. RDF subject - predicate - object Ruby was designed by Matz Ruby was designed by Matz http://dbpedia.org/resource/Ruby_(programming_language)
  24. 24. RDF subject - predicate - object Ruby was designed by Matz Ruby was designed by Matz http://dbpedia.org/resource/Ruby_(programming_language) http://dbpedia.org/resource/Yukihiro_Matsumoto
  25. 25. RDF subject - predicate - object Ruby was designed by Matz Ruby was designed by Matz http://dbpedia.org/resource/Ruby_(programming_language) http://dbpedia.org/property/designer http://dbpedia.org/resource/Yukihiro_Matsumoto
  26. 26. prefix dbprop: <http://dbpedia.org/property/> http://dbpedia.org/resource/Yukihiro_Matsumoto dbprop:designer http://dbpedia.org/resource/Ruby_(programming_language)
  27. 27. prefix dbprop: <http://dbpedia.org/property/> “Yukihiro Matsumoto” dbprop:name http://dbpedia.org/resource/Yukihiro_Matsumoto dbprop:designer http://dbpedia.org/resource/Ruby_(programming_language)
  28. 28. prefix dbprop: <http://dbpedia.org/property/> “Yukihiro Matsumoto” dbprop:name http://dbpedia.org/resource/Yukihiro_Matsumoto dbprop:designer dbprop:nickname “Matz” http://dbpedia.org/resource/Ruby_(programming_language)
  29. 29. prefix dbprop: <http://dbpedia.org/property/> http://dbpedia.org/resource/Japan “Yukihiro Matsumoto” dbprop:nationality dbprop:name http://dbpedia.org/resource/Yukihiro_Matsumoto dbprop:designer dbprop:nickname “Matz” http://dbpedia.org/resource/Ruby_(programming_language)
  30. 30. prefix dbprop: <http://dbpedia.org/property/> prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 35.683334 139.766663 geo:lat geo:long http://dbpedia.org/resource/Japan “Yukihiro Matsumoto” dbprop:nationality dbprop:name http://dbpedia.org/resource/Yukihiro_Matsumoto dbprop:designer dbprop:nickname “Matz” http://dbpedia.org/resource/Ruby_(programming_language)
  31. 31. <http://dbpedia.org/resource/Ruby_(programming_language)> <http://dbpedia.org/property/designer> <http://dbpedia.org/resource/Yukihiro_Matsumoto> . <http://dbpedia.org/resource/Ruby_(programming_language)> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://umbel.org/umbel/sc/Language> . ntriples
  32. 32. <http://dbpedia.org/resource/Ruby_(programming_language)> <http://dbpedia.org/property/designer> <http://dbpedia.org/resource/Yukihiro_Matsumoto> . <http://dbpedia.org/resource/Ruby_(programming_language)> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://umbel.org/umbel/sc/Language> . ntriples <rdf:RDF xmlns:log=quot;http://www.w3.org/2000/10/swap/log#quot; xmlns:rdf=quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#quot;> <Language xmlns=quot;http://umbel.org/umbel/sc/quot; rdf:about=quot;http://dbpedia.org/resource/Ruby_(programming_language)quot;> <designer xmlns=quot;http://dbpedia.org/property/quot; rdf:resource=quot;http://dbpedia.org/resource/Yukihiro_Matsumotoquot;/> </Language> </rdf:RDF> RDF/XML
  33. 33. <http://dbpedia.org/resource/Ruby_(programming_language)> <http://dbpedia.org/property/designer> <http://dbpedia.org/resource/Yukihiro_Matsumoto> . <http://dbpedia.org/resource/Ruby_(programming_language)> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://umbel.org/umbel/sc/Language> . ntriples <rdf:RDF xmlns:log=quot;http://www.w3.org/2000/10/swap/log#quot; xmlns:rdf=quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#quot;> <Language xmlns=quot;http://umbel.org/umbel/sc/quot; rdf:about=quot;http://dbpedia.org/resource/Ruby_(programming_language)quot;> <designer xmlns=quot;http://dbpedia.org/property/quot; rdf:resource=quot;http://dbpedia.org/resource/Yukihiro_Matsumotoquot;/> </Language> </rdf:RDF> RDF/XML @prefix dbprop: <http://dbpedia.org/property/> . <http://dbpedia.org/resource/Ruby_(programming_language)> a <http://umbel.org/umbel/sc/Language>; dbprop:designer <http://dbpedia.org/resource/Yukihiro_Matsumoto> . turtle
  34. 34. http://dbpedia.org
  35. 35. http://en.wikipedia.org/wiki/Ruby_(programming_language) http://dbpedia.org/resource/Ruby_(programming_language)
  36. 36. RDF grabbing time curl --include --location http://dbpedia.org/resource/Yukihiro_Matsumoto => html representation curl --include --location --header quot;Accept: application/rdf+xmlquot; http://dbpedia.org/resource/Yukihiro_Matsumoto => rdf representation rapper http://dbpedia.org/resource/Yukihiro_Matsumoto => returns triples e.g. <http://dbpedia.org/resource/Ruby_(programming_language)> <http://dbpedia.org/property/designer> <http://dbpedia.org/resource/Yukihiro_Matsumoto> . rapper http://dbpedia.org/property/designer => returns data about a property rapper -oturtle http://dbpedia.org/property/designer => returns data formatted in turtle
  37. 37. curl --include --location http://dbpedia.org/resource/Yukihiro_Matsumoto => redirect to http://dbpedia.org/page/Yukihiro_Matsumoto => html representation
  38. 38. curl --include --location --header quot;Accept: application/rdf+xmlquot; http://dbpedia.org/resource/Yukihiro_Matsumoto => rdf representation
  39. 39. rapper http://dbpedia.org/resource/Yukihiro_Matsumoto => returns triples e.g. <http://dbpedia.org/resource/Ruby_(programming_language)> <http://dbpedia.org/property/designer> <http://dbpedia.org/resource/Yukihiro_Matsumoto> .
  40. 40. rapper -oturtle http://dbpedia.org/property/designer => returns data formatted in turtle @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <http://dbpedia.org/property/designer> a rdf:Property ; rdfs:label quot;designerquot; .
  41. 41. RDF Vocabularies • FOAF, DOAP, Music Ontology, Programmes Ontology... • RDF Schema (RDFS) • Describe classes, properties, some restrictions • Web Ontology Language (OWL) • More control over restrictions • owl:sameAs
  42. 42. Ruby and RDF • Reddy - http://github.com/tommorris/reddy • Redland bindings - http://librdf.org • ActiveRDF - http://activerdf.org • Like ActiveRecord for RDF data
  43. 43. require 'rubygems' require 'active_rdf' # add DBpedia SPARQL endpoint as a datasource adapter = ConnectionPool.add_data_source(:type => :sparql, :url => quot;http://dbpedia.org/sparqlquot;, :engine => :virtuoso, :results => :sparql_xml) adapter.enabled = true # we register a short-hand notation for the namespaces Namespace.register(:dbprop, 'http://dbpedia.org/property/') Namespace.register(:dbowl, 'http://dbpedia.org/ontology/')
  44. 44. matz = RDFS::Resource.new(quot;http://dbpedia.org/resource/Yukihiro_Matsumotoquot;) => #<RDFS::Resource:0x1b91a58 @predicates={}, @uri=quot;http://dbpedia.org/ resource/Yukihiro_Matsumotoquot;> matz.dbprop::nickname => quot;Matzquot; matz.dbprop::nationality => #<RDFS::Resource:0x1b91a58 @predicates={}, @uri=quot;http://dbpedia.org/ resource/Japanquot;> japan = matz.dbprop::nationality => #<RDFS::Resource:0x1b91a58 @predicates={}, @uri=quot;http://dbpedia.org/ resource/Japanquot;> tokyo = japan.dbowl::capital => #<RDFS::Resource:0x1b91a58 @predicates={}, @uri=quot;http://dbpedia.org/ resource/Tokyoquot;> tokyo.dbprop::name => quot;Tokyoquot; tokyo.dbowl::populationTotal => 12790000
  45. 45. adapter2 = ConnectionPool.add_data_source :type => :rdflite adapter2.enabled = true Namespace.register(:mystuff, 'http://example.org/test/') => MYSTUFF tokyo.mystuff::rating = 5 => 5 tokyo.mystuff::rating => 5 tokyo.mystuff::is_in = japan => #<RDFS::Resource:0x1b91a58 @predicates={}, @uri=quot;http:// dbpedia.org/resource/Japanquot;>
  46. 46. njh’s homepage builder http://www.aelius.com/njh/
  47. 47. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix : <http://xmlns.com/foaf/0.1/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix dc: <http://purl.org/dc/elements/1.1/> . <http://www.aelius.com/njh/foaf.rdf> a :PersonalProfileDocument ; rdfs:label quot;Nicholas J Humfrey's FOAF Filequot; ; :maker <http://www.aelius.com/njh#me> ; :primaryTopic <http://www.aelius.com/njh#me> . <http://www.aelius.com/njh#me> a :Person ; dc:description quot;I am a Software Engineer, working for BBC Audio and Music in London.quot;@en ; :homepage <http://www.aelius.com/njh/> ; :based_near <http://dbpedia.org/resource/London> ; :knows <http://danbri.org/foaf.rdf#danbri>, <http://foafbuilder.qdos.com/people/ whomwah.com/foaf.rdf#me>, <http://id.ecs.soton.ac.uk/person/9639>; :currentProject <http://www.aelius.com/njh#project-captivednsd>, <http://www.aelius.com/ njh#project-dvbshout>; :interest <http://dbpedia.org/resource/C_(programming_language)>, <http://dbpedia.org/ resource/Cycling>, <http://dbpedia.org/resource/Debian>; owl:sameAs <http://dbtune.org/last-fm/njh>, <http://www.bbc.co.uk/users/njh#me>, <http:// qdos.com/user/89295d77e0e390538aac662e3f3cae03>;
  48. 48. and it’s all in ruby, check it out!
  49. 49. Publishing RDF in Rails http://bit.ly/rYPWS http://github.com/robmckinnon/ukcompanies/commit/c3aa368e7aa50e221a983a79faa8ca45bff8902a
  50. 50. Embrace REST!
  51. 51. Add the mime type http://bit.ly/rYPWS http://github.com/robmckinnon/ukcompanies/commit/c3aa368e7aa50e221a983a79faa8ca45bff8902a
  52. 52. respond block http://bit.ly/rYPWS http://github.com/robmckinnon/ukcompanies/commit/c3aa368e7aa50e221a983a79faa8ca45bff8902a
  53. 53. application.rdf.erb http://bit.ly/rYPWS http://github.com/robmckinnon/ukcompanies/commit/c3aa368e7aa50e221a983a79faa8ca45bff8902a
  54. 54. application.rdf.erb http://bit.ly/rYPWS http://github.com/robmckinnon/ukcompanies/commit/c3aa368e7aa50e221a983a79faa8ca45bff8902a
  55. 55. There’s plenty more! • Schemas (RDFS) and Ontologies (OWL) • SPARQL • Query language for Linked Data • Triple stores • Store RDF data, no need to design schema up front • RDFa • Embed RDF into HTML markup • Supported by Google and Yahoo

×